sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1831409 - in /sis/branches/JDK8/storage: sis-sql/src/main/java/org/apache/sis/internal/sql/ sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/ sis-sql/src/main/java/org/apache/sis/sql/ sis-storage/src/main/java/org/apache/sis/inter...
Date Fri, 11 May 2018 13:04:47 GMT
Author: desruisseaux
Date: Fri May 11 13:04:47 2018
New Revision: 1831409

URL: http://svn.apache.org/viewvc?rev=1831409&view=rev
Log:
Change Query interface to an abstract class allowing to move some SimpleQuery properties later.

Added:
    sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaModel.java
      - copied, changed from r1831408, sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java
Removed:
    sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java
Modified:
    sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
    sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
    sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/SQLQuery.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Query.java

Copied: sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaModel.java
(from r1831408, sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaModel.java?p2=sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaModel.java&p1=sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java&r1=1831408&r2=1831409&rev=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaModel.java
[UTF-8] Fri May 11 13:04:47 2018
@@ -14,43 +14,49 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.sql;
+package org.apache.sis.internal.sql.reverse;
 
 import java.util.Iterator;
 import org.apache.sis.util.CharSequences;
 
 
 /**
- * Miscellaneous utility methods.
+ * Base class of descriptions about a database entity (table or schema).
  *
  * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-public final class SQLUtilities {
+abstract class MetaModel {
     /**
-     * Do not allow instantiation of this class.
+     * The schema or table name.
      */
-    private SQLUtilities(){
+    final String name;
+
+    /**
+     * Creates a new object describing a database table or a schema.
+     *
+     * @param  name  the schema or table name.
+     */
+    MetaModel(final String name) {
+        this.name = name;
     }
 
     /**
-     * Returns a graphical representation of the specified objects. This representation can
be
+     * Formats a graphical representation of the specified objects. This representation can
be
      * printed to the {@linkplain System#out standard output stream} (for example) if it
uses
      * a monospaced font and supports Unicode.
      *
      * @param  root     the root name of the tree to format, or {@code null} if none.
      * @param  objects  the objects to format as root children, or {@code null} if none.
-     * @return a string representation of the tree.
+     * @param  sb       where to format the tree.
      */
-    public static String toTreeString(String root, final Iterable<?> objects) {
-        final StringBuilder sb = new StringBuilder(100);
+    static void appendTree(final String root, final Iterable<?> objects, final StringBuilder
sb, final String lineSeparator) {
         if (root != null) {
             sb.append(root);
         }
         if (objects != null) {
-            final String lineSeparator = System.lineSeparator();
             final Iterator<?> it = objects.iterator();
             boolean hasNext;
             if (it.hasNext()) do {
@@ -69,6 +75,5 @@ public final class SQLUtilities {
                 }
             } while (hasNext);
         }
-        return sb.toString();
     }
 }

Modified: sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java?rev=1831409&r1=1831408&r2=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
[UTF-8] Fri May 11 13:04:47 2018
@@ -19,38 +19,54 @@ package org.apache.sis.internal.sql.reve
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
-import org.apache.sis.internal.sql.SQLUtilities;
+import org.apache.sis.util.Debug;
 
 
 /**
  * Description of a database schema.
  *
- * @author Johann Sorel (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-final class SchemaMetaModel {
-
-    final String name;
-
+final class SchemaMetaModel extends MetaModel {
+    /**
+     * The tables in the schema.
+     */
     final Map<String,TableMetaModel> tables;
 
+    /**
+     * Creates a new schema of the given name.
+     * It is caller responsibility to populate the {@link #tables} map.
+     */
     SchemaMetaModel(final String name) {
-        this.name = name;
+        super(name);
         tables = new HashMap<>();
     }
 
+    /**
+     * Returns all tables in this schema.
+     */
     Collection<TableMetaModel> getTables() {
         return tables.values();
     }
 
+    /**
+     * Returns the table of the given name, or {@code null} if none.
+     */
     TableMetaModel getTable(final String name){
         return tables.get(name);
     }
 
+    /**
+     * Returns a string representation of this schema for debugging purposes.
+     */
+    @Debug
     @Override
     public String toString() {
-        return SQLUtilities.toTreeString(name, getTables());
+        final StringBuilder sb = new StringBuilder(100);
+        appendTree(name, getTables(), sb, System.lineSeparator());
+        return sb.toString();
     }
 }

Modified: sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java?rev=1831409&r1=1831408&r2=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
[UTF-8] Fri May 11 13:04:47 2018
@@ -19,19 +19,18 @@ package org.apache.sis.internal.sql.reve
 import java.util.ArrayList;
 import java.util.Collection;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
-import org.apache.sis.internal.sql.SQLUtilities;
+import org.apache.sis.util.Debug;
 
 
 /**
  * Description of a database table.
  *
- * @author Johann Sorel (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-final class TableMetaModel {
-
+final class TableMetaModel extends MetaModel {
     enum View {
         TABLE,
         SIMPLE_FEATURE_TYPE,
@@ -39,7 +38,6 @@ final class TableMetaModel {
         ALL_COMPLEX
     }
 
-    String name;
     String type;
 
     FeatureTypeBuilder tableType;
@@ -64,8 +62,8 @@ final class TableMetaModel {
      */
     final Collection<String> parents = new ArrayList<>();
 
-    TableMetaModel(final String name, String type) {
-        this.name = name;
+    TableMetaModel(final String name, final String type) {
+        super(name);
         this.type = type;
     }
 
@@ -89,19 +87,6 @@ final class TableMetaModel {
         return false;
     }
 
-    @Override
-    public String toString() {
-        final StringBuilder sb = new StringBuilder(name);
-        if (!importedKeys.isEmpty()) {
-            // TODO: use system line separator.
-            sb.append(SQLUtilities.toTreeString("\n Imported Keys", importedKeys)).append('\n');
-        }
-        if (!exportedKeys.isEmpty()) {
-            sb.append(SQLUtilities.toTreeString("\n Exported Keys", exportedKeys)).append('\n');
-        }
-        return sb.toString();
-    }
-
     FeatureTypeBuilder getType(final View view) {
         switch (view) {
             case TABLE:                return tableType;
@@ -111,4 +96,23 @@ final class TableMetaModel {
             default: throw new IllegalArgumentException("Unknown view type: " + view);
         }
     }
+
+    /**
+     * Returns a string representation of this schema for debugging purposes.
+     */
+    @Debug
+    @Override
+    public String toString() {
+        final String lineSeparator = System.lineSeparator();
+        final StringBuilder sb = new StringBuilder(100).append(name);
+        if (!importedKeys.isEmpty()) {
+            appendTree(" Imported Keys", importedKeys, sb.append(lineSeparator), lineSeparator);
+            sb.append(lineSeparator);
+        }
+        if (!exportedKeys.isEmpty()) {
+            appendTree(" Exported Keys", exportedKeys, sb.append(lineSeparator), lineSeparator);
+            sb.append(lineSeparator);
+        }
+        return sb.toString();
+    }
 }

Modified: sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/SQLQuery.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/SQLQuery.java?rev=1831409&r1=1831408&r2=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/SQLQuery.java [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/SQLQuery.java [UTF-8]
Fri May 11 13:04:47 2018
@@ -19,6 +19,7 @@ package org.apache.sis.sql;
 import org.apache.sis.storage.Query;
 import org.apache.sis.util.ArgumentChecks;
 
+
 /**
  * An SQL query executed directly on the database.
  * Such query should be transfered to the JDBC without or with minimum modifications.
@@ -28,7 +29,7 @@ import org.apache.sis.util.ArgumentCheck
  * @since   1.0
  * @module
  */
-public class SQLQuery implements Query {
+public class SQLQuery extends Query {
 
     private final String statement;
     private final String name;

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java?rev=1831409&r1=1831408&r2=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
[UTF-8] Fri May 11 13:04:47 2018
@@ -51,7 +51,7 @@ import org.opengis.feature.FeatureAssoci
  * @since   1.0
  * @module
  */
-public class SimpleQuery implements Query {
+public class SimpleQuery extends Query {
     /**
      * Sentinel limit value for queries of unlimited length.
      * This value can be given to {@link #setLimit(long)} or retrieved from {@link #getLimit()}.

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Query.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Query.java?rev=1831409&r1=1831408&r2=1831409&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Query.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Query.java
[UTF-8] Fri May 11 13:04:47 2018
@@ -46,13 +46,23 @@ import org.opengis.feature.Feature;
  * and (sometime) simple attribute transformations. Well known query languages include SQL
and CQL.
  *
  * @author Johann Sorel (Geomatys)
- * @version 0.8
+ * @version 1.0
  *
  * @see FeatureSet#subset(Query)
  *
  * @since 0.8
  * @module
  */
-public interface Query {
+public abstract class Query {
+    /*
+     * Current version does not yet contain any field. But some fields may be added in the
future.
+     * For example some methods from org.apache.sis.internal.storage.query.SimpleQuery may
move here.
+     * We use an abstract class instead than an interface for that reason.
+     */
 
+    /**
+     * Creates a new, initially empty, query.
+     */
+    protected Query() {
+    }
 }



Mime
View raw message