Modified: sis/branches/JDK8/ide-project/NetBeans/nbproject/genfiles.properties
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/nbproject/genfiles.properties?rev=1828799&r1=1828798&r2=1828799&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/nbproject/genfiles.properties 
[ISO-8859-1] (original)
+++ sis/branches/JDK8/ide-project/NetBeans/nbproject/genfiles.properties 
[ISO-8859-1] Tue Apr 10 08:52:43 2018
@@ -3,6 +3,6 @@
 build.xml.data.CRC32=58e6b21c
 build.xml.script.CRC32=462eaba0
 build.xml.stylesheet.CRC32=28e38971@1.53.1.46
-nbproject/build-impl.xml.data.CRC32=85a3ca8b
-nbproject/build-impl.xml.script.CRC32=9a596b34
-nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.88.0.48
+nbproject/build-impl.xml.data.CRC32=d50e046a
+nbproject/build-impl.xml.script.CRC32=d523edae
+nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

Added: 
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/SQLUtilities.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/SQLUtilities.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql;
+
+import java.util.Iterator;
+
+/**
+ * For internal use of SQL store.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final class SQLUtilities {
+
+    private SQLUtilities(){
+    }
+
+    /**
+     * Returns 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.
+     * @param  objects The objects to format as root children.
+     * @return A string representation of the tree.
+     */
+    public static String toStringTree(String root, final Iterable<?> objects) {
+        final StringBuilder sb = new StringBuilder();
+        if (root != null) {
+            sb.append(root);
+        }
+        if (objects != null) {
+            final Iterator<?> ite = objects.iterator();
+            while (ite.hasNext()) {
+                sb.append('\n');
+                final Object next = ite.next();
+                final boolean last = !ite.hasNext();
+                sb.append(last ? "└─ " : "├─ ");
+
+                final String[] parts = String.valueOf(next).split("\n");
+                sb.append(parts[0]);
+                for (int k=1;k<parts.length;k++) {
+                    sb.append('\n');
+                    sb.append(last ? ' ' : '│');
+                    sb.append("  ");
+                    sb.append(parts[k]);
+                }
+            }
+        }
+
+        return sb.toString();
+    }
+
+}

Added: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/CachedResultSet.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/CachedResultSet.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/CachedResultSet.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/CachedResultSet.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Cached a ResultSet content.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class CachedResultSet {
+
+    private final List<Map> records = new ArrayList<>();
+
+    public CachedResultSet() {
+    }
+
+    public CachedResultSet(ResultSet rs, String... columns) throws 
SQLException {
+        append(rs, columns);
+    }
+
+    public void append(ResultSet rs, String... columns) throws SQLException {
+        while (rs.next()) {
+            final Map record = new HashMap();
+            for (String col : columns) {
+                record.put(col, rs.getObject(col));
+            }
+            records.add(record);
+        }
+        rs.close();
+    }
+
+    public Collection<Map> records() {
+        return records;
+    }
+
+}

Added: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/ColumnMetaModel.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/ColumnMetaModel.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/ColumnMetaModel.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/ColumnMetaModel.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.UUID;
+import java.util.logging.Logger;
+import org.apache.sis.sql.dialect.SQLDialect;
+import org.apache.sis.storage.DataStoreException;
+
+/**
+ * Description of a table column.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class ColumnMetaModel {
+
+    public enum Type {
+        /**
+         * Indicate this field value is generated by the database.
+         */
+        AUTO,
+        /**
+         * Indicate a sequence is used to generate field values.
+         */
+        SEQUENCED,
+        /**
+         * Indicate field value must be provided.
+         */
+        PROVIDED
+    }
+
+    private final String schema;
+    private final String table;
+    private final String name;
+    private final int sqlType;
+    private final String sqlTypeName;
+    private final Class<?> clazz;
+    private final Type type;
+    private final String sequenceName;
+
+    /**
+     *
+     * @param schema database scheme where this column is found
+     * @param table database table where this column is found
+     * @param name name of the column
+     * @param sqlType column sql type
+     * @param sqlTypeName column sql type name
+     * @param clazz java type
+     * @param type if column is a primary key, specify how the value is 
generated
+     * @param sequenceName if column is a primary key, optional sequence name
+     */
+    public ColumnMetaModel(String schema, String table, String name,
+            int sqlType, String sqlTypeName, Class<?> clazz, Type type, String 
sequenceName) {
+        this.schema         = schema;
+        this.table          = table;
+        this.name           = name;
+        this.sqlType        = sqlType;
+        this.sqlTypeName    = sqlTypeName;
+        this.clazz          = clazz;
+        this.type           = type;
+        this.sequenceName   = sequenceName;
+    }
+
+    public String getSchema() {
+        return schema;
+    }
+
+    public String getTable() {
+        return table;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public int getSqlType() {
+        return sqlType;
+    }
+
+    public String getSqlTypeName() {
+        return sqlTypeName;
+    }
+
+    public Class<?> getJavaType() {
+        return clazz;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public String getSequenceName() {
+        return sequenceName;
+    }
+
+    /**
+     * Try to compute next column value.
+     *
+     * @param dialect database dialect
+     * @param logger database logger
+     * @param cx database connection
+     * @return next field value
+     * @throws SQLException
+     * @throws DataStoreException
+     */
+    public Object nextValue(final SQLDialect dialect, Logger logger, final 
Connection cx)
+            throws SQLException, DataStoreException {
+        Object next = null;
+
+        if (type == Type.AUTO || type == Type.SEQUENCED) {
+            //question the database for next value
+            next = dialect.nextValue(this, cx);
+        } else {
+            //generate value if possible
+            if (Number.class.isAssignableFrom(clazz)) {
+                //Get the maximum value in the database and increment it
+                final StringBuilder sql = new StringBuilder();
+                sql.append("SELECT 1 + MAX(");
+                dialect.encodeColumnName(sql, getName());
+                sql.append(") FROM ");
+                dialect.encodeSchemaAndTableName(sql, schema, table);
+
+                try (Statement st = cx.createStatement();
+                     ResultSet rs = st.executeQuery(sql.toString())) {
+                    rs.next();
+                    next = rs.getObject(1);
+                }
+
+                if (next == null) {
+                    //can be the result of an empty table
+                    next = 1;
+                }
+
+            } else if (CharSequence.class.isAssignableFrom(clazz)) {
+                //use an UUID to reduce risk of conflicts
+                next = UUID.randomUUID().toString();
+            }
+
+            if (next == null) {
+                throw new DataStoreException("Failed to generate a value for 
column " + toString());
+            }
+        }
+
+        return next;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder(name);
+        sb.append('[');
+        sb.append(sqlType);
+        sb.append(',');
+        sb.append(sqlTypeName);
+        sb.append(',');
+        sb.append(type);
+        sb.append(']');
+        return sb.toString();
+    }
+}

Added: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/InsertRelation.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/InsertRelation.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/InsertRelation.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/InsertRelation.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import org.opengis.feature.Feature;
+
+
+/**
+ * When inserting a complex feature in base. it must be divided in smaller 
elements.
+ * Those flat insertions and relations are represented by this class.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final class InsertRelation {
+
+    public Feature parent;
+    public Feature child;
+    public RelationMetaModel relation;
+
+}

Copied: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaDataConstants.java
 (from r1828730, 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/reverse/MetaDataConstants.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaDataConstants.java?p2=sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaDataConstants.java&p1=sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/reverse/MetaDataConstants.java&r1=1828730&r2=1828799&rev=1828799&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/reverse/MetaDataConstants.java
 (original)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/MetaDataConstants.java
 Tue Apr 10 08:52:43 2018
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.sis.sql.reverse;
+package org.apache.sis.internal.sql.reverse;
 
 /**
  * Constants defined by JDBC to retrieve a database meta-model.

Added: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/PrimaryKey.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/PrimaryKey.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/PrimaryKey.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/PrimaryKey.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.logging.Logger;
+import org.apache.sis.sql.dialect.SQLDialect;
+import org.apache.sis.storage.DataStoreException;
+
+/**
+ * Describe a table primary key.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class PrimaryKey {
+
+    private final String tableName;
+    private final List<ColumnMetaModel> columns;
+
+    public PrimaryKey(String tableName) {
+        this(tableName,null);
+    }
+
+    public PrimaryKey(String tableName, List<ColumnMetaModel> columns) {
+        this.tableName = tableName;
+        if (columns == null) columns = Collections.emptyList();
+        this.columns = columns;
+    }
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public List<ColumnMetaModel> getColumns() {
+        return columns;
+    }
+
+    public boolean isNull(){
+        return columns.isEmpty();
+    }
+
+    /**
+     * Create a feature identifier from primary key column values.
+     *
+     * @param rs ResultSet on a row
+     * @return feature identifier
+     * @throws SQLException
+     */
+    public String buildIdentifier(final ResultSet rs) throws SQLException {
+
+        final int size = columns.size();
+
+        if (size == 0) {
+            // no primary key columns, generate a random id
+            return UUID.randomUUID().toString();
+        } else if (size == 1) {
+            // unique column value
+            return rs.getString(columns.get(0).getName());
+        } else {
+            // aggregate column values
+            final Object[] values = new Object[size];
+            for (int i=0; i<size; i++) {
+                values[i] = rs.getString(columns.get(i).getName());
+            }
+            return buildIdentifier(values);
+        }
+    }
+
+    public static String buildIdentifier(final Object[] values) {
+        final StringBuilder sb = new StringBuilder();
+        for (int i=0; i<values.length; i++) {
+            if (i > 0) sb.append('.');
+            sb.append(values[i]);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Create primary key column field values.
+     *
+     * @param dialect database dialect
+     * @param logger database logger
+     * @param cx database connection
+     * @return primary key values
+     * @throws SQLException
+     * @throws DataStoreException
+     */
+    public Object[] nextValues(final SQLDialect dialect, Logger logger, final 
Connection cx)
+            throws SQLException, DataStoreException {
+        final Object[] parts = new Object[columns.size()];
+        for (int i=0; i<parts.length; i++) {
+            parts[i] = columns.get(i).nextValue(dialect, logger, cx);
+        }
+        return parts;
+    }
+
+}

Added: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/RelationMetaModel.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/RelationMetaModel.java?rev=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/RelationMetaModel.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/RelationMetaModel.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import org.apache.sis.util.ArgumentChecks;
+
+/**
+ * Description of a relation between two tables.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class RelationMetaModel {
+
+    private final String relationName;
+    private final String currentColumn;
+    private final String foreignSchema;
+    private final String foreignTable;
+    private final String foreignColumn;
+    private final boolean imported;
+    private final boolean deleteCascade;
+
+    public RelationMetaModel(final String relationName,final String 
currentColumn, final String foreignSchema,
+            final String foreignTable, final String foreignColumn,
+            boolean imported, boolean deleteCascade) {
+        ArgumentChecks.ensureNonNull("relation name", relationName);
+        ArgumentChecks.ensureNonNull("current column", currentColumn);
+        ArgumentChecks.ensureNonNull("foreign table", foreignTable);
+        ArgumentChecks.ensureNonNull("foreign column", foreignColumn);
+        this.relationName = relationName;
+        this.currentColumn = currentColumn;
+        this.foreignSchema = foreignSchema;
+        this.foreignTable = foreignTable;
+        this.foreignColumn = foreignColumn;
+        this.imported = imported;
+        this.deleteCascade = deleteCascade;
+    }
+
+    public String getRelationName() {
+        return relationName;
+    }
+
+    public String getCurrentColumn() {
+        return currentColumn;
+    }
+
+    public String getForeignColumn() {
+        return foreignColumn;
+    }
+
+    public String getForeignSchema() {
+        return foreignSchema;
+    }
+
+    public String getForeignTable() {
+        return foreignTable;
+    }
+
+    /**
+     * Indicate if this key is imported.
+     * @return
+     */
+    public boolean isImported() {
+        return imported;
+    }
+
+    /**
+     * @return true if relation implies a delete on cascade.
+     */
+    public boolean isDeleteCascade(){
+        return deleteCascade;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder(currentColumn);
+        sb.append((imported) ? " → " : " ← ");
+        sb.append(foreignSchema).append('.');
+        sb.append(foreignTable).append('.').append(foreignColumn);
+        return sb.toString();
+    }
+}

Added: 
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=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/SchemaMetaModel.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.sis.internal.sql.SQLUtilities;
+
+/**
+ * Description of a database schema.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class SchemaMetaModel {
+
+    final String name;
+    final Map<String, TableMetaModel> tables = new HashMap<String, 
TableMetaModel>();
+
+    public SchemaMetaModel(final String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Collection<TableMetaModel> getTables() {
+        return tables.values();
+    }
+
+    public TableMetaModel getTable(final String name){
+        return tables.get(name);
+    }
+
+    @Override
+    public String toString() {
+        return SQLUtilities.toStringTree(name, tables.values());
+    }
+}

Added: 
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=1828799&view=auto
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
 (added)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/internal/sql/reverse/TableMetaModel.java
 Tue Apr 10 08:52:43 2018
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.sql.reverse;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import org.apache.sis.feature.builder.FeatureTypeBuilder;
+import org.apache.sis.internal.sql.SQLUtilities;
+
+/**
+ * Description of a database table.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class TableMetaModel {
+
+    public enum View {
+        TABLE,
+        SIMPLE_FEATURE_TYPE,
+        COMPLEX_FEATURE_TYPE,
+        ALLCOMPLEX
+    }
+
+    String name;
+    String type;
+
+    FeatureTypeBuilder tableType;
+    FeatureTypeBuilder simpleFeatureType;
+    FeatureTypeBuilder complexFeatureType;
+    FeatureTypeBuilder allType;
+
+    PrimaryKey key;
+    /**
+     * those are 0:1 relations
+     */
+    final Collection<RelationMetaModel> importedKeys = new ArrayList<>();
+    /**
+     * those are 0:N relations
+     */
+    final Collection<RelationMetaModel> exportedKeys = new ArrayList<>();
+    /**
+     * inherited tables
+     */
+    final Collection<String> parents = new ArrayList<>();
+
+    public TableMetaModel(final String name, String type) {
+        this.name = name;
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public Collection<RelationMetaModel> getExportedKeys() {
+        return Collections.unmodifiableCollection(exportedKeys);
+    }
+
+    public Collection<RelationMetaModel> getImportedKeys() {
+        return Collections.unmodifiableCollection(importedKeys);
+    }
+
+    /**
+     * Detect if given type is a subtype. Conditions are :
+     * - having a relation toward another type
+     * - relation must be cascading
+     *
+     * @return true is type is a subtype
+     */
+    public boolean isSubType(){
+        for (RelationMetaModel relation : getImportedKeys()) {
+            if (relation.isDeleteCascade()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder(name);
+        if (!importedKeys.isEmpty()) {
+            sb.append(SQLUtilities.toStringTree("\n Imported Keys", 
importedKeys)).append('\n');
+        }
+        if (!exportedKeys.isEmpty()) {
+            sb.append(SQLUtilities.toStringTree("\n Exported Keys", 
exportedKeys)).append('\n');
+        }
+        return sb.toString();
+    }
+
+    public FeatureTypeBuilder getType(View view) {
+        switch (view) {
+            case TABLE:                return tableType;
+            case SIMPLE_FEATURE_TYPE:  return simpleFeatureType;
+            case COMPLEX_FEATURE_TYPE: return complexFeatureType;
+            case ALLCOMPLEX:           return allType;
+            default: throw new IllegalArgumentException("Unknowned view type : 
"+view);
+        }
+    }
+
+}

Modified: 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/dialect/SQLDialect.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/dialect/SQLDialect.java?rev=1828799&r1=1828798&r2=1828799&view=diff
==============================================================================
--- 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/dialect/SQLDialect.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/storage/sis-sql/src/main/java/org/apache/sis/sql/dialect/SQLDialect.java
 [UTF-8] Tue Apr 10 08:52:43 2018
@@ -16,6 +16,11 @@
  */
 package org.apache.sis.sql.dialect;
 
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.sis.internal.sql.reverse.ColumnMetaModel;
+import org.apache.sis.storage.DataStoreException;
+
 /**
  * Each database has specific syntax elements.
  *
@@ -29,4 +34,32 @@ package org.apache.sis.sql.dialect;
  */
 public interface SQLDialect {
 
+    /**
+     * Encode column name.
+     *
+     * @param sql StringBuilder to write into
+     * @param name column name, not null
+     */
+    void encodeColumnName(StringBuilder sql, String name);
+
+    /**
+     * Encode schema and table name portion of an sql query.
+     *
+     * @param sql StringBuilder to write into
+     * @param databaseSchema database schema, can be null
+     * @param tableName database table, not null
+     */
+    void encodeSchemaAndTableName(StringBuilder sql, String databaseSchema, 
String tableName);
+
+    /**
+     * If a column is an Auto-increment or has a sequence, try to extract next 
value.
+     *
+     * @param column database column description
+     * @param cx database connection
+     * @return column value or null
+     * @throws SQLException
+     * @throws DataStoreException
+     */
+    Object nextValue(ColumnMetaModel column, Connection cx) throws 
SQLException, DataStoreException;
+
 }


Reply via email to