You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2017/04/15 08:25:52 UTC

[01/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Repository: polygene-java
Updated Branches:
  refs/heads/develop d64c585ab -> a36086b60


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.MySQLVendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.MySQLVendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.MySQLVendor
new file mode 100644
index 0000000..18018e7
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.MySQLVendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.mysql.MySQLVendorImpl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor
new file mode 100644
index 0000000..f39ddf4
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.pgsql.PostgreSQLVendorImpl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLVendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLVendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLVendor
new file mode 100644
index 0000000..d9e4eb3
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLVendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLiteVendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLiteVendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLiteVendor
new file mode 100644
index 0000000..4330c13
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.SQLiteVendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.sqlite.SQLiteVendorImpl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractDataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractDataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractDataDefinitionTest.java
new file mode 100644
index 0000000..279c799
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractDataDefinitionTest.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableElementListBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.MatchType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.junit.Test;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractDataDefinitionTest extends AbstractSQLSyntaxTest
+{
+
+    @Test
+    public void definition1()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+         * CREATE TABLE qi4j_schema.qname_9
+         * (
+         * qname_id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
+         * entity_pk bigint NOT NULL,
+         * parent_qname integer,
+         * collection_path ltree NOT NULL,
+         * qname_value integer,
+         * PRIMARY KEY (qname_id, entity_pk),
+         * CONSTRAINT qname_9_parent_qname_fkey FOREIGN KEY (parent_qname, entity_pk)
+         * REFERENCES qi4j_schema.all_qnames (qname_id, entity_pk) MATCH SIMPLE
+         * ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+         * CONSTRAINT qname_9_qname_id_fkey FOREIGN KEY (qname_id, entity_pk)
+         * REFERENCES qi4j_schema.all_qnames (qname_id, entity_pk) MATCH SIMPLE
+         * ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
+         * CONSTRAINT qname_9_qname_value_fkey FOREIGN KEY (qname_value)
+         * REFERENCES qi4j_schema.used_classes (used_class_id)
+         * ON UPDATE CASCADE ON DELETE RESTRICT
+         * )
+         */
+
+        SQLVendor vendor = this.getVendor();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        DefinitionFactory d = vendor.getDefinitionFactory();
+        DataTypeFactory dt = vendor.getDataTypeFactory();
+        String schemaName = "qi4j_schema";
+
+        TableDefinitionBuilder builder = d.createTableDefinitionBuilder();
+        builder
+            .setTableName( t.tableName( schemaName, "qname_9" ) );
+
+        TableElementListBuilder cBuilder = d.createTableElementListBuilder();
+        cBuilder
+            .addTableElement( d.createColumnDefinition( "qname_id", dt.integer(), false, AutoGenerationPolicy.BY_DEFAULT ) )
+            .addTableElement( d.createColumnDefinition( "entity_pk", dt.bigInt(), false ) )
+            .addTableElement( d.createColumnDefinition( "parent_qname", dt.integer() ) )
+            .addTableElement( d.createColumnDefinition( "collection_path", dt.userDefined( "ltree" ), false ) )
+            .addTableElement( d.createColumnDefinition( "qname_value", dt.integer() ) )
+            .addTableElement( d.createTableConstraintDefinition(
+                d.createUniqueConstraintBuilder()
+                 .setUniqueness( UniqueSpecification.PRIMARY_KEY )
+                 .addColumns( "qname_id", "entity_pk" )
+                 .createExpression() )
+                            )
+            .addTableElement(
+                d.createTableConstraintDefinition(
+                    "qname_9_parent_qname_fkey",
+                    d.createForeignKeyConstraintBuilder()
+                     .addSourceColumns( "parent_qname", "entity_pk" )
+                     .setTargetTableName( t.tableName( schemaName, "all_qnames" ) )
+                     .addTargetColumns( "qname_id", "entity_pk" )
+                     .setMatchType( MatchType.SIMPLE )
+                     .setOnUpdate( ReferentialAction.CASCADE )
+                     .setOnDelete( ReferentialAction.CASCADE )
+                     .createExpression(),
+                    ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
+                                                 )
+                            )
+            .addTableElement(
+                d.createTableConstraintDefinition(
+                    "qname_9_qname_id_fkey",
+                    d.createForeignKeyConstraintBuilder()
+                     .addSourceColumns( "qname_id", "entity_pk" )
+                     .setTargetTableName( t.tableName( schemaName, "all_qnames" ) )
+                     .addTargetColumns( "qname_id", "entity_pk" )
+                     .setMatchType( MatchType.SIMPLE )
+                     .setOnUpdate( ReferentialAction.CASCADE )
+                     .setOnDelete( ReferentialAction.CASCADE )
+                     .createExpression(),
+                    ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE
+                                                 )
+                            )
+            .addTableElement(
+                d.createTableConstraintDefinition(
+                    "qname_9_qname_value_fkey",
+                    d.createForeignKeyConstraintBuilder()
+                     .addSourceColumns( "qname_value" )
+                     .setTargetTableName( t.tableName( schemaName, "used_classes" ) )
+                     .addTargetColumns( "used_class_id" )
+                     .setOnUpdate( ReferentialAction.CASCADE )
+                     .setOnDelete( ReferentialAction.RESTRICT )
+                     .createExpression()
+                                                 )
+                            );
+
+        builder.setTableContentsSource( cBuilder.createExpression() );
+
+        this.logStatement( "Table definition", vendor, builder.createExpression() );
+
+        // @formatter:on
+    }
+
+    @Test
+    public void definition2()
+        throws Exception
+    {
+        SQLVendor vendor = this.getVendor();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        DefinitionFactory d = vendor.getDefinitionFactory();
+        DataTypeFactory dt = vendor.getDataTypeFactory();
+
+        String schemaName = "the_schema";
+        String tableName = "the_table";
+        String colPKName = "pk_column";
+        String colValueName = "value_column";
+
+        TableDefinition def = d
+            .createTableDefinitionBuilder()
+            .setTableName( t.tableName( schemaName, tableName ) )
+            .setTableContentsSource(
+                d.createTableElementListBuilder()
+                 .addTableElement( d.createColumnDefinition( colPKName, dt.integer(), false ) )
+                 .addTableElement( d.createColumnDefinition( colValueName, dt.sqlVarChar(), false ) )
+                 .addTableElement(
+                     d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
+                                                         .setUniqueness( UniqueSpecification.PRIMARY_KEY ).addColumns( colPKName )
+                                                         .createExpression() ) )
+                 .addTableElement(
+                     d.createTableConstraintDefinition( d.createUniqueConstraintBuilder()
+                                                         .setUniqueness( UniqueSpecification.UNIQUE ).addColumns( colValueName ).createExpression() ) )
+                 .createExpression() ).createExpression();
+
+        this.logStatement( "Table definition", vendor, def );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractModificationTest.java
new file mode 100644
index 0000000..379da70
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractModificationTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.junit.Test;
+
+public abstract class AbstractModificationTest extends AbstractSQLSyntaxTest
+{
+
+    @Test
+    public void modification1()
+    {
+        // INSERT INTO schema.table
+        // VALUES (5, 'String', SELECT column FROM schema.other_table);
+
+        SQLVendor vendor = this.getVendor();
+
+        QueryFactory q = vendor.getQueryFactory();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        ModificationFactory m = vendor.getModificationFactory();
+        LiteralFactory l = vendor.getLiteralFactory();
+
+        InsertStatement insert = this.getVendor().getModificationFactory().insert()
+                                     .setTableName( t.tableName( "schema", "table" ) )
+                                     .setColumnSource(
+                                         m.columnSourceByValues().addValues(
+                                             l.n( 5 ),
+                                             l.s( "String" ),
+                                             q.simpleQueryBuilder()
+                                              .select( "column" )
+                                              .from( t.tableName( "schema", "other_table" ) )
+                                              .createExpression()
+                                                                           ).createExpression()
+                                                     )
+                                     .createExpression();
+
+        this.logStatement( "Table modification", vendor, insert );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractQueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractQueryTest.java
new file mode 100644
index 0000000..06c92e9
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractQueryTest.java
@@ -0,0 +1,364 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.junit.Test;
+
+/**
+ * Contains the tests for various queries to test functionality of parser.
+ * <p>
+ * TODO how to actually verify queries? Currently this only outputs them.
+ *
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractQueryTest extends AbstractSQLSyntaxTest
+{
+    protected void logQuery( SQLVendor vendor, QueryExpression query )
+    {
+        this.logStatement( "Query", vendor, query );
+    }
+
+    @Test
+    public void query1()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+        
+          SELECT t0.entity_identity
+          FROM (
+          SELECT DISTINCT t0.entity_pk, t0.entity_identity
+            FROM qi4j.entities t0
+            JOIN qi4j.qname_6 t1 ON (t0.entity_pk = t1.entity_pk AND t1.parent_qname IS NULL)
+            JOIN qi4j.qname_14 t2 ON (t1.qname_id = t2.parent_qname AND t1.entity_pk = t2.entity_pk)
+            JOIN qi4j.qname_15 t3 ON (t2.qname_id = t3.parent_qname AND t2.entity_pk = t3.entity_pk)
+            WHERE t0.entity_type_id IN (3, 4) AND
+            ((t3.qname_value IS NOT NULL AND t3.qname_value = ?) )
+            ) AS t0
+         
+         */
+
+        SQLVendor vendor = this.getVendor();
+
+        QueryFactory q = vendor.getQueryFactory();
+        BooleanFactory b = vendor.getBooleanFactory();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        LiteralFactory l = vendor.getLiteralFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        ColumnsBuilder innerSelectCols = q.columnsBuilder( SetQuantifier.DISTINCT ).addUnnamedColumns(
+            c.colName( "t0", "entity_pk" ), c.colName( "t0", "entity_identity" ) );
+
+        TableReferenceBuilder join = t.tableBuilder(
+            t.table( t.tableName( "qi4j", "entities" ), t.tableAlias( "t0" ) )
+                                                   ).addQualifiedJoin(
+            JoinType.INNER,
+            t.table( t.tableName( "qi4j", "qname_6" ), t.tableAlias( "t1" ) ),
+            t.jc(
+                b.booleanBuilder(
+                    b.eq( c.colName( "t0", "entity_pk" ), c.colName( "t1", "entity_pk" ) )
+                                ).and(
+                    b.isNull( c.colName( "t1", "parent_qname" ) )
+                                     ).createExpression()
+                )
+                                                                     ).addQualifiedJoin(
+            JoinType.INNER,
+            t.table( t.tableName( "qi4j", "qname_14" ), t.tableAlias( "t2" ) ),
+            t.jc(
+                b.booleanBuilder(
+                    b.eq( c.colName( "t1", "qname_id" ), c.colName( "t2", "parent_qname" ) )
+                                ).and(
+                    b.eq( c.colName( "t1", "entity_pk" ), c.colName( "t2", "entity_pk" ) )
+                                     ).createExpression()
+                )
+                                                                                       ).addQualifiedJoin(
+            JoinType.INNER,
+            t.table( t.tableName( "qi4j", "qname_15" ), t.tableAlias( "t3" ) ),
+            t.jc(
+                b.booleanBuilder(
+                    b.eq( c.colName( "t2", "qname_id" ), c.colName( "t3", "parent_qname" ) )
+                                ).and(
+                    b.eq( c.colName( "t2", "entity_pk" ), c.colName( "t3", "entity_pk" ) )
+                                     ).createExpression()
+                )
+                                                                                                         );
+
+        BooleanExpression innerWhere = b.booleanBuilder(
+            b.in( c.colName( "t0", "entity_type_id" ), l.n( 3 ), l.n( 4 ) )
+                                                       ).and( b.isNotNull( c.colName( "t3", "qname_value" ) )
+                                                            ).and( b.eq( c.colName( "t3", "qname_value" ), l.param() )
+                                                                 ).createExpression();
+
+        QuerySpecificationBuilder builder = q.querySpecificationBuilder();
+        builder.setSelect( innerSelectCols );
+        builder.getFrom().addTableReferences( join );
+        builder.getWhere().reset( innerWhere );
+
+        QuerySpecificationBuilder select =
+            q.querySpecificationBuilder();
+        select.getSelect().addUnnamedColumns( c.colName( "t0", "entity_identity" ) );
+        select.getFrom().addTableReferences( t.tableBuilder( t.table( q.createQuery( builder.createExpression() ), t.tableAlias( "t0" ) ) ) );
+
+        QueryExpression query = q.createQuery( q.queryBuilder( select.createExpression() ).createExpression() );
+
+        this.logQuery( vendor, query );
+
+        // @formatter:on
+
+    }
+
+    @Test
+    public void query2()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+          SELECT t0.entity_identity
+          FROM (SELECT DISTINCT t0.entity_pk, t0.entity_identity
+            FROM qi4j.entities t0
+            WHERE t0.entity_type_id IN (3, 4)
+            EXCEPT
+            SELECT DISTINCT t0.entity_pk, t0.entity_identity
+            FROM qi4j.entities t0
+            JOIN qi4j.qname_6 t1 ON (t0.entity_pk = t1.entity_pk AND t1.parent_qname IS NULL)
+            JOIN qi4j.qname_11 t2 ON (t1.qname_id = t2.parent_qname AND t1.entity_pk = t2.entity_pk)
+            LEFT JOIN qi4j.qname_12 t3 ON (t2.qname_id = t3.parent_qname AND t2.entity_pk = t3.entity_pk)
+            LEFT JOIN qi4j.qname_13 t4 ON (t2.qname_id = t4.parent_qname AND t2.entity_pk = t4.entity_pk)
+            WHERE t0.entity_type_id IN (3, 4)
+            GROUP BY t0.entity_pk, t0.entity_identity
+            HAVING COUNT(t2.qname_value) >= 2
+            ORDER BY t0.entity_pk ASC
+          ) AS t0
+        */
+        // @formatter:on
+
+        SQLVendor vendor = this.getVendor();
+
+        QueryFactory q = vendor.getQueryFactory();
+        BooleanFactory b = vendor.getBooleanFactory();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        LiteralFactory l = vendor.getLiteralFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        ColumnReferenceByName innerFirstCol = c.colName( "t0", "entity_pk" );
+        ColumnReferenceByName innerSecondCol = c.colName( "t0", "entity_identity" );
+        ColumnsBuilder innerSelectCols = q.columnsBuilder( SetQuantifier.DISTINCT ).addUnnamedColumns( innerFirstCol,
+                                                                                                       innerSecondCol );
+
+        BooleanExpression where = b.in( c.colName( "t0", "entity_type_id" ), l.n( 3 ), l.n( 4 ) );
+        QuerySpecificationBuilder firstInnerQuery = q.querySpecificationBuilder();
+        firstInnerQuery.setSelect( innerSelectCols );
+
+        firstInnerQuery.getFrom().addTableReferences(
+            t.tableBuilder( t.table( t.tableName( "qi4j", "entities" ), t.tableAlias( "t0" ) ) ) );
+
+        firstInnerQuery.getWhere().reset( where );
+
+        TableReferenceBuilder join = t
+            .tableBuilder( t.table( t.tableName( "qi4j", "entities" ), t.tableAlias( "t0" ) ) )
+            .addQualifiedJoin(
+                JoinType.INNER,
+                t.table( t.tableName( "qi4j", "qname_6" ), t.tableAlias( "t1" ) ),
+                t.jc( b.booleanBuilder( b.eq( c.colName( "t0", "entity_pk" ), c.colName( "t1", "entity_pk" ) ) )
+                       .and( b.isNull( c.colName( "t1", "parent_qname" ) ) ).createExpression() ) )
+            .addQualifiedJoin(
+                JoinType.INNER,
+                t.table( t.tableName( "qi4j", "qname_11" ), t.tableAlias( "t2" ) ),
+                t.jc( b.booleanBuilder( b.eq( c.colName( "t1", "qname_id" ), c.colName( "t2", "parent_qname" ) ) )
+                       .and( b.eq( c.colName( "t1", "entity_pk" ), c.colName( "t2", "entity_pk" ) ) ).createExpression() ) )
+            .addQualifiedJoin(
+                JoinType.LEFT_OUTER,
+                t.table( t.tableName( "qi4j", "qname_12" ), t.tableAlias( "t3" ) ),
+                t.jc( b.booleanBuilder( b.eq( c.colName( "t2", "qname_id" ), c.colName( "t3", "parent_qname" ) ) )
+                       .and( b.eq( c.colName( "t2", "entity_pk" ), c.colName( "t3", "entity_pk" ) ) ).createExpression() ) )
+            .addQualifiedJoin(
+                JoinType.LEFT_OUTER,
+                t.table( t.tableName( "qi4j", "qname_13" ), t.tableAlias( "t4" ) ),
+                t.jc( b.booleanBuilder( b.eq( c.colName( "t3", "qname_id" ), c.colName( "t4", "parent_qname" ) ) )
+                       .and( b.eq( c.colName( "t2", "entity_pk" ), c.colName( "t4", "entity_pk" ) ) ).createExpression() ) );
+
+        QuerySpecificationBuilder secondBuilder = q.querySpecificationBuilder();
+        secondBuilder.setSelect( innerSelectCols );
+        secondBuilder.getFrom().addTableReferences( join );
+        secondBuilder.getWhere().reset( where );
+        secondBuilder.getGroupBy().addGroupingElements( q.groupingElement( innerFirstCol ),
+                                                        q.groupingElement( innerSecondCol ) );
+        secondBuilder.getHaving().reset( b.geq( l.func( "COUNT", c.colName( "t2", "qname_value" ) ), l.n( 2 ) ) );
+        secondBuilder.getOrderBy().addSortSpecs( q.sortSpec( c.colName( "t0", "entity_pk" ), Ordering.ASCENDING ) );
+
+        QueryExpressionBody innerQuery = q.queryBuilder( firstInnerQuery.createExpression() )
+                                          .except( secondBuilder.createExpression() ).createExpression();
+
+        QuerySpecificationBuilder select = q.querySpecificationBuilder().setSelect(
+            q.columnsBuilder().addUnnamedColumns( c.colName( "t0", "entity_identity" ) ) );
+        select.getFrom().addTableReferences(
+            t.tableBuilder( t.table( q.createQuery( innerQuery ), t.tableAlias( "t0" ) ) ) );
+
+        QueryExpression query = q.createQuery( q.queryBuilder( select.createExpression() ).createExpression() );
+
+        this.logQuery( vendor, query );
+    }
+
+    @Test
+    public void query3()
+        throws Exception
+    {
+        // @formatter:off
+        // SELECT COUNT(firstCol), MAX(secondCol)
+        // FROM schema.table;
+        // @formatter:on
+
+        // This test is related to bug reported by Paul Merlin
+        // The simple query builder was iterating the columns in erroneus way,
+        // thus skipping all non-aliased columns
+        SQLVendor vendor = this.getVendor();
+
+        QueryFactory q = vendor.getQueryFactory();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+
+        String firstCol = "firstCol";
+        String secondCol = "secondCol";
+        String schemaName = "schema";
+        String tableName = "table";
+
+        QueryExpression query = q.simpleQueryBuilder().select( "COUNT(" + firstCol + ")", "MAX(" + secondCol + ")" )
+                                 .from( t.tableName( schemaName, tableName ) ).createExpression();
+
+        this.logQuery( vendor, query );
+    }
+
+    @Test
+    public void query4()
+        throws Exception
+    {
+        // @formatter:off
+        // SELECT * FROM schema.function_name(6, 'param2');
+        // @formatter:on
+
+        SQLVendor vendor = this.getVendor();
+        QueryFactory q = vendor.getQueryFactory();
+        LiteralFactory l = vendor.getLiteralFactory();
+
+        this.logQuery( vendor, q.callFunction( "schema", l.func( "function_name", l.n( 6 ), l.s( "param2" ) ) ) );
+    }
+
+    @Test
+    public void query5()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+          SELECT *
+          FROM table
+          WHERE table.value = ?
+          ORDER BY 1 ASC
+          OFFSET 3 ROWS
+          FETCH FIRST 6 ROWS ONLY
+        */
+
+        SQLVendor vendor = this.getVendor();
+
+        BooleanFactory b = vendor.getBooleanFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
+                                      .selectAllColumns()
+                                      .from( vendor.getTableReferenceFactory().tableName( "table" ) )
+                                      .where( b.eq( c.colName( "table", "value" ), vendor.getLiteralFactory().param() ) )
+                                      .orderByAsc( "1" )
+                                      .limit( 6 )
+                                      .offset( 3 )
+                                      .createExpression();
+        // @formatter:on
+
+        this.logQuery( vendor, query );
+    }
+
+    @Test
+    public void query6()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+          SELECT *
+          FROM table
+          WHERE table.value = ?
+          ORDER BY 1 ASC
+          OFFSET 3 ROWS
+        */
+
+        SQLVendor vendor = this.getVendor();
+
+        BooleanFactory b = vendor.getBooleanFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
+                                      .selectAllColumns()
+                                      .from( vendor.getTableReferenceFactory().tableName( "table" ) )
+                                      .where( b.eq( c.colName( "table", "value" ), vendor.getLiteralFactory().param() ) )
+                                      .orderByAsc( "1" )
+                                      .offset( 3 )
+                                      .createExpression();
+        // @formatter:on
+
+        this.logQuery( vendor, query );
+    }
+
+    @Test
+    public void query7()
+        throws Exception
+    {
+        // @formatter:off
+        /*
+          SELECT *
+          FROM table
+          WHERE table.value = ?
+          ORDER BY 1 ASC
+          FETCH FIRST 6 ROWS ONLY
+        */
+
+        SQLVendor vendor = this.getVendor();
+
+        BooleanFactory b = vendor.getBooleanFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        QueryExpression query = vendor.getQueryFactory().simpleQueryBuilder()
+                                      .selectAllColumns()
+                                      .from( vendor.getTableReferenceFactory().tableName( "table" ) )
+                                      .where( b.eq( c.colName( "table", "value" ), vendor.getLiteralFactory().param() ) )
+                                      .orderByAsc( "1" )
+                                      .limit( 6 )
+                                      .createExpression();
+        // @formatter:on
+
+        this.logQuery( vendor, query );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractSQLSyntaxTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractSQLSyntaxTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractSQLSyntaxTest.java
new file mode 100644
index 0000000..9bb8ab9
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/AbstractSQLSyntaxTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractSQLSyntaxTest
+{
+
+    private SQLVendor _vendor;
+
+    protected void logStatement( String statementType, SQLVendor vendor, SQLStatement statement )
+    {
+        String stringStmt = vendor.toString( statement );
+        LoggerFactory.getLogger( this.getClass().getName() ).info( statementType + ":" + "\n" + stringStmt + "\n" );
+
+        Assert.assertEquals(
+            "Strings must be same from both SQLVendor.toString(...) and statement.toString() methods.", stringStmt,
+            statement.toString() );
+    }
+
+    @Before
+    public final void setUp()
+        throws Exception
+    {
+        this._vendor = this.loadVendor();
+    }
+
+    @After
+    public final void tearDown()
+    {
+        this._vendor = null;
+    }
+
+    protected final SQLVendor getVendor()
+    {
+        return this._vendor;
+    }
+
+    protected abstract SQLVendor loadVendor()
+        throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultDataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultDataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultDataDefinitionTest.java
new file mode 100644
index 0000000..2ff1329
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultDataDefinitionTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultDataDefinitionTest extends AbstractDataDefinitionTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultModificationTest.java
new file mode 100644
index 0000000..2a040f5
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultModificationTest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+public class DefaultModificationTest extends AbstractModificationTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultSQLQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultSQLQueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultSQLQueryTest.java
new file mode 100644
index 0000000..c8a0eba
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/DefaultSQLQueryTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultSQLQueryTest extends AbstractQueryTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2DataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2DataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2DataDefinitionTest.java
new file mode 100644
index 0000000..a034907
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2DataDefinitionTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Paul Merlin.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.H2Vendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+public class H2DataDefinitionTest
+    extends AbstractDataDefinitionTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( H2Vendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2ModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2ModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2ModificationTest.java
new file mode 100644
index 0000000..752e827
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2ModificationTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.H2Vendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+public class H2ModificationTest extends AbstractModificationTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( H2Vendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2QueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2QueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2QueryTest.java
new file mode 100644
index 0000000..056b750
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/H2QueryTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Paul Merlin.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.H2Vendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+public class H2QueryTest
+    extends AbstractQueryTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( H2Vendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLDataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLDataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLDataDefinitionTest.java
new file mode 100644
index 0000000..25daacb
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLDataDefinitionTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.MySQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class MySQLDataDefinitionTest extends AbstractDataDefinitionTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( MySQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLModificationTest.java
new file mode 100644
index 0000000..54c6f04
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLModificationTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.MySQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+public class MySQLModificationTest extends AbstractModificationTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( MySQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLQueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLQueryTest.java
new file mode 100644
index 0000000..953137e
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/MySQLQueryTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.MySQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.junit.Test;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class MySQLQueryTest extends AbstractQueryTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( MySQLVendor.class );
+    }
+
+    @Test
+    public void mySQLQuery5()
+        throws Exception
+    {
+        ( (MySQLVendor) this.getVendor() ).setLegacyLimit( true );
+        super.query5();
+    }
+
+    @Test
+    public void mySQLQuery6()
+        throws Exception
+    {
+        ( (MySQLVendor) this.getVendor() ).setLegacyLimit( true );
+        super.query6();
+    }
+
+    @Test
+    public void mySQLQuery7()
+        throws Exception
+    {
+        ( (MySQLVendor) this.getVendor() ).setLegacyLimit( true );
+        super.query7();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLDataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLDataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLDataDefinitionTest.java
new file mode 100644
index 0000000..0a4a0f8
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLDataDefinitionTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PostgreSQLDataDefinitionTest extends AbstractDataDefinitionTest
+{
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( PostgreSQLVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLModificationTest.java
new file mode 100644
index 0000000..7d605b8
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLModificationTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql.PgSQLInsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.ValueSource;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.junit.Test;
+
+public class PostgreSQLModificationTest extends AbstractModificationTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( PostgreSQLVendor.class );
+    }
+
+    @Test
+    public void pgInsert1()
+    {
+        // INSERT INTO some_schema.some_table
+        // VALUES (DEFAULT, "SomeString")
+        // RETURNING id_column;
+        SQLVendor vendor = this.getVendor();
+
+        QueryFactory q = vendor.getQueryFactory();
+        TableReferenceFactory t = vendor.getTableReferenceFactory();
+        ModificationFactory m = vendor.getModificationFactory();
+        LiteralFactory l = vendor.getLiteralFactory();
+        ColumnsFactory c = vendor.getColumnsFactory();
+
+        InsertStatement insert =
+            ( (PgSQLInsertStatementBuilder) m.insert() )
+                .setReturningClause(
+                    q.columnsBuilder().addUnnamedColumns( c.colName( "id_column" ) )
+                     .createExpression() )
+                .setTableName( t.tableName( "some_schema", "some_table" ) )
+                .setColumnSource(
+                    m.columnSourceByValues()
+                     .addValues( ValueSource.Default.INSTANCE, l.s( "SomeString" ) )
+                     .createExpression()
+                                ).createExpression();
+
+        logStatement( "PGSQL table modification", vendor, insert );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLQueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLQueryTest.java
new file mode 100644
index 0000000..ca4dc37
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/PostgreSQLQueryTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.junit.Test;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PostgreSQLQueryTest extends AbstractQueryTest
+{
+
+    @Override
+    protected PostgreSQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( PostgreSQLVendor.class );
+    }
+
+    @Test
+    public void pgQuery5()
+        throws Exception
+    {
+        ( (PostgreSQLVendor) this.getVendor() ).setLegacyOffsetAndLimit( true );
+        super.query5();
+    }
+
+    @Test
+    public void pgQuery6()
+        throws Exception
+    {
+        ( (PostgreSQLVendor) this.getVendor() ).setLegacyOffsetAndLimit( true );
+        super.query6();
+    }
+
+    @Test
+    public void pgQuery7()
+        throws Exception
+    {
+        ( (PostgreSQLVendor) this.getVendor() ).setLegacyOffsetAndLimit( true );
+        super.query7();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteDataDefinitionTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteDataDefinitionTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteDataDefinitionTest.java
new file mode 100644
index 0000000..5e76755
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteDataDefinitionTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.apache.polygene.library.sql.generator.vendor.SQLiteVendor;
+
+public class SQLiteDataDefinitionTest
+    extends AbstractDataDefinitionTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLiteVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteModificationTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteModificationTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteModificationTest.java
new file mode 100644
index 0000000..35db800
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteModificationTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.apache.polygene.library.sql.generator.vendor.SQLiteVendor;
+
+public class SQLiteModificationTest extends AbstractModificationTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLiteVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteQueryTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteQueryTest.java b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteQueryTest.java
new file mode 100644
index 0000000..4ab7ebb
--- /dev/null
+++ b/libraries/sql-generator/src/test/java/org/apache/polygene/library/sql/generator/SQLiteQueryTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * Licensed 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.polygene.library.sql.generator;
+
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
+import org.apache.polygene.library.sql.generator.vendor.SQLiteVendor;
+
+public class SQLiteQueryTest
+    extends AbstractQueryTest
+{
+
+    @Override
+    protected SQLVendor loadVendor()
+        throws Exception
+    {
+        return SQLVendorProvider.createVendor( SQLiteVendor.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql/build.gradle
----------------------------------------------------------------------
diff --git a/libraries/sql/build.gradle b/libraries/sql/build.gradle
index adb28f6..9249981 100644
--- a/libraries/sql/build.gradle
+++ b/libraries/sql/build.gradle
@@ -27,9 +27,9 @@ jar { manifest { name = "Apache Polygene\u2122 Library - SQL" } }
 dependencies {
   api polygene.core.bootstrap
   api polygene.library( 'circuitbreaker' )
+  api libraries.slf4j_api
 
   implementation polygene.library( 'jmx' )
-  implementation libraries.slf4j_api
 
   runtimeOnly polygene.core.runtime
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/manual/src/docs/userguide/tools.txt
----------------------------------------------------------------------
diff --git a/manual/src/docs/userguide/tools.txt b/manual/src/docs/userguide/tools.txt
index 9da85a3..2d14312 100644
--- a/manual/src/docs/userguide/tools.txt
+++ b/manual/src/docs/userguide/tools.txt
@@ -36,6 +36,7 @@ include::../../../../tools/src/docs/yeoman_polygene.txt[]
 
 :leveloffset: 2
 
-include::../../../../tools/envisage/src/docs/envisage.txt[]
+include::../../../../tools/src/docs/envisage.txt[]
+// include::../../../../tools/envisage/src/docs/envisage.txt[]
 
 :leveloffset: 2

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 808f937..0cee4a7 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -49,6 +49,7 @@ include 'core:api',
         'libraries:sql',
         'libraries:sql-bonecp',
         'libraries:sql-dbcp',
+        'libraries:sql-generator',
         'libraries:sql-liquibase',
         'libraries:uid',
         'libraries:uowfile',

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/tools/envisage/src/docs/envisage.txt
----------------------------------------------------------------------
diff --git a/tools/envisage/src/docs/envisage.txt b/tools/envisage/src/docs/envisage.txt
deleted file mode 100644
index 4aecf37..0000000
--- a/tools/envisage/src/docs/envisage.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-///////////////////////////////////////////////////////////////
- * 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.
-///////////////////////////////////////////////////////////////
-
-[[tools-envisage,Envisage Tool]]
-= Envisage =
-
-Envisage is a Swing based visualization tool for the Polygene\u2122 Application model.
-Visualizations can be printed to PDFs.
-
-== Usage ==
-
-Envisage can be easily used directly and prior your Application activation:
-
-[snippet,java]
-----
-source=tools/envisage/src/test/java/org/apache/polygene/envisage/school/EnvisageSchoolSample.java
-tag=envisage
-----
-
-As you can see, Envisage operates on the ApplicationModel, this means that you
-can easily embed it in your own Applications too.
-
-From the sources you can run the `runEnvisageSample` or `runEnvisageSchoolSample` Gradle tasks
-to run interactive examples. See <<build-system>> if you need some guidance.
-
-== Screenshots ==
-
-image:tools-envisage-structure.png[width="800px"]
-
-image:tools-envisage-type.png[width="800px"]
-
-image:tools-envisage-stacked.png[width="800px"]
-
-image:tools-envisage-stacked-collapsed.png[width="800px"]
-
-== Embedd in your Application ==
-
-include::../../build/docs/buildinfo/artifact.txt[]
-

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/tools/generator-polygene/dev-status.xml
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/dev-status.xml b/tools/generator-polygene/dev-status.xml
new file mode 100644
index 0000000..dc6c0e6
--- /dev/null
+++ b/tools/generator-polygene/dev-status.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  ~  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.
+  ~
+  ~
+  -->
+<module xmlns="http://polygene.apache.org/schemas/2008/dev-status/1"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://polygene.apache.org/schemas/2008/dev-status/1
+        http://polygene.apache.org/schemas/2008/dev-status/1/dev-status.xsd">
+  <status>
+    <!--none,early,beta,stable,mature-->
+    <codebase>stable</codebase>
+
+    <!-- none, brief, good, complete -->
+    <documentation>good</documentation>
+
+    <!-- none, some, good, complete -->
+    <unittests>complete</unittests>
+
+  </status>
+  <licenses>
+    <license>ALv2</license>
+  </licenses>
+</module>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/tools/src/docs/envisage.txt
----------------------------------------------------------------------
diff --git a/tools/src/docs/envisage.txt b/tools/src/docs/envisage.txt
new file mode 100644
index 0000000..4aecf37
--- /dev/null
+++ b/tools/src/docs/envisage.txt
@@ -0,0 +1,55 @@
+///////////////////////////////////////////////////////////////
+ * 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.
+///////////////////////////////////////////////////////////////
+
+[[tools-envisage,Envisage Tool]]
+= Envisage =
+
+Envisage is a Swing based visualization tool for the Polygene\u2122 Application model.
+Visualizations can be printed to PDFs.
+
+== Usage ==
+
+Envisage can be easily used directly and prior your Application activation:
+
+[snippet,java]
+----
+source=tools/envisage/src/test/java/org/apache/polygene/envisage/school/EnvisageSchoolSample.java
+tag=envisage
+----
+
+As you can see, Envisage operates on the ApplicationModel, this means that you
+can easily embed it in your own Applications too.
+
+From the sources you can run the `runEnvisageSample` or `runEnvisageSchoolSample` Gradle tasks
+to run interactive examples. See <<build-system>> if you need some guidance.
+
+== Screenshots ==
+
+image:tools-envisage-structure.png[width="800px"]
+
+image:tools-envisage-type.png[width="800px"]
+
+image:tools-envisage-stacked.png[width="800px"]
+
+image:tools-envisage-stacked-collapsed.png[width="800px"]
+
+== Embedd in your Application ==
+
+include::../../build/docs/buildinfo/artifact.txt[]
+


[19/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Signed-off-by: niclas <ni...@spicter.com>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/a36086b6
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/a36086b6
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/a36086b6

Branch: refs/heads/develop
Commit: a36086b600a76ee1252ae3a7e857739ed4c2ff09
Parents: d64c585
Author: Stanislav Muhametsin <st...@gmail.com>
Authored: Sat Apr 15 16:25:22 2017 +0800
Committer: niclas <ni...@spicter.com>
Committed: Sat Apr 15 16:25:23 2017 +0800

----------------------------------------------------------------------
 .../instantiation/ValueInstantiationTests.java  |   6 +-
 .../test/cache/AbstractCachePoolTest.java       |  14 +-
 dependencies.gradle                             |   3 -
 extensions/indexing-sql/build.gradle            |   5 +-
 .../AbstractSQLIndexQueryAssembler.java         |   4 +-
 .../assembly/PostgreSQLIndexQueryAssembler.java |   6 +-
 .../support/common/GenericDatabaseExplorer.java |  42 +-
 .../postgresql/PostgreSQLAppStartup.java        |  14 +-
 .../postgresql/PostgreSQLIndexExporter.java     |   2 +-
 .../support/postgresql/PostgreSQLIndexing.java  |  18 +-
 .../support/postgresql/PostgreSQLQuerying.java  |   6 +-
 .../support/skeletons/AbstractSQLIndexing.java  |  32 +-
 .../support/skeletons/AbstractSQLQuerying.java  | 137 ++---
 .../support/skeletons/AbstractSQLStartup.java   |  37 +-
 .../postgresql/PostgreSQLDBIntegrityTest.java   |  13 +-
 .../library/sql/generator/Typeable.java         |  54 ++
 .../grammar/booleans/BetweenPredicate.java      |  46 ++
 .../grammar/booleans/BinaryPredicate.java       |  46 ++
 .../grammar/booleans/BooleanExpression.java     |  86 +++
 .../generator/grammar/booleans/BooleanTest.java |  94 +++
 .../booleans/ComposedBooleanExpression.java     |  31 +
 .../generator/grammar/booleans/Conjunction.java |  44 ++
 .../generator/grammar/booleans/Disjunction.java |  43 ++
 .../grammar/booleans/EqualsPredicate.java       |  31 +
 .../grammar/booleans/ExistsPredicate.java       |  36 ++
 .../booleans/GreaterOrEqualPredicate.java       |  32 +
 .../grammar/booleans/GreaterThanPredicate.java  |  31 +
 .../generator/grammar/booleans/InPredicate.java |  31 +
 .../grammar/booleans/IsNotNullPredicate.java    |  31 +
 .../grammar/booleans/IsNullPredicate.java       |  31 +
 .../grammar/booleans/LessOrEqualPredicate.java  |  32 +
 .../grammar/booleans/LessThanPredicate.java     |  31 +
 .../grammar/booleans/LikePredicate.java         |  32 +
 .../grammar/booleans/MultiPredicate.java        |  47 ++
 .../generator/grammar/booleans/Negation.java    |  37 ++
 .../grammar/booleans/NotBetweenPredicate.java   |  45 ++
 .../grammar/booleans/NotEqualsPredicate.java    |  31 +
 .../grammar/booleans/NotInPredicate.java        |  32 +
 .../grammar/booleans/NotLikePredicate.java      |  32 +
 .../grammar/booleans/NotRegexpPredicate.java    |  32 +
 .../generator/grammar/booleans/Predicate.java   |  57 ++
 .../grammar/booleans/RegexpPredicate.java       |  31 +
 .../grammar/booleans/UnaryPredicate.java        |  39 ++
 .../grammar/booleans/UniquePredicate.java       |  37 ++
 .../grammar/booleans/package-info.java          |  23 +
 .../grammar/builders/AbstractBuilder.java       |  36 ++
 .../builders/booleans/BooleanBuilder.java       |  65 ++
 .../grammar/builders/booleans/InBuilder.java    |  37 ++
 .../grammar/builders/booleans/package-info.java |  23 +
 .../definition/ForeignKeyConstraintBuilder.java | 133 ++++
 .../definition/SchemaDefinitionBuilder.java     |  81 +++
 .../definition/TableDefinitionBuilder.java      | 104 ++++
 .../definition/TableElementListBuilder.java     |  50 ++
 .../definition/UniqueConstraintBuilder.java     |  66 ++
 .../definition/ViewDefinitionBuilder.java       | 117 ++++
 .../builders/definition/package-info.java       |  23 +
 .../ColumnSourceByValuesBuilder.java            |  64 ++
 .../modification/DeleteBySearchBuilder.java     |  60 ++
 .../modification/InsertStatementBuilder.java    |  69 +++
 .../modification/UpdateBySearchBuilder.java     |  70 +++
 .../builders/modification/package-info.java     |  23 +
 .../pgsql/PgSQLInsertStatementBuilder.java      |  41 ++
 .../modification/pgsql/package-info.java        |  24 +
 .../grammar/builders/package-info.java          |  23 +
 .../builders/query/AbstractQueryBuilder.java    |  82 +++
 .../grammar/builders/query/ColumnsBuilder.java  |  87 +++
 .../grammar/builders/query/FromBuilder.java     |  54 ++
 .../grammar/builders/query/GroupByBuilder.java  |  52 ++
 .../grammar/builders/query/OrderByBuilder.java  |  52 ++
 .../grammar/builders/query/QueryBuilder.java    | 214 +++++++
 .../query/QuerySpecificationBuilder.java        | 140 +++++
 .../builders/query/SimpleQueryBuilder.java      | 127 ++++
 .../builders/query/TableReferenceBuilder.java   |  76 +++
 .../grammar/builders/query/package-info.java    |  23 +
 .../grammar/common/ColumnNameList.java          |  38 ++
 .../grammar/common/NonBooleanExpression.java    |  31 +
 .../generator/grammar/common/SQLConstants.java  |  82 +++
 .../generator/grammar/common/SQLFunctions.java  |  43 ++
 .../generator/grammar/common/SQLStatement.java  |  39 ++
 .../common/SchemaDefinitionStatement.java       |  34 +
 .../common/SchemaManipulationStatement.java     |  29 +
 .../grammar/common/SchemaStatement.java         |  31 +
 .../generator/grammar/common/SetQuantifier.java |  39 ++
 .../sql/generator/grammar/common/TableName.java |  40 ++
 .../grammar/common/TableNameDirect.java         |  37 ++
 .../grammar/common/TableNameFunction.java       |  38 ++
 .../grammar/common/ValueExpression.java         |  34 +
 .../grammar/common/datatypes/BigInt.java        |  31 +
 .../grammar/common/datatypes/Decimal.java       |  52 ++
 .../common/datatypes/DoublePrecision.java       |  31 +
 .../common/datatypes/IntervalDataType.java      |  40 ++
 .../grammar/common/datatypes/Numeric.java       |  52 ++
 .../datatypes/ParametrizableDataType.java       |  30 +
 .../grammar/common/datatypes/Real.java          |  31 +
 .../grammar/common/datatypes/SQLBoolean.java    |  31 +
 .../grammar/common/datatypes/SQLChar.java       |  46 ++
 .../grammar/common/datatypes/SQLDataType.java   |  33 +
 .../grammar/common/datatypes/SQLDate.java       |  31 +
 .../grammar/common/datatypes/SQLFloat.java      |  37 ++
 .../grammar/common/datatypes/SQLInteger.java    |  31 +
 .../grammar/common/datatypes/SQLInterval.java   |  61 ++
 .../grammar/common/datatypes/SQLTime.java       |  44 ++
 .../grammar/common/datatypes/SQLTimeStamp.java  |  42 ++
 .../grammar/common/datatypes/SmallInt.java      |  31 +
 .../common/datatypes/UserDefinedType.java       |  36 ++
 .../grammar/common/datatypes/package-info.java  |  23 +
 .../grammar/common/datatypes/pgsql/Text.java    |  33 +
 .../generator/grammar/common/package-info.java  |  23 +
 .../definition/schema/SchemaDefinition.java     |  54 ++
 .../definition/schema/SchemaElement.java        |  34 +
 .../grammar/definition/schema/package-info.java |  23 +
 .../definition/table/AutoGenerationPolicy.java  |  52 ++
 .../definition/table/CheckConstraint.java       |  34 +
 .../definition/table/ColumnDefinition.java      |  70 +++
 .../table/ConstraintCharacteristics.java        |  44 ++
 .../definition/table/ForeignKeyConstraint.java  |  79 +++
 .../grammar/definition/table/LikeClause.java    |  41 ++
 .../grammar/definition/table/MatchType.java     |  45 ++
 .../definition/table/ReferentialAction.java     |  57 ++
 .../definition/table/TableCommitAction.java     |  41 ++
 .../definition/table/TableConstraint.java       |  35 ++
 .../table/TableConstraintDefinition.java        |  55 ++
 .../definition/table/TableContentsSource.java   |  34 +
 .../definition/table/TableDefinition.java       |  65 ++
 .../grammar/definition/table/TableElement.java  |  36 ++
 .../definition/table/TableElementList.java      |  40 ++
 .../grammar/definition/table/TableScope.java    |  41 ++
 .../definition/table/UniqueConstraint.java      |  48 ++
 .../definition/table/UniqueSpecification.java   |  40 ++
 .../grammar/definition/table/package-info.java  |  23 +
 .../table/pgsql/PgSQLTableCommitAction.java     |  36 ++
 .../view/RegularViewSpecification.java          |  40 ++
 .../definition/view/ViewCheckOption.java        |  39 ++
 .../grammar/definition/view/ViewDefinition.java |  72 +++
 .../definition/view/ViewSpecification.java      |  33 +
 .../grammar/definition/view/package-info.java   |  23 +
 .../grammar/factories/BooleanFactory.java       | 283 +++++++++
 .../grammar/factories/ColumnsFactory.java       |  85 +++
 .../grammar/factories/DataTypeFactory.java      | 363 +++++++++++
 .../grammar/factories/DefinitionFactory.java    | 253 ++++++++
 .../grammar/factories/LiteralFactory.java       |  88 +++
 .../grammar/factories/ManipulationFactory.java  | 157 +++++
 .../grammar/factories/ModificationFactory.java  | 148 +++++
 .../grammar/factories/QueryFactory.java         | 227 +++++++
 .../factories/TableReferenceFactory.java        | 182 ++++++
 .../grammar/factories/package-info.java         |  23 +
 .../factories/pgsql/PgSQLDataTypeFactory.java   |  40 ++
 .../pgsql/PgSQLManipulationFactory.java         |  49 ++
 .../grammar/factories/pgsql/package-info.java   |  23 +
 .../grammar/literals/DirectLiteral.java         |  37 ++
 .../grammar/literals/LiteralExpression.java     |  33 +
 .../grammar/literals/NumericLiteral.java        |  36 ++
 .../grammar/literals/SQLFunctionLiteral.java    |  47 ++
 .../grammar/literals/StringLiteral.java         |  38 ++
 .../grammar/literals/TemporalLiteral.java       |  32 +
 .../grammar/literals/TimestampTimeLiteral.java  |  39 ++
 .../grammar/literals/package-info.java          |  23 +
 .../manipulation/AddColumnDefinition.java       |  40 ++
 .../AddTableConstraintDefinition.java           |  38 ++
 .../grammar/manipulation/AlterColumnAction.java |  53 ++
 .../manipulation/AlterColumnDefinition.java     |  46 ++
 .../grammar/manipulation/AlterStatement.java    |  33 +
 .../grammar/manipulation/AlterTableAction.java  |  34 +
 .../manipulation/AlterTableStatement.java       |  45 ++
 .../grammar/manipulation/DropBehaviour.java     |  41 ++
 .../manipulation/DropBehaviourContainer.java    |  36 ++
 .../manipulation/DropColumnDefinition.java      |  37 ++
 .../manipulation/DropSchemaStatement.java       |  37 ++
 .../grammar/manipulation/DropStatement.java     |  41 ++
 .../DropTableConstraintDefinition.java          |  37 ++
 .../manipulation/DropTableOrViewStatement.java  |  39 ++
 .../grammar/manipulation/ObjectType.java        |  46 ++
 .../grammar/manipulation/SetColumnDefault.java  |  37 ++
 .../grammar/manipulation/package-info.java      |  23 +
 .../pgsql/PgSQLDropTableOrViewStatement.java    |  31 +
 .../manipulation/pgsql/package-info.java        |  23 +
 .../grammar/modification/ColumnSource.java      |  60 ++
 .../modification/ColumnSourceByQuery.java       |  39 ++
 .../modification/ColumnSourceByValues.java      |  42 ++
 .../grammar/modification/DeleteBySearch.java    |  45 ++
 .../grammar/modification/DeleteStatement.java   |  35 ++
 .../modification/DynamicColumnSource.java       |  40 ++
 .../grammar/modification/InsertStatement.java   |  48 ++
 .../grammar/modification/SetClause.java         |  46 ++
 .../grammar/modification/TargetTable.java       |  49 ++
 .../grammar/modification/UpdateBySearch.java    |  56 ++
 .../grammar/modification/UpdateSource.java      |  33 +
 .../modification/UpdateSourceByExpression.java  |  39 ++
 .../grammar/modification/UpdateStatement.java   |  35 ++
 .../grammar/modification/ValueSource.java       |  82 +++
 .../grammar/modification/package-info.java      |  23 +
 .../pgsql/PgSQLInsertStatement.java             |  45 ++
 .../modification/pgsql/package-info.java        |  23 +
 .../generator/grammar/query/AsteriskSelect.java |  31 +
 .../grammar/query/ColumnReference.java          |  35 ++
 .../query/ColumnReferenceByExpression.java      |  40 ++
 .../grammar/query/ColumnReferenceByName.java    |  44 ++
 .../grammar/query/ColumnReferences.java         |  79 +++
 .../grammar/query/CorrespondingSpec.java        |  40 ++
 .../sql/generator/grammar/query/FromClause.java |  43 ++
 .../generator/grammar/query/GroupByClause.java  |  40 ++
 .../grammar/query/GroupingElement.java          |  59 ++
 .../grammar/query/LimitSpecification.java       |  42 ++
 .../grammar/query/OffsetSpecification.java      |  41 ++
 .../generator/grammar/query/OrderByClause.java  |  40 ++
 .../sql/generator/grammar/query/Ordering.java   |  21 +
 .../grammar/query/OrdinaryGroupingSet.java      |  40 ++
 .../grammar/query/QueryExpression.java          |  42 ++
 .../grammar/query/QueryExpressionBody.java      |  61 ++
 .../query/QueryExpressionBodyActual.java        |  33 +
 .../query/QueryExpressionBodyBinary.java        |  71 +++
 .../grammar/query/QueryExpressionBodyQuery.java |  32 +
 .../grammar/query/QuerySpecification.java       |  95 +++
 .../generator/grammar/query/RowDefinition.java  |  35 ++
 .../generator/grammar/query/RowSubQuery.java    |  32 +
 .../grammar/query/RowValueConstructor.java      |  34 +
 .../grammar/query/SelectColumnClause.java       |  40 ++
 .../generator/grammar/query/SetOperation.java   |  44 ++
 .../grammar/query/SortSpecification.java        |  46 ++
 .../sql/generator/grammar/query/TableAlias.java |  47 ++
 .../generator/grammar/query/TableReference.java |  41 ++
 .../query/TableReferenceByExpression.java       |  39 ++
 .../grammar/query/TableReferenceByName.java     |  40 ++
 .../grammar/query/TableReferencePrimary.java    |  40 ++
 .../grammar/query/TableValueConstructor.java    |  33 +
 .../grammar/query/joins/CrossJoinedTable.java   |  30 +
 .../grammar/query/joins/JoinCondition.java      |  39 ++
 .../grammar/query/joins/JoinSpecification.java  |  35 ++
 .../generator/grammar/query/joins/JoinType.java |  49 ++
 .../grammar/query/joins/JoinedTable.java        |  50 ++
 .../grammar/query/joins/NamedColumnsJoin.java   |  40 ++
 .../grammar/query/joins/NaturalJoinedTable.java |  37 ++
 .../query/joins/QualifiedJoinedTable.java       |  45 ++
 .../grammar/query/joins/UnionJoinedTable.java   |  31 +
 .../grammar/query/joins/package-info.java       |  23 +
 .../generator/grammar/query/package-info.java   |  23 +
 .../generator/implementation/TypeableImpl.java  | 104 ++++
 .../booleans/AbstractBooleanExpression.java     |  40 ++
 .../grammar/booleans/BetweenPredicateImpl.java  |  53 ++
 .../grammar/booleans/BinaryPredicateImpl.java   |  65 ++
 .../grammar/booleans/BooleanTestImpl.java       |  82 +++
 .../grammar/booleans/BooleanUtils.java          |  49 ++
 .../booleans/ComposedBooleanExpressionImpl.java |  54 ++
 .../grammar/booleans/ConjunctionImpl.java       |  70 +++
 .../grammar/booleans/DisjunctionImpl.java       |  70 +++
 .../grammar/booleans/EqualsPredicateImpl.java   |  43 ++
 .../grammar/booleans/ExistsPredicateImpl.java   |  49 ++
 .../booleans/GreaterOrEqualPredicateImpl.java   |  44 ++
 .../booleans/GreaterThanPredicateImpl.java      |  44 ++
 .../grammar/booleans/InPredicateImpl.java       |  56 ++
 .../booleans/IsNotNullPredicateImpl.java        |  43 ++
 .../grammar/booleans/IsNullPredicateImpl.java   |  43 ++
 .../booleans/LessOrEqualPredicateImpl.java      |  44 ++
 .../grammar/booleans/LessThanPredicateImpl.java |  44 ++
 .../grammar/booleans/LikePredicateImpl.java     |  43 ++
 .../grammar/booleans/MultiPredicateImpl.java    |  79 +++
 .../grammar/booleans/NegationImpl.java          |  61 ++
 .../booleans/NotBetweenPredicateImpl.java       |  55 ++
 .../booleans/NotEqualsPredicateImpl.java        |  44 ++
 .../grammar/booleans/NotInPredicateImpl.java    |  57 ++
 .../grammar/booleans/NotLikePredicateImpl.java  |  43 ++
 .../booleans/NotRegexpPredicateImpl.java        |  44 ++
 .../grammar/booleans/RegexpPredicateImpl.java   |  43 ++
 .../grammar/booleans/UnaryPredicateImpl.java    |  56 ++
 .../grammar/booleans/UniquePredicateImpl.java   |  49 ++
 .../builders/booleans/BooleanBuilderImpl.java   |  83 +++
 .../builders/booleans/InBuilderImpl.java        |  69 +++
 .../ForeignKeyConstraintBuilderImpl.java        | 140 +++++
 .../definition/SchemaDefinitionBuilderImpl.java |  88 +++
 .../definition/TableDefinitionBuilderImpl.java  |  98 +++
 .../definition/TableElementListBuilderImpl.java |  61 ++
 .../definition/UniqueConstraintBuilderImpl.java |  83 +++
 .../definition/ViewDefinitionBuilderImpl.java   | 110 ++++
 .../ColumnSourceByValuesBuilderImpl.java        |  93 +++
 .../modification/DeleteBySearchBuilderImpl.java |  71 +++
 .../InsertStatementBuilderImpl.java             |  72 +++
 .../modification/UpdateBySearchBuilderImpl.java |  87 +++
 .../pgsql/PgSQLInsertStatementBuilderImpl.java  |  52 ++
 .../query/AbstractQueryFactoryImpl.java         |  84 +++
 .../builders/query/ColumnsBuilderImpl.java      | 113 ++++
 .../grammar/builders/query/FromBuilderImpl.java |  75 +++
 .../builders/query/GroupByBuilderImpl.java      |  70 +++
 .../builders/query/OrderByBuilderImpl.java      |  69 +++
 .../builders/query/QueryBuilderImpl.java        | 148 +++++
 .../query/QuerySpecificationBuilderImpl.java    | 238 +++++++
 .../builders/query/SimpleQueryBuilderImpl.java  | 262 ++++++++
 .../query/TableReferenceBuilderImpl.java        |  78 +++
 .../grammar/common/ColumnNameListImpl.java      |  80 +++
 .../common/NonBooleanExpressionImpl.java        |  38 ++
 .../grammar/common/SQLBuilderBase.java          |  43 ++
 .../grammar/common/SQLFactoryBase.java          |  53 ++
 .../grammar/common/SQLSyntaxElementBase.java    |  52 ++
 .../grammar/common/TableNameDirectImpl.java     |  58 ++
 .../grammar/common/TableNameFunctionImpl.java   |  60 ++
 .../grammar/common/TableNameImpl.java           |  52 ++
 .../grammar/common/datatypes/BigIntImpl.java    |  46 ++
 .../grammar/common/datatypes/DecimalImpl.java   |  74 +++
 .../common/datatypes/DoublePrecisionImpl.java   |  43 ++
 .../grammar/common/datatypes/NumericImpl.java   |  73 +++
 .../grammar/common/datatypes/RealImpl.java      |  43 ++
 .../common/datatypes/SQLBooleanImpl.java        |  47 ++
 .../grammar/common/datatypes/SQLCharImpl.java   |  69 +++
 .../grammar/common/datatypes/SQLDateImpl.java   |  43 ++
 .../grammar/common/datatypes/SQLFloatImpl.java  |  60 ++
 .../common/datatypes/SQLIntegerImpl.java        |  46 ++
 .../common/datatypes/SQLIntervalImpl.java       | 103 ++++
 .../grammar/common/datatypes/SQLTimeImpl.java   |  74 +++
 .../common/datatypes/SQLTimeStampImpl.java      |  76 +++
 .../grammar/common/datatypes/SmallIntImpl.java  |  46 ++
 .../common/datatypes/UserDefinedTypeImpl.java   |  57 ++
 .../common/datatypes/pgsql/TextImpl.java        |  47 ++
 .../definition/schema/SchemaDefinitionImpl.java |  85 +++
 .../definition/table/CheckConstraintImpl.java   |  61 ++
 .../definition/table/ColumnDefinitionImpl.java  |  99 +++
 .../table/ForeignKeyConstraintImpl.java         | 113 ++++
 .../definition/table/LikeClauseImpl.java        |  63 ++
 .../table/TableConstraintDefinitionImpl.java    |  83 +++
 .../definition/table/TableDefinitionImpl.java   |  99 +++
 .../definition/table/TableElementListImpl.java  |  65 ++
 .../definition/table/UniqueConstraintImpl.java  |  74 +++
 .../view/RegularViewSpecificationImpl.java      |  60 ++
 .../definition/view/ViewDefinitionImpl.java     | 108 ++++
 .../factories/AbstractBooleanFactory.java       |  51 ++
 .../factories/AbstractColumnsFactory.java       |  44 ++
 .../factories/AbstractDataTypeFactory.java      | 109 ++++
 .../factories/AbstractDefinitionFactory.java    |  90 +++
 .../factories/AbstractModificationFactory.java  |  52 ++
 .../grammar/factories/AbstractQueryFactory.java |  60 ++
 .../factories/AbstractTableRefFactory.java      |  71 +++
 .../factories/DefaultBooleanFactory.java        | 209 +++++++
 .../factories/DefaultColumnsFactory.java        |  71 +++
 .../factories/DefaultDataTypeFactory.java       | 235 +++++++
 .../factories/DefaultDefinitionFactory.java     | 122 ++++
 .../factories/DefaultLiteralFactory.java        |  85 +++
 .../factories/DefaultManipulationFactory.java   | 122 ++++
 .../factories/DefaultModificationFactory.java   |  98 +++
 .../grammar/factories/DefaultQueryFactory.java  | 156 +++++
 .../factories/DefaultTableRefFactory.java       | 103 ++++
 .../pgsql/PgSQLDataTypeFactoryImpl.java         |  45 ++
 .../pgsql/PgSQLManipulationFactoryImpl.java     |  56 ++
 .../pgsql/PgSQLModificationFactoryImpl.java     |  41 ++
 .../grammar/literals/DirectLiteralImpl.java     |  59 ++
 .../grammar/literals/NumericLiteralImpl.java    |  59 ++
 .../literals/SQLFunctionLiteralImpl.java        |  83 +++
 .../grammar/literals/StringLiteralImpl.java     |  60 ++
 .../grammar/literals/TimestampLiteralImpl.java  |  61 ++
 .../manipulation/AddColumnDefinitionImpl.java   |  63 ++
 .../AddTableConstraintDefinitionImpl.java       |  62 ++
 .../manipulation/AlterColumnDefinitionImpl.java |  69 +++
 .../manipulation/AlterTableStatementImpl.java   |  70 +++
 .../manipulation/DropColumnDefinitionImpl.java  |  70 +++
 .../manipulation/DropSchemaStatementImpl.java   |  61 ++
 .../grammar/manipulation/DropStatementImpl.java |  66 ++
 .../DropTableConstraintDefinitionImpl.java      |  73 +++
 .../DropTableOrViewStatementImpl.java           |  63 ++
 .../manipulation/SetColumnDefaultImpl.java      |  60 ++
 .../PgSQLDropTableOrViewStatementImpl.java      |  66 ++
 .../modification/ColumnSourceByQueryImpl.java   |  54 ++
 .../modification/ColumnSourceByValuesImpl.java  |  64 ++
 .../modification/DeleteBySearchImpl.java        |  72 +++
 .../modification/DynamicColumnSourceImpl.java   |  57 ++
 .../modification/InsertStatementImpl.java       |  70 +++
 .../grammar/modification/SetClauseImpl.java     |  70 +++
 .../grammar/modification/TargetTableImpl.java   |  72 +++
 .../modification/UpdateBySearchImpl.java        |  98 +++
 .../UpdateSourceByExpressionImpl.java           |  61 ++
 .../pgsql/PgSQLInsertStatementImpl.java         |  46 ++
 .../grammar/query/AsteriskSelectImpl.java       |  42 ++
 .../query/ColumnReferenceByExpressionImpl.java  |  58 ++
 .../query/ColumnReferenceByNameImpl.java        |  68 ++
 .../grammar/query/ColumnReferenceImpl.java      |  38 ++
 .../grammar/query/ColumnReferencesImpl.java     |  79 +++
 .../grammar/query/CorrespondingSpecImpl.java    |  60 ++
 .../grammar/query/FromClauseImpl.java           |  72 +++
 .../grammar/query/GroupByClauseImpl.java        |  61 ++
 .../grammar/query/LimitSpecificationImpl.java   |  59 ++
 .../grammar/query/OffsetSpecificationImpl.java  |  60 ++
 .../grammar/query/OrderByClauseImpl.java        |  62 ++
 .../grammar/query/OrdinaryGroupingSetImpl.java  |  73 +++
 .../query/QueryExpressionBodyBinaryImpl.java    | 105 ++++
 .../grammar/query/QueryExpressionBodyImpl.java  |  37 ++
 .../grammar/query/QueryExpressionImpl.java      |  60 ++
 .../grammar/query/QuerySpecificationImpl.java   | 130 ++++
 .../grammar/query/RowDefinitionImpl.java        |  63 ++
 .../grammar/query/RowSubQueryImpl.java          |  60 ++
 .../grammar/query/SelectColumnClauseImpl.java   |  56 ++
 .../grammar/query/SortSpecificationImpl.java    |  71 +++
 .../grammar/query/TableAliasImpl.java           |  68 ++
 .../query/TableReferenceByExpressionImpl.java   |  54 ++
 .../grammar/query/TableReferenceByNameImpl.java |  53 ++
 .../grammar/query/TableReferenceImpl.java       |  44 ++
 .../query/TableReferencePrimaryImpl.java        |  54 ++
 .../query/TableValueConstructorImpl.java        |  61 ++
 .../query/joins/CrossJoinedTableImpl.java       |  55 ++
 .../grammar/query/joins/JoinConditionImpl.java  |  59 ++
 .../query/joins/JoinSpecificationImpl.java      |  39 ++
 .../grammar/query/joins/JoinedTableImpl.java    |  70 +++
 .../query/joins/NamedColumnsJoinImpl.java       |  59 ++
 .../query/joins/NaturalJoinedTableImpl.java     |  67 ++
 .../query/joins/QualifiedJoinedTableImpl.java   |  78 +++
 .../query/joins/UnionJoinedTableImpl.java       |  55 ++
 .../transformation/AbstractProcessor.java       |  51 ++
 .../BooleanExpressionProcessing.java            | 289 +++++++++
 .../transformation/ColumnProcessing.java        |  95 +++
 .../transformation/ConstantProcessor.java       |  49 ++
 .../transformation/DataTypeProcessing.java      | 275 +++++++++
 .../transformation/DefaultSQLProcessor.java     | 571 +++++++++++++++++
 .../transformation/DefinitionProcessing.java    | 516 ++++++++++++++++
 .../LiteralExpressionProcessing.java            | 128 ++++
 .../transformation/ManipulationProcessing.java  | 230 +++++++
 .../transformation/ModificationProcessing.java  | 291 +++++++++
 .../transformation/NoOpProcessor.java           |  34 +
 .../transformation/ProcessorUtils.java          |  60 ++
 .../transformation/QueryProcessing.java         | 615 +++++++++++++++++++
 .../TableReferenceProcessing.java               | 354 +++++++++++
 .../transformation/derby/DerbyProcessor.java    |  32 +
 .../transformation/h2/H2Processor.java          |  33 +
 .../mysql/DefinitionProcessing.java             |  54 ++
 .../transformation/mysql/MySQLProcessor.java    |  81 +++
 .../transformation/mysql/QueryProcessing.java   | 114 ++++
 .../transformation/mysql/TableProcessing.java   |  52 ++
 .../transformation/package-info.java            |  23 +
 .../pgsql/DefinitionProcessing.java             |  90 +++
 .../pgsql/LiteralExpressionProcessing.java      |  40 ++
 .../pgsql/ManipulationProcessing.java           |  56 ++
 .../pgsql/ModificationProcessing.java           |  48 ++
 .../pgsql/PostgreSQLProcessor.java              | 132 ++++
 .../transformation/pgsql/QueryProcessing.java   |  81 +++
 .../transformation/spi/SQLProcessor.java        |  30 +
 .../spi/SQLProcessorAggregator.java             |  47 ++
 .../sqlite/DefinitionProcessing.java            | 141 +++++
 .../transformation/sqlite/SQLiteProcessor.java  |  82 +++
 .../implementation/vendor/DefaultVendor.java    | 254 ++++++++
 .../vendor/derby/DerbyVendorImpl.java           |  44 ++
 .../implementation/vendor/h2/H2VendorImpl.java  |  45 ++
 .../vendor/mysql/MySQLVendorImpl.java           |  61 ++
 .../vendor/pgsql/PostgreSQLVendorImpl.java      | 108 ++++
 .../vendor/sqlite/SQLiteVendorImpl.java         |  45 ++
 .../sql/generator/vendor/DerbyVendor.java       |  25 +
 .../library/sql/generator/vendor/H2Vendor.java  |  25 +
 .../sql/generator/vendor/MySQLVendor.java       |  53 ++
 .../sql/generator/vendor/PostgreSQLVendor.java  |  67 ++
 .../library/sql/generator/vendor/SQLVendor.java | 137 +++++
 .../sql/generator/vendor/SQLVendorProvider.java |  52 ++
 .../sql/generator/vendor/SQLiteVendor.java      |  25 +
 .../vendor/UnsupportedElementException.java     |  53 ++
 .../sql/generator/vendor/package-info.java      |  23 +
 ...ene.library.sql.generator.vendor.DerbyVendor |   1 +
 ...lygene.library.sql.generator.vendor.H2Vendor |   1 +
 ...ene.library.sql.generator.vendor.MySQLVendor |   1 +
 ...ibrary.sql.generator.vendor.PostgreSQLVendor |   1 +
 ...ygene.library.sql.generator.vendor.SQLVendor |   1 +
 ...ne.library.sql.generator.vendor.SQLiteVendor |   1 +
 .../generator/AbstractDataDefinitionTest.java   | 166 +++++
 .../sql/generator/AbstractModificationTest.java |  57 ++
 .../sql/generator/AbstractQueryTest.java        | 364 +++++++++++
 .../sql/generator/AbstractSQLSyntaxTest.java    |  62 ++
 .../generator/DefaultDataDefinitionTest.java    |  32 +
 .../sql/generator/DefaultModificationTest.java  |  29 +
 .../sql/generator/DefaultSQLQueryTest.java      |  32 +
 .../sql/generator/H2DataDefinitionTest.java     |  32 +
 .../sql/generator/H2ModificationTest.java       |  30 +
 .../library/sql/generator/H2QueryTest.java      |  32 +
 .../sql/generator/MySQLDataDefinitionTest.java  |  33 +
 .../sql/generator/MySQLModificationTest.java    |  30 +
 .../library/sql/generator/MySQLQueryTest.java   |  58 ++
 .../generator/PostgreSQLDataDefinitionTest.java |  31 +
 .../generator/PostgreSQLModificationTest.java   |  68 ++
 .../sql/generator/PostgreSQLQueryTest.java      |  57 ++
 .../sql/generator/SQLiteDataDefinitionTest.java |  30 +
 .../sql/generator/SQLiteModificationTest.java   |  30 +
 .../library/sql/generator/SQLiteQueryTest.java  |  30 +
 libraries/sql/build.gradle                      |   2 +-
 manual/src/docs/userguide/tools.txt             |   3 +-
 settings.gradle                                 |   1 +
 tools/envisage/src/docs/envisage.txt            |  55 --
 tools/generator-polygene/dev-status.xml         |  39 ++
 tools/src/docs/envisage.txt                     |  55 ++
 478 files changed, 30156 insertions(+), 229 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ValueInstantiationTests.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ValueInstantiationTests.java b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ValueInstantiationTests.java
index 666d3d1..b149220 100644
--- a/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ValueInstantiationTests.java
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ValueInstantiationTests.java
@@ -19,14 +19,14 @@
  */
 package org.apache.polygene.runtime.instantiation;
 
-import org.junit.Assert;
-import org.junit.Test;
 import org.apache.polygene.api.mixin.Mixins;
 import org.apache.polygene.api.value.ValueBuilder;
 import org.apache.polygene.api.value.ValueComposite;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Assert;
+import org.junit.Test;
 
 import static org.junit.Assert.fail;
 
@@ -41,7 +41,7 @@ public class ValueInstantiationTests
     }
 
     @Test
-    public void whenTryingToCreateValueFromNullTypeThenExpectNullArgumentException()
+    public void whenTryingToCreateValueFromNullTypeThenExpectNullPointerException()
         throws Exception
     {
         // valueBuilderFactory.newValueBuilder()

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/core/testsupport/src/main/java/org/apache/polygene/test/cache/AbstractCachePoolTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/cache/AbstractCachePoolTest.java b/core/testsupport/src/main/java/org/apache/polygene/test/cache/AbstractCachePoolTest.java
index 3d5120f..937c03a 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/cache/AbstractCachePoolTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/cache/AbstractCachePoolTest.java
@@ -21,12 +21,12 @@ package org.apache.polygene.test.cache;
 
 import java.util.Collection;
 import java.util.Random;
-import org.apache.polygene.test.AbstractPolygeneTest;
-import org.junit.Test;
 import org.apache.polygene.api.constraint.ConstraintViolation;
 import org.apache.polygene.api.constraint.ConstraintViolationException;
 import org.apache.polygene.spi.cache.Cache;
 import org.apache.polygene.spi.cache.CachePool;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
@@ -51,7 +51,7 @@ public abstract class AbstractCachePoolTest
     }
 
     @Test
-    public void givenInvalidCacheNameWhenFetchingCacheExpectNullArgumentException()
+    public void givenInvalidCacheNameWhenFetchingCacheExpectIllegalArgumentException()
     {
         try
         {
@@ -62,11 +62,15 @@ public abstract class AbstractCachePoolTest
         {
             // expected
         }
+    }
+
+    @Test
+    public void givenNullKeyWhenFetchingCacheExpectConstraintViolationException()
+    {
         try
         {
             cache = cachePool.fetchCache( null, String.class );
-            fail( "Expected " + NullPointerException.class.getSimpleName() );
-
+            fail( "Expected " + ConstraintViolationException.class.getSimpleName() );
         }
         catch( ConstraintViolationException e )
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/dependencies.gradle
----------------------------------------------------------------------
diff --git a/dependencies.gradle b/dependencies.gradle
index 22595b8..8e467f4 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -54,7 +54,6 @@ def groovyVersion = '2.4.10'
 def hazelcastVersion = '3.8'
 def httpClientVersion = '4.5.3'
 def jacksonVersion = '2.8.7'
-def javasqlgeneratorVersion = '0.3.2'
 def jaxbApiVersion = '2.2.12'
 def jcloudsVersion = '2.0.1'
 def jdbmVersion = '2.4'
@@ -97,8 +96,6 @@ dependencies.libraries << [
   hazelcast           : "com.hazelcast:hazelcast:$hazelcastVersion",
   http_client         : "org.apache.httpcomponents:httpclient:$httpClientVersion",
   jackson_mapper      : "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion",
-  javaSqlGenerator    : "org.java-sql-generator:org.java-sql-generator.api:$javasqlgeneratorVersion",
-  javaSqlGeneratorImpl: "org.java-sql-generator:org.java-sql-generator.implementation:$javasqlgeneratorVersion",
   jaxb_api            : "javax.xml.bind:jaxb-api:$jaxbApiVersion",
   jclouds_core        : "org.apache.jclouds:jclouds-core:$jcloudsVersion",
   jclouds_blobstore   : "org.apache.jclouds:jclouds-allblobstore:$jcloudsVersion",

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/build.gradle b/extensions/indexing-sql/build.gradle
index e0e50e8..e333730 100644
--- a/extensions/indexing-sql/build.gradle
+++ b/extensions/indexing-sql/build.gradle
@@ -27,12 +27,9 @@ jar { manifest { name = "Apache Polygene\u2122 Extension - Indexing - SQL" } }
 dependencies {
   api polygene.core.bootstrap
   api polygene.library( 'sql' )
+  api polygene.library( 'sql-generator' )
 
   implementation polygene.extension( 'reindexer' )
-  implementation libraries.javaSqlGenerator
-  implementation( libraries.javaSqlGeneratorImpl ) {
-    exclude group: 'junit'
-  }
 
   runtimeOnly polygene.core.runtime
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
index a9dcd0c..776c3c9 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/AbstractSQLIndexQueryAssembler.java
@@ -30,8 +30,8 @@ import org.apache.polygene.index.reindexer.ReindexerConfiguration;
 import org.apache.polygene.index.reindexer.ReindexerService;
 import org.apache.polygene.index.sql.SQLIndexingEngineConfiguration;
 import org.apache.polygene.index.sql.support.common.ReindexingStrategy;
-import org.sql.generation.api.vendor.SQLVendor;
-import org.sql.generation.api.vendor.SQLVendorProvider;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
 
 public abstract class AbstractSQLIndexQueryAssembler<AssemblerType>
     extends Assemblers.VisibilityIdentityConfig<AssemblerType>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/PostgreSQLIndexQueryAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/PostgreSQLIndexQueryAssembler.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/PostgreSQLIndexQueryAssembler.java
index ace0969..b5e8cc6 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/PostgreSQLIndexQueryAssembler.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/assembly/PostgreSQLIndexQueryAssembler.java
@@ -21,9 +21,9 @@ package org.apache.polygene.index.sql.assembly;
 
 import java.io.IOException;
 import org.apache.polygene.index.sql.support.postgresql.PostgreSQLService;
-import org.sql.generation.api.vendor.PostgreSQLVendor;
-import org.sql.generation.api.vendor.SQLVendor;
-import org.sql.generation.api.vendor.SQLVendorProvider;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
 
 public class PostgreSQLIndexQueryAssembler
     extends AbstractSQLIndexQueryAssembler<PostgreSQLIndexQueryAssembler>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/common/GenericDatabaseExplorer.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/common/GenericDatabaseExplorer.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/common/GenericDatabaseExplorer.java
index ea2493d..d6128fd 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/common/GenericDatabaseExplorer.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/common/GenericDatabaseExplorer.java
@@ -29,11 +29,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.query.IndexExporter;
-import org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder;
-import org.sql.generation.api.grammar.factories.QueryFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.vendor.SQLVendor;
 
 /**
  * This is a helper class to traverse through all content in specified tables in database. Typical usecase would be by
@@ -41,7 +41,7 @@ import org.sql.generation.api.vendor.SQLVendor;
  */
 public final class GenericDatabaseExplorer
 {
-    public static enum IntegrityActions
+    public enum IntegrityActions
     {
         CASCADE,
         NO_ACTION,
@@ -50,7 +50,7 @@ public final class GenericDatabaseExplorer
         SET_NULL
     }
 
-    public static enum Deferrability
+    public enum Deferrability
     {
         INITIALLY_DEFERRED,
         INITIALLY_IMMEDIATE,
@@ -207,33 +207,33 @@ public final class GenericDatabaseExplorer
 
     }
 
-    public static interface DatabaseProcessor
+    public interface DatabaseProcessor
     {
-        public void beginProcessSchemaInfo( String schemaName );
+        void beginProcessSchemaInfo( String schemaName );
 
-        public void endProcessSchemaInfo( String schemaName );
+        void endProcessSchemaInfo( String schemaName );
 
-        public void beginProcessTableInfo( String schemaName, String tableName, String remarks );
+        void beginProcessTableInfo( String schemaName, String tableName, String remarks );
 
-        public void endProcessTableInfo( String schemaName, String tableName, String remarks );
+        void endProcessTableInfo( String schemaName, String tableName, String remarks );
 
-        public void beginProcessColumns( String schemaName, String tableName, String tableRemarks );
+        void beginProcessColumns( String schemaName, String tableName, String tableRemarks );
 
-        public void beginProcessColumnInfo( String schemaName, String tableName,
-                                            ColumnInfo colInfo, ForeignKeyInfo fkInfo );
+        void beginProcessColumnInfo( String schemaName, String tableName,
+                                     ColumnInfo colInfo, ForeignKeyInfo fkInfo );
 
-        public void endProcessColumnInfo( String schemaName, String tableName,
-                                          ColumnInfo colInfo, ForeignKeyInfo fkInfo );
+        void endProcessColumnInfo( String schemaName, String tableName,
+                                   ColumnInfo colInfo, ForeignKeyInfo fkInfo );
 
-        public void endProcessColumns( String schemaName, String tableName, String tableRemarks );
+        void endProcessColumns( String schemaName, String tableName, String tableRemarks );
 
-        public void beginProcessRows( String schemaName, String tableName, String tableRemarks );
+        void beginProcessRows( String schemaName, String tableName, String tableRemarks );
 
-        public void beginProcessRowInfo( String schemaName, String tableName, Object[] rowContents );
+        void beginProcessRowInfo( String schemaName, String tableName, Object[] rowContents );
 
-        public void endProcessRowInfo( String schemaName, String tableName, Object[] rowContents );
+        void endProcessRowInfo( String schemaName, String tableName, Object[] rowContents );
 
-        public void endProcessRows( String schemaName, String tableName, String tableRemarks );
+        void endProcessRows( String schemaName, String tableName, String tableRemarks );
     }
 
     public static abstract class DatabaseProcessorAdapter

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLAppStartup.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLAppStartup.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLAppStartup.java
index e2b3d71..ef6e746 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLAppStartup.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLAppStartup.java
@@ -27,13 +27,13 @@ import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.index.sql.support.skeletons.AbstractSQLStartup;
 import org.apache.polygene.library.sql.common.SQLUtil;
-import org.sql.generation.api.grammar.common.datatypes.SQLDataType;
-import org.sql.generation.api.grammar.definition.table.TableScope;
-import org.sql.generation.api.grammar.definition.table.pgsql.PgSQLTableCommitAction;
-import org.sql.generation.api.grammar.factories.DataTypeFactory;
-import org.sql.generation.api.grammar.factories.DefinitionFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableScope;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.pgsql.PgSQLTableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
 
 public class PostgreSQLAppStartup
     extends AbstractSQLStartup

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexExporter.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexExporter.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexExporter.java
index 9e80309..2dd7408 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexExporter.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexExporter.java
@@ -38,8 +38,8 @@ import org.apache.polygene.index.sql.support.common.GenericDatabaseExplorer.Data
 import org.apache.polygene.index.sql.support.common.GenericDatabaseExplorer.ForeignKeyInfo;
 import org.apache.polygene.index.sql.support.skeletons.SQLDBState;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.query.IndexExporter;
-import org.sql.generation.api.vendor.SQLVendor;
 
 public class PostgreSQLIndexExporter
     implements IndexExporter

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexing.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexing.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexing.java
index 06aca9e..ec39e99 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexing.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLIndexing.java
@@ -26,16 +26,16 @@ import java.sql.SQLException;
 import org.apache.polygene.index.sql.support.common.DBNames;
 import org.apache.polygene.index.sql.support.skeletons.AbstractSQLIndexing;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.ColumnSourceByValuesBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql.PgSQLInsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.ValueSource;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.entity.EntityState;
-import org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder;
-import org.sql.generation.api.grammar.builders.modification.pgsql.PgSQLInsertStatementBuilder;
-import org.sql.generation.api.grammar.factories.ColumnsFactory;
-import org.sql.generation.api.grammar.factories.LiteralFactory;
-import org.sql.generation.api.grammar.factories.ModificationFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.grammar.modification.InsertStatement;
-import org.sql.generation.api.grammar.modification.ValueSource;
-import org.sql.generation.api.vendor.SQLVendor;
 
 public class PostgreSQLIndexing
     extends AbstractSQLIndexing

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLQuerying.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLQuerying.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLQuerying.java
index 6e4723a..939c718 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLQuerying.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/postgresql/PostgreSQLQuerying.java
@@ -25,9 +25,9 @@ import java.util.function.Predicate;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.query.grammar.OrderBy;
 import org.apache.polygene.index.sql.support.skeletons.AbstractSQLQuerying;
-import org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder;
-import org.sql.generation.api.grammar.query.QueryExpression;
-import org.sql.generation.api.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 
 public class PostgreSQLQuerying
         extends AbstractSQLQuerying

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java
index 9459941..47e0503 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLIndexing.java
@@ -55,26 +55,26 @@ import org.apache.polygene.index.sql.support.common.QNameInfo.QNameType;
 import org.apache.polygene.index.sql.support.postgresql.PostgreSQLTypeHelper;
 import org.apache.polygene.index.sql.support.skeletons.SQLSkeletonUtil.Lazy;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.ColumnSourceByValuesBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.DeleteBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.UpdateBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.PolygeneSPI;
 import org.apache.polygene.spi.entity.EntityState;
 import org.apache.polygene.spi.entity.EntityStatus;
 import org.apache.polygene.spi.entitystore.EntityStoreException;
-import org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder;
-import org.sql.generation.api.grammar.builders.modification.DeleteBySearchBuilder;
-import org.sql.generation.api.grammar.builders.modification.UpdateBySearchBuilder;
-import org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder;
-import org.sql.generation.api.grammar.factories.BooleanFactory;
-import org.sql.generation.api.grammar.factories.ColumnsFactory;
-import org.sql.generation.api.grammar.factories.LiteralFactory;
-import org.sql.generation.api.grammar.factories.ModificationFactory;
-import org.sql.generation.api.grammar.factories.QueryFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.grammar.modification.DeleteStatement;
-import org.sql.generation.api.grammar.modification.InsertStatement;
-import org.sql.generation.api.grammar.modification.UpdateSourceByExpression;
-import org.sql.generation.api.grammar.modification.UpdateStatement;
-import org.sql.generation.api.grammar.query.QueryExpression;
-import org.sql.generation.api.vendor.SQLVendor;
 
 import static org.apache.polygene.index.sql.support.common.DBNames.ENTITY_TABLE_NAME;
 import static org.apache.polygene.index.sql.support.common.DBNames.ENTITY_TYPES_JOIN_TABLE_NAME;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLQuerying.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLQuerying.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLQuerying.java
index 331e034..1e8d0c0 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLQuerying.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLQuerying.java
@@ -36,7 +36,6 @@ import org.apache.polygene.api.common.QualifiedName;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.entity.EntityComposite;
 import org.apache.polygene.api.identity.HasIdentity;
-import org.apache.polygene.api.identity.Identity;
 import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
@@ -71,33 +70,33 @@ import org.apache.polygene.index.sql.support.api.SQLQuerying;
 import org.apache.polygene.index.sql.support.common.DBNames;
 import org.apache.polygene.index.sql.support.common.QNameInfo;
 import org.apache.polygene.index.sql.support.postgresql.PostgreSQLTypeHelper;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.InBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.GroupByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLFunctions;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.PolygeneSPI;
 import org.apache.polygene.spi.query.EntityFinderException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sql.generation.api.grammar.booleans.BooleanExpression;
-import org.sql.generation.api.grammar.builders.booleans.BooleanBuilder;
-import org.sql.generation.api.grammar.builders.booleans.InBuilder;
-import org.sql.generation.api.grammar.builders.query.GroupByBuilder;
-import org.sql.generation.api.grammar.builders.query.QueryBuilder;
-import org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder;
-import org.sql.generation.api.grammar.builders.query.TableReferenceBuilder;
-import org.sql.generation.api.grammar.common.NonBooleanExpression;
-import org.sql.generation.api.grammar.common.SQLFunctions;
-import org.sql.generation.api.grammar.common.SetQuantifier;
-import org.sql.generation.api.grammar.factories.BooleanFactory;
-import org.sql.generation.api.grammar.factories.ColumnsFactory;
-import org.sql.generation.api.grammar.factories.LiteralFactory;
-import org.sql.generation.api.grammar.factories.QueryFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.grammar.query.ColumnReference;
-import org.sql.generation.api.grammar.query.ColumnReferenceByName;
-import org.sql.generation.api.grammar.query.Ordering;
-import org.sql.generation.api.grammar.query.QueryExpression;
-import org.sql.generation.api.grammar.query.QuerySpecification;
-import org.sql.generation.api.grammar.query.TableReferenceByName;
-import org.sql.generation.api.grammar.query.joins.JoinType;
-import org.sql.generation.api.vendor.SQLVendor;
 
 public abstract class AbstractSQLQuerying
     implements SQLQuerying
@@ -190,26 +189,26 @@ public abstract class AbstractSQLQuerying
         }
     }
 
-    public static interface SQLBooleanCreator
+    public interface SQLBooleanCreator
     {
-        public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+        BooleanExpression getExpression(
             BooleanFactory factory,
             NonBooleanExpression left, NonBooleanExpression right
-        );
+                                       );
     }
 
-    private static interface BooleanExpressionProcessor
+    private interface BooleanExpressionProcessor
     {
-        public QueryBuilder processBooleanExpression(
+        QueryBuilder processBooleanExpression(
             AbstractSQLQuerying thisObject,
             Predicate<Composite> expression,
             Boolean negationActive,
             SQLVendor vendor,
-            org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+            BooleanExpression entityTypeCondition,
             Map<String, Object> variables,
             List<Object> values,
             List<Integer> valueSQLTypes
-        );
+                                             );
     }
 
     private static final Map<Class<? extends Predicate>, SQLBooleanCreator> SQL_OPERATORS;
@@ -232,10 +231,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( EqPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.eq( left, right );
             }
@@ -243,10 +242,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( GePredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.geq( left, right );
             }
@@ -254,10 +253,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( GtPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.gt( left, right );
             }
@@ -265,10 +264,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( LePredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.leq( left, right );
             }
@@ -276,10 +275,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( LtPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.lt( left, right );
             }
@@ -287,10 +286,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( ManyAssociationContainsPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.eq( left, right );
             }
@@ -298,10 +297,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( MatchesPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.regexp( left, right );
             }
@@ -309,10 +308,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( ContainsPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.eq( left, right );
             }
@@ -320,10 +319,10 @@ public abstract class AbstractSQLQuerying
         SQL_OPERATORS.put( ContainsAllPredicate.class, new SQLBooleanCreator()
         {
             @Override
-            public org.sql.generation.api.grammar.booleans.BooleanExpression getExpression(
+            public BooleanExpression getExpression(
                 BooleanFactory factory,
                 NonBooleanExpression left, NonBooleanExpression right
-            )
+                                                  )
             {
                 return factory.eq( left, right );
             }
@@ -605,10 +604,10 @@ public abstract class AbstractSQLQuerying
 
     private interface WhereClauseProcessor
     {
-        public void processWhereClause( QuerySpecificationBuilder builder,
-                                        BooleanBuilder afterWhere,
-                                        JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex
-        );
+        void processWhereClause( QuerySpecificationBuilder builder,
+                                 BooleanBuilder afterWhere,
+                                 JoinType joinStyle, Integer firstTableIndex, Integer lastTableIndex
+                               );
     }
 
     private static class PropertyNullWhereClauseProcessor
@@ -825,10 +824,10 @@ public abstract class AbstractSQLQuerying
         return result;
     }
 
-    protected org.sql.generation.api.grammar.booleans.BooleanExpression createTypeCondition(
+    protected BooleanExpression createTypeCondition(
         Class<?> resultType,
         SQLVendor vendor
-    )
+                                                   )
     {
         BooleanFactory b = vendor.getBooleanFactory();
         LiteralFactory l = vendor.getLiteralFactory();
@@ -862,7 +861,7 @@ public abstract class AbstractSQLQuerying
         Predicate<Composite> expression,
         Boolean negationActive,
         SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         Map<String, Object> variables,
         List<Object> values,
         List<Integer> valueSQLTypes
@@ -895,7 +894,7 @@ public abstract class AbstractSQLQuerying
 
     protected QuerySpecificationBuilder selectAllEntitiesOfCorrectType(
         SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition
+        BooleanExpression entityTypeCondition
     )
     {
         TableReferenceFactory t = vendor.getTableReferenceFactory();
@@ -918,7 +917,7 @@ public abstract class AbstractSQLQuerying
         final MatchesPredicate predicate,
         final Boolean negationActive,
         final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         final Map<String, Object> variables, final List<Object> values,
         final List<Integer> valueSQLTypes
     )
@@ -964,7 +963,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processComparisonPredicate(
         final ComparisonPredicate<?> predicate,
         final Boolean negationActive, final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         final Map<String, Object> variables,
         final List<Object> values, final List<Integer> valueSQLTypes
     )
@@ -1018,7 +1017,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processManyAssociationContainsPredicate(
         final ManyAssociationContainsPredicate<?> predicate, final Boolean negationActive,
         final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         Map<String, Object> variables,
         final List<Object> values, final List<Integer> valueSQLTypes
     )
@@ -1073,7 +1072,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processPropertyNullPredicate(
         final PropertyNullPredicate<?> predicate,
         final Boolean negationActive, final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition
+        BooleanExpression entityTypeCondition
     )
     {
         return this.singleQuery(
@@ -1091,7 +1090,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processPropertyNotNullPredicate(
         PropertyNotNullPredicate<?> predicate,
         boolean negationActive, SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition
+        BooleanExpression entityTypeCondition
     )
     {
         return this.singleQuery(
@@ -1109,7 +1108,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processAssociationNullPredicate(
         final AssociationNullPredicate<?> predicate,
         final Boolean negationActive, final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition
+        BooleanExpression entityTypeCondition
     )
     {
         return this.singleQuery(
@@ -1127,7 +1126,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processAssociationNotNullPredicate(
         final AssociationNotNullPredicate<?> predicate,
         final Boolean negationActive, final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition
+        BooleanExpression entityTypeCondition
     )
     {
         return this.singleQuery(
@@ -1145,7 +1144,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processContainsPredicate(
         final ContainsPredicate<?> predicate,
         final Boolean negationActive, final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         final Map<String, Object> variables,
         final List<Object> values, final List<Integer> valueSQLTypes
     )
@@ -1205,7 +1204,7 @@ public abstract class AbstractSQLQuerying
 
     protected QueryBuilder finalizeContainsQuery(
         SQLVendor vendor, QuerySpecification contains,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         Boolean negationActive
     )
     {
@@ -1230,7 +1229,7 @@ public abstract class AbstractSQLQuerying
     protected QueryBuilder processContainsAllPredicate(
         final ContainsAllPredicate<?> predicate, final Boolean negationActive,
         final SQLVendor vendor,
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition,
+        BooleanExpression entityTypeCondition,
         final Map<String, Object> variables, final List<Object> values,
         final List<Integer> valueSQLTypes
     )
@@ -1305,7 +1304,7 @@ public abstract class AbstractSQLQuerying
         Boolean includeLastAssoPathTable, //
         Boolean negationActive, //
         SQLVendor vendor, //
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, //
+        BooleanExpression entityTypeCondition, //
         WhereClauseProcessor whereClauseGenerator//
     )
     {
@@ -1322,7 +1321,7 @@ public abstract class AbstractSQLQuerying
         Boolean includeLastAssoPathTable, //
         Boolean negationActive, //
         SQLVendor vendor, //
-        org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, //
+        BooleanExpression entityTypeCondition, //
         WhereClauseProcessor whereClauseGenerator//
     )
     {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
index 1df5642..e2d2cc6 100644
--- a/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
+++ b/extensions/indexing-sql/src/main/java/org/apache/polygene/index/sql/support/skeletons/AbstractSQLStartup.java
@@ -48,7 +48,6 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
-import javax.annotation.PostConstruct;
 import javax.sql.DataSource;
 import org.apache.polygene.api.common.Optional;
 import org.apache.polygene.api.common.QualifiedName;
@@ -78,27 +77,27 @@ import org.apache.polygene.index.sql.support.common.RebuildingStrategy;
 import org.apache.polygene.index.sql.support.common.ReindexingStrategy;
 import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableElementListBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
 import org.apache.polygene.spi.entitystore.EntityStoreException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sql.generation.api.grammar.builders.definition.TableElementListBuilder;
-import org.sql.generation.api.grammar.common.datatypes.SQLDataType;
-import org.sql.generation.api.grammar.definition.table.AutoGenerationPolicy;
-import org.sql.generation.api.grammar.definition.table.ConstraintCharacteristics;
-import org.sql.generation.api.grammar.definition.table.ReferentialAction;
-import org.sql.generation.api.grammar.definition.table.UniqueSpecification;
-import org.sql.generation.api.grammar.factories.DataTypeFactory;
-import org.sql.generation.api.grammar.factories.DefinitionFactory;
-import org.sql.generation.api.grammar.factories.LiteralFactory;
-import org.sql.generation.api.grammar.factories.ModificationFactory;
-import org.sql.generation.api.grammar.factories.QueryFactory;
-import org.sql.generation.api.grammar.factories.TableReferenceFactory;
-import org.sql.generation.api.grammar.manipulation.DropBehaviour;
-import org.sql.generation.api.grammar.manipulation.ObjectType;
-import org.sql.generation.api.grammar.modification.DeleteBySearch;
-import org.sql.generation.api.grammar.modification.InsertStatement;
-import org.sql.generation.api.grammar.query.QueryExpression;
-import org.sql.generation.api.vendor.SQLVendor;
 
 import static org.apache.polygene.index.sql.support.common.DBNames.ALL_QNAMES_TABLE_NAME;
 import static org.apache.polygene.index.sql.support.common.DBNames.ALL_QNAMES_TABLE_PK_COLUMN_NAME;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java b/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
index e7971dc..58869a6 100644
--- a/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
+++ b/extensions/indexing-sql/src/test/java/org/apache/polygene/index/sql/postgresql/PostgreSQLDBIntegrityTest.java
@@ -31,16 +31,15 @@ import org.apache.polygene.index.sql.assembly.PostgreSQLIndexQueryAssembler;
 import org.apache.polygene.index.sql.support.common.DBNames;
 import org.apache.polygene.index.sql.support.common.GenericDatabaseExplorer;
 import org.apache.polygene.index.sql.support.common.GenericDatabaseExplorer.DatabaseProcessorAdapter;
-import org.apache.polygene.index.sql.support.postgresql.PostgreSQLAppStartup;
-import org.apache.polygene.test.internal.DockerRule;
 import org.apache.polygene.library.sql.common.SQLConfiguration;
 import org.apache.polygene.library.sql.common.SQLUtil;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendorProvider;
 import org.apache.polygene.test.AbstractPolygeneTest;
+import org.apache.polygene.test.internal.DockerRule;
 import org.junit.Assert;
 import org.junit.ClassRule;
 import org.junit.Test;
-import org.sql.generation.api.vendor.PostgreSQLVendor;
-import org.sql.generation.api.vendor.SQLVendorProvider;
 
 public class PostgreSQLDBIntegrityTest
     extends AbstractPolygeneTest
@@ -48,14 +47,14 @@ public class PostgreSQLDBIntegrityTest
     @ClassRule
     public static final DockerRule DOCKER = new DockerRule( "postgres", 3000L, "PostgreSQL init process complete; ready for start up." );
 
-    public static interface TestEntity
+    public interface TestEntity
         extends EntityComposite
     {
         @UseDefaults
-        public Property<String> testString();
+        Property<String> testString();
 
         @UseDefaults
-        public Property<Integer> testInt();
+        Property<Integer> testInt();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/Typeable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/Typeable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/Typeable.java
new file mode 100644
index 0000000..40988a5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/Typeable.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * The {@link Object#getClass()} method returns the actual class of the object. Sometimes, that is not what is wanted;
+ * instead it would be good to know which API interface the object implements. Let's say we have a API interface
+ * hierarchy, and we know that each object implements only one specific interface (it may implement more, but all others
+ * must be then super-interface of the actual implemented one). Then we have a mapping from types of interfaces to some
+ * other things, like algorithms or some other functionality. We can not use {@link Map#get(Object)} or
+ * {@link Map#containsKey(Object)} methods for the result of {@link Object#getClass()}, since we would much rather use
+ * API interfaces than actual implementing classes as keys. And because of that, each time, we need to iterate through
+ * whole map, and check for each key that whether the specified object is instance of this key. In other words, quite
+ * inefficient.
+ * </p>
+ * <p>
+ * <p>
+ * This is when this interface comes to aid. It provides a method returning an API interface/class, which is implemented
+ * by the implementation. Then one can use the {@link Map#get(Object)} and {@link Map#containsKey(Object)} methods in
+ * order to retrieve the object associated with specific API interface, without the need to iterate through whole map.
+ * </p>
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Typeable<BaseType>
+{
+
+    /**
+     * Returns the API interface/class, which is implemented by this object.
+     *
+     * @return The API interface/class, which is implemented by this object.
+     */
+    Class<? extends BaseType> getImplementedType();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BetweenPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BetweenPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BetweenPredicate.java
new file mode 100644
index 0000000..15ca4be
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BetweenPredicate.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * The interface for syntax element representing SQL expression {@code BETWEEN }x {@code AND} y.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BetweenPredicate
+    extends MultiPredicate
+{
+
+    /**
+     * Returns the minimum value (the expression on the left side of {@code AND}).
+     *
+     * @return The minimum value.
+     */
+    NonBooleanExpression getMinimum();
+
+    /**
+     * Returns the maxmimum value (the expression on the right side of {@code AND}).
+     *
+     * @return The maximum value.
+     */
+    NonBooleanExpression getMaximum();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BinaryPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BinaryPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BinaryPredicate.java
new file mode 100644
index 0000000..64a8edc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BinaryPredicate.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * A common interface for all boolean expressions taking two value expressions and having some operator between them.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BinaryPredicate
+    extends Predicate
+{
+
+    /**
+     * Returns the expression on the left side of the operator.
+     *
+     * @return The expression on the left side of the operator.
+     */
+    NonBooleanExpression getLeft();
+
+    /**
+     * Returns the expression on the right side of the operator.
+     *
+     * @return The expression on the right side of the operator.
+     */
+    NonBooleanExpression getRight();
+}


[12/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowSubQuery.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowSubQuery.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowSubQuery.java
new file mode 100644
index 0000000..7b1628f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowSubQuery.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This syntax element represents subquery in {@code VALUES} expression in query.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface RowSubQuery
+    extends RowValueConstructor
+{
+
+    QueryExpression getQueryExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowValueConstructor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowValueConstructor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowValueConstructor.java
new file mode 100644
index 0000000..89827b9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowValueConstructor.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This syntax elements represents either subquery or parenthesized row definition of {@code VALUES} expression in
+ * query.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface RowValueConstructor
+    extends Typeable<RowValueConstructor>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SelectColumnClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SelectColumnClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SelectColumnClause.java
new file mode 100644
index 0000000..1b111e3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SelectColumnClause.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+
+/**
+ * This is common interface for columns of {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SelectColumnClause
+    extends Typeable<SelectColumnClause>
+{
+    /**
+     * Returns the set quantifier for the columns of {@code SELECT} statement.
+     *
+     * @return The set quantifier for the columns of {@code SELECT} statement.
+     * @see SetQuantifier
+     */
+    SetQuantifier getSetQuantifier();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SetOperation.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SetOperation.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SetOperation.java
new file mode 100644
index 0000000..259eec2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SetOperation.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This enum represents the possible set operations to combine queries with. These set operations are {@link #UNION},
+ * {@link #INTERSECT}, and {@link #EXCEPT}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class SetOperation
+{
+    /**
+     * The {@code UNION} between two queries.
+     */
+    public static final SetOperation UNION = new SetOperation();
+
+    /**
+     * The {@code INTERSECT} between two queries.
+     */
+    public static final SetOperation INTERSECT = new SetOperation();
+
+    /**
+     * The set difference ({@code EXCEPT}) between two queries.
+     */
+    public static final SetOperation EXCEPT = new SetOperation();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SortSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SortSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SortSpecification.java
new file mode 100644
index 0000000..2a59780
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/SortSpecification.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * This syntax element represents the sort specification used in {@code ORDER BY} clause.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SortSpecification
+    extends Typeable<SortSpecification>
+{
+    /**
+     * Returns the {@link Ordering} of this sort specification.
+     *
+     * @return The {@link Ordering} of this sort specification.
+     */
+    Ordering getOrderingSpecification();
+
+    /**
+     * The value expression, which may be a column reference, for example.
+     *
+     * @return The value expression of this sort specification.
+     */
+    ValueExpression getValueExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableAlias.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableAlias.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableAlias.java
new file mode 100644
index 0000000..3d85359
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableAlias.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * This syntax element represents the alias for a table. Table alias may have additional list of column aliases.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableAlias
+    extends Typeable<TableAlias>
+{
+
+    /**
+     * Returns an alias for a table name.
+     *
+     * @return The alias for the table name.
+     */
+    String getTableAlias();
+
+    /**
+     * Returns aliases for columns in the original table.
+     *
+     * @return Aliases for columns in the original table. May be {@code null}.
+     */
+    ColumnNameList getColumnAliases();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReference.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReference.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReference.java
new file mode 100644
index 0000000..90998a6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReference.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinedTable;
+
+/**
+ * This is common interface for all table references in {@code FROM} clause.
+ *
+ * @author Stanislav Muhametsin
+ * @see FromClause
+ * @see TableReferencePrimary
+ * @see JoinedTable
+ */
+public interface TableReference
+{
+    /**
+     * Helper method to cast this object into {@link Typeable}.
+     *
+     * @return This object.
+     */
+    Typeable<?> asTypeable();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByExpression.java
new file mode 100644
index 0000000..403c7a6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByExpression.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This syntax element represents the sub-query which acts as a table in {@code FROM} clause.
+ *
+ * @author Stanislav Muhametsin
+ * @see FromClause
+ * @see QueryExpression
+ */
+public interface TableReferenceByExpression
+    extends TableReferencePrimary
+{
+
+    /**
+     * Returns the query to use.
+     *
+     * @return The query to use.
+     */
+    QueryExpression getQuery();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByName.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByName.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByName.java
new file mode 100644
index 0000000..432e982
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferenceByName.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+
+/**
+ * This syntax element represents the reference to a table in {@code FROM} clause.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableName
+ */
+public interface TableReferenceByName
+    extends TableReferencePrimary
+{
+    /**
+     * Returns the table name.
+     *
+     * @return The table name.
+     * @see TableName
+     */
+    TableName getTableName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferencePrimary.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferencePrimary.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferencePrimary.java
new file mode 100644
index 0000000..aa71ad8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableReferencePrimary.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for non-joined table references.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableReferencePrimary
+    extends TableReference, Typeable<TableReferencePrimary>
+{
+
+    /**
+     * Returns the alias for this table.
+     *
+     * @return The alias for this table.
+     * @see TableAlias
+     */
+    TableAlias getTableAlias();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableValueConstructor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableValueConstructor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableValueConstructor.java
new file mode 100644
index 0000000..5f5a967
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/TableValueConstructor.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+
+/**
+ * This syntax element represents the {@code VALUES} expression in query.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableValueConstructor
+    extends QueryExpressionBodyActual
+{
+    List<RowValueConstructor> getRows();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/CrossJoinedTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/CrossJoinedTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/CrossJoinedTable.java
new file mode 100644
index 0000000..2be150a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/CrossJoinedTable.java
@@ -0,0 +1,30 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+/**
+ * This syntax element represents the cross join ({@code CROSS JOIN} between two tables.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface CrossJoinedTable
+    extends JoinedTable
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinCondition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinCondition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinCondition.java
new file mode 100644
index 0000000..caab8cb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinCondition.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+
+/**
+ * This syntax element represents the join condition, used in {@link QualifiedJoinedTable}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface JoinCondition
+    extends JoinSpecification
+{
+
+    /**
+     * Returns the join condition for the {@link QualifiedJoinedTable}.
+     *
+     * @return The join condition for the {@link QualifiedJoinedTable}.
+     */
+    BooleanExpression getSearchConidition();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinSpecification.java
new file mode 100644
index 0000000..b13dcc4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinSpecification.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for join specification used in {@link QualifiedJoinedTable}.
+ *
+ * @author Stanislav Muhametsin
+ * @see JoinCondition
+ * @see NamedColumnsJoin
+ */
+public interface JoinSpecification
+    extends Typeable<JoinSpecification>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinType.java
new file mode 100644
index 0000000..cfbd3ac
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinType.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+/**
+ * This enum represents the join type, used in {@link QualifiedJoinedTable} and {@link NaturalJoinedTable}. Is one of
+ * {@link #INNER}, {@link #LEFT_OUTER}, {@link #RIGHT_OUTER}, or {@link #FULL_OUTER}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class JoinType
+{
+    /**
+     * The {@code INNER} join, typically default.
+     */
+    public static final JoinType INNER = new JoinType();
+
+    /**
+     * The {@code LEFT OUTER} join.
+     */
+    public static final JoinType LEFT_OUTER = new JoinType();
+
+    /**
+     * The {@code RIGHT OUTER} join.
+     */
+    public static final JoinType RIGHT_OUTER = new JoinType();
+
+    /**
+     * The {@code FULL OUTER} join.
+     */
+    public static final JoinType FULL_OUTER = new JoinType();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinedTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinedTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinedTable.java
new file mode 100644
index 0000000..ddc1300
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/JoinedTable.java
@@ -0,0 +1,50 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+
+/**
+ * This is common interface for joined tables.
+ *
+ * @author Stanislav Muhametsin
+ * @see CrossJoinedTable
+ * @see NaturalJoinedTable
+ * @see QualifiedJoinedTable
+ * @see UnionJoinedTable
+ */
+public interface JoinedTable
+    extends QueryExpressionBody, TableReference
+{
+    /**
+     * Returns the table on the left side of the join.
+     *
+     * @return The table on the left side of the join.
+     */
+    TableReference getLeft();
+
+    /**
+     * Gets the table on the right side of the join.
+     *
+     * @return The table on the right side of the join.
+     */
+    TableReference getRight();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NamedColumnsJoin.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NamedColumnsJoin.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NamedColumnsJoin.java
new file mode 100644
index 0000000..a018ce1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NamedColumnsJoin.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * This syntax element represents the join based on same-named columns in two tables having same value. Used in
+ * {@link QualifiedJoinedTable}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NamedColumnsJoin
+    extends JoinSpecification
+{
+
+    /**
+     * Returns the column names. Might be {@code null}.
+     *
+     * @return The column names. Might be {@code null}.
+     */
+    ColumnNameList getColumnNames();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NaturalJoinedTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NaturalJoinedTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NaturalJoinedTable.java
new file mode 100644
index 0000000..064aba1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/NaturalJoinedTable.java
@@ -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.polygene.library.sql.generator.grammar.query.joins;
+
+/**
+ * This syntax element represents the {@code NATURAL JOIN} between two tables.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NaturalJoinedTable
+    extends JoinedTable
+{
+
+    /**
+     * Returns the join type for this {@code NATURAL JOIN}.
+     *
+     * @return The join type for this {@code NATURAL JOIN}.
+     */
+    JoinType getJoinType();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/QualifiedJoinedTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/QualifiedJoinedTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/QualifiedJoinedTable.java
new file mode 100644
index 0000000..6525b4c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/QualifiedJoinedTable.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+/**
+ * This syntax element represents the qualified join ({@code JOIN} between two tables.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface QualifiedJoinedTable
+    extends JoinedTable
+{
+    /**
+     * Returns the join type for this {@code JOIN}.
+     *
+     * @return The join type for this {@code JOIN}.
+     * @see JoinType
+     */
+    JoinType getJoinType();
+
+    /**
+     * Returns the join specification for this {@code JOIN}.
+     *
+     * @return The join specification for this {@code JOIN}.
+     * @see JoinSpecification
+     */
+    JoinSpecification getJoinSpecification();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/UnionJoinedTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/UnionJoinedTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/UnionJoinedTable.java
new file mode 100644
index 0000000..c04263e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/UnionJoinedTable.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query.joins;
+
+/**
+ * This syntax element represents the {@code UNION JOIN} between two tables.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UnionJoinedTable
+    extends JoinedTable
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/package-info.java
new file mode 100644
index 0000000..4ca3d8b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/joins/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package provides syntax interfaces for joined tables, mostly used in {@code FROM} clause.
+ */
+package org.apache.polygene.library.sql.generator.grammar.query.joins;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/package-info.java
new file mode 100644
index 0000000..2f30389
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package and its sub-package contain elements related to SQL queries ({@code SELECT} statements).
+ */
+package org.apache.polygene.library.sql.generator.grammar.query;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/TypeableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/TypeableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/TypeableImpl.java
new file mode 100644
index 0000000..70c2e8b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/TypeableImpl.java
@@ -0,0 +1,104 @@
+/*
+ *  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.polygene.library.sql.generator.implementation;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is base class for all classes implementing sub-types of {@link Typeable}. It is meant to be extended by actual
+ * domain-specific classes implementing the API interfaces/classes inherited from {@link Typeable}. For simple usecases,
+ * typically {@code <ImplementedType>} and {@code <RealImplementedType>} are both the same.
+ *
+ * @param <ImplementedType>     The base type for API interface or class.
+ * @param <RealImplementedType> The actual, possibly extended in other project, type of API interface or class. This is
+ *                              useful when one has a complex and extendable type hierarchy and wants the implementation class to be
+ *                              extendable as well.
+ * @author Stanislav Muhametsin
+ */
+public abstract class TypeableImpl<ImplementedType extends Typeable<?>, RealImplementedType extends ImplementedType>
+    implements Typeable<ImplementedType>
+{
+
+    /**
+     * The implemented API type of this object.
+     */
+    private final Class<? extends RealImplementedType> _expressionClass;
+
+    /**
+     * Constructs new base implementation for {@link Typeable}.
+     *
+     * @param realImplementingType The API type, which this specific instance implements. Must not be null.
+     * @throws IllegalArgumentException If the {@code realImplementingType} is {@code null}.
+     */
+    protected TypeableImpl( Class<? extends RealImplementedType> realImplementingType )
+    {
+        if( realImplementingType == null )
+        {
+            throw new IllegalArgumentException( "The implemented type can not be null." );
+        }
+
+        this._expressionClass = realImplementingType;
+    }
+
+    /**
+     */
+    public Class<? extends RealImplementedType> getImplementedType()
+    {
+        return this._expressionClass;
+    }
+
+    /**
+     * This {@link Typeable} equals to {@code obj}, when {@code this} == {@code obj}, OR when {@code obj} is not null,
+     * and {@code obj} is instance of {@link Typeable}, and this.{@link #getImplementedType()} returns SAME type as
+     * {@code obj}. {@link #getImplementedType()}, and {@code this}.{@link #doesEqual(Typeable)} returns {@code true}
+     * when given {@code obj}.
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        return this == obj
+               || ( obj != null && obj instanceof Typeable<?>
+                    && this.getImplementedType().equals( ( (Typeable<?>) obj ).getImplementedType() ) && this
+                        .doesEqual( this._expressionClass.cast( obj ) ) );
+    }
+
+    /**
+     * Override this method to test equaling to other objects implementing same API type as this.
+     *
+     * @param another Another object implementing same API type as {@code this}. Is guaranteed to be non-null and
+     *                different reference than {@code this}, when called by {@link Typeable#equals(Object)}.
+     * @return {@code true} if this object equals to {@code another}; false otherwise.
+     */
+    protected abstract boolean doesEqual( RealImplementedType another );
+
+    /**
+     * Helper method to check that either both arguments are {@code null}s, or one is non-null and equals to another.
+     * Note that this method fails if {@code one.equals(another)} fails when {@code another} is null.
+     *
+     * @param <T>     The type of objects.
+     * @param one     First object to check.
+     * @param another Second object to check.
+     * @return {@code (one == null && another == null) || (one != null && one.equals( another ))}.
+     */
+    public static final <T> boolean bothNullOrEquals( T one, T another )
+    {
+        return ( one == null && another == null ) || ( one != null && one.equals( another ) );
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/AbstractBooleanExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/AbstractBooleanExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/AbstractBooleanExpression.java
new file mode 100644
index 0000000..d2485f6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/AbstractBooleanExpression.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractBooleanExpression<ExpressionType extends BooleanExpression> extends
+                                                                                          SQLSyntaxElementBase<ValueExpression, ExpressionType>
+    implements BooleanExpression
+{
+
+    protected AbstractBooleanExpression( SQLProcessorAggregator processor,
+                                         Class<? extends ExpressionType> expressionClass )
+    {
+        super( processor, expressionClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BetweenPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BetweenPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BetweenPredicateImpl.java
new file mode 100644
index 0000000..e5bdb8e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BetweenPredicateImpl.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class BetweenPredicateImpl extends MultiPredicateImpl<BetweenPredicate>
+    implements BetweenPredicate
+{
+    public BetweenPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                 NonBooleanExpression minimum, NonBooleanExpression maximum )
+    {
+        this( processor, BetweenPredicate.class, left, minimum, maximum );
+    }
+
+    protected BetweenPredicateImpl( SQLProcessorAggregator processor, Class<? extends BetweenPredicate> predicateClass,
+                                    NonBooleanExpression left, NonBooleanExpression minimum, NonBooleanExpression maximum )
+    {
+        super( processor, predicateClass, left, minimum, maximum );
+    }
+
+    public NonBooleanExpression getMaximum()
+    {
+        return this.getRights().get( 1 );
+    }
+
+    public NonBooleanExpression getMinimum()
+    {
+        return this.getRights().get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BinaryPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BinaryPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BinaryPredicateImpl.java
new file mode 100644
index 0000000..af0d1f1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BinaryPredicateImpl.java
@@ -0,0 +1,65 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BinaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class BinaryPredicateImpl<ExpressionType extends BinaryPredicate> extends
+                                                                                  AbstractBooleanExpression<ExpressionType>
+    implements BinaryPredicate
+{
+
+    private final NonBooleanExpression _left;
+
+    private final NonBooleanExpression _right;
+
+    protected BinaryPredicateImpl( SQLProcessorAggregator processor, Class<? extends ExpressionType> expressionClass,
+                                   NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( right, "right" );
+
+        this._left = left;
+        this._right = right;
+    }
+
+    public NonBooleanExpression getLeft()
+    {
+        return this._left;
+    }
+
+    public NonBooleanExpression getRight()
+    {
+        return this._right;
+    }
+
+    @Override
+    protected boolean doesEqual( ExpressionType another )
+    {
+        return this._left.equals( another.getLeft() ) && this._right.equals( another.getRight() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanTestImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanTestImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanTestImpl.java
new file mode 100644
index 0000000..61cc960
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanTestImpl.java
@@ -0,0 +1,82 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class BooleanTestImpl extends ComposedBooleanExpressionImpl<BooleanTest>
+    implements BooleanTest
+{
+
+    private final BooleanExpression _booleanExpression;
+    private final TestType _testType;
+    private final TruthValue _truthValue;
+
+    public BooleanTestImpl( SQLProcessorAggregator processor, BooleanExpression expression, TestType testType,
+                            TruthValue truthValue )
+    {
+        this( processor, BooleanTest.class, expression, testType, truthValue );
+    }
+
+    protected BooleanTestImpl( SQLProcessorAggregator processor, Class<? extends BooleanTest> expressionClass,
+                               BooleanExpression expression, TestType testType, TruthValue truthValue )
+    {
+        super( processor, expressionClass );
+
+        Objects.requireNonNull( expression, "expression" );
+
+        if( BooleanUtils.isEmpty( expression ) )
+        {
+            throw new IllegalArgumentException( "Boolean test must be on something." );
+        }
+
+        this._booleanExpression = expression;
+        this._testType = testType;
+        this._truthValue = truthValue;
+    }
+
+    public BooleanExpression getBooleanExpression()
+    {
+        return this._booleanExpression;
+    }
+
+    public TestType getTestType()
+    {
+        return this._testType;
+    }
+
+    public TruthValue getTruthValue()
+    {
+        return this._truthValue;
+    }
+
+    public Iterator<BooleanExpression> iterator()
+    {
+        return Arrays.asList( this._booleanExpression ).iterator();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanUtils.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanUtils.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanUtils.java
new file mode 100644
index 0000000..a5d797a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/BooleanUtils.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.ComposedBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate.EmptyPredicate;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class BooleanUtils
+{
+
+    public static Boolean isEmpty( BooleanExpression expression )
+    {
+        Boolean result = expression == EmptyPredicate.INSTANCE;
+        if( !result && expression instanceof ComposedBooleanExpression )
+        {
+            for( BooleanExpression exp : (ComposedBooleanExpression) expression )
+            {
+                result = isEmpty( exp );
+                if( !result )
+                {
+                    break;
+                }
+            }
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ComposedBooleanExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ComposedBooleanExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ComposedBooleanExpressionImpl.java
new file mode 100644
index 0000000..bb00466
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ComposedBooleanExpressionImpl.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Iterator;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.ComposedBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class ComposedBooleanExpressionImpl<ExpressionType extends ComposedBooleanExpression> extends
+                                                                                                      AbstractBooleanExpression<ExpressionType>
+    implements ComposedBooleanExpression
+{
+
+    protected ComposedBooleanExpressionImpl( SQLProcessorAggregator processor,
+                                             Class<? extends ExpressionType> expressionClass )
+    {
+        super( processor, expressionClass );
+    }
+
+    @Override
+    protected boolean doesEqual( ExpressionType another )
+    {
+        Iterator<BooleanExpression> thisIter = this.iterator();
+        Iterator<BooleanExpression> anotherIter = another.iterator();
+        Boolean prevResult = true;
+        while( thisIter.hasNext() && anotherIter.hasNext() && prevResult )
+        {
+            prevResult = thisIter.next().equals( anotherIter.next() );
+        }
+
+        return !thisIter.hasNext() && !anotherIter.hasNext() && prevResult;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ConjunctionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ConjunctionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ConjunctionImpl.java
new file mode 100644
index 0000000..d96f6d1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ConjunctionImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Conjunction;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ConjunctionImpl extends ComposedBooleanExpressionImpl<Conjunction>
+    implements Conjunction
+{
+
+    private final BooleanExpression _left;
+
+    private final BooleanExpression _right;
+
+    public ConjunctionImpl( SQLProcessorAggregator processor, BooleanExpression left, BooleanExpression right )
+    {
+        this( processor, Conjunction.class, left, right );
+    }
+
+    protected ConjunctionImpl( SQLProcessorAggregator processor, Class<? extends Conjunction> expressionClass,
+                               BooleanExpression left, BooleanExpression right )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( right, "right" );
+
+        this._left = left;
+        this._right = right;
+    }
+
+    public BooleanExpression getLeft()
+    {
+        return this._left;
+    }
+
+    public BooleanExpression getRight()
+    {
+        return this._right;
+    }
+
+    public Iterator<BooleanExpression> iterator()
+    {
+        return Arrays.asList( this._left, this._right ).iterator();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/DisjunctionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/DisjunctionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/DisjunctionImpl.java
new file mode 100644
index 0000000..c8e507f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/DisjunctionImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Disjunction;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DisjunctionImpl extends ComposedBooleanExpressionImpl<Disjunction>
+    implements Disjunction
+{
+
+    private final BooleanExpression _left;
+
+    private final BooleanExpression _right;
+
+    public DisjunctionImpl( SQLProcessorAggregator processor, BooleanExpression left, BooleanExpression right )
+    {
+        this( processor, Disjunction.class, left, right );
+    }
+
+    protected DisjunctionImpl( SQLProcessorAggregator processor, Class<? extends Disjunction> expressionClass,
+                               BooleanExpression left, BooleanExpression right )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( right, "right" );
+
+        this._left = left;
+        this._right = right;
+    }
+
+    public BooleanExpression getLeft()
+    {
+        return this._left;
+    }
+
+    public BooleanExpression getRight()
+    {
+        return this._right;
+    }
+
+    public Iterator<BooleanExpression> iterator()
+    {
+        return Arrays.asList( this._left, this._right ).iterator();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/EqualsPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/EqualsPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/EqualsPredicateImpl.java
new file mode 100644
index 0000000..7668478
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/EqualsPredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.EqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class EqualsPredicateImpl extends BinaryPredicateImpl<EqualsPredicate>
+    implements EqualsPredicate
+{
+
+    public EqualsPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        this( processor, EqualsPredicate.class, left, right );
+    }
+
+    protected EqualsPredicateImpl( SQLProcessorAggregator processor, Class<? extends EqualsPredicate> predicateClass,
+                                   NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ExistsPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ExistsPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ExistsPredicateImpl.java
new file mode 100644
index 0000000..44c1623
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/ExistsPredicateImpl.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.ExistsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ExistsPredicateImpl extends UnaryPredicateImpl<ExistsPredicate>
+    implements ExistsPredicate
+{
+
+    public ExistsPredicateImpl( SQLProcessorAggregator processor, QueryExpression query )
+    {
+        this( processor, ExistsPredicate.class, query );
+    }
+
+    protected ExistsPredicateImpl( SQLProcessorAggregator processor, Class<? extends ExistsPredicate> predicateClass,
+                                   QueryExpression query )
+    {
+        super( processor, predicateClass, query );
+    }
+
+    @Override
+    public QueryExpression getValueExpression()
+    {
+        return (QueryExpression) super.getValueExpression();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterOrEqualPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterOrEqualPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterOrEqualPredicateImpl.java
new file mode 100644
index 0000000..8b8f582
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterOrEqualPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class GreaterOrEqualPredicateImpl extends BinaryPredicateImpl<GreaterOrEqualPredicate>
+    implements GreaterOrEqualPredicate
+{
+
+    public GreaterOrEqualPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                        NonBooleanExpression right )
+    {
+        this( processor, GreaterOrEqualPredicate.class, left, right );
+    }
+
+    protected GreaterOrEqualPredicateImpl( SQLProcessorAggregator processor,
+                                           Class<? extends GreaterOrEqualPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterThanPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterThanPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterThanPredicateImpl.java
new file mode 100644
index 0000000..3fa3b62
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/GreaterThanPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class GreaterThanPredicateImpl extends BinaryPredicateImpl<GreaterThanPredicate>
+    implements GreaterThanPredicate
+{
+
+    public GreaterThanPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                     NonBooleanExpression right )
+    {
+        this( processor, GreaterThanPredicate.class, left, right );
+    }
+
+    protected GreaterThanPredicateImpl( SQLProcessorAggregator processor,
+                                        Class<? extends GreaterThanPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}


[16/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameFunction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameFunction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameFunction.java
new file mode 100644
index 0000000..2e38392
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameFunction.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+
+/**
+ * A table name function serves as a function call when selecting data.
+ *
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface TableNameFunction
+    extends TableName
+{
+    /**
+     * Returns the function to call.
+     *
+     * @return The function to call.
+     */
+    SQLFunctionLiteral getFunction();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ValueExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ValueExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ValueExpression.java
new file mode 100644
index 0000000..de07261
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ValueExpression.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+
+/**
+ * A common interface for {@link BooleanExpression} and {@link NonBooleanExpression}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ValueExpression
+    extends Typeable<ValueExpression>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/BigInt.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/BigInt.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/BigInt.java
new file mode 100644
index 0000000..a82b1f4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/BigInt.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code BIGINT} type (typically 64-bit integer).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BigInt
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Decimal.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Decimal.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Decimal.java
new file mode 100644
index 0000000..d4b441e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Decimal.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * <p>
+ * This class represents the {@code DECIMAL} data type, sometimes abbreviated as {@code DEC}. The site
+ * http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between {@code NUMERIC} and
+ * {@code DECIMAL}:
+ * </p>
+ * <p>
+ * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be exactly
+ * as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+ * </p>
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Decimal
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the precision (first integer) for this {@code DECIMAL}.
+     *
+     * @return The precision for this {@code DECIMAL}.
+     */
+    Integer getPrecision();
+
+    /**
+     * Returns the scale (second integer) for this {@code DECIMAL}.
+     *
+     * @return The precision for this {@code DECIMAL}.
+     */
+    Integer getScale();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/DoublePrecision.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/DoublePrecision.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/DoublePrecision.java
new file mode 100644
index 0000000..431b75c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/DoublePrecision.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents {@code DOUBLE PRECISION} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DoublePrecision
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/IntervalDataType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/IntervalDataType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/IntervalDataType.java
new file mode 100644
index 0000000..fb9b93e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/IntervalDataType.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class contains all the types for fields in {@code INTERVAL} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class IntervalDataType
+{
+    public static final IntervalDataType YEAR = new IntervalDataType();
+
+    public static final IntervalDataType MONTH = new IntervalDataType();
+
+    public static final IntervalDataType DAY = new IntervalDataType();
+
+    public static final IntervalDataType HOUR = new IntervalDataType();
+
+    public static final IntervalDataType MINUTE = new IntervalDataType();
+
+    public static final IntervalDataType SECOND = new IntervalDataType();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Numeric.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Numeric.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Numeric.java
new file mode 100644
index 0000000..842e1be
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Numeric.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * <p>
+ * This class represents the {@code NUMERIC} type. The site
+ * http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between {@code NUMERIC} and
+ * {@code DECIMAL}:
+ * </p>
+ * <p>
+ * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be exactly
+ * as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+ * </p>
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Numeric
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the precision (first integer) for this {@code NUMERIC}.
+     *
+     * @return The precision for this {@code NUMERIC}.
+     */
+    Integer getPrecision();
+
+    /**
+     * Returns the scale (second integer) for this {@code NUMERIC}.
+     *
+     * @return The precision for this {@code NUMERIC}.
+     */
+    Integer getScale();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/ParametrizableDataType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/ParametrizableDataType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/ParametrizableDataType.java
new file mode 100644
index 0000000..b056181
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/ParametrizableDataType.java
@@ -0,0 +1,30 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This is marker interface for SQL data types which may be parametrized (like, {@code DECIMAL} or {@code VARCHAR}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ParametrizableDataType
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Real.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Real.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Real.java
new file mode 100644
index 0000000..3a73cae
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/Real.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code REAL} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Real
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLBoolean.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLBoolean.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLBoolean.java
new file mode 100644
index 0000000..870aff6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLBoolean.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code BOOLEAN} type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLBoolean
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLChar.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLChar.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLChar.java
new file mode 100644
index 0000000..82ec6db
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLChar.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents {@code CHARACTER} and {@code CHARACTER VARYING} data types, typically abbreviated as
+ * {@code CHAR} and {@code VARCHAR}, respectively.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLChar
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns {@code true} if this is {@code CHARACTER VARYING}; {@code false otherwise}.
+     *
+     * @return {@code true} if this is {@code CHARACTER VARYING}; {@code false otherwise}.
+     */
+    Boolean isVarying();
+
+    /**
+     * Returns the length specification for this {@code CHARACTER} or {@code CHARACTER VARYING}. Returns {@code null} if
+     * none specified.
+     *
+     * @return The length for this {@code CHARACTER} or {@code CHARACTER VARYING}.
+     */
+    Integer getLength();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDataType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDataType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDataType.java
new file mode 100644
index 0000000..9df446a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDataType.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for all SQL data types. The data types provided in this project cover most of of SQL
+ * predefined types, however each vendor may extend these with their own custom types.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLDataType
+    extends Typeable<SQLDataType>
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDate.java
new file mode 100644
index 0000000..eae5f4d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLDate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code DATE} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLDate
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLFloat.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLFloat.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLFloat.java
new file mode 100644
index 0000000..2b89cc1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLFloat.java
@@ -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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code FLOAT} type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLFloat
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the precision for this {@code FLOAT}.
+     *
+     * @return The precision for this {@code FLOAT}.
+     */
+    Integer getPrecision();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInteger.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInteger.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInteger.java
new file mode 100644
index 0000000..951f5c0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInteger.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code INTEGER} type, sometimes abbreviated as {@code INT} (typically 32-bit integer).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLInteger
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInterval.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInterval.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInterval.java
new file mode 100644
index 0000000..5f35b90
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLInterval.java
@@ -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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code INTEGER} type, sometimes abbreviated as {@code INT} (typically 32-bit integer).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLInterval
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the start field type for this {@code INTERVAL}.
+     *
+     * @return The start field type for this {@code INTERVAL}.
+     */
+    IntervalDataType getStartField();
+
+    /**
+     * Return the start field precision for this {@code INTERVAL}. May be {@code null} if none specified.
+     *
+     * @return The start field precision for this {@code INTERVAL}.
+     */
+    Integer getStartFieldPrecision();
+
+    /**
+     * Returns the end field precision for this {@code INTERVAL}. Will always be {@code null} for single datetime field
+     * intervals.
+     *
+     * @return The end field precision for this {@code INTERVAL}.
+     */
+    IntervalDataType getEndField();
+
+    /**
+     * Returns the fraction seconds precision for this {@code INTERVAL}. Will always be {@code null} if the end field
+     * type is not {@link IntervalDataType#SECOND}, or if this is single datetime field interval, and its start type is
+     * not {@link IntervalDataType#SECOND}.
+     *
+     * @return The fraction seconds precision for this {@code INTERVAL}.
+     */
+    Integer getSecondFracs();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTime.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTime.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTime.java
new file mode 100644
index 0000000..3f11b38
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTime.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents {@code TIME} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLTime
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the precision for this {@code TIME}. May be {@code null}.
+     *
+     * @return The precision for this {@code TIME}.
+     */
+    Integer getPrecision();
+
+    /**
+     * Returns whether the {@code TIME} should be with time zone. May be {@code null} if no choice specified.
+     *
+     * @return
+     */
+    Boolean isWithTimeZone();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTimeStamp.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTimeStamp.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTimeStamp.java
new file mode 100644
index 0000000..2a01623
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SQLTimeStamp.java
@@ -0,0 +1,42 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface SQLTimeStamp
+    extends SQLDataType, ParametrizableDataType
+{
+
+    /**
+     * Returns the precision for this {@code TIMESTAMP}. May be {@code null}.
+     *
+     * @return The precision for this {@code TIMESTAMP}.
+     */
+    Integer getPrecision();
+
+    /**
+     * Returns whether the {@code TIMESTAMP} should be with time zone. May be {@code null} if no choice specified.
+     *
+     * @return
+     */
+    Boolean isWithTimeZone();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SmallInt.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SmallInt.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SmallInt.java
new file mode 100644
index 0000000..2fd83e5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/SmallInt.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+/**
+ * This class represents the {@code SMALLINT} type (typically 16-bit integer).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SmallInt
+    extends SQLDataType
+{
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/UserDefinedType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/UserDefinedType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/UserDefinedType.java
new file mode 100644
index 0000000..cded18a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/UserDefinedType.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+
+/**
+ * This is a general way of handling any user-created or otherwise custom type. It is advisable to always use the
+ * methods provided by your vendor's data type factory (most likely sub-interface of {@link DataTypeFactory}) instead of
+ * using this interface. However, when data type is dynamically created, it is quite a must to use this type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UserDefinedType
+    extends SQLDataType
+{
+
+    String getTextualRepresentation();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/package-info.java
new file mode 100644
index 0000000..08e9d95
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This is the package containing support for (most)pre-defined SQL data types.
+ */
+package org.apache.polygene.library.sql.generator.grammar.common.datatypes;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/pgsql/Text.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/pgsql/Text.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/pgsql/Text.java
new file mode 100644
index 0000000..01ef739
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/datatypes/pgsql/Text.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common.datatypes.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+
+/**
+ * This data type represents the {@code TEXT} data type in PostgreSQL.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Text
+    extends SQLDataType
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/package-info.java
new file mode 100644
index 0000000..1581cb0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains interfaces and classes common for most parts of SQL generator.
+ */
+package org.apache.polygene.library.sql.generator.grammar.common;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaDefinition.java
new file mode 100644
index 0000000..ede7a43
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaDefinition.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.schema;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaDefinitionStatement;
+
+/**
+ * This syntax element represents the {@code CREATE SCHEMA} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SchemaDefinition
+    extends SchemaDefinitionStatement
+{
+
+    /**
+     * Returns the name of the schema to be created.
+     *
+     * @return The name of the schema to be created.
+     */
+    String getSchemaName();
+
+    /**
+     * Returns the character set for this schema. May be {@code null} if none specified.
+     *
+     * @return The character set for this schema. May be {@code null} if none specified.
+     */
+    String getSchemaCharset();
+
+    /**
+     * Returns any additional elements for this schema. May be empty if none are present.
+     *
+     * @return Any additional elements for this schema. May be empty if none are present.
+     */
+    List<SchemaElement> getSchemaElements();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaElement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaElement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaElement.java
new file mode 100644
index 0000000..24a895e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/SchemaElement.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.schema;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is a common interface for all definitions that may be present in schema definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see SchemaDefinition
+ */
+public interface SchemaElement
+{
+
+    Typeable<?> asTypeable();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/package-info.java
new file mode 100644
index 0000000..6fe4d50
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/schema/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains syntax interfaces for {@code CREATE SCHEMA} statement.
+ */
+package org.apache.polygene.library.sql.generator.grammar.definition.schema;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/AutoGenerationPolicy.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/AutoGenerationPolicy.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/AutoGenerationPolicy.java
new file mode 100644
index 0000000..44576e7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/AutoGenerationPolicy.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This class defines the policy for auto-generated columns ({@code GENERATED <strategy> AS IDENTITY}.
+ *
+ * @author Stanislav Muhametsin
+ * @see ColumnDefinition
+ */
+public final class AutoGenerationPolicy
+{
+    private final String _policyName;
+
+    public AutoGenerationPolicy( String policyName )
+    {
+        this._policyName = policyName;
+    }
+
+    /**
+     * Represents the {@code GENERATED ALWAYS AS IDENTITY} auto generation policy.
+     */
+    public static final AutoGenerationPolicy ALWAYS = new AutoGenerationPolicy( "ALWAYS" );
+
+    /**
+     * Represents the {@code GENERATED BY DEFAULT AS IDENTITY} auto generation policy.
+     */
+    public static final AutoGenerationPolicy BY_DEFAULT = new AutoGenerationPolicy( "BY DEFAULT" );
+
+    @Override
+    public String toString()
+    {
+        return this._policyName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/CheckConstraint.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/CheckConstraint.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/CheckConstraint.java
new file mode 100644
index 0000000..febef93
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/CheckConstraint.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+
+/**
+ * This syntax element represents the {@code CHECK( ... )} constraint in table definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public interface CheckConstraint
+    extends TableConstraint
+{
+    BooleanExpression getCheckCondition();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ColumnDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ColumnDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ColumnDefinition.java
new file mode 100644
index 0000000..c13fe32
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ColumnDefinition.java
@@ -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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+
+/**
+ * This syntax element represents the column definition of the table definition statement.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public interface ColumnDefinition
+    extends TableElement
+{
+
+    /**
+     * Returns the name of this column.
+     *
+     * @return The name of this column.
+     */
+    String getColumnName();
+
+    /**
+     * Returns the data type of this column.
+     *
+     * @return The data type of this column.
+     */
+    SQLDataType getDataType();
+
+    /**
+     * Returns the default clause for this column. May be {@code null} if no default value is defined.
+     *
+     * @return The default clause for this column. May be {@code null} if no default value is defined.
+     */
+    String getDefault();
+
+    /**
+     * Returns {@code true} if this column may have {@code NULL} values, otherwise (when {@code NOT NULL} constraints is
+     * present) returns {@code false}.
+     *
+     * @return {@code true} if this column may have {@code NULL} values; {@code false} otherwise.
+     */
+    Boolean mayBeNull();
+
+    /**
+     * Returns the auto generation policy for this column. May be {@code null} if no auto generation policy exists for
+     * this column.
+     *
+     * @return Auto generation policy for this column, or {@code null} if the column is not auto-generated.
+     */
+    AutoGenerationPolicy getAutoGenerationPolicy();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ConstraintCharacteristics.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ConstraintCharacteristics.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ConstraintCharacteristics.java
new file mode 100644
index 0000000..90d7638
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ConstraintCharacteristics.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This enum represents three different policies for checking constraints time. These policies are
+ * {@link #INITIALLY_IMMEDIATE_DEFERRABLE}, {@link #INITIALLY_DEFERRED_DEFERRABLE}, and {@link #NOT_DEFERRABLE}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class ConstraintCharacteristics
+{
+    /**
+     * Represents the {@code INITIALLY IMMEDIATE DEFERRABLE} constraint time check.
+     */
+    public static final ConstraintCharacteristics INITIALLY_IMMEDIATE_DEFERRABLE = new ConstraintCharacteristics();
+
+    /**
+     * Represents the {@code INITIALLY DEFERRED DEFERRABLE} constraint time check.
+     */
+    public static final ConstraintCharacteristics INITIALLY_DEFERRED_DEFERRABLE = new ConstraintCharacteristics();
+
+    /**
+     * Represents the {@code [INITIALLY IMMEDIATE] NOT DEFERRABLE} constraint time check.
+     */
+    public static final ConstraintCharacteristics NOT_DEFERRABLE = new ConstraintCharacteristics();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ForeignKeyConstraint.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ForeignKeyConstraint.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ForeignKeyConstraint.java
new file mode 100644
index 0000000..55acc2c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ForeignKeyConstraint.java
@@ -0,0 +1,79 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * This syntax element represents the {@code FOREIGN KEY(col1, col2, ...) ...} table constraint in table definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableConstraint
+ * @see TableDefinition
+ */
+public interface ForeignKeyConstraint
+    extends TableConstraint
+{
+
+    /**
+     * Returns the list of column names in this table.
+     *
+     * @return The list of column names in this table.
+     */
+    ColumnNameList getSourceColumns();
+
+    /**
+     * Returns the name of the table where the columns in this table are referencing to.
+     *
+     * @return The name of the table where the columns in this table are referencing to.
+     */
+    TableNameDirect getTargetTableName();
+
+    /**
+     * Returns the list of column names in target table. Will be {@code null} if none specified.
+     *
+     * @return The list of column names in target table. Will be {@code null} if none specified.
+     */
+    ColumnNameList getTargetColumns();
+
+    /**
+     * Returns the match type for this foreign key. May be {@code null} if no match type is specified.
+     *
+     * @return The match type for this foreign key. May be {@code null} if no match type is specified.
+     */
+    MatchType getMatchType();
+
+    /**
+     * Returns the referential action of updating the rows. May be {@code null} if none specified.
+     *
+     * @return The referential action of updating the rows. May be {@code null} if none specified.
+     * @see ReferentialAction
+     */
+    ReferentialAction getOnUpdate();
+
+    /**
+     * Returns the referential action of deleting the rows. May be {@code null} if none specified.
+     *
+     * @return The referential action of deleting the rows. May be {@code null} if none specified.
+     * @see ReferentialAction
+     */
+    ReferentialAction getOnDelete();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/LikeClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/LikeClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/LikeClause.java
new file mode 100644
index 0000000..2ef51e9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/LikeClause.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * This syntax element represents the {@code LIKE
+ * <table name>} clause in table definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public interface LikeClause
+    extends TableElement
+{
+
+    /**
+     * Returns the name of the table for this {@code LIKE} clause.
+     *
+     * @return The name of the table for this {@code LIKE} clause.
+     */
+    TableNameDirect getTableName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/MatchType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/MatchType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/MatchType.java
new file mode 100644
index 0000000..00c8183
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/MatchType.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This enum represents the three different ways of matching foreign keys. May be {@link #FULL}, {@link #PARTIAL}, or
+ * {@link #SIMPLE}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class MatchType
+{
+
+    /**
+     * Represents the full match ({@code MATCH FULL}).
+     */
+    public static final MatchType FULL = new MatchType();
+
+    /**
+     * Represents the partial match ({@code MATCH PARTIAL}).
+     */
+    public static final MatchType PARTIAL = new MatchType();
+
+    /**
+     * Represents the simple match ({@code MATCH SIMPLE}).
+     */
+    public static final MatchType SIMPLE = new MatchType();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ReferentialAction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ReferentialAction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ReferentialAction.java
new file mode 100644
index 0000000..f1f056d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/ReferentialAction.java
@@ -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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This enum represents the five referential actions of SQL. These are {@link #CASCADE}, {@link #SET_NULL},
+ * {@link #SET_DEFAULT}, {@link #RESTRICT}, and {@link #NO_ACTION}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class ReferentialAction
+{
+
+    /**
+     * Represents the cascading policy ({@code CASCADE}.
+     */
+    public static final ReferentialAction CASCADE = new ReferentialAction();
+
+    /**
+     * Represents the policy, which sets the value as {@code NULL} ({@code SET NULL}.
+     */
+    public static final ReferentialAction SET_NULL = new ReferentialAction();
+
+    /**
+     * Represents the policy, which sets the value as default ({@code SET DEFAULT}.
+     */
+    public static final ReferentialAction SET_DEFAULT = new ReferentialAction();
+
+    /**
+     * Represents the policy, which checks the integrity <b>before</b> {@code UPDATE} or {@code DELETE} statement, and
+     * the statement will not be executed if it violates integrity.
+     */
+    public static final ReferentialAction RESTRICT = new ReferentialAction();
+
+    /**
+     * Represents the policy, which checks the integrity <b>after</b> {@code UPDATE} or {@code DELETE} statement, and
+     * the statement will not be executed if it violates integrity.
+     */
+    public static final ReferentialAction NO_ACTION = new ReferentialAction();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableCommitAction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableCommitAction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableCommitAction.java
new file mode 100644
index 0000000..c232fa5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableCommitAction.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This enum is for table commit action ({@code ON COMMIT} ...) in table definition. The commit action may be either
+ * {@link #ON_COMMIT_PRESERVE_ROWS} or {@link #ON_COMMIT_DELETE_ROWS}.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public final class TableCommitAction
+{
+
+    /**
+     * The commit action for {@code ON COMMIT PRESERVE ROWS}.
+     */
+    public static final TableCommitAction ON_COMMIT_PRESERVE_ROWS = new TableCommitAction();
+
+    /**
+     * The commit action for {@code ON COMMIT DELETE ROWS}.
+     */
+    public static final TableCommitAction ON_COMMIT_DELETE_ROWS = new TableCommitAction();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraint.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraint.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraint.java
new file mode 100644
index 0000000..1f0c30e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraint.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is a common interface for all table constraints.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableConstraintDefinition
+ * @see TableDefinition
+ */
+public interface TableConstraint
+    extends Typeable<TableConstraint>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraintDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraintDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraintDefinition.java
new file mode 100644
index 0000000..b7e6232
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableConstraintDefinition.java
@@ -0,0 +1,55 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This syntax element represents the constraint definition for a table.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableElement
+ * @see TableDefinition
+ * @see TableConstraint
+ */
+public interface TableConstraintDefinition
+    extends TableElement
+{
+
+    /**
+     * Returns the optional name for this constraint. Will be {@code null} if no name defined for this constraint.
+     *
+     * @return The optional name for this constraint. Will be {@code null} if no name defined for this constraint.
+     */
+    String getConstraintName();
+
+    /**
+     * Returns the constraint characteristics for this constraint. Will be {@code null} if no characteristics defined.
+     *
+     * @return The constraint characteristics for this constraint. Will be {@code null} if no characteristics defined.
+     * @see ConstraintCharacteristics
+     */
+    ConstraintCharacteristics getCharacteristics();
+
+    /**
+     * Returns the actual table constraint.
+     *
+     * @return The actual table constraint.
+     */
+    TableConstraint getConstraint();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableContentsSource.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableContentsSource.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableContentsSource.java
new file mode 100644
index 0000000..d129fc9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableContentsSource.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is a common interface for table source in table definition (in most cases, it is a comma-separated list of
+ * column definitions).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableContentsSource
+    extends Typeable<TableContentsSource>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableDefinition.java
new file mode 100644
index 0000000..37e90e5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableDefinition.java
@@ -0,0 +1,65 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaDefinitionStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+
+/**
+ * This syntax element represents the table definition ({@code CREATE TABLE }) statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableDefinition
+    extends SchemaDefinitionStatement, SchemaElement
+{
+    /**
+     * Returns the table scope for this table. May be {@code null} if no scope defined.
+     *
+     * @return The table scope for this table. May be {@code null} if no scope defined.
+     * @see TableScope
+     */
+    TableScope getTableScope();
+
+    /**
+     * Returns the name for this table.
+     *
+     * @return The name for this table.
+     * @see TableName
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Returns the commit action for this table. May be {@code null} if no commit action defined.
+     *
+     * @return The commit action for this table. May be {@code null} if no commit action defined.
+     * @see TableCommitAction
+     */
+    TableCommitAction getCommitAction();
+
+    /**
+     * Returns the actual body of this table definition. Usually is a list of column definitions and constraints.
+     *
+     * @return The actual body of this table definition.
+     */
+    TableContentsSource getContents();
+}


[10/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/InsertStatementBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/InsertStatementBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/InsertStatementBuilderImpl.java
new file mode 100644
index 0000000..31b0373
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/InsertStatementBuilderImpl.java
@@ -0,0 +1,72 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.InsertStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class InsertStatementBuilderImpl extends SQLBuilderBase
+    implements InsertStatementBuilder
+{
+
+    private TableNameDirect _tableName;
+
+    private ColumnSource _columnSource;
+
+    public InsertStatementBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+    }
+
+    public InsertStatement createExpression()
+    {
+        return new InsertStatementImpl( this.getProcessor(), this._tableName, this._columnSource );
+    }
+
+    public InsertStatementBuilder setTableName( TableNameDirect tableName )
+    {
+        this._tableName = tableName;
+        return this;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._tableName;
+    }
+
+    public InsertStatementBuilder setColumnSource( ColumnSource source )
+    {
+        this._columnSource = source;
+        return this;
+    }
+
+    public ColumnSource getColumnSource()
+    {
+        return this._columnSource;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/UpdateBySearchBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/UpdateBySearchBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/UpdateBySearchBuilderImpl.java
new file mode 100644
index 0000000..93b9271
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/UpdateBySearchBuilderImpl.java
@@ -0,0 +1,87 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.modification;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.UpdateBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.UpdateBySearchImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UpdateBySearchBuilderImpl extends SQLBuilderBase
+    implements UpdateBySearchBuilder
+{
+
+    private TargetTable _targetTable;
+
+    private final List<SetClause> _setClauses;
+
+    private final BooleanBuilder _whereBuilder;
+
+    public UpdateBySearchBuilderImpl( SQLProcessorAggregator processor, BooleanBuilder whereBuilder )
+    {
+        super( processor );
+        Objects.requireNonNull( whereBuilder, "where builder" );
+
+        this._setClauses = new ArrayList<SetClause>();
+        this._whereBuilder = whereBuilder;
+    }
+
+    public UpdateBySearch createExpression()
+    {
+        return new UpdateBySearchImpl( this.getProcessor(), this._targetTable, this._setClauses,
+                                       this._whereBuilder.createExpression() );
+    }
+
+    public UpdateBySearchBuilder setTargetTable( TargetTable table )
+    {
+        this._targetTable = table;
+        return this;
+    }
+
+    public BooleanBuilder getWhereBuilder()
+    {
+        return this._whereBuilder;
+    }
+
+    public UpdateBySearchBuilder addSetClauses( SetClause... clauses )
+    {
+        for( SetClause clause : clauses )
+        {
+            this._setClauses.add( clause );
+        }
+        return this;
+    }
+
+    public List<SetClause> getSetClauses()
+    {
+        return Collections.unmodifiableList( this._setClauses );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilderImpl.java
new file mode 100644
index 0000000..7aa4861
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilderImpl.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.modification.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql.PgSQLInsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.InsertStatementBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.pgsql.PgSQLInsertStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class PgSQLInsertStatementBuilderImpl extends InsertStatementBuilderImpl implements
+                                                                                PgSQLInsertStatementBuilder
+{
+
+    private SelectColumnClause _returning;
+
+    public PgSQLInsertStatementBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+    }
+
+    public PgSQLInsertStatementBuilder setReturningClause( SelectColumnClause clause )
+    {
+        this._returning = clause;
+        return this;
+    }
+
+    @Override
+    public InsertStatement createExpression()
+    {
+        return new PgSQLInsertStatementImpl( this.getProcessor(), this.getTableName(),
+                                             this.getColumnSource(), this._returning );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/AbstractQueryFactoryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/AbstractQueryFactoryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/AbstractQueryFactoryImpl.java
new file mode 100644
index 0000000..a4e76a5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/AbstractQueryFactoryImpl.java
@@ -0,0 +1,84 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.query.AbstractQueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.LimitSpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public abstract class AbstractQueryFactoryImpl<ExpressionType> extends SQLBuilderBase
+    implements AbstractQueryBuilder<ExpressionType>
+{
+
+    private LimitSpecification _limit;
+    private OffsetSpecification _offset;
+
+    protected AbstractQueryFactoryImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+    }
+
+    public AbstractQueryBuilder<ExpressionType> limit()
+    {
+        this._limit = new LimitSpecificationImpl( this.getProcessor(), null );
+        return this;
+    }
+
+    public AbstractQueryBuilder<ExpressionType> limit( Integer max )
+    {
+        return this.limit( this.getProcessor().getVendor().getLiteralFactory().n( max ) );
+    }
+
+    public AbstractQueryBuilder<ExpressionType> limit( NonBooleanExpression max )
+    {
+        this._limit =
+            ( max == null ? null : this.getProcessor().getVendor().getQueryFactory().limit( max ) );
+        return this;
+    }
+
+    public AbstractQueryBuilder<ExpressionType> offset( Integer skip )
+    {
+        return this.offset( this.getProcessor().getVendor().getLiteralFactory().n( skip ) );
+    }
+
+    public AbstractQueryBuilder<ExpressionType> offset( NonBooleanExpression skip )
+    {
+        this._offset =
+            ( skip == null ? null : this.getProcessor().getVendor().getQueryFactory().offset( skip ) );
+        return this;
+    }
+
+    protected LimitSpecification getLimit()
+    {
+        return this._limit;
+    }
+
+    protected OffsetSpecification getOffset()
+    {
+        return this._offset;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/ColumnsBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/ColumnsBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/ColumnsBuilderImpl.java
new file mode 100644
index 0000000..2df5f54
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/ColumnsBuilderImpl.java
@@ -0,0 +1,113 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.AsteriskSelectImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.ColumnReferencesImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnsBuilderImpl extends SQLBuilderBase
+    implements ColumnsBuilder
+{
+    private final List<ColumnReferenceInfo> _columns;
+    private SetQuantifier _quantifier;
+
+    public ColumnsBuilderImpl( SQLProcessorAggregator processor, SetQuantifier setQuantifier )
+    {
+        super( processor );
+        Objects.requireNonNull( setQuantifier, "set quantifier" );
+
+        this._quantifier = setQuantifier;
+        this._columns = new ArrayList<ColumnReferenceInfo>();
+    }
+
+    public ColumnsBuilder addUnnamedColumns( ColumnReference... columns )
+    {
+        for( ColumnReference col : columns )
+        {
+            this.addNamedColumns( new ColumnReferenceInfo( null, col ) );
+        }
+
+        return this;
+    }
+
+    public ColumnsBuilder addNamedColumns( ColumnReferenceInfo... namedColumns )
+    {
+        for( ColumnReferenceInfo info : namedColumns )
+        {
+            Objects.requireNonNull( info, "named column" );
+            this._columns.add( info );
+        }
+
+        return this;
+    }
+
+    public ColumnsBuilder setSetQuantifier( SetQuantifier newSetQuantifier )
+    {
+        Objects.requireNonNull( newSetQuantifier, "new set quantifier" );
+        this._quantifier = newSetQuantifier;
+
+        return this;
+    }
+
+    public ColumnsBuilder selectAll()
+    {
+        this._columns.clear();
+        return this;
+    }
+
+    public List<ColumnReferenceInfo> getColumns()
+    {
+        return Collections.unmodifiableList( this._columns );
+    }
+
+    public SetQuantifier getSetQuantifier()
+    {
+        return this._quantifier;
+    }
+
+    public SelectColumnClause createExpression()
+    {
+        SelectColumnClause result = null;
+        if( this._columns.isEmpty() )
+        {
+            result = new AsteriskSelectImpl( this.getProcessor(), this._quantifier );
+        }
+        else
+        {
+            result = new ColumnReferencesImpl( this.getProcessor(), this._quantifier, this._columns );
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/FromBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/FromBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/FromBuilderImpl.java
new file mode 100644
index 0000000..50d2d2b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/FromBuilderImpl.java
@@ -0,0 +1,75 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.FromBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.FromClauseImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class FromBuilderImpl extends SQLBuilderBase
+    implements FromBuilder
+{
+
+    private final List<TableReferenceBuilder> _tableRefs;
+
+    public FromBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._tableRefs = new ArrayList<TableReferenceBuilder>();
+    }
+
+    public FromBuilder addTableReferences( TableReferenceBuilder... tableRefs )
+    {
+        for( TableReferenceBuilder ref : tableRefs )
+        {
+            Objects.requireNonNull( ref, "table reference" );
+            this._tableRefs.add( ref );
+        }
+
+        return this;
+    }
+
+    public List<TableReferenceBuilder> getTableReferences()
+    {
+        return Collections.unmodifiableList( this._tableRefs );
+    }
+
+    public FromClause createExpression()
+    {
+        List<TableReference> refs = new ArrayList<TableReference>( this._tableRefs.size() );
+        for( TableReferenceBuilder builder : this._tableRefs )
+        {
+            refs.add( builder.createExpression() );
+        }
+
+        return new FromClauseImpl( this.getProcessor(), refs );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/GroupByBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/GroupByBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/GroupByBuilderImpl.java
new file mode 100644
index 0000000..84c9b12
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/GroupByBuilderImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.GroupByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.GroupByClauseImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class GroupByBuilderImpl extends SQLBuilderBase
+    implements GroupByBuilder
+{
+
+    private final List<GroupingElement> _elements;
+
+    public GroupByBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._elements = new ArrayList<GroupingElement>();
+    }
+
+    public GroupByBuilder addGroupingElements( GroupingElement... elements )
+    {
+        Objects.requireNonNull( elements, "elements" );
+        for( GroupingElement element : elements )
+        {
+            Objects.requireNonNull( element, "element" );
+        }
+
+        this._elements.addAll( Arrays.asList( elements ) );
+        return this;
+    }
+
+    public List<GroupingElement> getGroupingElements()
+    {
+        return Collections.unmodifiableList( this._elements );
+    }
+
+    public GroupByClause createExpression()
+    {
+        return new GroupByClauseImpl( this.getProcessor(), this._elements );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/OrderByBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/OrderByBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/OrderByBuilderImpl.java
new file mode 100644
index 0000000..128851f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/OrderByBuilderImpl.java
@@ -0,0 +1,69 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.OrderByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.OrderByClauseImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class OrderByBuilderImpl extends SQLBuilderBase
+    implements OrderByBuilder
+{
+
+    private final List<SortSpecification> _sortSpecs;
+
+    public OrderByBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._sortSpecs = new ArrayList<SortSpecification>();
+    }
+
+    public OrderByBuilder addSortSpecs( SortSpecification... specs )
+    {
+        for( SortSpecification spec : specs )
+        {
+            Objects.requireNonNull( spec, "specification" );
+        }
+
+        this._sortSpecs.addAll( Arrays.asList( specs ) );
+        return this;
+    }
+
+    public List<SortSpecification> getSortSpecs()
+    {
+        return Collections.unmodifiableList( this._sortSpecs );
+    }
+
+    public OrderByClause createExpression()
+    {
+        return new OrderByClauseImpl( this.getProcessor(), this._sortSpecs );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QueryBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QueryBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QueryBuilderImpl.java
new file mode 100644
index 0000000..ca93068
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QueryBuilderImpl.java
@@ -0,0 +1,148 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.SetOperation;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.QueryExpressionBodyBinaryImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QueryBuilderImpl extends SQLBuilderBase
+    implements QueryBuilder
+{
+
+    public static final SetQuantifier DEFAULT_SET_QUANTIFIER_FOR_UNIONS = SetQuantifier.DISTINCT;
+
+    public static final SetQuantifier DEFAULT_SET_QUANTIFIER_FOR_INTERSECTIONS = SetQuantifier.DISTINCT;
+
+    public static final SetQuantifier DEFAULT_SET_QUANTIFIER_FOR_EXCEPTS = SetQuantifier.DISTINCT;
+
+    private final SetQuantifier _defaultSetQuantifierForUnions;
+
+    private final SetQuantifier _defaultSetQuantifierForIntersections;
+
+    private final SetQuantifier _defaultSetQuantifierForExcepts;
+
+    private QueryExpressionBody _topLevelExpression;
+
+    public QueryBuilderImpl( SQLProcessorAggregator processor, QueryExpressionBody topLevelExpression )
+    {
+        this( processor, topLevelExpression, DEFAULT_SET_QUANTIFIER_FOR_UNIONS,
+              DEFAULT_SET_QUANTIFIER_FOR_INTERSECTIONS, DEFAULT_SET_QUANTIFIER_FOR_EXCEPTS );
+    }
+
+    protected QueryBuilderImpl( SQLProcessorAggregator processor, QueryExpressionBody topLevelExpression,
+                                SetQuantifier defaultSetQuantifierForUnions, SetQuantifier defaultSetQuantifierForIntersections,
+                                SetQuantifier defaultSetQuantifierForExcepts )
+    {
+        super( processor );
+        Objects.requireNonNull( defaultSetQuantifierForUnions, "default quantifier for unions" );
+        Objects.requireNonNull( defaultSetQuantifierForIntersections, "default quantifier for intersections" );
+        Objects.requireNonNull( defaultSetQuantifierForExcepts, "default quantifier for excepts" );
+        Objects.requireNonNull( topLevelExpression, "top level expression" );
+
+        this._defaultSetQuantifierForExcepts = defaultSetQuantifierForExcepts;
+        this._defaultSetQuantifierForIntersections = defaultSetQuantifierForIntersections;
+        this._defaultSetQuantifierForUnions = defaultSetQuantifierForUnions;
+        this._topLevelExpression = topLevelExpression;
+    }
+
+    public QueryBuilder union( QueryExpressionBody another )
+    {
+        return this.union( this._defaultSetQuantifierForUnions, another );
+    }
+
+    public QueryBuilder union( CorrespondingSpec correspondingSpec, QueryExpressionBody another )
+    {
+        return this.union( this._defaultSetQuantifierForUnions, correspondingSpec, another );
+    }
+
+    public QueryBuilder union( SetQuantifier setQuantifier, QueryExpressionBody another )
+    {
+        return this.union( setQuantifier, null, another );
+    }
+
+    public QueryBuilder union( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                               QueryExpressionBody another )
+    {
+        this._topLevelExpression = new QueryExpressionBodyBinaryImpl( this.getProcessor(), SetOperation.UNION,
+                                                                      this._topLevelExpression, another, setQuantifier, correspondingSpec );
+        return this;
+    }
+
+    public QueryBuilder intersect( QueryExpressionBody another )
+    {
+        return this.intersect( this._defaultSetQuantifierForIntersections, another );
+    }
+
+    public QueryBuilder intersect( CorrespondingSpec correspondingSpec, QueryExpressionBody another )
+    {
+        return this.intersect( this._defaultSetQuantifierForIntersections, correspondingSpec, another );
+    }
+
+    public QueryBuilder intersect( SetQuantifier setQuantifier, QueryExpressionBody another )
+    {
+        return this.intersect( setQuantifier, null, another );
+    }
+
+    public QueryBuilder intersect( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                                   QueryExpressionBody another )
+    {
+        this._topLevelExpression = new QueryExpressionBodyBinaryImpl( this.getProcessor(), SetOperation.INTERSECT,
+                                                                      this._topLevelExpression, another, setQuantifier, correspondingSpec );
+        return this;
+    }
+
+    public QueryBuilder except( QueryExpressionBody another )
+    {
+        return this.except( this._defaultSetQuantifierForExcepts, another );
+    }
+
+    public QueryBuilder except( CorrespondingSpec correspondingSpec, QueryExpressionBody another )
+    {
+        return this.except( this._defaultSetQuantifierForExcepts, correspondingSpec, another );
+    }
+
+    public QueryBuilder except( SetQuantifier setQuantifier, QueryExpressionBody another )
+    {
+        return this.except( setQuantifier, null, another );
+    }
+
+    public QueryBuilder except( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                                QueryExpressionBody another )
+    {
+        this._topLevelExpression = new QueryExpressionBodyBinaryImpl( this.getProcessor(), SetOperation.EXCEPT,
+                                                                      this._topLevelExpression, another, setQuantifier, correspondingSpec );
+        return this;
+    }
+
+    public QueryExpressionBody createExpression()
+    {
+        return this._topLevelExpression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QuerySpecificationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QuerySpecificationBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QuerySpecificationBuilderImpl.java
new file mode 100644
index 0000000..c7e83aa
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/QuerySpecificationBuilderImpl.java
@@ -0,0 +1,238 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.FromBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.GroupByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.OrderByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.QuerySpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QuerySpecificationBuilderImpl extends AbstractQueryFactoryImpl<QuerySpecification>
+    implements QuerySpecificationBuilder
+{
+
+    private ColumnsBuilder _select;
+
+    private FromBuilder _from;
+
+    private BooleanBuilder _where;
+
+    private GroupByBuilder _groupBy;
+
+    private BooleanBuilder _having;
+
+    private OrderByBuilder _orderBy;
+
+    private final QueryFactory _queryFactory;
+
+    public QuerySpecificationBuilderImpl( SQLProcessorAggregator processor, QueryFactory q, ColumnsBuilder select,
+                                          FromBuilder from, BooleanBuilder where, GroupByBuilder groupBy, BooleanBuilder having, OrderByBuilder orderBy )
+    {
+        super( processor );
+
+        Objects.requireNonNull( q, "Query factory" );
+        Objects.requireNonNull( select, "select" );
+        Objects.requireNonNull( from, "from" );
+        Objects.requireNonNull( where, "where" );
+        Objects.requireNonNull( groupBy, "group by" );
+        Objects.requireNonNull( having, "having" );
+        Objects.requireNonNull( orderBy, "order by" );
+
+        this._queryFactory = q;
+        this._select = select;
+        this._from = from;
+        this._where = where;
+        this._groupBy = groupBy;
+        this._having = having;
+        this._orderBy = orderBy;
+    }
+
+    public FromBuilder getFrom()
+    {
+        return this._from;
+    }
+
+    public ColumnsBuilder getSelect()
+    {
+        return this._select;
+    }
+
+    public BooleanBuilder getWhere()
+    {
+        return this._where;
+    }
+
+    public GroupByBuilder getGroupBy()
+    {
+        return this._groupBy;
+    }
+
+    public BooleanBuilder getHaving()
+    {
+        return this._having;
+    }
+
+    public OrderByBuilder getOrderBy()
+    {
+        return this._orderBy;
+    }
+
+    public QuerySpecificationBuilder trimGroupBy()
+    {
+        if( this._having.createExpression() != Predicate.EmptyPredicate.INSTANCE )
+        {
+            List<ColumnReference> groupByColumns = new ArrayList<ColumnReference>();
+            for( GroupingElement element : this._groupBy.getGroupingElements() )
+            {
+                if( element instanceof OrdinaryGroupingSet )
+                {
+                    for( NonBooleanExpression exp : ( (OrdinaryGroupingSet) element ).getColumns() )
+                    {
+                        if( exp instanceof ColumnReference )
+                        {
+                            groupByColumns.add( (ColumnReference) exp );
+                        }
+                    }
+                }
+            }
+            for( ColumnReferenceInfo column : this._select.getColumns() )
+            {
+                Boolean noColumn = true;
+                for( ColumnReference groupByColumn : groupByColumns )
+                {
+                    if( column.getReference().equals( groupByColumn ) )
+                    {
+                        noColumn = false;
+                        break;
+                    }
+                }
+
+                if( noColumn )
+                {
+                    this._groupBy.addGroupingElements( this._queryFactory.groupingElement( column.getReference() ) );
+                }
+            }
+        }
+
+        return this;
+    }
+
+    public QuerySpecification createExpression()
+    {
+        return new QuerySpecificationImpl( this.getProcessor(), this._select.createExpression(),
+                                           this._from.createExpression(), this._where.createExpression(), this._groupBy.createExpression(),
+                                           this._having.createExpression(), this._orderBy.createExpression(), this.getOffset(), this.getLimit() );
+    }
+
+    public QuerySpecificationBuilder setSelect( ColumnsBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._select = builder;
+        return this;
+    }
+
+    public QuerySpecificationBuilder setFrom( FromBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._from = builder;
+        return this;
+    }
+
+    public QuerySpecificationBuilder setWhere( BooleanBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._where = builder;
+        return this;
+    }
+
+    public QuerySpecificationBuilder setGroupBy( GroupByBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._groupBy = builder;
+        return this;
+    }
+
+    public QuerySpecificationBuilder setHaving( BooleanBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._having = builder;
+        return this;
+    }
+
+    public QuerySpecificationBuilder setOrderBy( OrderByBuilder builder )
+    {
+        Objects.requireNonNull( builder, "builder" );
+        this._orderBy = builder;
+        return this;
+    }
+
+    protected QueryFactory getQueryFactory()
+    {
+        return this._queryFactory;
+    }
+
+    @Override
+    public QuerySpecificationBuilder limit()
+    {
+        return (QuerySpecificationBuilder) super.limit();
+    }
+
+    @Override
+    public QuerySpecificationBuilder limit( Integer max )
+    {
+        return (QuerySpecificationBuilder) super.limit( max );
+    }
+
+    @Override
+    public QuerySpecificationBuilder limit( NonBooleanExpression max )
+    {
+        return (QuerySpecificationBuilder) super.limit( max );
+    }
+
+    @Override
+    public QuerySpecificationBuilder offset( Integer skip )
+    {
+        return (QuerySpecificationBuilder) super.offset( skip );
+    }
+
+    @Override
+    public QuerySpecificationBuilder offset( NonBooleanExpression skip )
+    {
+        return (QuerySpecificationBuilder) super.offset( skip );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/SimpleQueryBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/SimpleQueryBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/SimpleQueryBuilderImpl.java
new file mode 100644
index 0000000..0da15e0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/SimpleQueryBuilderImpl.java
@@ -0,0 +1,262 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.SimpleQueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SimpleQueryBuilderImpl extends AbstractQueryFactoryImpl<QueryExpression>
+    implements SimpleQueryBuilder
+{
+
+    private final List<ColumnReference> _columns;
+
+    private final Map<Integer, String> _columnAliases;
+
+    private final List<TableName> _from;
+
+    private BooleanExpression _where;
+
+    private final List<String> _groupBy;
+
+    private BooleanExpression _having;
+
+    private final List<String> _orderBy;
+
+    private final List<Ordering> _orderings;
+
+    private final SQLVendor _vendor;
+
+    private boolean _selectAll;
+
+    public SimpleQueryBuilderImpl( SQLProcessorAggregator processor, SQLVendor vendor )
+    {
+        super( processor );
+        Objects.requireNonNull( vendor, "Vendor" );
+
+        this._vendor = vendor;
+        this._columns = new ArrayList<ColumnReference>();
+        this._columnAliases = new HashMap<Integer, String>();
+        this._from = new ArrayList<TableName>();
+        this._groupBy = new ArrayList<String>();
+        this._orderBy = new ArrayList<String>();
+        this._orderings = new ArrayList<Ordering>();
+        this._selectAll = false;
+    }
+
+    public QueryExpression createExpression()
+    {
+        QueryFactory q = this._vendor.getQueryFactory();
+
+        QuerySpecificationBuilder builda = q.querySpecificationBuilder();
+
+        this.processQuerySpecBuilder( builda );
+
+        return q.createQuery( builda.createExpression() );
+    }
+
+    protected void processQuerySpecBuilder( QuerySpecificationBuilder builda )
+    {
+        QueryFactory q = this._vendor.getQueryFactory();
+        ColumnsFactory c = this._vendor.getColumnsFactory();
+        TableReferenceFactory t = this._vendor.getTableReferenceFactory();
+
+        if( this._selectAll )
+        {
+            builda.getSelect().selectAll();
+        }
+        else
+        {
+            for( Integer colIndex = 0; colIndex < this._columns.size(); ++colIndex )
+            {
+                ColumnReference ref = this._columns.get( colIndex );
+                String alias = this._columnAliases.get( colIndex );
+                builda.getSelect().addNamedColumns( new ColumnReferenceInfo( alias, ref ) );
+            }
+        }
+        for( TableName tableName : this._from )
+        {
+            builda.getFrom().addTableReferences( t.tableBuilder( t.table( tableName ) ) );
+        }
+
+        builda.getWhere().reset( this._where );
+
+        for( String groupBy : this._groupBy )
+        {
+            builda.getGroupBy().addGroupingElements( q.groupingElement( c.colName( groupBy ) ) );
+        }
+
+        builda.getHaving().reset( this._having );
+
+        for( Integer orderByIndex = 0; orderByIndex < this._orderBy.size(); ++orderByIndex )
+        {
+            builda.getOrderBy().addSortSpecs(
+                q.sortSpec( c.colName( this._orderBy.get( orderByIndex ) ), this._orderings.get( orderByIndex ) ) );
+        }
+
+        if( this.getOffset() != null )
+        {
+            builda.offset( this.getOffset().getSkip() );
+        }
+
+        if( this.getLimit() != null )
+        {
+            builda.limit( this.getLimit().getCount() );
+        }
+    }
+
+    protected SQLVendor getVendor()
+    {
+        return this._vendor;
+    }
+
+    public SimpleQueryBuilder select( String... columnNames )
+    {
+        this._selectAll = false;
+        for( String col : columnNames )
+        {
+            this._columns.add( this._vendor.getColumnsFactory().colName( col ) );
+        }
+        return this;
+    }
+
+    public SimpleQueryBuilder select( ValueExpression... expressions )
+    {
+        this._selectAll = false;
+        for( ValueExpression exp : expressions )
+        {
+            this._columns.add( this._vendor.getColumnsFactory().colExp( exp ) );
+        }
+        return this;
+    }
+
+    public SimpleQueryBuilder selectAllColumns()
+    {
+        this._selectAll = true;
+        return this;
+    }
+
+    public SimpleQueryBuilder as( String columnAlias )
+    {
+        this._columnAliases.put( this._columns.size() - 1, columnAlias );
+        return this;
+    }
+
+    public SimpleQueryBuilder from( TableName... tableNames )
+    {
+        for( TableName table : tableNames )
+        {
+            this._from.add( table );
+        }
+        return this;
+    }
+
+    public SimpleQueryBuilder where( BooleanExpression searchCondition )
+    {
+        this._where = searchCondition;
+        return this;
+    }
+
+    public SimpleQueryBuilder groupBy( String... columns )
+    {
+        for( String col : columns )
+        {
+            this._groupBy.add( col );
+        }
+        return this;
+    }
+
+    public SimpleQueryBuilder having( BooleanExpression groupingCondition )
+    {
+        this._having = groupingCondition;
+        return this;
+    }
+
+    public SimpleQueryBuilder orderByAsc( String... columns )
+    {
+        for( String col : columns )
+        {
+            this._orderBy.add( col );
+            this._orderings.add( Ordering.ASCENDING );
+        }
+        return this;
+    }
+
+    public SimpleQueryBuilder orderByDesc( String... columns )
+    {
+        for( String col : columns )
+        {
+            this._orderBy.add( col );
+            this._orderings.add( Ordering.DESCENDING );
+        }
+        return this;
+    }
+
+    @Override
+    public SimpleQueryBuilder limit()
+    {
+        return (SimpleQueryBuilder) super.limit();
+    }
+
+    @Override
+    public SimpleQueryBuilder limit( Integer max )
+    {
+        return (SimpleQueryBuilder) super.limit( max );
+    }
+
+    @Override
+    public SimpleQueryBuilder limit( NonBooleanExpression max )
+    {
+        return (SimpleQueryBuilder) super.limit( max );
+    }
+
+    @Override
+    public SimpleQueryBuilder offset( Integer skip )
+    {
+        return (SimpleQueryBuilder) super.offset( skip );
+    }
+
+    @Override
+    public SimpleQueryBuilder offset( NonBooleanExpression skip )
+    {
+        return (SimpleQueryBuilder) super.offset( skip );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/TableReferenceBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/TableReferenceBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/TableReferenceBuilderImpl.java
new file mode 100644
index 0000000..a98dd35
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/query/TableReferenceBuilderImpl.java
@@ -0,0 +1,78 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferencePrimary;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.CrossJoinedTableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.NaturalJoinedTableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.QualifiedJoinedTableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.UnionJoinedTableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class TableReferenceBuilderImpl extends SQLBuilderBase
+    implements TableReferenceBuilder
+{
+
+    private TableReference _currentTable;
+
+    public TableReferenceBuilderImpl( SQLProcessorAggregator processor, TableReferencePrimary startingTable )
+    {
+        super( processor );
+        Objects.requireNonNull( startingTable, "starting table" );
+
+        this._currentTable = startingTable;
+    }
+
+    public TableReferenceBuilder addQualifiedJoin( JoinType joinType, TableReference right, JoinSpecification joinSpec )
+    {
+        this._currentTable = new QualifiedJoinedTableImpl( this.getProcessor(), this._currentTable, right, joinType,
+                                                           joinSpec );
+        return this;
+    }
+
+    public TableReferenceBuilder addCrossJoin( TableReference right )
+    {
+        this._currentTable = new CrossJoinedTableImpl( this.getProcessor(), this._currentTable, right );
+        return this;
+    }
+
+    public TableReferenceBuilder addNaturalJoin( JoinType joinType, TableReference right )
+    {
+        this._currentTable = new NaturalJoinedTableImpl( this.getProcessor(), this._currentTable, right, joinType );
+        return this;
+    }
+
+    public TableReferenceBuilder addUnionJoin( TableReference right )
+    {
+        this._currentTable = new UnionJoinedTableImpl( this.getProcessor(), this._currentTable, right );
+        return this;
+    }
+
+    public TableReference createExpression()
+    {
+        return this._currentTable;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/ColumnNameListImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/ColumnNameListImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/ColumnNameListImpl.java
new file mode 100644
index 0000000..a04ba7c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/ColumnNameListImpl.java
@@ -0,0 +1,80 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnNameListImpl extends SQLSyntaxElementBase<ColumnNameList, ColumnNameList>
+    implements ColumnNameList
+{
+
+    private final List<String> _columnNames;
+
+    public ColumnNameListImpl( SQLProcessorAggregator processor, Collection<String> columnNames )
+    {
+        this( processor, ColumnNameList.class, columnNames );
+    }
+
+    protected ColumnNameListImpl( SQLProcessorAggregator processor,
+                                  Class<? extends ColumnNameList> implClass,
+                                  Collection<String> columnNames )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( columnNames, "column names" );
+
+        if( columnNames.isEmpty() )
+        {
+            throw new IllegalArgumentException( "Column name list must have at least one column." );
+        }
+
+        for( String columnName : columnNames )
+        {
+            Objects.requireNonNull( columnName, "column name" );
+        }
+
+        this._columnNames = Collections.unmodifiableList( new ArrayList<String>( columnNames ) );
+    }
+
+    public ColumnNameListImpl( SQLProcessorAggregator processor, String... columnNames )
+    {
+        this( processor, Arrays.asList( columnNames ) );
+    }
+
+    public List<String> getColumnNames()
+    {
+        return this._columnNames;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnNameList another )
+    {
+        return this._columnNames.equals( another.getColumnNames() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/NonBooleanExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/NonBooleanExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/NonBooleanExpressionImpl.java
new file mode 100644
index 0000000..7e92690
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/NonBooleanExpressionImpl.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class NonBooleanExpressionImpl<ExpressionType extends NonBooleanExpression> extends
+                                                                                            SQLSyntaxElementBase<ValueExpression, ExpressionType>
+{
+
+    protected NonBooleanExpressionImpl( SQLProcessorAggregator aggregator,
+                                        Class<? extends ExpressionType> expressionClass )
+    {
+        super( aggregator, expressionClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLBuilderBase.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLBuilderBase.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLBuilderBase.java
new file mode 100644
index 0000000..099a07b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLBuilderBase.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public abstract class SQLBuilderBase
+{
+    private final SQLProcessorAggregator _processor;
+
+    protected SQLBuilderBase( SQLProcessorAggregator processor )
+    {
+        Objects.requireNonNull( processor, "Processor" );
+
+        this._processor = processor;
+    }
+
+    protected SQLProcessorAggregator getProcessor()
+    {
+        return this._processor;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLFactoryBase.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLFactoryBase.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLFactoryBase.java
new file mode 100644
index 0000000..5f0ecc8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLFactoryBase.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public abstract class SQLFactoryBase
+{
+
+    private final SQLVendor _vendor;
+    private final SQLProcessorAggregator _processor;
+
+    protected SQLFactoryBase( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        Objects.requireNonNull( vendor, "vendor" );
+        Objects.requireNonNull( processor, "SQL processor" );
+
+        this._vendor = vendor;
+        this._processor = processor;
+    }
+
+    protected SQLVendor getVendor()
+    {
+        return this._vendor;
+    }
+
+    protected SQLProcessorAggregator getProcessor()
+    {
+        return this._processor;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLSyntaxElementBase.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLSyntaxElementBase.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLSyntaxElementBase.java
new file mode 100644
index 0000000..1dc548b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/SQLSyntaxElementBase.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public abstract class SQLSyntaxElementBase<BaseInterfaceType extends Typeable<?>, ActualInterfaceType extends BaseInterfaceType>
+    extends TypeableImpl<BaseInterfaceType, ActualInterfaceType>
+{
+    private final SQLProcessorAggregator _processor;
+
+    protected SQLSyntaxElementBase( SQLProcessorAggregator processor,
+                                    Class<? extends ActualInterfaceType> realImplementingType )
+    {
+        super( realImplementingType );
+
+        Objects.requireNonNull( processor, "SQL Processor" );
+
+        this._processor = processor;
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        this._processor.process( this, builder );
+        return builder.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameDirectImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameDirectImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameDirectImpl.java
new file mode 100644
index 0000000..2e98080
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameDirectImpl.java
@@ -0,0 +1,58 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableNameDirectImpl extends TableNameImpl<TableNameDirect>
+    implements TableNameDirect
+{
+    private final String _tableName;
+
+    public TableNameDirectImpl( SQLProcessorAggregator processor, String schemaName, String tableName )
+    {
+        this( processor, TableNameDirect.class, schemaName, tableName );
+    }
+
+    protected TableNameDirectImpl( SQLProcessorAggregator processor, Class<? extends TableNameDirect> implClass,
+                                   String schemaName, String tableName )
+    {
+        super( processor, implClass, schemaName );
+        Objects.requireNonNull( tableName, "table name" );
+
+        this._tableName = tableName;
+    }
+
+    public String getTableName()
+    {
+        return this._tableName;
+    }
+
+    @Override
+    protected boolean doesEqual( TableNameDirect another )
+    {
+        return super.doesEqual( another ) && this._tableName.equals( another.getTableName() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameFunctionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameFunctionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameFunctionImpl.java
new file mode 100644
index 0000000..d758473
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameFunctionImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class TableNameFunctionImpl extends TableNameImpl<TableNameFunction>
+    implements TableNameFunction
+{
+
+    private final SQLFunctionLiteral _function;
+
+    public TableNameFunctionImpl( SQLProcessorAggregator processor, String schemaName, SQLFunctionLiteral function )
+    {
+        this( processor, TableNameFunction.class, schemaName, function );
+    }
+
+    protected TableNameFunctionImpl( SQLProcessorAggregator processor, Class<? extends TableNameFunction> implClass,
+                                     String schemaName, SQLFunctionLiteral function )
+    {
+        super( processor, implClass, schemaName );
+        Objects.requireNonNull( function, "SQL function" );
+
+        this._function = function;
+    }
+
+    public SQLFunctionLiteral getFunction()
+    {
+        return this._function;
+    }
+
+    @Override
+    protected boolean doesEqual( TableNameFunction another )
+    {
+        return super.doesEqual( another ) && this._function.equals( another.getFunction() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameImpl.java
new file mode 100644
index 0000000..d6f63f0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/TableNameImpl.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class TableNameImpl<TableNameType extends TableName> extends SQLSyntaxElementBase<TableName, TableNameType>
+    implements TableName
+{
+    private final String _schemaName;
+
+    protected TableNameImpl( SQLProcessorAggregator processor, Class<? extends TableNameType> implClass,
+                             String schemaName )
+    {
+        super( processor, implClass );
+
+        this._schemaName = schemaName;
+    }
+
+    public String getSchemaName()
+    {
+        return this._schemaName;
+    }
+
+    @Override
+    protected boolean doesEqual( TableNameType another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._schemaName, another.getSchemaName() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/BigIntImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/BigIntImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/BigIntImpl.java
new file mode 100644
index 0000000..6a8aa73
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/BigIntImpl.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class BigIntImpl
+    implements BigInt
+{
+    public BigIntImpl()
+    {
+    }
+
+    /**
+     * Returns {@link BigInt}.
+     */
+    public Class<BigInt> getImplementedType()
+    {
+        return BigInt.class;
+    }
+
+    /**
+     * The singleton instance of {@code BIGINT}.
+     */
+    public static final BigInt INSTANCE = new BigIntImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DecimalImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DecimalImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DecimalImpl.java
new file mode 100644
index 0000000..2015562
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DecimalImpl.java
@@ -0,0 +1,74 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class DecimalImpl extends TypeableImpl<SQLDataType, Decimal>
+    implements Decimal
+{
+    private final Integer _precision;
+    private final Integer _scale;
+
+    public DecimalImpl( Integer precision, Integer scale )
+    {
+        super( Decimal.class );
+
+        this._precision = precision;
+        this._scale = scale;
+    }
+
+    @Override
+    protected boolean doesEqual( Decimal another )
+    {
+        return bothNullOrEquals( this._precision, another.getPrecision() )
+               && bothNullOrEquals( this._scale, another.getScale() );
+    }
+
+    /**
+     * Returns the precision (first integer) for this {@code DECIMAL}.
+     *
+     * @return The precision for this {@code DECIMAL}.
+     */
+    public Integer getPrecision()
+    {
+        return this._precision;
+    }
+
+    /**
+     * Returns the scale (second integer) for this {@code DECIMAL}.
+     *
+     * @return The precision for this {@code DECIMAL}.
+     */
+    public Integer getScale()
+    {
+        return this._scale;
+    }
+
+    /**
+     * This instance represents {@code DECIMAL} without precision and scale.
+     */
+    public static final Decimal PLAIN_DECIMAL = new DecimalImpl( null, null );
+}
\ No newline at end of file


[07/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLDataTypeFactoryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLDataTypeFactoryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLDataTypeFactoryImpl.java
new file mode 100644
index 0000000..2cbc4ae
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLDataTypeFactoryImpl.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.pgsql.Text;
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLDataTypeFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.pgsql.TextImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultDataTypeFactory;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PgSQLDataTypeFactoryImpl extends DefaultDataTypeFactory
+    implements PgSQLDataTypeFactory
+{
+
+    public PgSQLDataTypeFactoryImpl( PostgreSQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public Text text()
+    {
+        return TextImpl.INSTANCE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLManipulationFactoryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLManipulationFactoryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLManipulationFactoryImpl.java
new file mode 100644
index 0000000..52c43ce
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLManipulationFactoryImpl.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLManipulationFactory;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultManipulationFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PgSQLManipulationFactoryImpl extends DefaultManipulationFactory
+    implements PgSQLManipulationFactory
+{
+    public PgSQLManipulationFactoryImpl( PostgreSQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    @Override
+    public PgSQLDropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                                         DropBehaviour dropBehaviour )
+    {
+        return this.createDropTableOrViewStatement( tableName, theType, dropBehaviour, false );
+    }
+
+    public PgSQLDropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                                         DropBehaviour dropBehaviour, Boolean useIfExists )
+    {
+        return new PgSQLDropTableOrViewStatementImpl( this.getProcessor(), theType, dropBehaviour, tableName,
+                                                      useIfExists );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLModificationFactoryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLModificationFactoryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLModificationFactoryImpl.java
new file mode 100644
index 0000000..18905ec
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/pgsql/PgSQLModificationFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.pgsql.PgSQLInsertStatementBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultModificationFactory;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+
+public class PgSQLModificationFactoryImpl extends DefaultModificationFactory
+{
+
+    public PgSQLModificationFactoryImpl( PostgreSQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    @Override
+    public InsertStatementBuilder insert()
+    {
+        return new PgSQLInsertStatementBuilderImpl( this.getProcessor() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/DirectLiteralImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/DirectLiteralImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/DirectLiteralImpl.java
new file mode 100644
index 0000000..f2fc875
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/DirectLiteralImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.literals;
+
+import org.apache.polygene.library.sql.generator.grammar.literals.DirectLiteral;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DirectLiteralImpl extends NonBooleanExpressionImpl<DirectLiteral>
+    implements DirectLiteral
+{
+
+    private final String _literal;
+
+    public DirectLiteralImpl( SQLProcessorAggregator processor, String literal )
+    {
+        this( processor, DirectLiteral.class, literal );
+    }
+
+    protected DirectLiteralImpl( SQLProcessorAggregator processor, Class<? extends DirectLiteral> implClass,
+                                 String literal )
+    {
+        super( processor, implClass );
+
+        this._literal = literal;
+    }
+
+    public String getDirectLiteral()
+    {
+        return this._literal;
+    }
+
+    @Override
+    protected boolean doesEqual( DirectLiteral another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._literal, another.getDirectLiteral() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/NumericLiteralImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/NumericLiteralImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/NumericLiteralImpl.java
new file mode 100644
index 0000000..bc714c2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/NumericLiteralImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.literals;
+
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NumericLiteralImpl extends NonBooleanExpressionImpl<NumericLiteral>
+    implements NumericLiteral
+{
+
+    private final Number _number;
+
+    public NumericLiteralImpl( SQLProcessorAggregator processor, Number number )
+    {
+        this( processor, NumericLiteral.class, number );
+    }
+
+    protected NumericLiteralImpl( SQLProcessorAggregator processor, Class<? extends NumericLiteral> implClass,
+                                  Number number )
+    {
+        super( processor, implClass );
+
+        this._number = number;
+    }
+
+    public Number getNumber()
+    {
+        return this._number;
+    }
+
+    @Override
+    protected boolean doesEqual( NumericLiteral another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._number, another.getNumber() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/SQLFunctionLiteralImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/SQLFunctionLiteralImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/SQLFunctionLiteralImpl.java
new file mode 100644
index 0000000..e397e2f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/SQLFunctionLiteralImpl.java
@@ -0,0 +1,83 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.literals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SQLFunctionLiteralImpl extends NonBooleanExpressionImpl<SQLFunctionLiteral>
+    implements SQLFunctionLiteral
+{
+
+    private final String _name;
+
+    private final List<ValueExpression> _parameters;
+
+    public SQLFunctionLiteralImpl( SQLProcessorAggregator processor, String name, ValueExpression... parameters )
+    {
+        this( processor, name, Arrays.asList( parameters ) );
+    }
+
+    public SQLFunctionLiteralImpl( SQLProcessorAggregator processor, String name, List<ValueExpression> parameters )
+    {
+        this( processor, SQLFunctionLiteral.class, name, parameters );
+    }
+
+    protected SQLFunctionLiteralImpl( SQLProcessorAggregator processor, Class<? extends SQLFunctionLiteral> implClass,
+                                      String name, List<ValueExpression> parameters )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( name, "name" );
+        Objects.requireNonNull( parameters, "parameters" );
+        for( ValueExpression exp : parameters )
+        {
+            Objects.requireNonNull( exp, "parameter" );
+        }
+
+        this._name = name;
+        this._parameters = Collections.unmodifiableList( new ArrayList<ValueExpression>( parameters ) );
+    }
+
+    public String getFunctionName()
+    {
+        return this._name;
+    }
+
+    public List<ValueExpression> getParameters()
+    {
+        return this._parameters;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLFunctionLiteral another )
+    {
+        return this._name.equals( another.getFunctionName() ) && this._parameters.equals( another.getParameters() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/StringLiteralImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/StringLiteralImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/StringLiteralImpl.java
new file mode 100644
index 0000000..fa3b075
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/StringLiteralImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.literals;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.literals.StringLiteral;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class StringLiteralImpl extends NonBooleanExpressionImpl<StringLiteral>
+    implements StringLiteral
+{
+
+    private final String _literal;
+
+    public StringLiteralImpl( SQLProcessorAggregator processor, String literal )
+    {
+        this( processor, StringLiteral.class, literal );
+    }
+
+    protected StringLiteralImpl( SQLProcessorAggregator processor, Class<? extends StringLiteral> implClass,
+                                 String literal )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( literal, "literal" );
+
+        this._literal = literal;
+    }
+
+    public String getString()
+    {
+        return this._literal;
+    }
+
+    @Override
+    protected boolean doesEqual( StringLiteral another )
+    {
+        return this._literal.equals( another.getString() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/TimestampLiteralImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/TimestampLiteralImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/TimestampLiteralImpl.java
new file mode 100644
index 0000000..8245bd1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/literals/TimestampLiteralImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.literals;
+
+import java.sql.Timestamp;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TimestampLiteralImpl extends NonBooleanExpressionImpl<TimestampTimeLiteral>
+    implements TimestampTimeLiteral
+{
+
+    private final Timestamp _date;
+
+    public TimestampLiteralImpl( SQLProcessorAggregator processor, Timestamp date )
+    {
+        this( processor, TimestampTimeLiteral.class, date );
+    }
+
+    protected TimestampLiteralImpl( SQLProcessorAggregator processor, Class<? extends TimestampTimeLiteral> implClass,
+                                    Timestamp date )
+    {
+        super( processor, implClass );
+
+        Objects.requireNonNull( date, "Timestamp" );
+        this._date = date;
+    }
+
+    public Timestamp getTimestamp()
+    {
+        return this._date;
+    }
+
+    @Override
+    protected boolean doesEqual( TimestampTimeLiteral another )
+    {
+        return this._date.equals( another.getTimestamp() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddColumnDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddColumnDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddColumnDefinitionImpl.java
new file mode 100644
index 0000000..4400ebc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddColumnDefinitionImpl.java
@@ -0,0 +1,63 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class AddColumnDefinitionImpl extends SQLSyntaxElementBase<AlterTableAction, AddColumnDefinition>
+    implements AddColumnDefinition
+{
+
+    private final ColumnDefinition _columnDefinition;
+
+    public AddColumnDefinitionImpl( SQLProcessorAggregator processor, ColumnDefinition columnDefinition )
+    {
+        this( processor, AddColumnDefinition.class, columnDefinition );
+    }
+
+    protected AddColumnDefinitionImpl( SQLProcessorAggregator processor,
+                                       Class<? extends AddColumnDefinition> realImplementingType, ColumnDefinition columnDefinition )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( columnDefinition, "Column definition" );
+
+        this._columnDefinition = columnDefinition;
+    }
+
+    @Override
+    protected boolean doesEqual( AddColumnDefinition another )
+    {
+        return this._columnDefinition.equals( another.getColumnDefinition() );
+    }
+
+    public ColumnDefinition getColumnDefinition()
+    {
+        return this._columnDefinition;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddTableConstraintDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddTableConstraintDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddTableConstraintDefinitionImpl.java
new file mode 100644
index 0000000..d23ddf3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AddTableConstraintDefinitionImpl.java
@@ -0,0 +1,62 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class AddTableConstraintDefinitionImpl extends
+                                              SQLSyntaxElementBase<AlterTableAction, AddTableConstraintDefinition>
+    implements AddTableConstraintDefinition
+{
+
+    private final TableConstraintDefinition _constraint;
+
+    public AddTableConstraintDefinitionImpl( SQLProcessorAggregator processor, TableConstraintDefinition constraint )
+    {
+        this( processor, AddTableConstraintDefinition.class, constraint );
+    }
+
+    protected AddTableConstraintDefinitionImpl( SQLProcessorAggregator processor,
+                                                Class<? extends AddTableConstraintDefinition> realImplementingType, TableConstraintDefinition constraint )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( constraint, "Constraint" );
+        this._constraint = constraint;
+    }
+
+    @Override
+    protected boolean doesEqual( AddTableConstraintDefinition another )
+    {
+        return this._constraint.equals( another.getConstraint() );
+    }
+
+    public TableConstraintDefinition getConstraint()
+    {
+        return this._constraint;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterColumnDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterColumnDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterColumnDefinitionImpl.java
new file mode 100644
index 0000000..5689e9c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterColumnDefinitionImpl.java
@@ -0,0 +1,69 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class AlterColumnDefinitionImpl extends SQLSyntaxElementBase<AlterTableAction, AlterColumnDefinition>
+    implements AlterColumnDefinition
+{
+
+    private final String _columnName;
+    private final AlterColumnAction _action;
+
+    public AlterColumnDefinitionImpl( SQLProcessorAggregator processor, String columnName, AlterColumnAction action )
+    {
+        this( processor, AlterColumnDefinition.class, columnName, action );
+    }
+
+    protected AlterColumnDefinitionImpl( SQLProcessorAggregator processor,
+                                         Class<? extends AlterColumnDefinition> realImplementingType, String columnName, AlterColumnAction action )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( columnName, "Column name" );
+        Objects.requireNonNull( action, "Alter column action" );
+        this._columnName = columnName;
+        this._action = action;
+    }
+
+    @Override
+    protected boolean doesEqual( AlterColumnDefinition another )
+    {
+        return this._columnName.equals( another.getColumnName() ) && this._action.equals( another.getAction() );
+    }
+
+    public AlterColumnAction getAction()
+    {
+        return this._action;
+    }
+
+    public String getColumnName()
+    {
+        return this._columnName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterTableStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterTableStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterTableStatementImpl.java
new file mode 100644
index 0000000..284ac6d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/AlterTableStatementImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableStatement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class AlterTableStatementImpl extends SQLSyntaxElementBase<SchemaStatement, AlterTableStatement>
+    implements AlterTableStatement
+{
+
+    private final TableNameDirect _tableName;
+    private final AlterTableAction _action;
+
+    public AlterTableStatementImpl( SQLProcessorAggregator processor, TableNameDirect tableName, AlterTableAction action )
+    {
+        this( processor, AlterTableStatement.class, tableName, action );
+    }
+
+    protected AlterTableStatementImpl( SQLProcessorAggregator processor,
+                                       Class<? extends AlterTableStatement> realImplementingType, TableNameDirect tableName, AlterTableAction action )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( tableName, "Table name" );
+        Objects.requireNonNull( action, "Alter table taction" );
+        this._tableName = tableName;
+        this._action = action;
+    }
+
+    @Override
+    protected boolean doesEqual( AlterTableStatement another )
+    {
+        return this._tableName.equals( another.getTableName() ) && this._action.equals( another.getAction() );
+    }
+
+    public AlterTableAction getAction()
+    {
+        return this._action;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._tableName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropColumnDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropColumnDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropColumnDefinitionImpl.java
new file mode 100644
index 0000000..3db7753
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropColumnDefinitionImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropColumnDefinition;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DropColumnDefinitionImpl extends SQLSyntaxElementBase<AlterTableAction, DropColumnDefinition>
+    implements DropColumnDefinition
+{
+
+    private final String _columnName;
+    private final DropBehaviour _dropBehaviour;
+
+    public DropColumnDefinitionImpl( SQLProcessorAggregator processor, String columnName, DropBehaviour dropBehaviour )
+    {
+        this( processor, DropColumnDefinition.class, columnName, dropBehaviour );
+    }
+
+    protected DropColumnDefinitionImpl( SQLProcessorAggregator processor,
+                                        Class<? extends DropColumnDefinition> realImplementingType, String columnName, DropBehaviour dropBehaviour )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( columnName, "Column name" );
+        Objects.requireNonNull( dropBehaviour, "Drop behaviour" );
+        this._columnName = columnName;
+        this._dropBehaviour = dropBehaviour;
+    }
+
+    @Override
+    protected boolean doesEqual( DropColumnDefinition another )
+    {
+        return this._dropBehaviour.equals( another.getDropBehaviour() )
+               && this._columnName.equals( another.getColumnName() );
+    }
+
+    public String getColumnName()
+    {
+        return this._columnName;
+    }
+
+    public DropBehaviour getDropBehaviour()
+    {
+        return this._dropBehaviour;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropSchemaStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropSchemaStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropSchemaStatementImpl.java
new file mode 100644
index 0000000..3aaef7b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropSchemaStatementImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DropSchemaStatementImpl extends DropStatementImpl<DropSchemaStatement>
+    implements DropSchemaStatement
+{
+
+    private final String _schemaName;
+
+    public DropSchemaStatementImpl( SQLProcessorAggregator processor, DropBehaviour dropBehaviour, String schemaName )
+    {
+        this( processor, DropSchemaStatement.class, ObjectType.SCHEMA, dropBehaviour, schemaName );
+    }
+
+    protected DropSchemaStatementImpl( SQLProcessorAggregator processor,
+                                       Class<? extends DropSchemaStatement> realImplementingType, ObjectType whatToDrop, DropBehaviour dropBehaviour,
+                                       String schemaName )
+    {
+        super( processor, realImplementingType, whatToDrop, dropBehaviour );
+        Objects.requireNonNull( schemaName, "Schema name" );
+        this._schemaName = schemaName;
+    }
+
+    @Override
+    protected boolean doesEqual( DropSchemaStatement another )
+    {
+        return this._schemaName.equals( another.getSchemaName() ) && super.doesEqual( another );
+    }
+
+    public String getSchemaName()
+    {
+        return this._schemaName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropStatementImpl.java
new file mode 100644
index 0000000..e09f573
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropStatementImpl.java
@@ -0,0 +1,66 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DropStatementImpl<DropStatementType extends DropStatement> extends
+                                                                        SQLSyntaxElementBase<SchemaStatement, DropStatementType>
+    implements DropStatement
+{
+
+    private final DropBehaviour _dropBehaviour;
+    private final ObjectType _whatToDrop;
+
+    protected DropStatementImpl( SQLProcessorAggregator processor,
+                                 Class<? extends DropStatementType> realImplementingType, ObjectType whatToDrop, DropBehaviour dropBehaviour )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( whatToDrop, "What to drop" );
+        Objects.requireNonNull( dropBehaviour, "Drop behaviour" );
+        this._whatToDrop = whatToDrop;
+        this._dropBehaviour = dropBehaviour;
+    }
+
+    protected boolean doesEqual( DropStatementType another )
+    {
+        return this._dropBehaviour.equals( another.getDropBehaviour() )
+               && this._whatToDrop.equals( another.whatToDrop() );
+    }
+
+    public DropBehaviour getDropBehaviour()
+    {
+        return this._dropBehaviour;
+    }
+
+    public ObjectType whatToDrop()
+    {
+        return this._whatToDrop;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableConstraintDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableConstraintDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableConstraintDefinitionImpl.java
new file mode 100644
index 0000000..3e85d7c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableConstraintDefinitionImpl.java
@@ -0,0 +1,73 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DropTableConstraintDefinitionImpl extends
+                                               SQLSyntaxElementBase<AlterTableAction, DropTableConstraintDefinition>
+    implements DropTableConstraintDefinition
+{
+
+    private final String _constraintName;
+    private final DropBehaviour _dropBehaviour;
+
+    public DropTableConstraintDefinitionImpl( SQLProcessorAggregator processor, String constraintName,
+                                              DropBehaviour dropBehaviour )
+    {
+        this( processor, DropTableConstraintDefinition.class, constraintName, dropBehaviour );
+    }
+
+    protected DropTableConstraintDefinitionImpl( SQLProcessorAggregator processor,
+                                                 Class<? extends DropTableConstraintDefinition> realImplementingType, String constraintName,
+                                                 DropBehaviour dropBehaviour )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( constraintName, "Constraint name" );
+        Objects.requireNonNull( dropBehaviour, "Drop behaviour" );
+        this._constraintName = constraintName;
+        this._dropBehaviour = dropBehaviour;
+    }
+
+    @Override
+    protected boolean doesEqual( DropTableConstraintDefinition another )
+    {
+        return this._constraintName.equals( another.getConstraintName() )
+               && this._dropBehaviour.equals( another.getDropBehaviour() );
+    }
+
+    public String getConstraintName()
+    {
+        return this._constraintName;
+    }
+
+    public DropBehaviour getDropBehaviour()
+    {
+        return this._dropBehaviour;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableOrViewStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableOrViewStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableOrViewStatementImpl.java
new file mode 100644
index 0000000..f0c0df0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/DropTableOrViewStatementImpl.java
@@ -0,0 +1,63 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DropTableOrViewStatementImpl extends DropStatementImpl<DropTableOrViewStatement>
+    implements DropTableOrViewStatement
+{
+
+    private final TableNameDirect _name;
+
+    public DropTableOrViewStatementImpl( SQLProcessorAggregator processor, ObjectType whatToDrop,
+                                         DropBehaviour dropBehaviour, TableNameDirect name )
+    {
+        this( processor, DropTableOrViewStatement.class, whatToDrop, dropBehaviour, name );
+    }
+
+    protected DropTableOrViewStatementImpl( SQLProcessorAggregator processor,
+                                            Class<? extends DropTableOrViewStatement> realImplementingType, ObjectType whatToDrop,
+                                            DropBehaviour dropBehaviour, TableNameDirect name )
+    {
+        super( processor, realImplementingType, whatToDrop, dropBehaviour );
+        Objects.requireNonNull( name, "Table name" );
+        this._name = name;
+    }
+
+    @Override
+    protected boolean doesEqual( DropTableOrViewStatement another )
+    {
+        return this._name.equals( another.getTableName() ) && super.doesEqual( another );
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/SetColumnDefaultImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/SetColumnDefaultImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/SetColumnDefaultImpl.java
new file mode 100644
index 0000000..278f166
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/SetColumnDefaultImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.SetColumnDefault;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SetColumnDefaultImpl extends SQLSyntaxElementBase<AlterColumnAction, SetColumnDefault>
+    implements SetColumnDefault
+{
+
+    private final String _default;
+
+    public SetColumnDefaultImpl( SQLProcessorAggregator processor, String colDefault )
+    {
+        this( processor, SetColumnDefault.class, colDefault );
+    }
+
+    protected SetColumnDefaultImpl( SQLProcessorAggregator processor,
+                                    Class<? extends SetColumnDefault> realImplementingType, String colDefault )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( colDefault, "Column default" );
+        this._default = colDefault;
+    }
+
+    @Override
+    protected boolean doesEqual( SetColumnDefault another )
+    {
+        return this._default.equals( another.getDefault() );
+    }
+
+    public String getDefault()
+    {
+        return this._default;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatementImpl.java
new file mode 100644
index 0000000..f9e5e77
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatementImpl.java
@@ -0,0 +1,66 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.manipulation.pgsql;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.DropTableOrViewStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PgSQLDropTableOrViewStatementImpl extends DropTableOrViewStatementImpl
+    implements PgSQLDropTableOrViewStatement
+{
+
+    private final Boolean _useIfExists;
+
+    public PgSQLDropTableOrViewStatementImpl( SQLProcessorAggregator processor, ObjectType whatToDrop,
+                                              DropBehaviour dropBehaviour, TableNameDirect name, Boolean useIfExists )
+    {
+        this( processor, PgSQLDropTableOrViewStatement.class, whatToDrop, dropBehaviour, name, useIfExists );
+    }
+
+    protected PgSQLDropTableOrViewStatementImpl( SQLProcessorAggregator processor,
+                                                 Class<? extends PgSQLDropTableOrViewStatement> realImplementingType, ObjectType whatToDrop,
+                                                 DropBehaviour dropBehaviour, TableNameDirect name, Boolean useIfExists )
+    {
+        super( processor, realImplementingType, whatToDrop, dropBehaviour, name );
+        Objects.requireNonNull( useIfExists, "Use IF EXISTS" );
+        this._useIfExists = useIfExists;
+    }
+
+    @Override
+    protected boolean doesEqual( DropTableOrViewStatement another )
+    {
+        return super.doesEqual( another )
+               && this._useIfExists.equals( ( (PgSQLDropTableOrViewStatement) another ).useIfExists() );
+    }
+
+    public Boolean useIfExists()
+    {
+        return this._useIfExists;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByQueryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByQueryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByQueryImpl.java
new file mode 100644
index 0000000..fdd9479
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByQueryImpl.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnSourceByQueryImpl extends DynamicColumnSourceImpl<ColumnSourceByQuery>
+    implements ColumnSourceByQuery
+{
+
+    private final QueryExpression _query;
+
+    public ColumnSourceByQueryImpl( SQLProcessorAggregator processor, ColumnNameList columnNames, QueryExpression query )
+    {
+        this( processor, ColumnSourceByQuery.class, columnNames, query );
+    }
+
+    protected ColumnSourceByQueryImpl( SQLProcessorAggregator processor,
+                                       Class<? extends ColumnSourceByQuery> expressionClass, ColumnNameList columnNames, QueryExpression query )
+    {
+        super( processor, expressionClass, columnNames );
+        Objects.requireNonNull( query, "query" );
+        this._query = query;
+    }
+
+    public QueryExpression getQuery()
+    {
+        return this._query;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByValuesImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByValuesImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByValuesImpl.java
new file mode 100644
index 0000000..f999371
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/ColumnSourceByValuesImpl.java
@@ -0,0 +1,64 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnSourceByValuesImpl extends DynamicColumnSourceImpl<ColumnSourceByValues>
+    implements ColumnSourceByValues
+{
+
+    private final List<ValueExpression> _expressions;
+
+    public ColumnSourceByValuesImpl( SQLProcessorAggregator processor, ColumnNameList columnNames,
+                                     List<ValueExpression> expressions )
+    {
+        this( processor, ColumnSourceByValues.class, columnNames, expressions );
+    }
+
+    protected ColumnSourceByValuesImpl( SQLProcessorAggregator processor,
+                                        Class<? extends ColumnSourceByValues> expressionClass, ColumnNameList columnNames,
+                                        List<ValueExpression> expressions )
+    {
+        super( processor, expressionClass, columnNames );
+        Objects.requireNonNull( expressions, "expressions" );
+        if( expressions.isEmpty() )
+        {
+            throw new IllegalArgumentException( "Empty column source list not allowed." );
+        }
+
+        this._expressions = Collections.unmodifiableList( new ArrayList<ValueExpression>( expressions ) );
+    }
+
+    public List<ValueExpression> getValues()
+    {
+        return this._expressions;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DeleteBySearchImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DeleteBySearchImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DeleteBySearchImpl.java
new file mode 100644
index 0000000..21efdf7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DeleteBySearchImpl.java
@@ -0,0 +1,72 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DeleteBySearchImpl extends SQLSyntaxElementBase<DeleteStatement, DeleteBySearch>
+    implements DeleteBySearch
+{
+
+    private final TargetTable _targetTable;
+
+    private final BooleanExpression _where;
+
+    public DeleteBySearchImpl( SQLProcessorAggregator processor, TargetTable targetTable, BooleanExpression where )
+    {
+        this( processor, DeleteBySearch.class, targetTable, where );
+    }
+
+    protected DeleteBySearchImpl( SQLProcessorAggregator processor, Class<? extends DeleteBySearch> expressionClass,
+                                  TargetTable targetTable, BooleanExpression where )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( targetTable, "target table" );
+        this._targetTable = targetTable;
+        this._where = where;
+    }
+
+    public TargetTable getTargetTable()
+    {
+        return this._targetTable;
+    }
+
+    public BooleanExpression getWhere()
+    {
+        return this._where;
+    }
+
+    @Override
+    protected boolean doesEqual( DeleteBySearch another )
+    {
+        return this._targetTable.equals( another.getTargetTable() )
+               && TypeableImpl.bothNullOrEquals( this._where, another.getWhere() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DynamicColumnSourceImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DynamicColumnSourceImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DynamicColumnSourceImpl.java
new file mode 100644
index 0000000..2467b35
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/DynamicColumnSourceImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.DynamicColumnSource;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class DynamicColumnSourceImpl<ColumnSourceType extends DynamicColumnSource> extends
+                                                                                            SQLSyntaxElementBase<ColumnSource, ColumnSourceType>
+    implements DynamicColumnSource
+{
+
+    private final ColumnNameList _columnNames;
+
+    protected DynamicColumnSourceImpl( SQLProcessorAggregator processor,
+                                       Class<? extends ColumnSourceType> expressionClass, ColumnNameList columnNames )
+    {
+        super( processor, expressionClass );
+
+        this._columnNames = columnNames;
+    }
+
+    public ColumnNameList getColumnNames()
+    {
+        return this._columnNames;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnSourceType another )
+    {
+        return ( this._columnNames != null && this._columnNames.equals( another.getColumnNames() ) )
+               || ( this._columnNames == null && another.getColumnNames() == null );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/InsertStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/InsertStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/InsertStatementImpl.java
new file mode 100644
index 0000000..f7c92f1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/InsertStatementImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class InsertStatementImpl extends SQLSyntaxElementBase<InsertStatement, InsertStatement>
+    implements InsertStatement
+{
+
+    private final TableNameDirect _tableName;
+    private final ColumnSource _columnSource;
+
+    public InsertStatementImpl( SQLProcessorAggregator processor, TableNameDirect tableName, ColumnSource columnSource )
+    {
+        this( processor, InsertStatement.class, tableName, columnSource );
+    }
+
+    protected InsertStatementImpl( SQLProcessorAggregator processor, Class<? extends InsertStatement> expressionClass,
+                                   TableNameDirect tableName, ColumnSource columnSource )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( tableName, "tableName" );
+        Objects.requireNonNull( columnSource, "column source" );
+        this._tableName = tableName;
+        this._columnSource = columnSource;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._tableName;
+    }
+
+    public ColumnSource getColumnSource()
+    {
+        return this._columnSource;
+    }
+
+    @Override
+    protected boolean doesEqual( InsertStatement another )
+    {
+        return this._tableName.equals( another.getTableName() )
+               && this._columnSource.equals( another.getColumnSource() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/SetClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/SetClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/SetClauseImpl.java
new file mode 100644
index 0000000..25716fe
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/SetClauseImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSource;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SetClauseImpl extends SQLSyntaxElementBase<SetClause, SetClause>
+    implements SetClause
+{
+
+    private final String _target;
+
+    private final UpdateSource _source;
+
+    public SetClauseImpl( SQLProcessorAggregator processor, String updateTarget, UpdateSource updateSource )
+    {
+        this( processor, SetClause.class, updateTarget, updateSource );
+    }
+
+    protected SetClauseImpl( SQLProcessorAggregator processor, Class<? extends SetClause> expressionClass,
+                             String updateTarget, UpdateSource updateSource )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( updateTarget, "update target" );
+        Objects.requireNonNull( updateSource, "source" );
+
+        this._target = updateTarget;
+        this._source = updateSource;
+    }
+
+    public UpdateSource getUpdateSource()
+    {
+        return this._source;
+    }
+
+    public String getUpdateTarget()
+    {
+        return this._target;
+    }
+
+    @Override
+    protected boolean doesEqual( SetClause another )
+    {
+        return this._target.equals( another.getUpdateTarget() ) && this._source.equals( another.getUpdateSource() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/TargetTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/TargetTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/TargetTableImpl.java
new file mode 100644
index 0000000..af8a119
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/TargetTableImpl.java
@@ -0,0 +1,72 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TargetTableImpl extends SQLSyntaxElementBase<TargetTable, TargetTable>
+    implements TargetTable
+{
+
+    private Boolean _isOnly;
+
+    private TableNameDirect _tableName;
+
+    public TargetTableImpl( SQLProcessorAggregator processor, Boolean isOnly, TableNameDirect tableName )
+    {
+        this( processor, TargetTable.class, isOnly, tableName );
+    }
+
+    protected TargetTableImpl( SQLProcessorAggregator processor, Class<? extends TargetTable> expressionClass,
+                               Boolean isOnly, TableNameDirect tableName )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( tableName, "table name" );
+        if( isOnly == null )
+        {
+            isOnly = false;
+        }
+        this._tableName = tableName;
+        this._isOnly = isOnly;
+    }
+
+    public Boolean isOnly()
+    {
+        return this._isOnly;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._tableName;
+    }
+
+    @Override
+    protected boolean doesEqual( TargetTable another )
+    {
+        return this._tableName.equals( another.getTableName() ) && this._isOnly.equals( another.isOnly() );
+    }
+}


[18/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanExpression.java
new file mode 100644
index 0000000..79cd276
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanExpression.java
@@ -0,0 +1,86 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * A common interface for all boolean expressions in SQL language.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BooleanExpression
+    extends ValueExpression
+{
+
+    /**
+     * This class represents a boolean expression which always evaluates to true ({@code TRUE}).
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class True
+        implements BooleanExpression
+    {
+        private True()
+        {
+
+        }
+
+        /**
+         * Returns {@link True}.
+         */
+        public Class<? extends ValueExpression> getImplementedType()
+        {
+            return True.class;
+        }
+
+        /**
+         * Returns the singleton instance representing {@code TRUE}.
+         */
+        public static final True INSTANCE = new True();
+    }
+
+    /**
+     * This class represents a boolean expression which always evaluates to false ({@code FALSE}.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class False
+        implements BooleanExpression
+    {
+        private False()
+        {
+
+        }
+
+        /**
+         * Returns {@link False}.
+         */
+        public Class<? extends ValueExpression> getImplementedType()
+        {
+            return False.class;
+        }
+
+        /**
+         * Returns the singleton instance representing {@code FALSE}.
+         */
+        public static final False INSTANCE = new False();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanTest.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanTest.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanTest.java
new file mode 100644
index 0000000..9d0a05b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/BooleanTest.java
@@ -0,0 +1,94 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing {@code <X> IS [NOT] (TRUE | FALSE | UNKNOWN)} expression (boolean
+ * test), where {@code <X>} is some boolean expression.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BooleanTest
+    extends ComposedBooleanExpression
+{
+    /**
+     * The type of the test.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class TestType
+    {
+
+        /**
+         * The test which tests the expression against the truth value.
+         */
+        public static final TestType IS = new TestType();
+
+        /**
+         * The test which tests the expression against the negation of the truth value.
+         */
+        public static final TestType IS_NOT = new TestType();
+    }
+
+    /**
+     * The tested truth value.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class TruthValue
+    {
+
+        /**
+         * The {@code TRUE} truth value.
+         */
+        public static final TruthValue TRUE = new TruthValue();
+
+        /**
+         * The {@code FALSE} truth value.
+         */
+        public static final TruthValue FALSE = new TruthValue();
+
+        /**
+         * The {@code UNKNOWN} truth value.
+         */
+        public static final TruthValue UNKNOWN = new TruthValue();
+    }
+
+    /**
+     * Returns the boolean expression to be tested.
+     *
+     * @return The boolean expression to be tested.
+     */
+    BooleanExpression getBooleanExpression();
+
+    /**
+     * Returns the test type - whether it should, or should not, be something.
+     *
+     * @return The test type.
+     */
+    TestType getTestType();
+
+    /**
+     * The truth value which must evaluate from the expression.
+     *
+     * @return The truth value which must evaluate from the expression.
+     */
+    TruthValue getTruthValue();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ComposedBooleanExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ComposedBooleanExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ComposedBooleanExpression.java
new file mode 100644
index 0000000..1dbeb76
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ComposedBooleanExpression.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * A common interface for all boolean expressions composing of other boolean expressions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ComposedBooleanExpression
+    extends BooleanExpression, Iterable<BooleanExpression>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Conjunction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Conjunction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Conjunction.java
new file mode 100644
index 0000000..33b6e29
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Conjunction.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * A conjunction ({@code AND}) of two boolean expressions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Conjunction
+    extends ComposedBooleanExpression
+{
+
+    /**
+     * Returns the boolean expression on the left side of {@code AND}.
+     *
+     * @return The boolean expression on the left side of {@code AND}.
+     */
+    BooleanExpression getLeft();
+
+    /**
+     * Returns the boolean expression on the right side of {@code AND}.
+     *
+     * @return The boolean expression on the right side of {@code AND}.
+     */
+    BooleanExpression getRight();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Disjunction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Disjunction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Disjunction.java
new file mode 100644
index 0000000..b9725ff
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Disjunction.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * A disjunction ({@code OR} of two boolean expressions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Disjunction
+    extends ComposedBooleanExpression
+{
+    /**
+     * Returns the boolean expression on the left side of {@code OR}.
+     *
+     * @return The boolean expression on the left side of {@code OR}.
+     */
+    BooleanExpression getLeft();
+
+    /**
+     * Returns the boolean expression on the right side of {@code OR}.
+     *
+     * @return The boolean expression on the right side of {@code OR}.
+     */
+    BooleanExpression getRight();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/EqualsPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/EqualsPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/EqualsPredicate.java
new file mode 100644
index 0000000..9aad53b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/EqualsPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing equality test (x {@code =} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface EqualsPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ExistsPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ExistsPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ExistsPredicate.java
new file mode 100644
index 0000000..bb203d5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/ExistsPredicate.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * The interface for syntax element representing existence test ({@code EXISTS}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ExistsPredicate
+    extends UnaryPredicate
+{
+    /**
+     * Returns the query on which {@code EXISTS} operates on.
+     */
+    QueryExpression getValueExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterOrEqualPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterOrEqualPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterOrEqualPredicate.java
new file mode 100644
index 0000000..ac5d684
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterOrEqualPredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left value being greater than, or equal to right value (x
+ * {@code >=} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface GreaterOrEqualPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterThanPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterThanPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterThanPredicate.java
new file mode 100644
index 0000000..9132336
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/GreaterThanPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left value being greater than right value (x {@code >} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface GreaterThanPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/InPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/InPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/InPredicate.java
new file mode 100644
index 0000000..2326f5f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/InPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of something being one of the specified set of values (x
+ * {@code IN (}y, z, {@code ...)}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface InPredicate
+    extends MultiPredicate
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNotNullPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNotNullPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNotNullPredicate.java
new file mode 100644
index 0000000..956cfb7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNotNullPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing test for something being not {@code NULL} (x {@code IS NOT NULL}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface IsNotNullPredicate
+    extends UnaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNullPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNullPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNullPredicate.java
new file mode 100644
index 0000000..7612fbe
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/IsNullPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing test for something being {@code NULL} (x {@code IS NULL}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface IsNullPredicate
+    extends UnaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessOrEqualPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessOrEqualPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessOrEqualPredicate.java
new file mode 100644
index 0000000..61f78dc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessOrEqualPredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left value being lesser than, or equal to right value (x
+ * {@code <=} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface LessOrEqualPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessThanPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessThanPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessThanPredicate.java
new file mode 100644
index 0000000..fc89053
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LessThanPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left value being less than right value (x {@code <} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface LessThanPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LikePredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LikePredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LikePredicate.java
new file mode 100644
index 0000000..3c213d4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/LikePredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left expression matching the supplied pattern using basic
+ * SQL match (x {@code LIKE} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface LikePredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/MultiPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/MultiPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/MultiPredicate.java
new file mode 100644
index 0000000..955c103
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/MultiPredicate.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * A common interface for all predicates accepting more than two expressions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface MultiPredicate
+    extends Predicate
+{
+
+    /**
+     * Returns the expression on the left side (the first expression).
+     *
+     * @return The first expression.
+     */
+    NonBooleanExpression getLeft();
+
+    /**
+     * Returns the remaining expressions after the first one.
+     *
+     * @return The remaining expressions after the first one.
+     */
+    List<NonBooleanExpression> getRights();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Negation.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Negation.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Negation.java
new file mode 100644
index 0000000..2a34115
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Negation.java
@@ -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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * A negation ({@code NOT} x) of a boolean expression.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Negation
+    extends ComposedBooleanExpression
+{
+
+    /**
+     * Returns the boolean expression being negated.
+     *
+     * @return The boolean expression being negated.
+     */
+    BooleanExpression getNegated();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotBetweenPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotBetweenPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotBetweenPredicate.java
new file mode 100644
index 0000000..c1f7c1f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotBetweenPredicate.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * The interface for syntax element representing SQL expression {@code NOT BETWEEN} x {@code AND} y.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NotBetweenPredicate
+    extends MultiPredicate
+{
+    /**
+     * Returns the minimum value (the expression on the left side of {@code AND}).
+     *
+     * @return The minimum value.
+     */
+    NonBooleanExpression getMinimum();
+
+    /**
+     * Returns the maxmimum value (the expression on the right side of {@code AND}).
+     *
+     * @return The maximum value.
+     */
+    NonBooleanExpression getMaximum();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotEqualsPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotEqualsPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotEqualsPredicate.java
new file mode 100644
index 0000000..c6e69fc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotEqualsPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing inequality test (x {@code <>} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NotEqualsPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotInPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotInPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotInPredicate.java
new file mode 100644
index 0000000..cb9addd
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotInPredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of something not being one of the specified set of values (x
+ * {@code NOT IN (}y, z, {@code ...)}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NotInPredicate
+    extends MultiPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotLikePredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotLikePredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotLikePredicate.java
new file mode 100644
index 0000000..efc3a4d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotLikePredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left expression not matching the supplied pattern using
+ * basic SQL match (x {@code NOT LIKE} y).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NotLikePredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotRegexpPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotRegexpPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotRegexpPredicate.java
new file mode 100644
index 0000000..7f83dcc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/NotRegexpPredicate.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left expression not matching the supplied pattern using
+ * advanced regular expression match (operator varies). By default this kind of matching is not supported.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NotRegexpPredicate
+    extends BinaryPredicate
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Predicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Predicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Predicate.java
new file mode 100644
index 0000000..c58cf58
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/Predicate.java
@@ -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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * A common interfaces for predicates (boolean expressions not containing other boolean expressions).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface Predicate
+    extends BooleanExpression
+{
+    /**
+     * A class representing empty predicate. The result of empty predicate is empty string. If empty predicate is
+     * encountered inside {@link Conjunction} or {@link Disjunction}, their operator is omitted. So, <i>empty
+     * predicate</i> {@code AND} <i>something</i> becomes just <i>something</i>.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class EmptyPredicate
+        implements Predicate
+    {
+        private EmptyPredicate()
+        {
+        }
+
+        /**
+         * Returns {@link EmptyPredicate}.
+         */
+        public Class<? extends BooleanExpression> getImplementedType()
+        {
+            return EmptyPredicate.class;
+        }
+
+        /**
+         * Singleton instance of {@link EmptyPredicate}.
+         */
+        public static final EmptyPredicate INSTANCE = new EmptyPredicate();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/RegexpPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/RegexpPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/RegexpPredicate.java
new file mode 100644
index 0000000..f44732b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/RegexpPredicate.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+/**
+ * The interface for syntax element representing the test of left expression matching the supplied pattern using
+ * advanced regular expression match (operator varies). By default this kind of matching is not supported.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface RegexpPredicate
+    extends BinaryPredicate
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UnaryPredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UnaryPredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UnaryPredicate.java
new file mode 100644
index 0000000..37aed37
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UnaryPredicate.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * A common interface for all boolean expressions requiring exactly one value expression.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UnaryPredicate
+    extends Predicate
+{
+
+    /**
+     * Returns the value expression for this predicate.
+     *
+     * @return The value expression for this predicate.
+     */
+    NonBooleanExpression getValueExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UniquePredicate.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UniquePredicate.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UniquePredicate.java
new file mode 100644
index 0000000..f91eeab
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/UniquePredicate.java
@@ -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.polygene.library.sql.generator.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * The interface for syntax element representing the test for uniqueness ({@code UNIQUE} sub-query).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UniquePredicate
+    extends UnaryPredicate
+{
+
+    /**
+     * Gets the query on which {@code UNIQUE} operates on.
+     */
+    QueryExpression getValueExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/package-info.java
new file mode 100644
index 0000000..5d5fd7f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/booleans/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package provides interfaces for syntax elements of boolean expressions in SQL language. As all syntax elements, they provide a read-only API to their contents.
+ */
+package org.apache.polygene.library.sql.generator.grammar.booleans;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/AbstractBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/AbstractBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/AbstractBuilder.java
new file mode 100644
index 0000000..a938b1b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/AbstractBuilder.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders;
+
+/**
+ * A common interface for all builders.
+ *
+ * @param <ExpressionType> The type of the expression being built.
+ * @author Stanislav Muhametsin
+ */
+public interface AbstractBuilder<ExpressionType>
+{
+    /**
+     * Returns the expression which was being built by this builder.
+     *
+     * @return The expression built by this builder.
+     */
+    ExpressionType createExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/BooleanBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/BooleanBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/BooleanBuilder.java
new file mode 100644
index 0000000..7788daa
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/BooleanBuilder.java
@@ -0,0 +1,65 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+
+/**
+ * A builder-pattern interface to build boolean expressions. It holds the current expression, modifying it as per user's
+ * instructions, and returns it once the {@link #createExpression()} method is called.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface BooleanBuilder
+    extends AbstractBuilder<BooleanExpression>
+{
+
+    /**
+     * Sets current expression as current expression {@code AND next}.
+     *
+     * @param next The expression on a right hand of {@code AND}.
+     * @return This builder.
+     */
+    BooleanBuilder and( BooleanExpression next );
+
+    /**
+     * Sets current expression as current expression {@code OR next}
+     *
+     * @param next The expression on a right hand of {@code OR}
+     * @return This builder.
+     */
+    BooleanBuilder or( BooleanExpression next );
+
+    /**
+     * Sets current expression as {@code NOT} current expression.
+     *
+     * @return This builder.
+     */
+    BooleanBuilder not();
+
+    /**
+     * Sets current expression as given parameter.
+     *
+     * @param newExpression The new expression.
+     * @return This builder.
+     */
+    BooleanBuilder reset( BooleanExpression newExpression );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/InBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/InBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/InBuilder.java
new file mode 100644
index 0000000..23295ed
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/InBuilder.java
@@ -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.polygene.library.sql.generator.grammar.builders.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * The builder to build {@code IN} expressions
+ *
+ * @author Stanislav Muhametsin
+ * @see InPredicate
+ */
+public interface InBuilder
+    extends AbstractBuilder<InPredicate>
+{
+
+    InBuilder addValues( NonBooleanExpression... expressions );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/package-info.java
new file mode 100644
index 0000000..2f741fb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/booleans/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains builders for various boolean expressions.
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders.booleans;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ForeignKeyConstraintBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ForeignKeyConstraintBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ForeignKeyConstraintBuilder.java
new file mode 100644
index 0000000..50cbeeb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ForeignKeyConstraintBuilder.java
@@ -0,0 +1,133 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.MatchType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+
+/**
+ * The builder for table constraint {@code FOREIGN KEY(source columns) REFERENCES table_name(target columns) etc....}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ForeignKeyConstraintBuilder
+    extends AbstractBuilder<ForeignKeyConstraint>
+{
+
+    /**
+     * Adds source column names to this foreign key constraint.
+     *
+     * @param columnNames The source column names to be added to this foreign key constraint.
+     * @return This builder.
+     */
+    ForeignKeyConstraintBuilder addSourceColumns( String... columnNames );
+
+    /**
+     * Adds target column names to this foreign key constraint.
+     *
+     * @param columnNames The target column names to be added to this foreign key constraint.
+     * @return This builder.
+     */
+    ForeignKeyConstraintBuilder addTargetColumns( String... columnNames );
+
+    /**
+     * Sets the target table name for this foreign key constraint.
+     *
+     * @param tableName The target table name for this foreign key constraint.
+     * @return This builder.
+     */
+    ForeignKeyConstraintBuilder setTargetTableName( TableNameDirect tableName );
+
+    /**
+     * Sets the match type for this foreign key constraint.
+     *
+     * @param matchType The match type for this foreign key constraint.
+     * @return This builder.
+     * @see MatchType
+     */
+    ForeignKeyConstraintBuilder setMatchType( MatchType matchType );
+
+    /**
+     * Sets the {@code ON UPDATE} action.
+     *
+     * @param action The action to perform {@code ON UPDATE}.
+     * @return This builder.
+     * @see ReferentialAction
+     */
+    ForeignKeyConstraintBuilder setOnUpdate( ReferentialAction action );
+
+    /**
+     * Sets the {@code ON DELETE} action.
+     *
+     * @param action The action to perform {@code ON DELETE}.
+     * @return This builder.
+     * @see ReferentialAction
+     */
+    ForeignKeyConstraintBuilder setOnDelete( ReferentialAction action );
+
+    /**
+     * Returns the source column names for this foreign key constraint.
+     *
+     * @return The source column names for this foreign key constraint.
+     */
+    List<String> getSourceColumns();
+
+    /**
+     * Returns the target column names for this foreign key constraint.
+     *
+     * @return The target column names for this foreign key constraint.
+     */
+    List<String> getTargetColumns();
+
+    /**
+     * Returns the target table name for this foreign key constraint.
+     *
+     * @return The target table name for this foreign key constraint.
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Returns the match type for this foreign key constraint.
+     *
+     * @return The match type for this foreign key constraint.
+     * @see MatchType
+     */
+    MatchType getMatchType();
+
+    /**
+     * Returns the {@code ON UPDATE} action for this foreign key constraint.
+     *
+     * @return The {@code ON UPDATE} action for this foreign key constraint.
+     * @see ReferentialAction
+     */
+    ReferentialAction getOnUpdate();
+
+    /**
+     * Returns the {@code ON DELETE} action for this foreign key constraint.
+     *
+     * @return The {@code ON DELETE} action for this foreign key constraint.
+     * @see ReferentialAction
+     */
+    ReferentialAction getOnDelete();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/SchemaDefinitionBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/SchemaDefinitionBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/SchemaDefinitionBuilder.java
new file mode 100644
index 0000000..6f1080a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/SchemaDefinitionBuilder.java
@@ -0,0 +1,81 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+
+/**
+ * This is builder interface for creating schema definition statements ({@code CREATE SCHEMA} ...).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SchemaDefinitionBuilder
+    extends AbstractBuilder<SchemaDefinition>
+{
+
+    /**
+     * Sets the name for the schema to be created.
+     *
+     * @param schemaName The name for the schema to be created.
+     * @return This builder.
+     */
+    SchemaDefinitionBuilder setSchemaName( String schemaName );
+
+    /**
+     * Sets the character set for the schema to be created.
+     *
+     * @param charset The charset for the schema to be created.
+     * @return This builder.
+     */
+    SchemaDefinitionBuilder setSchemaCharset( String charset );
+
+    /**
+     * Adds schema elements for the schema to be created.
+     *
+     * @param elements The schema elements for the schema to be created.
+     * @return This builder.
+     * @see SchemaElement
+     */
+    SchemaDefinitionBuilder addSchemaElements( SchemaElement... elements );
+
+    /**
+     * Returns the name of the schema to be created.
+     *
+     * @return The name of the schema to be created.
+     */
+    String getSchemaName();
+
+    /**
+     * Returns the name of the character set for the schema to be created.
+     *
+     * @return The name of the character set for the schema to be created.
+     */
+    String getSchemaCharset();
+
+    /**
+     * Returns all the schema elements for the schema to be created.
+     *
+     * @return All the schema elements for the schema to be created.
+     */
+    List<SchemaElement> getSchemaElements();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableDefinitionBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableDefinitionBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableDefinitionBuilder.java
new file mode 100644
index 0000000..ed65f94
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableDefinitionBuilder.java
@@ -0,0 +1,104 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableContentsSource;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableScope;
+
+/**
+ * This is the builder for table definition statements ({@code CREATE TABLE} ...).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableDefinitionBuilder
+    extends AbstractBuilder<TableDefinition>
+{
+
+    /**
+     * Sets the scope for this table.
+     *
+     * @param scope The scope for this table.
+     * @return This builder.
+     * @see TableScope
+     */
+    TableDefinitionBuilder setTableScope( TableScope scope );
+
+    /**
+     * Sets the name for this table.
+     *
+     * @param tableName The name for this table.
+     * @return This builder.
+     * @see TableName
+     */
+    TableDefinitionBuilder setTableName( TableNameDirect tableName );
+
+    /**
+     * Sets the commit action for this table.
+     *
+     * @param commitAction The commit action for this table.
+     * @return This builder.
+     * @see TableCommitAction
+     */
+    TableDefinitionBuilder setCommitAction( TableCommitAction commitAction );
+
+    /**
+     * Sets the contents source for this table.
+     *
+     * @param contents The contents source for this table.
+     * @return This builder.
+     * @see TableContentsSource
+     * @see TableElementList
+     */
+    TableDefinitionBuilder setTableContentsSource( TableContentsSource contents );
+
+    /**
+     * Returns the scope for this table.
+     *
+     * @return The scope for this table.
+     */
+    TableScope getTableScope();
+
+    /**
+     * Returns the name for this table.
+     *
+     * @return The name for this table.
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Returns the commit action for this table.
+     *
+     * @return The commit action for this table.
+     */
+    TableCommitAction getCommitAction();
+
+    /**
+     * Returns the table contents source for this table.
+     *
+     * @return The table contents source for this table.
+     */
+    TableContentsSource getTableContentsSource();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableElementListBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableElementListBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableElementListBuilder.java
new file mode 100644
index 0000000..50defa2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/TableElementListBuilder.java
@@ -0,0 +1,50 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+
+/**
+ * This is the builder for table element list used in {@code CREATE TABLE} statements.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableElementListBuilder
+    extends AbstractBuilder<TableElementList>
+{
+
+    /**
+     * Adds the table element to this list.
+     *
+     * @param element The table element to add to this list.
+     * @return This builder.
+     */
+    TableElementListBuilder addTableElement( TableElement element );
+
+    /**
+     * Returns all the elements that this builder has.
+     *
+     * @return All the elements that this builder has.
+     */
+    List<TableElement> getTableElements();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/UniqueConstraintBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/UniqueConstraintBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/UniqueConstraintBuilder.java
new file mode 100644
index 0000000..4dfc67c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/UniqueConstraintBuilder.java
@@ -0,0 +1,66 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+
+/**
+ * This is builder for {@code UNIQUE(...)} and {@code PRIMARY KEY(...)} table constraints in table definition.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UniqueConstraintBuilder
+    extends AbstractBuilder<UniqueConstraint>
+{
+
+    /**
+     * Sets the uniqueness kind for this uniqueness constraint.
+     *
+     * @param uniqueness The uniqueness kind for this uniqueness constraint.
+     * @return This builder.
+     * @see UniqueSpecification
+     */
+    UniqueConstraintBuilder setUniqueness( UniqueSpecification uniqueness );
+
+    /**
+     * Adds the columns that have to be unique.
+     *
+     * @param columnNames The column names that have to be unique.
+     * @return This builder.
+     */
+    UniqueConstraintBuilder addColumns( String... columnNames );
+
+    /**
+     * Returns the uniqueness type for this uniqueness constraint.
+     *
+     * @return The uniqueness type for this uniqueness constraint.
+     */
+    UniqueSpecification getUniqueness();
+
+    /**
+     * Returns the column names that have to be unique.
+     *
+     * @return The column names that have to be unique.
+     */
+    List<String> getColumns();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ViewDefinitionBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ViewDefinitionBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ViewDefinitionBuilder.java
new file mode 100644
index 0000000..ae61aa2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/ViewDefinitionBuilder.java
@@ -0,0 +1,117 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.definition;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewCheckOption;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * This is a builder for {@code CREATE VIEW} statements.
+ *
+ * @author Stanislav Muhametsin
+ * @see ViewDefinition
+ */
+public interface ViewDefinitionBuilder
+    extends AbstractBuilder<ViewDefinition>
+{
+
+    /**
+     * Sets whether this view is {@code RECURSIVE}.
+     *
+     * @param isRecursive True if view is to be {@code RECURSIVE}; false otherwise.
+     * @return This builder.
+     */
+    ViewDefinitionBuilder setRecursive( Boolean isRecursive );
+
+    /**
+     * Sets the name for this view.
+     *
+     * @param viewName The name for this view.
+     * @return This builder.
+     */
+    ViewDefinitionBuilder setViewName( TableNameDirect viewName );
+
+    /**
+     * Sets the query for this view.
+     *
+     * @param query The query for this view.
+     * @return This builder.
+     */
+    ViewDefinitionBuilder setQuery( QueryExpression query );
+
+    /**
+     * Sets the view check option for this view.
+     *
+     * @param viewCheck The view check option for this view.
+     * @return This builder.
+     * @see ViewCheckOption
+     */
+    ViewDefinitionBuilder setViewCheckOption( ViewCheckOption viewCheck );
+
+    /**
+     * Sets the view specification for this view. Typically is a list of columns (via {@link RegularViewSpecification}).
+     *
+     * @param spec The view specification.
+     * @return This builder.
+     * @see ViewSpecification
+     */
+    ViewDefinitionBuilder setViewSpecification( ViewSpecification spec );
+
+    /**
+     * Returns whether this view is to be {@code RECURSIVE}.
+     *
+     * @return True if this view is to be {@code RECURSIVE}; false otherwise.
+     */
+    Boolean isRecursive();
+
+    /**
+     * Returns the name of the view.
+     *
+     * @return The name of the view.
+     */
+    TableNameDirect getViewName();
+
+    /**
+     * Returns the query for the view.
+     *
+     * @return The query for the view.
+     */
+    QueryExpression getQueryExpression();
+
+    /**
+     * Returns the view check option.
+     *
+     * @return The view check option.
+     * @see ViewCheckOption
+     */
+    ViewCheckOption getViewCheckOption();
+
+    /**
+     * Returns the view specification. Typically is a list of columns (via {@link RegularViewSpecification}).
+     *
+     * @return The view specification.
+     */
+    ViewSpecification getViewSpecification();
+}


[17/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java
new file mode 100644
index 0000000..d438ea9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This is package containing builders for syntax elements used in SQL Data Definition statements (typically {@code CREATE} statements).
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders.definition;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java
new file mode 100644
index 0000000..dc3a709
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java
@@ -0,0 +1,64 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.modification;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+
+/**
+ * This builder builds the {@link ColumnSourceByValues} syntax element.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnSourceByValuesBuilder
+    extends AbstractBuilder<ColumnSourceByValues>
+{
+    /**
+     * Adds the expressions as values to columns.
+     *
+     * @param values The value expressions to add.
+     * @return This builder.
+     */
+    ColumnSourceByValuesBuilder addValues( ValueExpression... values );
+
+    /**
+     * Returns the value expressions for the columns.
+     *
+     * @return The value expressions for the columns.
+     */
+    List<ValueExpression> getValues();
+
+    /**
+     * Adds the names for the columns.
+     *
+     * @param columnNames The names for columns.
+     * @return This builder.
+     */
+    ColumnSourceByValuesBuilder addColumnNames( String... columnNames );
+
+    /**
+     * Returns the names for the columns.
+     *
+     * @return The names for the columns.
+     */
+    List<String> getColumnNames();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java
new file mode 100644
index 0000000..4d1ca4a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+
+/**
+ * This builder builds statements deleting rows matching search condition ({@code DELETE FROM} table {@code [WHERE}
+ * searchCondition {@code ]}).
+ *
+ * @author Stanislav Muhametsin
+ * @see TargetTable
+ * @see BooleanBuilder
+ */
+public interface DeleteBySearchBuilder
+    extends AbstractBuilder<DeleteBySearch>
+{
+    /**
+     * Sets the target table for this {@code DELETE} statement.
+     *
+     * @param table The target table for this {@code DELETE} statement.
+     * @return This builder.
+     */
+    DeleteBySearchBuilder setTargetTable( TargetTable table );
+
+    /**
+     * Retrieves the target table for this {@code DELETE} statement.
+     *
+     * @return The target table for this {@code DELETE} statement.
+     */
+    TargetTable getTargetTable();
+
+    /**
+     * Returns the builder for search condition for this {@code DELETE} statement (boolean expression after
+     * {@code WHERE}). The search condition is optional.
+     *
+     * @return The builder for search condition for this {@code DELETE} statement.
+     */
+    BooleanBuilder getWhere();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java
new file mode 100644
index 0000000..c404bc5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java
@@ -0,0 +1,69 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+
+/**
+ * This builder builds statements inserting rows to tables ({@code INSERT INTO } tableName {@code [(} column names
+ * {@code )]} expression).
+ *
+ * @author Stanislav Muhametsin
+ * @see TableName
+ * @see ColumnSource
+ */
+public interface InsertStatementBuilder
+    extends AbstractBuilder<InsertStatement>
+{
+
+    /**
+     * Sets the table name for this {@code INSERT} statement.
+     *
+     * @param tableName The table name for this {@code INSERT} statement.
+     * @return This builder.
+     */
+    InsertStatementBuilder setTableName( TableNameDirect tableName );
+
+    /**
+     * Returns the table name for this {@code INSERT} statement.
+     *
+     * @return The table name for this {@code INSERT} statement.
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Sets the source for the columns for this {@code INSERT} statement.
+     *
+     * @param source The source for columns for this {@code INSERT} statement.
+     * @return This builder.
+     */
+    InsertStatementBuilder setColumnSource( ColumnSource source );
+
+    /**
+     * Returns the source for the columns for this {@code INSERT} statement.
+     *
+     * @return The source for the columns for this {@code INSERT} statement.
+     */
+    ColumnSource getColumnSource();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java
new file mode 100644
index 0000000..c82087c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java
@@ -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.polygene.library.sql.generator.grammar.builders.modification;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+
+/**
+ * This builder builds statements updating rows matching search condition ({@code UPDATE} table {@code SET} set-clauses
+ * {@code [WHERE} searchCondition {@code ]}).
+ *
+ * @author Stanislav Muhametsin
+ * @see SetClause
+ * @see BooleanBuilder
+ */
+public interface UpdateBySearchBuilder
+    extends AbstractBuilder<UpdateBySearch>
+{
+    /**
+     * Sets the target table for this {@code UPDATE} statement.
+     *
+     * @param table The target table for this {@code UPDATE} statement.
+     * @return This builder.
+     */
+    UpdateBySearchBuilder setTargetTable( TargetTable table );
+
+    /**
+     * Returns the builder for search condition for this {@code UPDATE} statement (boolean expression after
+     * {@code WHERE}). The search condition is optional.
+     *
+     * @return The builder for search condition for this {@code UPDATE} statement.
+     */
+    BooleanBuilder getWhereBuilder();
+
+    /**
+     * Adds the clause to the set-clause list of this {@code UPDATE} statement.
+     *
+     * @param clauses The set-clauses for this {@code UPDATE} statement.
+     * @return This builder.
+     */
+    UpdateBySearchBuilder addSetClauses( SetClause... clauses );
+
+    /**
+     * Returns the list of set clauses which has been added to this builder.
+     *
+     * @return The list of set clauses which has been added to this builder.
+     */
+    List<SetClause> getSetClauses();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java
new file mode 100644
index 0000000..181488c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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 to hold builders common for SQL modification clauses ({@code INSERT}, {@code UPDATE}, and {@code DELETE}).
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders.modification;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java
new file mode 100644
index 0000000..38cbca3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.modification.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+
+/**
+ * This build is used for creating {@code INSERT} statements specific for PostgreSQL databases.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface PgSQLInsertStatementBuilder extends InsertStatementBuilder
+{
+
+    /**
+     * Sets the {@code RETURNING} clause for this {@code INSERT} statement.
+     *
+     * @param clause The {@code RETURNING} clause. May be {@code null} if no {@code RETURNING}
+     *               clause is desired.
+     * @return This builder.
+     */
+    PgSQLInsertStatementBuilder setReturningClause( SelectColumnClause clause );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java
new file mode 100644
index 0000000..359bfff
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java
@@ -0,0 +1,24 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains modification statement ( {@code UPDATE}, {@code INSERT} or {@code DELETE})
+ * builders specific for PostgreSQL database.
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java
new file mode 100644
index 0000000..dc3e00c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * A package containing builders for common elements of SQL syntax.
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java
new file mode 100644
index 0000000..86a1b2e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java
@@ -0,0 +1,82 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface AbstractQueryBuilder<ExpressionType>
+    extends AbstractBuilder<ExpressionType>
+{
+    /**
+     * Adds the {@code FETCH FIRST ROW ONLY} expression for this query. The resulting {@link LimitSpecification} will
+     * have its count as {@code null}.
+     *
+     * @return This builder.
+     */
+    AbstractQueryBuilder<ExpressionType> limit();
+
+    /**
+     * Adds the {@code FETCH FIRST <number> ROWS ONLY} expression for this query. Calling this method is equivalent of
+     * calling {@link #limit(NonBooleanExpression)} and passing the {@link NumericLiteral} representing the given number
+     * as the parameter.
+     *
+     * @param max The maximum amount of rows for this query to return. Use {@code null} to remove the
+     *            {@code FETCH FIRST <number> ROWS ONLY} expression.
+     * @return This builder.
+     */
+    AbstractQueryBuilder<ExpressionType> limit( Integer max );
+
+    /**
+     * Adds the {@code FETCH FIRST <number> ROWS ONLY} expression for this query.
+     *
+     * @param max The maximum amount of rows for this query to return. May be subquery or something else that evaluates
+     *            to number or {@code NULL}. Use {@code null} to remove the {@code FETCH FIRST <number> ROWS ONLY}
+     *            expression.
+     * @return This builder.
+     */
+    AbstractQueryBuilder<ExpressionType> limit( NonBooleanExpression max );
+
+    /**
+     * Adds the {@code OFFSET <number> ROWS} expression for this query. Calling this method is equivalen of calling
+     * {@link #offset(NonBooleanExpression)} and passing the {@link NumericLiteral} representing the given number as the
+     * parameter.
+     *
+     * @param skip The amount of rows to skip before starting to include them into this query. Use {@code null} to
+     *             remove the {@code OFFSET <number> ROWS} expression.
+     * @return This builder.
+     */
+    AbstractQueryBuilder<ExpressionType> offset( Integer skip );
+
+    /**
+     * Adds the {@code OFFSET <number> ROWS} expression for this query.
+     *
+     * @param skip The amount of rows to skip before starting to include them into this query. May be subquery or
+     *             something else that evaluates to number or {@code NULL}. Use {@code null} to remove the
+     *             {@code OFFSET <number> ROWS} expression.
+     * @return This builder.
+     */
+    AbstractQueryBuilder<ExpressionType> offset( NonBooleanExpression skip );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java
new file mode 100644
index 0000000..e11a70b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java
@@ -0,0 +1,87 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+
+/**
+ * This builder builds the columns for {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ * @see SelectColumnClause
+ * @see QuerySpecification
+ * @see ColumnReference
+ */
+public interface ColumnsBuilder
+    extends AbstractBuilder<SelectColumnClause>
+{
+    /**
+     * Adds columns without aliases to this {@code SELECT} statement.
+     *
+     * @param columns Columns without aliases to add to this {@code SELECT} statement.
+     * @return This builder.
+     */
+    ColumnsBuilder addUnnamedColumns( ColumnReference... columns );
+
+    /**
+     * Add columns with aliases to this {@code SELECT} statement.
+     *
+     * @param namedColumns Columns with aliases to add to this {@code SELECT} statement.
+     * @return
+     */
+    ColumnsBuilder addNamedColumns( ColumnReferenceInfo... namedColumns );
+
+    /**
+     * Sets the set quantifier ({@code ALL} or {@code DISTINCT}) for this {@code SELECT} statement.
+     *
+     * @param newSetQuantifier The new set quantifier.
+     * @return This builder.
+     * @see SetQuantifier
+     */
+    ColumnsBuilder setSetQuantifier( SetQuantifier newSetQuantifier );
+
+    /**
+     * Marks that all columns should be selected ({@literal SELECT} *). This will empty a list of columns to select.
+     *
+     * @return This builder.
+     */
+    ColumnsBuilder selectAll();
+
+    /**
+     * Returns the columns of this {@code SELECT} statement. It returns empty by default, or after calling
+     * {@link #selectAll()} method.
+     *
+     * @return A list of columns of this {@code SELECT} statement. Might be empty.
+     */
+    List<ColumnReferenceInfo> getColumns();
+
+    /**
+     * Returns the set quantifier ({@code ALL} or {@code DISTINCT}) of this {@code SELECT} statement.
+     *
+     * @return The set quantifier of this {@code SELECT} statement.
+     */
+    SetQuantifier getSetQuantifier();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java
new file mode 100644
index 0000000..cbed912
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+
+/**
+ * The builder that builds the {@code FROM} clause in SQL {@code SELECT} query. It treats {@code FROM} clause as a list
+ * of {@link TableReference}s, and acts as aggregator for {@link TableReferenceBuilder}s.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableReference
+ * @see TableReferenceBuilder
+ */
+public interface FromBuilder
+    extends AbstractBuilder<FromClause>
+{
+
+    /**
+     * Adds table reference builders to this {@code FROM} clause. When {@link #createExpression()} method will be called
+     * on this builder, it will build all table references from builders that were added through this method.
+     *
+     * @param tableRefs Table reference builders to add to this {@code FROM} clause.
+     * @return This builder.
+     */
+    FromBuilder addTableReferences( TableReferenceBuilder... tableRefs );
+
+    /**
+     * Returns a list of table reference builders in this builder.
+     *
+     * @return A list of table reference builders in this builder. Might be empty.
+     */
+    List<TableReferenceBuilder> getTableReferences();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java
new file mode 100644
index 0000000..102d379
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+
+/**
+ * The builder that builds the {@code GROUP BY} clause in SQL {@code SELECT} query.
+ *
+ * @author Stanislav Muhametsin
+ * @see GroupByClause
+ * @see GroupingElement
+ */
+public interface GroupByBuilder
+    extends AbstractBuilder<GroupByClause>
+{
+
+    /**
+     * Adds grouping elements to this {@code GROUP BY} clause.
+     *
+     * @param elements The grouping elements for this {@code GROUP BY} clause.
+     * @return This builder.
+     */
+    GroupByBuilder addGroupingElements( GroupingElement... elements );
+
+    /**
+     * Returns the list of added grouping elements.
+     *
+     * @return The list of added grouping elements.
+     */
+    List<GroupingElement> getGroupingElements();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java
new file mode 100644
index 0000000..49cbaa3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+
+/**
+ * The builder that builds the {@code ORDER BY} clause in SQL {@code SELECT} query.
+ *
+ * @author Stanislav Muhametsin
+ * @see OrderByClause
+ * @see SortSpecification
+ */
+public interface OrderByBuilder
+    extends AbstractBuilder<OrderByClause>
+{
+
+    /**
+     * Adds sort specifications to this {@code ORDER BY} clause.
+     *
+     * @param specs The sort specifications for this {@code ORDER BY} clause.
+     * @return This builder.
+     */
+    OrderByBuilder addSortSpecs( SortSpecification... specs );
+
+    /**
+     * Returns the list of added sort specifications.
+     *
+     * @return The added sort specifications.
+     */
+    List<SortSpecification> getSortSpecs();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java
new file mode 100644
index 0000000..3ae57b3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java
@@ -0,0 +1,214 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+
+/**
+ * The builder that builds the SQL queries having {@code UNION}, {@code INTERSECT}, or {@code EXCEPT} between the
+ * {@code SELECT} statements.
+ *
+ * @author Stanislav Muhametsin
+ * @see QueryExpressionBody
+ * @see QuerySpecification
+ * @see QuerySpecificationBuilder
+ * @see CorrespondingSpec
+ */
+public interface QueryBuilder
+    extends AbstractBuilder<QueryExpressionBody>
+{
+    /**
+     * <p>
+     * Adds {@code UNION} between current query and the given query. Then makes resulting query the current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #union(SetQuantifier, QueryExpressionBody)} and giving
+     * {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param another The query to perform {@code UNION} with.
+     * @return This builder.
+     */
+    QueryBuilder union( QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code UNION <setQuantifier>} between current query and the given query. Then makes resulting query the
+     * current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #union(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving
+     * {@code null} as second parameter.
+     * </p>
+     *
+     * @param setQuantifier The set quantifier for this union.
+     * @param another       The query to perform {@code UNION} with.
+     * @return This builder.
+     */
+    QueryBuilder union( SetQuantifier setQuantifier, QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code UNION <correspondingSpec>} between current query and the given query. Then makes resulting query the
+     * current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #union(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving
+     * {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param correspondingSpec The column correspondence specification.
+     * @param another           The query to perform {@code UNION} with.
+     * @return This builder.
+     */
+    QueryBuilder union( CorrespondingSpec correspondingSpec, QueryExpressionBody another );
+
+    /**
+     * Adds {@code UNION <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes
+     * resulting query the current query.
+     *
+     * @param setQuantifier     The set quantifier for this union.
+     * @param correspondingSpec The column correspondence specification. May be {@code null}.
+     * @param another           The query to perform {@code UNION} with.
+     * @return This builder.
+     */
+    QueryBuilder union( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                        QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code INTERSECT} between current query and the given query. Then makes resulting query the current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #intersect(SetQuantifier, QueryExpressionBody)} and giving
+     * {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param another The query to perform {@code INTERSECT} with.
+     * @return This builder.
+     */
+    QueryBuilder intersect( QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code INTERSECT <setQuantifier>} between current query and the given query. Then makes resulting query the
+     * current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #intersect(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and
+     * giving {@code null} as second parameter.
+     * </p>
+     *
+     * @param setQuantifier The set quantifier for this union.
+     * @param another       The query to perform {@code INTERSECT} with.
+     * @return This builder.
+     */
+    QueryBuilder intersect( SetQuantifier setQuantifier, QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code INTERSECT <correspondingSpec>} between current query and the given query. Then makes resulting query
+     * the current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #intersect(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and
+     * giving {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param correspondingSpec The column correspondence specification.
+     * @param another           The query to perform {@code INTERSECT} with.
+     * @return This builder.
+     */
+    QueryBuilder intersect( CorrespondingSpec correspondingSpec, QueryExpressionBody another );
+
+    /**
+     * Adds {@code INTERSECT <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes
+     * resulting query the current query.
+     *
+     * @param setQuantifier     The set quantifier for this union.
+     * @param correspondingSpec The column correspondence specification. May be {@code null}.
+     * @param another           The query to perform {@code INTERSECT} with.
+     * @return This builder.
+     */
+    QueryBuilder intersect( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                            QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code EXCEPT} between current query and the given query. Then makes resulting query the current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #except(SetQuantifier, QueryExpressionBody)} and giving
+     * {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param another The query to perform {@code EXCEPT} with.
+     * @return This builder.
+     */
+    QueryBuilder except( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec,
+                         QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code EXCEPT <setQuantifier>} between current query and the given query. Then makes resulting query the
+     * current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #except(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving
+     * {@code null} as second parameter.
+     * </p>
+     *
+     * @param setQuantifier The set quantifier for this union.
+     * @param another       The query to perform {@code EXCEPT} with.
+     * @return This builder.
+     */
+    QueryBuilder except( QueryExpressionBody another );
+
+    /**
+     * <p>
+     * Adds {@code EXCEPT <correspondingSpec>} between current query and the given query. Then makes resulting query the
+     * current query.
+     * </p>
+     * <p>
+     * This is equivalent on calling {@link #except(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving
+     * {@link SetQuantifier#DISTINCT} as first parameter.
+     * </p>
+     *
+     * @param correspondingSpec The column correspondence specification.
+     * @param another           The query to perform {@code EXCEPT} with.
+     * @return This builder.
+     */
+    QueryBuilder except( SetQuantifier setQuantifier, QueryExpressionBody another );
+
+    /**
+     * Adds {@code EXCEPT <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes
+     * resulting query the current query.
+     *
+     * @param setQuantifier     The set quantifier for this union.
+     * @param correspondingSpec The column correspondence specification. May be {@code null}.
+     * @param another           The query to perform {@code EXCEPT} with.
+     * @return This builder.
+     */
+    QueryBuilder except( CorrespondingSpec correspondingSpec, QueryExpressionBody another );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java
new file mode 100644
index 0000000..3be9d71
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java
@@ -0,0 +1,140 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+
+/**
+ * This builder builds a single {@code SELECT} query. It acts as an aggregator for {@link ColumnsBuilder} for columns in
+ * {@code SELECT}, {@link FromBuilder} for tables in {@code FROM} clause, {@link BooleanBuilder} for search condition in
+ * {@code WHERE} clause, {@link GroupByBuilder} for {@code GROUP BY} clause, another {@link BooleanBuilder} for grouping
+ * conditions in {@code HAVING} clause, and finally {@link OrderByBuilder} for {@code ORDER BY} clause.
+ *
+ * @author Stanislav Muhametsin
+ * @see QuerySpecification
+ */
+public interface QuerySpecificationBuilder
+    extends AbstractQueryBuilder<QuerySpecification>
+{
+
+    /**
+     * Gets the builder for columns in this {@code SELECT} statement.
+     *
+     * @return The builder for columns in this {@code SELECT} statement.
+     */
+    ColumnsBuilder getSelect();
+
+    /**
+     * Gets the builder for {@code FROM} clause of this {@code SELECT} statement.
+     *
+     * @return The builder for {@code FROM} clause of this {@code SELECT} statement.
+     */
+    FromBuilder getFrom();
+
+    /**
+     * Gets the builder for search condition in {@code WHERE} clause of this {@code SELECT} statement.
+     *
+     * @return The builder for search condition in {@code WHERE} clause of this {@code SELECT} statement.
+     */
+    BooleanBuilder getWhere();
+
+    /**
+     * Gets the builder for {@code GROUP BY} clause of this {@code SELECT} statement.
+     *
+     * @return The builder for {@code GROUP BY} clause of this {@code SELECT} statement.
+     */
+    GroupByBuilder getGroupBy();
+
+    /**
+     * Gets the builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement.
+     *
+     * @return The builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement.
+     */
+    BooleanBuilder getHaving();
+
+    /**
+     * Gets the builder for {@code ORDER BY} clause of this {@code SELECT} statement.
+     *
+     * @return The builder for {@code ORDER BY} clause of this {@code SELECT} statement.
+     */
+    OrderByBuilder getOrderBy();
+
+    /**
+     * Checks that all selected columns are in {@code GROUP BY} clause. If they are not, it adds them as last columns of
+     * {@code GROUP BY} clause.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder trimGroupBy();
+
+    /**
+     * Sets the builder for columns in {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setSelect( ColumnsBuilder builder );
+
+    /**
+     * Sets the builder for {@code FROM} clause of this {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setFrom( FromBuilder builder );
+
+    /**
+     * Sets the builder for search condition in {@code WHERE} clause of this {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setWhere( BooleanBuilder builder );
+
+    /**
+     * Sets the builder for {@code GROUP BY} clause of this {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setGroupBy( GroupByBuilder builder );
+
+    /**
+     * Sets the builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setHaving( BooleanBuilder builder );
+
+    /**
+     * Sets the builder for {@code ORDER BY} clause of this {@code SELECT} statement.
+     *
+     * @return This builder.
+     */
+    QuerySpecificationBuilder setOrderBy( OrderByBuilder builder );
+
+    QuerySpecificationBuilder limit();
+
+    QuerySpecificationBuilder limit( Integer max );
+
+    QuerySpecificationBuilder limit( NonBooleanExpression max );
+
+    QuerySpecificationBuilder offset( Integer skip );
+
+    QuerySpecificationBuilder offset( NonBooleanExpression skip );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java
new file mode 100644
index 0000000..e3907dd
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java
@@ -0,0 +1,127 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * This is builder to quickly create simple queries, without the generic and not-so-easy-to-use methods of traditional
+ * {@link QuerySpecificationBuilder} + {@link QueryFactory} style. Using this builder is generally not thread-safe.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SimpleQueryBuilder
+    extends AbstractQueryBuilder<QueryExpression>
+{
+
+    /**
+     * Adds the specified columns to the {@code SELECT} list.
+     *
+     * @param columnNames The names of the columns.
+     * @return This builder.
+     */
+    SimpleQueryBuilder select( String... columnNames );
+
+    /**
+     * Adds the specified column expressions to the {@code SELECT} list.
+     *
+     * @param expressions The value expressions for columns.
+     * @return This builder.
+     */
+    SimpleQueryBuilder select( ValueExpression... expressions );
+
+    /**
+     * Selects all columns ({@code SELECT *}).
+     *
+     * @return This builder.
+     */
+    SimpleQueryBuilder selectAllColumns();
+
+    /**
+     * Adds alias to the most recently added column.
+     *
+     * @param columnAlias The alias for most recently added column;
+     * @return This builder.
+     */
+    SimpleQueryBuilder as( String columnAlias );
+
+    /**
+     * Adds table names for {@code FROM} clause of this query.
+     *
+     * @param tableNames The table names to add.
+     * @return This builder.
+     */
+    SimpleQueryBuilder from( TableName... tableNames );
+
+    /**
+     * Sets the search condition ({@code WHERE} clause) for this query.
+     *
+     * @param searchCondition The search condition for this query.
+     * @return This builder.
+     */
+    SimpleQueryBuilder where( BooleanExpression searchCondition );
+
+    /**
+     * Adds {@code GROUP BY} columns for this query.
+     *
+     * @param columns The column names for {@code GROUP BY} clause.
+     * @return This builder.
+     */
+    SimpleQueryBuilder groupBy( String... columns );
+
+    /**
+     * Adds {@code HAVING} grouping condition for this query.
+     *
+     * @param groupingCondition The grouping condition for this query.
+     * @return This builder.
+     */
+    SimpleQueryBuilder having( BooleanExpression groupingCondition );
+
+    /**
+     * Adds {@code ORDER BY} columns for this query, with {@code ASC} as ordering specification.
+     *
+     * @param columns The column names for {@code ORDER BY}.
+     * @return This builder.
+     */
+    SimpleQueryBuilder orderByAsc( String... columns );
+
+    /**
+     * Adds {@code ORDER BY} columns for this query, with {@code DESC} as ordering specification.
+     *
+     * @param columns The column names for {@code ORDER BY}.
+     * @return This builder.
+     */
+    SimpleQueryBuilder orderByDesc( String... columns );
+
+    SimpleQueryBuilder limit();
+
+    SimpleQueryBuilder limit( Integer max );
+
+    SimpleQueryBuilder limit( NonBooleanExpression max );
+
+    SimpleQueryBuilder offset( Integer skip );
+
+    SimpleQueryBuilder offset( NonBooleanExpression skip );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java
new file mode 100644
index 0000000..1365809
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java
@@ -0,0 +1,76 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.builders.query;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+
+/**
+ * The builder to build joined tables. A joined table contains 0 or more joins.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableReference
+ */
+public interface TableReferenceBuilder
+    extends AbstractBuilder<TableReference>
+{
+    /**
+     * Adds a qualified join ({@code JOIN}) to whatever current table of builder, and overwrites the current table with
+     * the result.
+     *
+     * @param joinType The join type.
+     * @param right    The table on the right side of the join.
+     * @param joinSpec The join specification.
+     * @return This builder
+     * @see JoinType
+     * @see JoinSpecification
+     */
+    TableReferenceBuilder addQualifiedJoin( JoinType joinType, TableReference right, JoinSpecification joinSpec );
+
+    /**
+     * Adds a cross join ({@code CROSS JOIN}) to whatever current table of builder, and overwrites the current table
+     * with the result.
+     *
+     * @param right The table on the right side of the join.
+     * @return This builder.
+     */
+    TableReferenceBuilder addCrossJoin( TableReference right );
+
+    /**
+     * Adds a natural join ({@code NATURAL JOIN}) to whatever current table of builder, and overwrites the current table
+     * with the result.
+     *
+     * @param joinType The join type.
+     * @param right    The table on the right side of the join.
+     * @return This builder.
+     */
+    TableReferenceBuilder addNaturalJoin( JoinType joinType, TableReference right );
+
+    /**
+     * Adds an union join ({@code UNION JOIN}) to whatever current table of builder, and overwrites the current table
+     * with the result.
+     *
+     * @param right The table on the right side of the join.
+     * @return This builder
+     */
+    TableReferenceBuilder addUnionJoin( TableReference right );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java
new file mode 100644
index 0000000..a3d21fe
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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 to hold builders for SQL queries ({@code SELECT} -statements).
+ */
+package org.apache.polygene.library.sql.generator.grammar.builders.query;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java
new file mode 100644
index 0000000..53b0b12
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This interface presents a non-empty list of plain-text column names.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnNameList extends Typeable<ColumnNameList>
+{
+    /**
+     * Returns the list of column names. This list will be always non-empty.
+     *
+     * @return The non-empty list of column names.
+     */
+    List<String> getColumnNames();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java
new file mode 100644
index 0000000..4ecc86b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * A common interface for all expressions, which return non-boolean value.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NonBooleanExpression
+    extends ValueExpression
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java
new file mode 100644
index 0000000..57f1402
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java
@@ -0,0 +1,82 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * A container for common textual constants of SQL language.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLConstants
+{
+    String SELECT = "SELECT";
+
+    String FROM = "FROM";
+
+    String WHERE = "WHERE";
+
+    String GROUP_BY = "GROUP BY";
+
+    String HAVING = "HAVING";
+
+    String ORDER_BY = "ORDER BY";
+
+    String TABLE_COLUMN_SEPARATOR = ".";
+
+    String SCHEMA_TABLE_SEPARATOR = ".";
+
+    String TOKEN_SEPARATOR = " ";
+
+    String AND = "AND";
+
+    String OR = "OR";
+
+    String NOT = "NOT";
+
+    String ASTERISK = "*";
+
+    String COMMA = ",";
+
+    String PERIOD = ".";
+
+    String QUESTION_MARK = "?";
+
+    String OPEN_PARENTHESIS = "(";
+
+    String CLOSE_PARENTHESIS = ")";
+
+    String ALIAS_DEFINER = "AS";
+
+    String NEWLINE = "\n";
+
+    String NULL = "NULL";
+
+    String IS = "IS";
+
+    String CREATE = "CREATE";
+
+    String OFFSET_PREFIX = "OFFSET";
+
+    String OFFSET_POSTFIX = "ROWS";
+
+    String LIMIT_PREFIX = "FETCH FIRST";
+
+    String LIMIT_POSTFIX = "ROWS ONLY";
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java
new file mode 100644
index 0000000..06a644f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * A container for textual names of default SQL functions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLFunctions
+{
+
+    String AVG = "AVG";
+
+    String MAX = "MAX";
+
+    String MIN = "MIN";
+
+    String SUM = "SUM";
+
+    String EVERY = "EVERY";
+
+    String ANY = "ANY";
+
+    String COUNT = "COUNT";
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java
new file mode 100644
index 0000000..d9120c9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * A single SQL statement, which is to be sent to database.
+ *
+ * @author Stanislav Muhametsin
+ * @see QueryExpression
+ * @see DeleteStatement
+ * @see UpdateStatement
+ * @see InsertStatement
+ */
+public interface SQLStatement
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java
new file mode 100644
index 0000000..23ecde5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+
+/**
+ * This is a common interface for all definition ({@code CREATE}) clauses.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public interface SchemaDefinitionStatement
+    extends SchemaStatement
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java
new file mode 100644
index 0000000..d27c4c3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java
@@ -0,0 +1,29 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface SchemaManipulationStatement
+    extends SchemaStatement
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java
new file mode 100644
index 0000000..10560b8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface SchemaStatement
+    extends Typeable<SchemaStatement>, SQLStatement
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java
new file mode 100644
index 0000000..524bc61
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * Set quantifer, can be either {@link #ALL} or {@link #DISTINCT}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class SetQuantifier
+{
+
+    /**
+     * Set quantifier for {@code DISTINCT} element.
+     */
+    public static final SetQuantifier DISTINCT = new SetQuantifier();
+
+    /**
+     * Set quantifier for {@code ALL} element.
+     */
+    public static final SetQuantifier ALL = new SetQuantifier();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java
new file mode 100644
index 0000000..8cbd2cb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.common;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for table names. Table name may be either {@link TableNameDirect} or
+ * {@link TableNameFunction}.
+ *
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface TableName
+    extends Typeable<TableName>
+{
+    /**
+     * Gets the schema name. Returns {@code null} if this is not schema-qualified table name.
+     *
+     * @return Schema name of the schema-qualified table name, or {@code null} if this is not a schema-qualified table
+     * name.
+     */
+    String getSchemaName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java
new file mode 100644
index 0000000..7936c7a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java
@@ -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.polygene.library.sql.generator.grammar.common;
+
+/**
+ * A direct table name may be just table name, or schema-qualified table name.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableNameDirect
+    extends TableName
+{
+
+    /**
+     * Gets name of the table. Returns always non-{@code null}.
+     *
+     * @return The name of the table. Always non-{@code null}.
+     */
+    String getTableName();
+}


[05/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceImpl.java
new file mode 100644
index 0000000..762c002
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class TableReferenceImpl<TypeableType extends Typeable<? super TypeableType>, RealType extends TypeableType>
+    extends SQLSyntaxElementBase<TypeableType, RealType>
+    implements TableReference
+{
+
+    public TableReferenceImpl( SQLProcessorAggregator processor, Class<? extends RealType> expressionClass )
+    {
+        super( processor, expressionClass );
+    }
+
+    public Typeable<?> asTypeable()
+    {
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferencePrimaryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferencePrimaryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferencePrimaryImpl.java
new file mode 100644
index 0000000..9423618
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferencePrimaryImpl.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferencePrimary;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableReferencePrimaryImpl<TableReferenceType extends TableReferencePrimary> extends
+                                                                                         TableReferenceImpl<TableReferencePrimary, TableReferenceType>
+    implements TableReferencePrimary
+{
+
+    private final TableAlias _tableAlias;
+
+    public TableReferencePrimaryImpl( SQLProcessorAggregator processor,
+                                      Class<? extends TableReferenceType> tableReferenceClass, TableAlias alias )
+    {
+        super( processor, tableReferenceClass );
+        this._tableAlias = alias;
+    }
+
+    public TableAlias getTableAlias()
+    {
+        return this._tableAlias;
+    }
+
+    @Override
+    protected boolean doesEqual( TableReferenceType another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._tableAlias, another.getTableAlias() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableValueConstructorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableValueConstructorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableValueConstructorImpl.java
new file mode 100644
index 0000000..84dc5c9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableValueConstructorImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.grammar.query.TableValueConstructor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableValueConstructorImpl extends QueryExpressionBodyImpl<TableValueConstructor>
+    implements TableValueConstructor
+{
+
+    private final List<RowValueConstructor> _rows;
+
+    public TableValueConstructorImpl( SQLProcessorAggregator processor, List<RowValueConstructor> rows )
+    {
+        this( processor, TableValueConstructor.class, rows );
+    }
+
+    protected TableValueConstructorImpl( SQLProcessorAggregator processor,
+                                         Class<? extends TableValueConstructor> expressionClass, List<RowValueConstructor> rows )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( rows, "rows" );
+        this._rows = Collections.unmodifiableList( rows );
+    }
+
+    public List<RowValueConstructor> getRows()
+    {
+        return this._rows;
+    }
+
+    @Override
+    protected boolean doesEqual( TableValueConstructor other )
+    {
+        return this._rows.equals( other.getRows() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/CrossJoinedTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/CrossJoinedTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/CrossJoinedTableImpl.java
new file mode 100644
index 0000000..a60d038
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/CrossJoinedTableImpl.java
@@ -0,0 +1,55 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.CrossJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class CrossJoinedTableImpl extends JoinedTableImpl<CrossJoinedTable>
+    implements CrossJoinedTable
+{
+
+    public CrossJoinedTableImpl( SQLProcessorAggregator processor, TableReference left, TableReference right )
+    {
+        this( processor, CrossJoinedTable.class, left, right );
+    }
+
+    protected CrossJoinedTableImpl( SQLProcessorAggregator processor, Class<? extends CrossJoinedTable> implClass,
+                                    TableReference left, TableReference right )
+    {
+        super( processor, implClass, left, right );
+    }
+
+    @Override
+    protected boolean doesEqual( CrossJoinedTable another )
+    {
+        boolean result = this.getRight().equals( another.getRight() );
+        if( result )
+        {
+            result = super.doesEqual( another );
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinConditionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinConditionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinConditionImpl.java
new file mode 100644
index 0000000..7859695
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinConditionImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinCondition;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class JoinConditionImpl extends JoinSpecificationImpl<JoinCondition>
+    implements JoinCondition
+{
+
+    private final BooleanExpression _searchCondition;
+
+    public JoinConditionImpl( SQLProcessorAggregator processor, BooleanExpression searchCondition )
+    {
+        this( processor, JoinCondition.class, searchCondition );
+    }
+
+    protected JoinConditionImpl( SQLProcessorAggregator processor, Class<? extends JoinCondition> implClass,
+                                 BooleanExpression searchCondition )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( searchCondition, "search condition" );
+        this._searchCondition = searchCondition;
+    }
+
+    public BooleanExpression getSearchConidition()
+    {
+        return this._searchCondition;
+    }
+
+    @Override
+    protected boolean doesEqual( JoinCondition another )
+    {
+        return this._searchCondition.equals( another.getSearchConidition() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinSpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinSpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinSpecificationImpl.java
new file mode 100644
index 0000000..ef7c914
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinSpecificationImpl.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class JoinSpecificationImpl<JoinSpecificationType extends JoinSpecification> extends
+                                                                                             SQLSyntaxElementBase<JoinSpecification, JoinSpecificationType>
+    implements JoinSpecification
+{
+
+    public JoinSpecificationImpl( SQLProcessorAggregator processor,
+                                  Class<? extends JoinSpecificationType> expressionClass )
+    {
+        super( processor, expressionClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinedTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinedTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinedTableImpl.java
new file mode 100644
index 0000000..07a9b04
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/JoinedTableImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.QueryExpressionBodyImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class JoinedTableImpl<TableReferenceType extends JoinedTable> extends
+                                                                              QueryExpressionBodyImpl<TableReferenceType>
+    implements JoinedTable
+{
+
+    private final TableReference _left;
+    private final TableReference _right;
+
+    protected JoinedTableImpl( SQLProcessorAggregator processor,
+                               Class<? extends TableReferenceType> tableReferenceClass, TableReference left, TableReference right )
+    {
+        super( processor, tableReferenceClass );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( right, "right" );
+        this._left = left;
+        this._right = right;
+    }
+
+    public TableReference getLeft()
+    {
+        return this._left;
+    }
+
+    public TableReference getRight()
+    {
+        return this._right;
+    }
+
+    public Typeable<?> asTypeable()
+    {
+        return this;
+    }
+
+    @Override
+    protected boolean doesEqual( TableReferenceType another )
+    {
+        return this._left.equals( another.getLeft() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NamedColumnsJoinImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NamedColumnsJoinImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NamedColumnsJoinImpl.java
new file mode 100644
index 0000000..7bc45d9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NamedColumnsJoinImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NamedColumnsJoin;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NamedColumnsJoinImpl extends JoinSpecificationImpl<NamedColumnsJoin>
+    implements NamedColumnsJoin
+{
+
+    private final ColumnNameList _columnNames;
+
+    public NamedColumnsJoinImpl( SQLProcessorAggregator processor, ColumnNameList columnNames )
+    {
+        this( processor, NamedColumnsJoin.class, columnNames );
+    }
+
+    protected NamedColumnsJoinImpl( SQLProcessorAggregator processor, Class<? extends NamedColumnsJoin> implClass,
+                                    ColumnNameList columnNames )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( columnNames, "column names" );
+        this._columnNames = columnNames;
+    }
+
+    public ColumnNameList getColumnNames()
+    {
+        return this._columnNames;
+    }
+
+    @Override
+    protected boolean doesEqual( NamedColumnsJoin another )
+    {
+        return this._columnNames.equals( another.getColumnNames() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NaturalJoinedTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NaturalJoinedTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NaturalJoinedTableImpl.java
new file mode 100644
index 0000000..b1663f7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/NaturalJoinedTableImpl.java
@@ -0,0 +1,67 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NaturalJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NaturalJoinedTableImpl extends JoinedTableImpl<NaturalJoinedTable>
+    implements NaturalJoinedTable
+{
+
+    private final JoinType _joinType;
+
+    public NaturalJoinedTableImpl( SQLProcessorAggregator processor, TableReference left, TableReference right,
+                                   JoinType joinType )
+    {
+        this( processor, NaturalJoinedTable.class, left, right, joinType );
+    }
+
+    protected NaturalJoinedTableImpl( SQLProcessorAggregator processor, Class<? extends NaturalJoinedTable> implClass,
+                                      TableReference left, TableReference right, JoinType joinType )
+    {
+        super( processor, implClass, left, right );
+        Objects.requireNonNull( joinType, "join type" );
+        this._joinType = joinType;
+    }
+
+    public JoinType getJoinType()
+    {
+        return this._joinType;
+    }
+
+    @Override
+    protected boolean doesEqual( NaturalJoinedTable another )
+    {
+        boolean result = this._joinType.equals( another.getJoinType() ) && this.getRight().equals( another.getRight() );
+        if( result )
+        {
+            result = super.doesEqual( another );
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/QualifiedJoinedTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/QualifiedJoinedTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/QualifiedJoinedTableImpl.java
new file mode 100644
index 0000000..864c82b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/QualifiedJoinedTableImpl.java
@@ -0,0 +1,78 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.QualifiedJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QualifiedJoinedTableImpl extends JoinedTableImpl<QualifiedJoinedTable>
+    implements QualifiedJoinedTable
+{
+
+    private final JoinType _joinType;
+
+    private final JoinSpecification _joinSpec;
+
+    public QualifiedJoinedTableImpl( SQLProcessorAggregator processor, TableReference left, TableReference right,
+                                     JoinType joinType, JoinSpecification joinSpec )
+    {
+        this( processor, QualifiedJoinedTable.class, left, right, joinType, joinSpec );
+    }
+
+    protected QualifiedJoinedTableImpl( SQLProcessorAggregator processor,
+                                        Class<? extends QualifiedJoinedTable> implClass, TableReference left, TableReference right, JoinType joinType,
+                                        JoinSpecification joinSpec )
+    {
+        super( processor, implClass, left, right );
+        Objects.requireNonNull( joinType, "join type" );
+        Objects.requireNonNull( joinSpec, "join specification" );
+        this._joinType = joinType;
+        this._joinSpec = joinSpec;
+    }
+
+    public JoinType getJoinType()
+    {
+        return this._joinType;
+    }
+
+    public JoinSpecification getJoinSpecification()
+    {
+        return this._joinSpec;
+    }
+
+    @Override
+    protected boolean doesEqual( QualifiedJoinedTable another )
+    {
+        boolean result = this._joinType.equals( another.getJoinType() )
+                         && this._joinSpec.equals( another.getJoinSpecification() ) && this.getRight().equals( another.getRight() );
+        if( result )
+        {
+            result = super.doesEqual( another );
+        }
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/UnionJoinedTableImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/UnionJoinedTableImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/UnionJoinedTableImpl.java
new file mode 100644
index 0000000..9d7496b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/joins/UnionJoinedTableImpl.java
@@ -0,0 +1,55 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query.joins;
+
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.UnionJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UnionJoinedTableImpl extends JoinedTableImpl<UnionJoinedTable>
+    implements UnionJoinedTable
+{
+
+    public UnionJoinedTableImpl( SQLProcessorAggregator processor, TableReference left, TableReference right )
+    {
+        this( processor, UnionJoinedTable.class, left, right );
+    }
+
+    protected UnionJoinedTableImpl( SQLProcessorAggregator processor, Class<? extends UnionJoinedTable> implClass,
+                                    TableReference left, TableReference right )
+    {
+        super( processor, implClass, left, right );
+    }
+
+    @Override
+    protected boolean doesEqual( UnionJoinedTable another )
+    {
+        boolean result = this.getRight().equals( another.getRight() );
+        if( result )
+        {
+            result = super.doesEqual( another );
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/AbstractProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/AbstractProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/AbstractProcessor.java
new file mode 100644
index 0000000..661014d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/AbstractProcessor.java
@@ -0,0 +1,51 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractProcessor<ProcessableType extends Typeable<?>>
+    implements SQLProcessor
+{
+
+    private final Class<? extends ProcessableType> _type;
+
+    public AbstractProcessor( Class<? extends ProcessableType> realType )
+    {
+        Objects.requireNonNull( realType, "Processable type" );
+        this._type = realType;
+    }
+
+    public void process( SQLProcessorAggregator aggregator, Typeable<?> object, StringBuilder builder )
+    {
+        if( object != null )
+        {
+            this.doProcess( aggregator, this._type.cast( object ), builder );
+        }
+    }
+
+    protected abstract void doProcess( SQLProcessorAggregator aggregator, ProcessableType object, StringBuilder builder );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/BooleanExpressionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/BooleanExpressionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/BooleanExpressionProcessing.java
new file mode 100644
index 0000000..8b42d9b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/BooleanExpressionProcessing.java
@@ -0,0 +1,289 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Iterator;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BinaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest.TestType;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Conjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Disjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.MultiPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Negation;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UnaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.BooleanUtils;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * Currently not thread-safe.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class BooleanExpressionProcessing
+{
+    public static class UnaryPredicateProcessor extends AbstractProcessor<UnaryPredicate>
+    {
+        public enum UnaryOperatorOrientation
+        {
+            BEFORE_EXPRESSION, // After expression
+            AFTER_EXPRESSION
+            // Before expression
+        }
+
+        public static final UnaryOperatorOrientation DEFAULT_ORIENTATION = UnaryOperatorOrientation.AFTER_EXPRESSION;
+
+        private final UnaryOperatorOrientation _orientation;
+        private final String _operator;
+
+        public UnaryPredicateProcessor( String operator )
+        {
+            this( DEFAULT_ORIENTATION, operator );
+        }
+
+        public UnaryPredicateProcessor( UnaryOperatorOrientation unaryOrientation, String unaryOperator )
+        {
+            super( UnaryPredicate.class );
+            Objects.requireNonNull( unaryOrientation, "unary operator orientation" );
+            Objects.requireNonNull( unaryOperator, "unary operator" );
+            this._orientation = unaryOrientation;
+            this._operator = unaryOperator;
+        }
+
+        protected void doProcess( SQLProcessorAggregator processor, UnaryPredicate predicate, StringBuilder builder )
+        {
+            UnaryOperatorOrientation orientation = this._orientation;
+            if( orientation == UnaryOperatorOrientation.BEFORE_EXPRESSION )
+            {
+                builder.append( this._operator ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+
+            NonBooleanExpression exp = predicate.getValueExpression();
+            Boolean isQuery = exp instanceof QueryExpression;
+            if( isQuery )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS );
+            }
+            processor.process( exp, builder );
+            if( isQuery )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+
+            if( orientation == UnaryOperatorOrientation.AFTER_EXPRESSION )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( this._operator );
+            }
+        }
+    }
+
+    public static class BinaryPredicateProcessor extends AbstractProcessor<BinaryPredicate>
+    {
+        private final String _operator;
+
+        public BinaryPredicateProcessor( String binaryOperator )
+        {
+            super( BinaryPredicate.class );
+            Objects.requireNonNull( binaryOperator, "binary operator" );
+
+            this._operator = binaryOperator;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, BinaryPredicate predicate, StringBuilder builder )
+        {
+            processor.process( predicate.getLeft(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( this._operator )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( predicate.getRight(), builder );
+        }
+    }
+
+    public static class MultiPredicateProcessor extends AbstractProcessor<MultiPredicate>
+    {
+        private final String _operator;
+        private final String _separator;
+        private final Boolean _needParenthesis;
+
+        public MultiPredicateProcessor( String multiOperator, String multiSeparator, Boolean needParenthesis )
+        {
+            super( MultiPredicate.class );
+            Objects.requireNonNull( multiOperator, "multi-operator" );
+            Objects.requireNonNull( multiSeparator, "multi separator" );
+            Objects.requireNonNull( needParenthesis, "need parenthesis" );
+
+            this._operator = multiOperator;
+            this._separator = multiSeparator;
+            this._needParenthesis = needParenthesis;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, MultiPredicate predicate, StringBuilder builder )
+        {
+            processor.process( predicate.getLeft(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( this._operator )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            if( this._needParenthesis )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS );
+            }
+
+            Iterator<NonBooleanExpression> iter = predicate.getRights().iterator();
+            while( iter.hasNext() )
+            {
+                NonBooleanExpression next = iter.next();
+                Boolean isQuery = next instanceof QueryExpression;
+
+                if( isQuery )
+                {
+                    builder.append( SQLConstants.OPEN_PARENTHESIS );
+                }
+
+                processor.process( next, builder );
+
+                if( isQuery )
+                {
+                    builder.append( SQLConstants.CLOSE_PARENTHESIS );
+                }
+
+                if( iter.hasNext() )
+                {
+                    builder.append( this._separator );
+                }
+            }
+
+            if( this._needParenthesis )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class NegationProcessor extends AbstractProcessor<Negation>
+    {
+        public NegationProcessor()
+        {
+            super( Negation.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, Negation object, StringBuilder builder )
+        {
+            BooleanExpression negated = object.getNegated();
+            if( !BooleanUtils.isEmpty( negated ) )
+            {
+                builder.append( SQLConstants.NOT ).append( SQLConstants.TOKEN_SEPARATOR );
+                aggregator.process( negated, builder );
+            }
+        }
+    }
+
+    public static void processBinaryComposedObject( SQLProcessorAggregator aggregator, BooleanExpression left,
+                                                    BooleanExpression right, StringBuilder builder, String operator )
+    {
+        Boolean leftEmpty = BooleanUtils.isEmpty( left );
+        Boolean rightEmpty = BooleanUtils.isEmpty( right );
+        if( !leftEmpty || !rightEmpty )
+        {
+            Boolean oneEmpty = leftEmpty || rightEmpty;
+            if( !oneEmpty )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS );
+            }
+            aggregator.process( left, builder );
+
+            if( !oneEmpty )
+            {
+                if( !leftEmpty )
+                {
+                    builder.append( SQLConstants.TOKEN_SEPARATOR );
+                }
+                builder.append( operator );
+                if( !rightEmpty )
+                {
+                    builder.append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+
+            aggregator.process( right, builder );
+            if( !oneEmpty )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class ConjunctionProcessor extends AbstractProcessor<Conjunction>
+    {
+
+        public ConjunctionProcessor()
+        {
+            super( Conjunction.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, Conjunction object, StringBuilder builder )
+        {
+            processBinaryComposedObject( aggregator, object.getLeft(), object.getRight(), builder, SQLConstants.AND );
+        }
+    }
+
+    public static class DisjunctionProcessor extends AbstractProcessor<Disjunction>
+    {
+        public DisjunctionProcessor()
+        {
+            super( Disjunction.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, Disjunction object, StringBuilder builder )
+        {
+            processBinaryComposedObject( aggregator, object.getLeft(), object.getRight(), builder, SQLConstants.OR );
+        }
+    }
+
+    public static class BooleanTestProcessor extends AbstractProcessor<BooleanTest>
+    {
+        public BooleanTestProcessor()
+        {
+            super( BooleanTest.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, BooleanTest object, StringBuilder builder )
+        {
+            BooleanExpression testable = object.getBooleanExpression();
+            builder.append( SQLConstants.OPEN_PARENTHESIS );
+            aggregator.process( testable, builder );
+            builder.append( SQLConstants.CLOSE_PARENTHESIS ).append( SQLConstants.IS )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            if( object.getTestType() == TestType.IS_NOT )
+            {
+                builder.append( SQLConstants.NOT ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+
+            builder.append( object.getTruthValue().toString() );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ColumnProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ColumnProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ColumnProcessing.java
new file mode 100644
index 0000000..2c2dbf8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ColumnProcessing.java
@@ -0,0 +1,95 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Iterator;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnProcessing
+{
+
+    public static class ColumnReferenceByNameProcessor extends AbstractProcessor<ColumnReferenceByName>
+    {
+        public ColumnReferenceByNameProcessor()
+        {
+            super( ColumnReferenceByName.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, ColumnReferenceByName columnRef,
+                                  StringBuilder builder )
+        {
+            String tableName = columnRef.getTableName();
+            if( ProcessorUtils.notNullAndNotEmpty( tableName ) )
+            {
+                builder.append( tableName ).append( SQLConstants.TABLE_COLUMN_SEPARATOR );
+            }
+
+            builder.append( columnRef.getColumnName() );
+        }
+    }
+
+    public static class ColumnReferenceByExpressionProcessor extends AbstractProcessor<ColumnReferenceByExpression>
+    {
+
+        public ColumnReferenceByExpressionProcessor()
+        {
+            super( ColumnReferenceByExpression.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, ColumnReferenceByExpression columnRef,
+                                  StringBuilder builder )
+        {
+            processor.process( columnRef.getExpression(), builder );
+        }
+    }
+
+    public static class ColumnNamesProcessor extends AbstractProcessor<ColumnNameList>
+    {
+        public ColumnNamesProcessor()
+        {
+            super( ColumnNameList.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, ColumnNameList object, StringBuilder builder )
+        {
+            builder.append( SQLConstants.OPEN_PARENTHESIS );
+            Iterator<String> iter = object.getColumnNames().iterator();
+            while( iter.hasNext() )
+            {
+                builder.append( iter.next() );
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ConstantProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ConstantProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ConstantProcessor.java
new file mode 100644
index 0000000..a27c5f5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ConstantProcessor.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ConstantProcessor
+    implements SQLProcessor
+{
+
+    private final String _constant;
+
+    public ConstantProcessor( String constant )
+    {
+        if( constant == null )
+        {
+            constant = "";
+        }
+
+        this._constant = constant;
+    }
+
+    public void process( SQLProcessorAggregator aggregator, Typeable<?> object, StringBuilder builder )
+    {
+        builder.append( this._constant );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DataTypeProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DataTypeProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DataTypeProcessing.java
new file mode 100644
index 0000000..abb1b2d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DataTypeProcessing.java
@@ -0,0 +1,275 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.IntervalDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInterval;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.UserDefinedType;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DataTypeProcessing
+{
+
+    public static class UserDefinedDataTypeProcessor extends AbstractProcessor<UserDefinedType>
+    {
+
+        public UserDefinedDataTypeProcessor()
+        {
+            super( UserDefinedType.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, UserDefinedType object, StringBuilder builder )
+        {
+            builder.append( object.getTextualRepresentation() );
+        }
+    }
+
+    public static class DecimalProcessor extends AbstractProcessor<Decimal>
+    {
+
+        public DecimalProcessor()
+        {
+            super( Decimal.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, Decimal object, StringBuilder builder )
+        {
+            builder.append( "DECIMAL" );
+            if( object.getPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getPrecision() );
+                if( object.getScale() != null )
+                {
+                    builder.append( object.getScale() );
+                }
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class NumericProcessor extends AbstractProcessor<Numeric>
+    {
+
+        public NumericProcessor()
+        {
+            super( Numeric.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, Numeric object, StringBuilder builder )
+        {
+            builder.append( "NUMERIC" );
+            if( object.getPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getPrecision() );
+                if( object.getScale() != null )
+                {
+                    builder.append( object.getScale() );
+                }
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class SQLCharProcessor extends AbstractProcessor<SQLChar>
+    {
+        public SQLCharProcessor()
+        {
+            super( SQLChar.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SQLChar object, StringBuilder builder )
+        {
+            builder.append( "CHARACTER" );
+            if( object.isVarying() )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "VARYING" );
+            }
+
+            if( object.getLength() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getLength() )
+                       .append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class SQLFloatProcessor extends AbstractProcessor<SQLFloat>
+    {
+
+        public SQLFloatProcessor()
+        {
+            super( SQLFloat.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SQLFloat object, StringBuilder builder )
+        {
+            builder.append( "FLOAT" );
+            if( object.getPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getPrecision() )
+                       .append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class SQLIntervalProcessor extends AbstractProcessor<SQLInterval>
+    {
+
+        private final static Map<IntervalDataType, String> _defaultIntervalDataTypes;
+
+        static
+        {
+            Map<IntervalDataType, String> map = new HashMap<IntervalDataType, String>();
+            map.put( IntervalDataType.YEAR, "YEAR" );
+            map.put( IntervalDataType.MONTH, "MONTH" );
+            map.put( IntervalDataType.DAY, "DAY" );
+            map.put( IntervalDataType.HOUR, "HOUR" );
+            map.put( IntervalDataType.MINUTE, "MINUTE" );
+            map.put( IntervalDataType.SECOND, "SECOND" );
+
+            _defaultIntervalDataTypes = map;
+        }
+
+        private final Map<IntervalDataType, String> _intervalDataTypes;
+
+        public SQLIntervalProcessor()
+        {
+            this( _defaultIntervalDataTypes );
+        }
+
+        public SQLIntervalProcessor( Map<IntervalDataType, String> intervalDataTypes )
+        {
+            super( SQLInterval.class );
+
+            this._intervalDataTypes = intervalDataTypes;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SQLInterval object, StringBuilder builder )
+        {
+            builder.append( "INTERVAL" ).append( SQLConstants.TOKEN_SEPARATOR )
+                   .append( this._intervalDataTypes.get( object.getStartField() ) );
+
+            if( object.getStartFieldPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getStartFieldPrecision() );
+
+                if( object.getEndField() == null && object.getSecondFracs() != null )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR )
+                           .append( object.getSecondFracs() );
+                }
+
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+
+            if( object.getEndField() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "TO" ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( this._intervalDataTypes.get( object.getEndField() ) );
+
+                if( object.getSecondFracs() != null )
+                {
+                    builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getSecondFracs() )
+                           .append( SQLConstants.CLOSE_PARENTHESIS );
+                }
+            }
+        }
+    }
+
+    public static class SQLTimeProcessor extends AbstractProcessor<SQLTime>
+    {
+
+        public SQLTimeProcessor()
+        {
+            super( SQLTime.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SQLTime object, StringBuilder builder )
+        {
+            builder.append( "TIME" );
+            if( object.getPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getPrecision() )
+                       .append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+
+            if( object.isWithTimeZone() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "WITH" );
+                if( !object.isWithTimeZone() )
+                {
+                    builder.append( "OUT" );
+                }
+
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "TIME ZONE" );
+            }
+        }
+    }
+
+    public static class SQLTimeStampProcessor extends AbstractProcessor<SQLTimeStamp>
+    {
+
+        public SQLTimeStampProcessor()
+        {
+            super( SQLTimeStamp.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SQLTimeStamp object, StringBuilder builder )
+        {
+            builder.append( "TIMESTAMP" );
+            if( object.getPrecision() != null )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( object.getPrecision() )
+                       .append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+
+            if( object.isWithTimeZone() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "WITH" );
+                if( !object.isWithTimeZone() )
+                {
+                    builder.append( "OUT" );
+                }
+
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "TIME ZONE" );
+            }
+        }
+    }
+}


[08/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractColumnsFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractColumnsFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractColumnsFactory.java
new file mode 100644
index 0000000..c67e8a8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractColumnsFactory.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractColumnsFactory extends SQLFactoryBase
+    implements ColumnsFactory
+{
+
+    protected AbstractColumnsFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public ColumnReferenceByName colName( String colName )
+    {
+        return this.colName( null, colName );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDataTypeFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDataTypeFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDataTypeFactory.java
new file mode 100644
index 0000000..f4944dd
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDataTypeFactory.java
@@ -0,0 +1,109 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractDataTypeFactory extends SQLFactoryBase
+    implements DataTypeFactory
+{
+
+    protected AbstractDataTypeFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public Decimal decimal()
+    {
+        return this.decimal( null, null );
+    }
+
+    public Decimal decimal( Integer precision )
+    {
+        return this.decimal( precision, null );
+    }
+
+    public Numeric numeric()
+    {
+        return this.numeric( null, null );
+    }
+
+    public Numeric numeric( Integer precision )
+    {
+        return this.numeric( precision, null );
+    }
+
+    public SQLChar sqlChar()
+    {
+        return this.sqlChar( null );
+    }
+
+    public SQLFloat sqlFloat()
+    {
+        return this.sqlFloat( null );
+    }
+
+    public SQLChar sqlVarChar()
+    {
+        return this.sqlVarChar( null );
+    }
+
+    public SQLTime time()
+    {
+        return this.time( null, null );
+    }
+
+    public SQLTime time( Boolean withTimeZone )
+    {
+        return this.time( null, withTimeZone );
+    }
+
+    public SQLTime time( Integer precision )
+    {
+        return this.time( precision, null );
+    }
+
+    public SQLTimeStamp timeStamp()
+    {
+        return this.timeStamp( null, null );
+    }
+
+    public SQLTimeStamp timeStamp( Boolean withTimeZone )
+    {
+        return this.timeStamp( null, withTimeZone );
+    }
+
+    public SQLTimeStamp timeStamp( Integer precision )
+    {
+        return this.timeStamp( precision, null );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDefinitionFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDefinitionFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDefinitionFactory.java
new file mode 100644
index 0000000..dcccb79
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractDefinitionFactory.java
@@ -0,0 +1,90 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractDefinitionFactory extends SQLFactoryBase
+    implements DefinitionFactory
+{
+
+    protected AbstractDefinitionFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType )
+    {
+        return this.createColumnDefinition( columnName, columnDataType, null, true );
+    }
+
+    public ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, Boolean mayBeNull )
+    {
+        return this.createColumnDefinition( columnName, columnDataType, null, mayBeNull );
+    }
+
+    public ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, String columnDefault )
+    {
+        return this.createColumnDefinition( columnName, columnDataType, columnDefault, true );
+    }
+
+    public ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType,
+                                                    String columnDefault, Boolean mayBeNull )
+    {
+        return this.createColumnDefinition( columnName, columnDataType, columnDefault, mayBeNull, null );
+    }
+
+    public ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, Boolean mayBeNull,
+                                                    AutoGenerationPolicy autoGenerationPolicy )
+    {
+        return this.createColumnDefinition( columnName, columnDataType, null, mayBeNull, autoGenerationPolicy );
+    }
+
+    public TableConstraintDefinition createTableConstraintDefinition( String name, TableConstraint constraint )
+    {
+        return this.createTableConstraintDefinition( name, constraint, null );
+    }
+
+    public TableConstraintDefinition createTableConstraintDefinition( TableConstraint constraint )
+    {
+        return this.createTableConstraintDefinition( null, constraint, null );
+    }
+
+    public TableConstraintDefinition createTableConstraintDefinition( TableConstraint constraint,
+                                                                      ConstraintCharacteristics characteristics )
+    {
+        return this.createTableConstraintDefinition( null, constraint, characteristics );
+    }
+
+    protected abstract ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType,
+                                                                String columnDefault, Boolean mayBeNull, AutoGenerationPolicy autoGenerationPolicy );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractModificationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractModificationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractModificationFactory.java
new file mode 100644
index 0000000..cc7dc33
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractModificationFactory.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractModificationFactory extends SQLFactoryBase
+    implements ModificationFactory
+{
+
+    protected AbstractModificationFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public TargetTable createTargetTable( TableNameDirect tableName )
+    {
+        return this.createTargetTable( tableName, false );
+    }
+
+    public ColumnSourceByQuery columnSourceByQuery( QueryExpression query )
+    {
+        return this.columnSourceByQuery( null, query );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractQueryFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractQueryFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractQueryFactory.java
new file mode 100644
index 0000000..af2df2a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractQueryFactory.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.ColumnsBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractQueryFactory extends SQLFactoryBase
+    implements QueryFactory
+{
+
+    protected AbstractQueryFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public QueryBuilder queryBuilder()
+    {
+        return this.queryBuilder( QueryExpressionBody.EmptyQueryExpressionBody.INSTANCE );
+    }
+
+    public ColumnsBuilder columnsBuilder()
+    {
+        return new ColumnsBuilderImpl( this.getProcessor(), SetQuantifier.ALL );
+    }
+
+    public QueryExpression callFunction( SQLFunctionLiteral function )
+    {
+        return this.callFunction( null, function );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractTableRefFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractTableRefFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractTableRefFactory.java
new file mode 100644
index 0000000..3865fef
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractTableRefFactory.java
@@ -0,0 +1,71 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractTableRefFactory extends SQLFactoryBase
+    implements TableReferenceFactory
+{
+
+    protected AbstractTableRefFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public TableReferenceByName table( TableName tableName )
+    {
+        return this.table( tableName, null );
+    }
+
+    public TableNameDirect tableName( String tableName )
+    {
+        return this.tableName( null, tableName );
+    }
+
+    public TableAlias tableAlias( String tableNameAlias )
+    {
+        return this.tableAliasWithCols( tableNameAlias );
+    }
+
+    public TableReferenceByExpression table( QueryExpression query )
+    {
+        return this.table( query, null );
+    }
+
+    public TableNameFunction tableName( SQLFunctionLiteral function )
+    {
+        return this.tableName( null, function );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultBooleanFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultBooleanFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultBooleanFactory.java
new file mode 100644
index 0000000..bd5e159
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultBooleanFactory.java
@@ -0,0 +1,209 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest.TestType;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest.TruthValue;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Conjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Disjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.EqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.ExistsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNotNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Negation;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotBetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotEqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotInPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotLikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotRegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.RegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UniquePredicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.InBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.BetweenPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.BooleanTestImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.ConjunctionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.DisjunctionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.EqualsPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.ExistsPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.GreaterOrEqualPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.GreaterThanPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.IsNotNullPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.IsNullPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.LessOrEqualPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.LessThanPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.LikePredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NegationImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NotBetweenPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NotEqualsPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NotInPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NotLikePredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.NotRegexpPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.RegexpPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.UniquePredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.booleans.BooleanBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.booleans.InBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultBooleanFactory extends AbstractBooleanFactory
+{
+
+    public DefaultBooleanFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public EqualsPredicate eq( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new EqualsPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public NotEqualsPredicate neq( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new NotEqualsPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public LessThanPredicate lt( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new LessThanPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public LessOrEqualPredicate leq( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new LessOrEqualPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public GreaterThanPredicate gt( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new GreaterThanPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public GreaterOrEqualPredicate geq( NonBooleanExpression left, NonBooleanExpression right )
+    {
+        return new GreaterOrEqualPredicateImpl( this.getProcessor(), left, right );
+    }
+
+    public IsNullPredicate isNull( NonBooleanExpression what )
+    {
+        return new IsNullPredicateImpl( this.getProcessor(), what );
+    }
+
+    public IsNotNullPredicate isNotNull( NonBooleanExpression what )
+    {
+        return new IsNotNullPredicateImpl( this.getProcessor(), what );
+    }
+
+    public Negation not( BooleanExpression what )
+    {
+        return new NegationImpl( this.getProcessor(), what );
+    }
+
+    public Conjunction and( BooleanExpression left, BooleanExpression right )
+    {
+        return new ConjunctionImpl( this.getProcessor(), left, right );
+    }
+
+    public Disjunction or( BooleanExpression left, BooleanExpression right )
+    {
+        return new DisjunctionImpl( this.getProcessor(), left, right );
+    }
+
+    public BetweenPredicate between( NonBooleanExpression left, NonBooleanExpression minimum,
+                                     NonBooleanExpression maximum )
+    {
+        return new BetweenPredicateImpl( this.getProcessor(), left, minimum, maximum );
+    }
+
+    public NotBetweenPredicate notBetween( NonBooleanExpression left, NonBooleanExpression minimum,
+                                           NonBooleanExpression maximum )
+    {
+        return new NotBetweenPredicateImpl( this.getProcessor(), left, minimum, maximum );
+    }
+
+    public InBuilder inBuilder( NonBooleanExpression what )
+    {
+        return new InBuilderImpl( this.getProcessor(), what );
+    }
+
+    public NotInPredicate notIn( NonBooleanExpression what, NonBooleanExpression... values )
+    {
+        return new NotInPredicateImpl( this.getProcessor(), what, values );
+    }
+
+    public LikePredicate like( NonBooleanExpression what, NonBooleanExpression pattern )
+    {
+        return new LikePredicateImpl( this.getProcessor(), what, pattern );
+    }
+
+    public NotLikePredicate notLike( NonBooleanExpression what, NonBooleanExpression pattern )
+    {
+        return new NotLikePredicateImpl( this.getProcessor(), what, pattern );
+    }
+
+    public RegexpPredicate regexp( NonBooleanExpression what, NonBooleanExpression pattern )
+    {
+        return new RegexpPredicateImpl( this.getProcessor(), what, pattern );
+    }
+
+    public NotRegexpPredicate notRegexp( NonBooleanExpression what, NonBooleanExpression pattern )
+    {
+        return new NotRegexpPredicateImpl( this.getProcessor(), what, pattern );
+    }
+
+    public ExistsPredicate exists( QueryExpression query )
+    {
+        return new ExistsPredicateImpl( this.getProcessor(), query );
+    }
+
+    public UniquePredicate unique( QueryExpression query )
+    {
+        return new UniquePredicateImpl( this.getProcessor(), query );
+    }
+
+    public BooleanTest test( BooleanExpression expression, TestType testType, TruthValue truthValue )
+    {
+        return new BooleanTestImpl( this.getProcessor(), expression, testType, truthValue );
+    }
+
+    public BooleanBuilder booleanBuilder( BooleanExpression first )
+    {
+        return new BooleanBuilderImpl( this.getProcessor(), this, this.transformNullToEmpty( first ) );
+    }
+
+    private final BooleanExpression transformNullToEmpty( BooleanExpression expression )
+    {
+        return expression == null ? Predicate.EmptyPredicate.INSTANCE : expression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultColumnsFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultColumnsFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultColumnsFactory.java
new file mode 100644
index 0000000..2e1258b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultColumnsFactory.java
@@ -0,0 +1,71 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import java.util.Collection;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.ColumnsBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.ColumnNameListImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.ColumnReferenceByExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.ColumnReferenceByNameImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultColumnsFactory extends AbstractColumnsFactory
+{
+
+    public DefaultColumnsFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public ColumnsBuilder columnsBuilder( SetQuantifier setQuantifier )
+    {
+        return new ColumnsBuilderImpl( this.getProcessor(), setQuantifier );
+    }
+
+    public ColumnReferenceByName colName( String tableName, String colName )
+    {
+        return new ColumnReferenceByNameImpl( this.getProcessor(), tableName, colName );
+    }
+
+    public ColumnReferenceByExpression colExp( ValueExpression expression )
+    {
+        return new ColumnReferenceByExpressionImpl( this.getProcessor(), expression );
+    }
+
+    public ColumnNameList colNames( String... names )
+    {
+        return new ColumnNameListImpl( this.getProcessor(), names );
+    }
+
+    public ColumnNameList colNames( Collection<String> names )
+    {
+        return new ColumnNameListImpl( this.getProcessor(), names );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDataTypeFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDataTypeFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDataTypeFactory.java
new file mode 100644
index 0000000..a934d18
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDataTypeFactory.java
@@ -0,0 +1,235 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.DoublePrecision;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.IntervalDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Real;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLBoolean;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDate;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInterval;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.UserDefinedType;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.BigIntImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.DecimalImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.DoublePrecisionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.NumericImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.RealImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLBooleanImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLCharImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLDateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLFloatImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLIntegerImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLIntervalImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLTimeImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SQLTimeStampImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.SmallIntImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.datatypes.UserDefinedTypeImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultDataTypeFactory extends AbstractDataTypeFactory
+{
+
+    public DefaultDataTypeFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public BigInt bigInt()
+    {
+        return BigIntImpl.INSTANCE;
+    }
+
+    public Decimal decimal( Integer precision, Integer scale )
+    {
+        return precision == null ? DecimalImpl.PLAIN_DECIMAL : new DecimalImpl( precision, scale );
+    }
+
+    public DoublePrecision doublePrecision()
+    {
+        return DoublePrecisionImpl.INSTANCE;
+    }
+
+    public Numeric numeric( Integer precision, Integer scale )
+    {
+        return precision == null ? NumericImpl.PLAIN_NUMERIC : new NumericImpl( precision, scale );
+    }
+
+    public Real real()
+    {
+        return RealImpl.INSTANCE;
+    }
+
+    public SmallInt smallInt()
+    {
+        return SmallIntImpl.INSTANCE;
+    }
+
+    public SQLBoolean sqlBoolean()
+    {
+        return SQLBooleanImpl.INSTANCE;
+    }
+
+    public SQLChar sqlChar( Integer length )
+    {
+        return length == null ? SQLCharImpl.PLAIN_FIXED : new SQLCharImpl( false, length );
+    }
+
+    public SQLChar sqlVarChar( Integer length )
+    {
+        return length == null ? SQLCharImpl.PLAIN_VARYING : new SQLCharImpl( true, length );
+    }
+
+    public SQLDate date()
+    {
+        return SQLDateImpl.INSTANCE;
+    }
+
+    public SQLFloat sqlFloat( Integer precision )
+    {
+        return precision == null ? SQLFloatImpl.PLAIN_FLOAT : new SQLFloatImpl( precision );
+    }
+
+    public SQLInteger integer()
+    {
+        return SQLIntegerImpl.INSTANCE;
+    }
+
+    public SQLInterval yearMonthInterval( IntervalDataType startField, Integer startFieldPrecision,
+                                          IntervalDataType endField )
+    {
+        Objects.requireNonNull( startField, "Start field" );
+
+        SQLInterval result = null;
+        if( ( startField == IntervalDataType.YEAR || startField == IntervalDataType.MONTH )
+            && ( endField == null || endField == IntervalDataType.YEAR || endField == IntervalDataType.MONTH ) )
+        {
+            result = new SQLIntervalImpl( startField, startFieldPrecision, endField, null );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The interval data types must be either YEAR or MONTH." );
+        }
+
+        return result;
+    }
+
+    public SQLInterval dayTimeInterval( IntervalDataType startField, Integer startFieldPrecision,
+                                        IntervalDataType endField, Integer secondFracs )
+    {
+        Objects.requireNonNull( startField, "Start field" );
+        SQLInterval result = null;
+        if( startField != IntervalDataType.YEAR
+            && startField != IntervalDataType.MONTH
+            && ( endField == null || ( endField != IntervalDataType.YEAR && endField != IntervalDataType.MONTH && startField != IntervalDataType.SECOND ) ) )
+        {
+            if( secondFracs != null
+                && ( startField != IntervalDataType.SECOND || ( endField != null && endField != IntervalDataType.SECOND ) ) )
+            {
+                // Trying to set second fractionals, even when not needed
+                secondFracs = null;
+            }
+
+            if( endField == null && secondFracs != null && startFieldPrecision == null )
+            {
+                throw new IllegalArgumentException(
+                    "When specifying second fracs for single day-time intervals, the start field precision must be specified also." );
+            }
+
+            result = new SQLIntervalImpl( startField, startFieldPrecision, endField, secondFracs );
+        }
+        else
+        {
+            throw new IllegalArgumentException(
+                "The interval data types must be either DAY, HOUR, MINUTE, or SECOND. For single day-time intervals, the start field must not be SECOND if end field is non-null." );
+        }
+        return result;
+    }
+
+    public SQLTime time( Integer precision, Boolean withTimeZone )
+    {
+        SQLTime result = null;
+        if( precision == null )
+        {
+            if( withTimeZone == null )
+            {
+                result = SQLTimeImpl.PLAIN_TIME;
+            }
+            else if( withTimeZone )
+            {
+                result = SQLTimeImpl.PLAIN_TIME_WITH_TZ;
+            }
+            else
+            {
+                result = SQLTimeImpl.PLAIN_TIME_WITHOUT_TZ;
+            }
+        }
+        else
+        {
+            result = new SQLTimeImpl( precision, withTimeZone );
+        }
+
+        return result;
+    }
+
+    public SQLTimeStamp timeStamp( Integer precision, Boolean withTimeZone )
+    {
+        SQLTimeStamp result = null;
+        if( precision == null )
+        {
+            if( withTimeZone == null )
+            {
+                result = SQLTimeStampImpl.PLAIN_TIMESTAMP;
+            }
+            else if( withTimeZone )
+            {
+                result = SQLTimeStampImpl.PLAIN_TIMESTAMP_WITH_TZ;
+            }
+            else
+            {
+                result = SQLTimeStampImpl.PLAIN_TIMESTAMP_WITHOUT_TZ;
+            }
+        }
+        else
+        {
+            result = new SQLTimeStampImpl( precision, withTimeZone );
+        }
+
+        return result;
+    }
+
+    public UserDefinedType userDefined( String textualContent )
+    {
+        return new UserDefinedTypeImpl( textualContent );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDefinitionFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDefinitionFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDefinitionFactory.java
new file mode 100644
index 0000000..9c5805b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultDefinitionFactory.java
@@ -0,0 +1,122 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ForeignKeyConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.SchemaDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableElementListBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.UniqueConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ViewDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.CheckConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.LikeClause;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.ForeignKeyConstraintBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.SchemaDefinitionBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.TableDefinitionBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.TableElementListBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.UniqueConstraintBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.definition.ViewDefinitionBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.CheckConstraintImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.ColumnDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.LikeClauseImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.TableConstraintDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.view.RegularViewSpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultDefinitionFactory extends AbstractDefinitionFactory
+{
+    public DefaultDefinitionFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public SchemaDefinitionBuilder createSchemaDefinitionBuilder()
+    {
+        return new SchemaDefinitionBuilderImpl( this.getProcessor() );
+    }
+
+    public TableDefinitionBuilder createTableDefinitionBuilder()
+    {
+        return new TableDefinitionBuilderImpl( this.getProcessor() );
+    }
+
+    public TableElementListBuilder createTableElementListBuilder()
+    {
+        return new TableElementListBuilderImpl( this.getProcessor() );
+    }
+
+    @Override
+    protected ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType,
+                                                       String columnDefault, Boolean mayBeNull, AutoGenerationPolicy autoGenerationPolicy )
+    {
+        return new ColumnDefinitionImpl( this.getProcessor(), columnName, columnDataType, columnDefault, mayBeNull,
+                                         autoGenerationPolicy );
+    }
+
+    public LikeClause createLikeClause( TableNameDirect tableName )
+    {
+        return new LikeClauseImpl( this.getProcessor(), tableName );
+    }
+
+    public TableConstraintDefinition createTableConstraintDefinition( String name, TableConstraint constraint,
+                                                                      ConstraintCharacteristics characteristics )
+    {
+        return new TableConstraintDefinitionImpl( this.getProcessor(), name, constraint, characteristics );
+    }
+
+    public CheckConstraint createCheckConstraint( BooleanExpression check )
+    {
+        return new CheckConstraintImpl( this.getProcessor(), check );
+    }
+
+    public UniqueConstraintBuilder createUniqueConstraintBuilder()
+    {
+        return new UniqueConstraintBuilderImpl( this.getProcessor(), this.getVendor().getColumnsFactory() );
+    }
+
+    public ForeignKeyConstraintBuilder createForeignKeyConstraintBuilder()
+    {
+        return new ForeignKeyConstraintBuilderImpl( this.getProcessor(), this.getVendor().getColumnsFactory() );
+    }
+
+    public ViewDefinitionBuilder createViewDefinitionBuilder()
+    {
+        return new ViewDefinitionBuilderImpl( this.getProcessor() );
+    }
+
+    public RegularViewSpecification createRegularViewSpecification( String... columnNames )
+    {
+        return new RegularViewSpecificationImpl( this.getProcessor(), this.getVendor().getColumnsFactory()
+                                                                          .colNames( columnNames ) );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultLiteralFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultLiteralFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultLiteralFactory.java
new file mode 100644
index 0000000..eb096e4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultLiteralFactory.java
@@ -0,0 +1,85 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import java.sql.Timestamp;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.literals.DirectLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.StringLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.literals.DirectLiteralImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.literals.NumericLiteralImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.literals.SQLFunctionLiteralImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.literals.StringLiteralImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.literals.TimestampLiteralImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultLiteralFactory extends SQLFactoryBase
+    implements LiteralFactory
+{
+
+    private final DirectLiteral _param;
+
+    public DefaultLiteralFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+
+        this._param = new DirectLiteralImpl( this.getProcessor(), SQLConstants.QUESTION_MARK );
+    }
+
+    public DirectLiteral l( String literalContents )
+    {
+        return new DirectLiteralImpl( this.getProcessor(), literalContents );
+    }
+
+    public DirectLiteral param()
+    {
+        return _param;
+    }
+
+    public StringLiteral s( String literal )
+    {
+        return new StringLiteralImpl( this.getProcessor(), literal );
+    }
+
+    public TimestampTimeLiteral dt( Timestamp date )
+    {
+        return new TimestampLiteralImpl( this.getProcessor(), date );
+    }
+
+    public NumericLiteral n( Number number )
+    {
+        return new NumericLiteralImpl( this.getProcessor(), number );
+    }
+
+    public SQLFunctionLiteral func( String name, ValueExpression... parameters )
+    {
+        return new SQLFunctionLiteralImpl( this.getProcessor(), name, parameters );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultManipulationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultManipulationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultManipulationFactory.java
new file mode 100644
index 0000000..66596e6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultManipulationFactory.java
@@ -0,0 +1,122 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.factories.ManipulationFactory;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.SetColumnDefault;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.AddColumnDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.AddTableConstraintDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.AlterColumnDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.AlterTableStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.DropColumnDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.DropSchemaStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.DropTableConstraintDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.DropTableOrViewStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.manipulation.SetColumnDefaultImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultManipulationFactory extends SQLFactoryBase
+    implements ManipulationFactory
+{
+
+    public DefaultManipulationFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public AlterTableStatement createAlterTableStatement( TableNameDirect tableName, AlterTableAction action )
+    {
+        return new AlterTableStatementImpl( this.getProcessor(), tableName, action );
+    }
+
+    public AddColumnDefinition createAddColumnDefinition( ColumnDefinition definition )
+    {
+        return new AddColumnDefinitionImpl( this.getProcessor(), definition );
+    }
+
+    public AddTableConstraintDefinition createAddTableConstraintDefinition(
+        TableConstraintDefinition constraintDefinition )
+    {
+        return new AddTableConstraintDefinitionImpl( this.getProcessor(), constraintDefinition );
+    }
+
+    public AlterColumnDefinition createAlterColumnDefinition( String columnName, AlterColumnAction action )
+    {
+        return new AlterColumnDefinitionImpl( this.getProcessor(), columnName, action );
+    }
+
+    public SetColumnDefault createSetColumnDefault( String newDefault )
+    {
+        return new SetColumnDefaultImpl( this.getProcessor(), newDefault );
+    }
+
+    public DropColumnDefinition createDropColumnDefinition( String columnName, DropBehaviour dropBehaviour )
+    {
+        return new DropColumnDefinitionImpl( this.getProcessor(), columnName, dropBehaviour );
+    }
+
+    public DropTableConstraintDefinition createDropTableConstraintDefinition( String constraintName,
+                                                                              DropBehaviour dropBehaviour )
+    {
+        return new DropTableConstraintDefinitionImpl( this.getProcessor(), constraintName, dropBehaviour );
+    }
+
+    public DropSchemaStatement createDropSchemaStatement( String schemaName, DropBehaviour dropBehaviour )
+    {
+        return new DropSchemaStatementImpl( this.getProcessor(), dropBehaviour, schemaName );
+    }
+
+    public DropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                                    DropBehaviour dropBehaviour )
+    {
+        DropTableOrViewStatement result = null;
+        if( theType == ObjectType.TABLE || theType == ObjectType.VIEW )
+        {
+            result = new DropTableOrViewStatementImpl( this.getProcessor(), theType, dropBehaviour, tableName );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Object type " + theType
+                                                + " is not a valid type for DROP TABLE or DROP VIEW statement." );
+        }
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultModificationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultModificationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultModificationFactory.java
new file mode 100644
index 0000000..e519918
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultModificationFactory.java
@@ -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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.ColumnSourceByValuesBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.DeleteBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.UpdateBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.ColumnSourceByValuesBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.DeleteBySearchBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.InsertStatementBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.modification.UpdateBySearchBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.ColumnSourceByQueryImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.SetClauseImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.TargetTableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.UpdateSourceByExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultModificationFactory extends AbstractModificationFactory
+{
+
+    public DefaultModificationFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public ColumnSourceByValuesBuilder columnSourceByValues()
+    {
+        return new ColumnSourceByValuesBuilderImpl( this.getProcessor() );
+    }
+
+    public ColumnSourceByQuery columnSourceByQuery( ColumnNameList columnNames, QueryExpression query )
+    {
+        return new ColumnSourceByQueryImpl( this.getProcessor(), columnNames, query );
+    }
+
+    public DeleteBySearchBuilder deleteBySearch()
+    {
+        return new DeleteBySearchBuilderImpl( this.getProcessor(), this.getVendor().getBooleanFactory()
+                                                                       .booleanBuilder() );
+    }
+
+    public InsertStatementBuilder insert()
+    {
+        return new InsertStatementBuilderImpl( this.getProcessor() );
+    }
+
+    public UpdateBySearchBuilder updateBySearch()
+    {
+        return new UpdateBySearchBuilderImpl( this.getProcessor(), this.getVendor().getBooleanFactory()
+                                                                       .booleanBuilder() );
+    }
+
+    public TargetTable createTargetTable( TableNameDirect tableName, Boolean isOnly )
+    {
+        return new TargetTableImpl( this.getProcessor(), isOnly, tableName );
+    }
+
+    public UpdateSourceByExpression updateSourceByExp( ValueExpression expression )
+    {
+        return new UpdateSourceByExpressionImpl( this.getProcessor(), expression );
+    }
+
+    public SetClause setClause( String updateTarget, UpdateSource updateSource )
+    {
+        return new SetClauseImpl( this.getProcessor(), updateTarget, updateSource );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultQueryFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultQueryFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultQueryFactory.java
new file mode 100644
index 0000000..fe5f64e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultQueryFactory.java
@@ -0,0 +1,156 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import java.util.Arrays;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.FromBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.GroupByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.OrderByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.SimpleQueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.RowDefinition;
+import org.apache.polygene.library.sql.generator.grammar.query.RowSubQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.TableValueConstructor;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.ColumnsBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.FromBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.GroupByBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.OrderByBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.QueryBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.QuerySpecificationBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.SimpleQueryBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.LimitSpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.OffsetSpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.OrdinaryGroupingSetImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.QueryExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.RowDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.RowSubQueryImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.SortSpecificationImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.TableValueConstructorImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultQueryFactory extends AbstractQueryFactory
+{
+
+    public DefaultQueryFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public QueryExpression createQuery( QueryExpressionBody body )
+    {
+        return new QueryExpressionImpl( this.getProcessor(), body );
+    }
+
+    public QuerySpecificationBuilder querySpecificationBuilder()
+    {
+        return new QuerySpecificationBuilderImpl( this.getProcessor(), this, this.columnsBuilder(), this.fromBuilder(),
+                                                  this.getVendor().getBooleanFactory().booleanBuilder(), this.groupByBuilder(), this.getVendor()
+                                                                                                                                    .getBooleanFactory().booleanBuilder(), this.orderByBuilder() );
+    }
+
+    public ColumnsBuilder columnsBuilder( SetQuantifier setQuantifier )
+    {
+        return new ColumnsBuilderImpl( this.getProcessor(), setQuantifier );
+    }
+
+    public QueryBuilder queryBuilder( QueryExpressionBody query )
+    {
+        return new QueryBuilderImpl( this.getProcessor(), query );
+    }
+
+    public GroupByBuilder groupByBuilder()
+    {
+        return new GroupByBuilderImpl( this.getProcessor() );
+    }
+
+    public OrdinaryGroupingSet groupingElement( NonBooleanExpression... expressions )
+    {
+        return new OrdinaryGroupingSetImpl( this.getProcessor(), expressions );
+    }
+
+    public FromBuilder fromBuilder()
+    {
+        return new FromBuilderImpl( this.getProcessor() );
+    }
+
+    public OrderByBuilder orderByBuilder()
+    {
+        return new OrderByBuilderImpl( this.getProcessor() );
+    }
+
+    public SortSpecification sortSpec( ValueExpression expression, Ordering ordering )
+    {
+        return new SortSpecificationImpl( this.getProcessor(), expression, ordering );
+    }
+
+    public SimpleQueryBuilder simpleQueryBuilder()
+    {
+        return new SimpleQueryBuilderImpl( this.getProcessor(), this.getVendor() );
+    }
+
+    public TableValueConstructor values( RowValueConstructor... rows )
+    {
+        return new TableValueConstructorImpl( this.getProcessor(), Arrays.asList( rows ) );
+    }
+
+    public RowSubQuery rowSubQuery( QueryExpression subQuery )
+    {
+        return new RowSubQueryImpl( this.getProcessor(), subQuery );
+    }
+
+    public RowDefinition row( ValueExpression... elements )
+    {
+        return new RowDefinitionImpl( this.getProcessor(), Arrays.asList( elements ) );
+    }
+
+    public QueryExpression callFunction( String schemaName, SQLFunctionLiteral function )
+    {
+        return this.simpleQueryBuilder().selectAllColumns()
+                   .from( this.getVendor().getTableReferenceFactory().tableName( schemaName, function ) ).createExpression();
+    }
+
+    public LimitSpecification limit( NonBooleanExpression count )
+    {
+        return new LimitSpecificationImpl( this.getProcessor(), count );
+    }
+
+    public OffsetSpecification offset( NonBooleanExpression offset )
+    {
+        return new OffsetSpecificationImpl( this.getProcessor(), offset );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultTableRefFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultTableRefFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultTableRefFactory.java
new file mode 100644
index 0000000..612c9f4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/DefaultTableRefFactory.java
@@ -0,0 +1,103 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferencePrimary;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinCondition;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NamedColumnsJoin;
+import org.apache.polygene.library.sql.generator.implementation.grammar.builders.query.TableReferenceBuilderImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.TableNameDirectImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.TableNameFunctionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.TableAliasImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.TableReferenceByExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.TableReferenceByNameImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.JoinConditionImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.query.joins.NamedColumnsJoinImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultTableRefFactory extends AbstractTableRefFactory
+{
+
+    public DefaultTableRefFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public JoinCondition jc( BooleanExpression condition )
+    {
+        return new JoinConditionImpl( this.getProcessor(), condition );
+    }
+
+    public NamedColumnsJoin nc( ColumnNameList columnNames )
+    {
+        return new NamedColumnsJoinImpl( this.getProcessor(), columnNames );
+    }
+
+    public TableReferenceByName table( TableName tableName, TableAlias alias )
+    {
+        return new TableReferenceByNameImpl( this.getProcessor(), tableName, alias );
+    }
+
+    public TableNameDirect tableName( String schemaName, String tableName )
+    {
+        return new TableNameDirectImpl( this.getProcessor(), schemaName, tableName );
+    }
+
+    public TableNameFunction tableName( String schemaName, SQLFunctionLiteral function )
+    {
+        return new TableNameFunctionImpl( this.getProcessor(), schemaName, function );
+    }
+
+    public TableAlias tableAliasWithCols( String tableNameAlias, String... colNames )
+    {
+        ColumnNameList colNameList = null;
+        if( colNames.length > 0 )
+        {
+            colNameList = this.getVendor().getColumnsFactory().colNames( colNames );
+        }
+
+        return new TableAliasImpl( this.getProcessor(), tableNameAlias, colNameList );
+    }
+
+    public TableReferenceByExpression table( QueryExpression query, TableAlias alias )
+    {
+        return new TableReferenceByExpressionImpl( this.getProcessor(), query, alias );
+    }
+
+    public TableReferenceBuilder tableBuilder( TableReferencePrimary firstTable )
+    {
+        return new TableReferenceBuilderImpl( this.getProcessor(), firstTable );
+    }
+}


[02/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ManipulationProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ManipulationProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ManipulationProcessing.java
new file mode 100644
index 0000000..9aa0c6a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ManipulationProcessing.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropTableOrViewStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ProcessorUtils;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ManipulationProcessing
+{
+
+    public static class PgSQLDropTableOrViewStatementProcessor extends DropTableOrViewStatementProcessor
+    {
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropTableOrViewStatement object,
+                                  StringBuilder builder )
+        {
+            builder.append( "DROP" ).append( SQLConstants.TOKEN_SEPARATOR )
+                   .append( this.getObjectTypes().get( object.whatToDrop() ) ).append( SQLConstants.TOKEN_SEPARATOR );
+
+            Boolean useIfExists = ( (PgSQLDropTableOrViewStatement) object ).useIfExists();
+            if( useIfExists )
+            {
+                builder.append( "IF EXISTS" ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+
+            aggregator.process( object.getTableName(), builder );
+
+            ProcessorUtils.processDropBehaviour( object.getDropBehaviour(), builder );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ModificationProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ModificationProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ModificationProcessing.java
new file mode 100644
index 0000000..100e311
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/ModificationProcessing.java
@@ -0,0 +1,48 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.pgsql.PgSQLInsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.InsertStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class ModificationProcessing
+{
+
+    public static class PgSQLInsertStatementProcessor extends InsertStatementProcessor
+    {
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, InsertStatement object,
+                                  StringBuilder builder )
+        {
+            super.doProcess( processor, object, builder );
+
+            SelectColumnClause returning = ( (PgSQLInsertStatement) object ).getReturningClause();
+            if( returning != null )
+            {
+                builder.append( SQLConstants.NEWLINE ).append( "RETURNING " );
+                processor.process( returning, builder );
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/PostgreSQLProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/PostgreSQLProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/PostgreSQLProcessor.java
new file mode 100644
index 0000000..3dbc059
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/PostgreSQLProcessor.java
@@ -0,0 +1,132 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BinaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotRegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.RegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.pgsql.Text;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.pgsql.PgSQLTableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.pgsql.PgSQLInsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.BinaryPredicateProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ConstantProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.TableDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.DefinitionProcessing.PGColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.LiteralExpressionProcessing.PGDateTimeLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.ManipulationProcessing.PgSQLDropTableOrViewStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.ModificationProcessing.PgSQLInsertStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.QueryProcessing.PgSQLLimitSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.QueryProcessing.PgSQLOffsetSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.QueryProcessing.PgSQLQuerySpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PostgreSQLProcessor extends DefaultSQLProcessor
+{
+
+    private static final Map<Class<? extends Typeable<?>>, SQLProcessor> _defaultProcessors;
+
+    private static final Map<Class<? extends BinaryPredicate>, String> _defaultPgSQLBinaryOperators;
+
+    static
+    {
+        Map<Class<? extends BinaryPredicate>, String> binaryOperators =
+            new HashMap<Class<? extends BinaryPredicate>, String>(
+                DefaultSQLProcessor.getDefaultBinaryOperators() );
+        binaryOperators.put( RegexpPredicate.class, "~" );
+        binaryOperators.put( NotRegexpPredicate.class, "!~" );
+        _defaultPgSQLBinaryOperators = binaryOperators;
+
+        Map<Class<? extends Typeable<?>>, SQLProcessor> processors =
+            new HashMap<Class<? extends Typeable<?>>, SQLProcessor>(
+                DefaultSQLProcessor.getDefaultProcessors() );
+
+        // Override default processor for date-time
+        processors.put( TimestampTimeLiteral.class, new PGDateTimeLiteralProcessor() );
+
+        // Override default processor for column definition
+        Map<Class<?>, String> dataTypeSerials = new HashMap<Class<?>, String>();
+        dataTypeSerials.put( BigInt.class, "BIGSERIAL" );
+        dataTypeSerials.put( SQLInteger.class, "SERIAL" );
+        dataTypeSerials.put( SmallInt.class, "SMALLSERIAL" );
+        processors.put( ColumnDefinition.class,
+                        new PGColumnDefinitionProcessor( Collections.unmodifiableMap( dataTypeSerials ) ) );
+
+        // Add support for regexp comparing
+        processors
+            .put(
+                RegexpPredicate.class,
+                new BinaryPredicateProcessor( _defaultPgSQLBinaryOperators
+                                                  .get( RegexpPredicate.class ) ) );
+        processors.put(
+            NotRegexpPredicate.class,
+            new BinaryPredicateProcessor( _defaultPgSQLBinaryOperators
+                                              .get( NotRegexpPredicate.class ) ) );
+
+        // Add support for PostgreSQL legacy LIMIT/OFFSET
+        processors.put( QuerySpecification.class, new PgSQLQuerySpecificationProcessor() );
+        processors.put( OffsetSpecification.class, new PgSQLOffsetSpecificationProcessor() );
+        processors.put( LimitSpecification.class, new PgSQLLimitSpecificationProcessor() );
+
+        // Add support for "TEXT" data type
+        processors.put( Text.class, new ConstantProcessor( "TEXT" ) );
+
+        // Add "DROP" table commit action
+        Map<TableCommitAction, String> commitActions = new HashMap<TableCommitAction, String>(
+            TableDefinitionProcessor.getDefaultCommitActions() );
+        commitActions.put( PgSQLTableCommitAction.DROP, "DROP" );
+        processors.put( TableDefinition.class,
+                        new TableDefinitionProcessor( TableDefinitionProcessor.getDefaultTableScopes(),
+                                                      commitActions ) );
+
+        // Add "IF EXISTS" functionality to DROP TABLE/VIEW statements
+        processors.put( PgSQLDropTableOrViewStatement.class,
+                        new PgSQLDropTableOrViewStatementProcessor() );
+
+        // Add support for PostgreSQL-specific INSTERT statement RETURNING clause
+        processors.put( PgSQLInsertStatement.class, new PgSQLInsertStatementProcessor() );
+
+        _defaultProcessors = processors;
+    }
+
+    public PostgreSQLProcessor( SQLVendor vendor )
+    {
+        super( vendor, _defaultProcessors );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/QueryProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/QueryProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/QueryProcessing.java
new file mode 100644
index 0000000..a5bb806
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/QueryProcessing.java
@@ -0,0 +1,81 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.LimitSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.OffsetSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.QuerySpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class QueryProcessing
+{
+
+    private static final String LEGACY_LIMIT_PREFIX = "LIMIT";
+    private static final String LEGACY_LIMIT_POSTFIX = null;
+    private static final String LEGACY_OFFSET_PREFIX = "OFFSET";
+    private static final String LEGACY_OFFSET_POSTFIX = null;
+
+    public static class PgSQLQuerySpecificationProcessor extends QuerySpecificationProcessor
+    {
+        @Override
+        protected boolean isOffsetBeforeLimit( SQLProcessorAggregator processor )
+        {
+            return !( (PostgreSQLVendor) processor.getVendor() ).legacyOffsetAndLimit();
+        }
+    }
+
+    public static class PgSQLOffsetSpecificationProcessor extends OffsetSpecificationProcessor
+    {
+        @Override
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return ( (PostgreSQLVendor) processor.getVendor() ).legacyOffsetAndLimit() ? LEGACY_OFFSET_PREFIX : super
+                .getPrefix( processor );
+        }
+
+        @Override
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return ( (PostgreSQLVendor) processor.getVendor() ).legacyOffsetAndLimit() ? LEGACY_OFFSET_POSTFIX : super
+                .getPostfix( processor );
+        }
+    }
+
+    public static class PgSQLLimitSpecificationProcessor extends LimitSpecificationProcessor
+    {
+        @Override
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return ( (PostgreSQLVendor) processor.getVendor() ).legacyOffsetAndLimit() ? LEGACY_LIMIT_PREFIX : super
+                .getPrefix( processor );
+        }
+
+        @Override
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return ( (PostgreSQLVendor) processor.getVendor() ).legacyOffsetAndLimit() ? LEGACY_LIMIT_POSTFIX : super
+                .getPostfix( processor );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessor.java
new file mode 100644
index 0000000..f0e6f37
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessor.java
@@ -0,0 +1,30 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.spi;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface SQLProcessor
+{
+    void process( SQLProcessorAggregator aggregator, Typeable<?> object, StringBuilder builder );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessorAggregator.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessorAggregator.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessorAggregator.java
new file mode 100644
index 0000000..cbbe6de
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/spi/SQLProcessorAggregator.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.spi;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface SQLProcessorAggregator
+{
+    void process( Typeable<?> object, StringBuilder builder );
+
+    SQLVendor getVendor();
+
+    /**
+     * <p>
+     * This provides a way to access current path in a SQL syntax tree. The first element is the root one, then the next
+     * one is its child, etc. This stack is read-only.
+     * </p>
+     * <p>
+     * Currently I'm not sure if there is an efficient way to acquire read-only stacks rather than creating a new one
+     * from contents of another.
+     * </p>
+     *
+     * @return A current path in SQL syntax tree.
+     */
+    // public Stack<Typeable<?>> getCurrentSyntaxTree();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/DefinitionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/DefinitionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/DefinitionProcessing.java
new file mode 100644
index 0000000..9bd835e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/DefinitionProcessing.java
@@ -0,0 +1,141 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.sqlite;
+
+import java.util.Map;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.SchemaDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.TableElementListProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class DefinitionProcessing
+{
+    public static class SQLListeTableElementListProcessor
+        extends TableElementListProcessor
+    {
+        @Override
+        protected void processTableElement( SQLProcessorAggregator aggregator, TableElement object,
+                                            StringBuilder builder, boolean hasNext )
+        {
+            if( object.getImplementedType().isAssignableFrom( TableConstraintDefinition.class ) )
+            {
+                TableConstraint constraint =
+                    TableConstraintDefinition.class.cast( object ).getConstraint();
+                if( constraint.getImplementedType().isAssignableFrom( UniqueConstraint.class ) )
+                {
+                    UniqueConstraint unique = UniqueConstraint.class.cast( constraint );
+                    if( UniqueSpecification.PRIMARY_KEY.equals( unique.getUniquenessKind() ) )
+                    {
+                        return; // Skip the whole TableElement for SQL autogen support, see below
+                    }
+                }
+            }
+            super.processTableElement( aggregator, object, builder, hasNext );
+        }
+    }
+
+    public static class SQLiteSchemaDefinitionProcessor
+        extends SchemaDefinitionProcessor
+    {
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SchemaDefinition object,
+                                  StringBuilder builder )
+        {
+            // Just process schema elements
+            this.processSchemaElements( aggregator, object, builder );
+        }
+    }
+
+    public static class SQLiteColumnDefinitionProcessor
+        extends ColumnDefinitionProcessor
+    {
+        private final Map<Class<?>, String> _autoGenDataTypes;
+
+        public SQLiteColumnDefinitionProcessor( Map<Class<?>, String> autoGenDataTypes )
+        {
+            Objects.requireNonNull( autoGenDataTypes, "Data type serial names" );
+            this._autoGenDataTypes = autoGenDataTypes;
+        }
+
+        @Override
+        protected void processDataType( SQLProcessorAggregator aggregator, ColumnDefinition object,
+                                        StringBuilder builder )
+        {
+            AutoGenerationPolicy autoGenPolicy = object.getAutoGenerationPolicy();
+            if( autoGenPolicy == null )
+            {
+                super.processDataType( aggregator, object, builder );
+            }
+            else
+            {
+                // SQLite can't handle the ALWAYS strategy
+                if( AutoGenerationPolicy.BY_DEFAULT.equals( autoGenPolicy ) )
+                {
+                    // SQLite MUST use INTEGER type when autogenerated
+                    Class<?> dtClass = object.getDataType().getClass();
+                    Boolean success = false;
+                    for( Map.Entry<Class<?>, String> entry : this._autoGenDataTypes.entrySet() )
+                    {
+                        success = entry.getKey().isAssignableFrom( dtClass );
+                        if( success )
+                        {
+                            builder.append( entry.getValue() );
+                            break;
+                        }
+                    }
+                    if( !success )
+                    {
+                        throw new UnsupportedOperationException( "Unsupported column data type "
+                                                                 + object.getDataType()
+                                                                 + " for auto-generated column." );
+                    }
+                }
+                else
+                {
+                    throw new UnsupportedOperationException( "Unsupported auto generation policy: "
+                                                             + autoGenPolicy
+                                                             + "." );
+                }
+            }
+        }
+
+        @Override
+        protected void processMayBeNull( ColumnDefinition object, StringBuilder builder )
+        {
+            // Nothing to do - auto generation policy handled in data type orc
+        }
+
+        @Override
+        protected void processAutoGenerationPolicy( ColumnDefinition object, StringBuilder builder )
+        {
+            // Nothing to do - auto generation policy handled in data type orc
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/SQLiteProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/SQLiteProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/SQLiteProcessor.java
new file mode 100644
index 0000000..d013c2c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/sqlite/SQLiteProcessor.java
@@ -0,0 +1,82 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.sqlite;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.NoOpProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.TableProcessing;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLListeTableElementListProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLiteColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.DefinitionProcessing.SQLiteSchemaDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+public class SQLiteProcessor
+    extends DefaultSQLProcessor
+{
+
+    private static final Map<Class<? extends Typeable<?>>, SQLProcessor> _defaultProcessors;
+
+    static
+    {
+        Map<Class<? extends Typeable<?>>, SQLProcessor> processors = new HashMap<Class<? extends Typeable<?>>, SQLProcessor>(
+            DefaultSQLProcessor.getDefaultProcessors() );
+
+        // SQLite does not understand schema-qualified table names (or anything related to schemas)
+        processors.put( TableNameDirect.class, new TableProcessing.MySQLTableNameDirectProcessor() );
+        processors.put( TableNameFunction.class, new TableProcessing.MySQLTableNameFunctionProcessor() );
+
+        // Only process schema elements from schema definition, and ignore drop schema statements
+        processors.put( SchemaDefinition.class, new SQLiteSchemaDefinitionProcessor() );
+        processors.put( DropSchemaStatement.class, new NoOpProcessor() );
+
+        // SQLite MUST use INTEGER PRIMARY KEY AUTOINCREMENT type when autogenerated
+        // see http://www.sqlite.org/autoinc.html
+
+        // Override default table element list support
+        processors.put( TableElementList.class, new SQLListeTableElementListProcessor() );
+
+        // Override default column definition support
+        Map<Class<?>, String> autoGenDataTypes = new HashMap<Class<?>, String>();
+        autoGenDataTypes.put( BigInt.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
+        autoGenDataTypes.put( SQLInteger.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
+        autoGenDataTypes.put( SmallInt.class, "INTEGER PRIMARY KEY AUTOINCREMENT" );
+        processors.put( ColumnDefinition.class, new SQLiteColumnDefinitionProcessor( autoGenDataTypes ) );
+
+        _defaultProcessors = processors;
+    }
+
+    public SQLiteProcessor( SQLVendor vendor )
+    {
+        super( vendor, _defaultProcessors );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/DefaultVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/DefaultVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/DefaultVendor.java
new file mode 100644
index 0000000..c5f96dd
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/DefaultVendor.java
@@ -0,0 +1,254 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.vendor;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ManipulationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultBooleanFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultColumnsFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultDataTypeFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultDefinitionFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultLiteralFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultManipulationFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultModificationFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultQueryFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.DefaultTableRefFactory;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefaultVendor
+    implements SQLVendor
+{
+
+    protected interface ProcessorCallback
+    {
+        SQLProcessorAggregator get( SQLVendor vendor );
+    }
+
+    protected interface Callback<T>
+    {
+        T get( SQLVendor vendor, SQLProcessorAggregator processor );
+    }
+
+    protected static final Callback<BooleanFactory> BOOLEAN_FACTORY = new Callback<BooleanFactory>()
+    {
+        public BooleanFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultBooleanFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<ColumnsFactory> COLUMNS_FACTORY = new Callback<ColumnsFactory>()
+    {
+        public ColumnsFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultColumnsFactory( vendor, processor );
+        }
+    };
+    protected static final Callback<LiteralFactory> LITERAL_FACTORY = new Callback<LiteralFactory>()
+    {
+        public LiteralFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultLiteralFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<ModificationFactory> MODIFICATION_FACTORY = new Callback<ModificationFactory>()
+    {
+        public ModificationFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultModificationFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<QueryFactory> QUERY_FACTORY = new Callback<QueryFactory>()
+    {
+        public QueryFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultQueryFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<TableReferenceFactory> TABLE_REFERENCE_FACTORY = new Callback<TableReferenceFactory>()
+    {
+        public TableReferenceFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultTableRefFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<DefinitionFactory> DEFINITION_FACTORY = new Callback<DefinitionFactory>()
+    {
+        public DefinitionFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultDefinitionFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<ManipulationFactory> MANIPULATION_FACTORY = new Callback<ManipulationFactory>()
+    {
+        public ManipulationFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultManipulationFactory( vendor, processor );
+        }
+    };
+
+    protected static final Callback<DataTypeFactory> DATA_TYPE_FACTORY = new Callback<DataTypeFactory>()
+    {
+        public DataTypeFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+        {
+            return new DefaultDataTypeFactory( vendor, processor );
+        }
+    };
+
+    protected static final ProcessorCallback DEFAULT_PROCESSOR = new ProcessorCallback()
+    {
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new DefaultSQLProcessor( vendor );
+        }
+    };
+
+    private final QueryFactory _queryFactory;
+
+    private final BooleanFactory _booleanFactory;
+
+    private final TableReferenceFactory _fromFactory;
+
+    private final LiteralFactory _literalFactory;
+
+    private final ColumnsFactory _columnsFactory;
+
+    private final ModificationFactory _modificationFactory;
+
+    private final DefinitionFactory _definitionFactory;
+
+    private final ManipulationFactory _manipulationFactory;
+
+    private final DataTypeFactory _dataTypeFactory;
+
+    private final SQLProcessorAggregator _processor;
+
+    public DefaultVendor()
+    {
+        this( DEFAULT_PROCESSOR );
+    }
+
+    protected DefaultVendor( ProcessorCallback processor )
+    {
+        this( processor, BOOLEAN_FACTORY, COLUMNS_FACTORY, LITERAL_FACTORY, MODIFICATION_FACTORY, QUERY_FACTORY,
+              TABLE_REFERENCE_FACTORY, DEFINITION_FACTORY, MANIPULATION_FACTORY, DATA_TYPE_FACTORY );
+    }
+
+    protected DefaultVendor( ProcessorCallback processor, Callback<? extends BooleanFactory> booleanFactory,
+                             Callback<? extends ColumnsFactory> columnsFactory, Callback<? extends LiteralFactory> literalFactory,
+                             Callback<? extends ModificationFactory> modificationFactory, Callback<? extends QueryFactory> queryFactory,
+                             Callback<? extends TableReferenceFactory> tableReferenceFactory,
+                             Callback<? extends DefinitionFactory> definitionFactory,
+                             Callback<? extends ManipulationFactory> manipulationFactory, Callback<? extends DataTypeFactory> dataTypeFactory )
+    {
+        Objects.requireNonNull( processor, "processor" );
+
+        this._processor = processor.get( this );
+        this._booleanFactory = booleanFactory.get( this, this._processor );
+        this._columnsFactory = columnsFactory.get( this, this._processor );
+        this._literalFactory = literalFactory.get( this, this._processor );
+        this._queryFactory = queryFactory.get( this, this._processor );
+        this._modificationFactory = modificationFactory.get( this, this._processor );
+        this._fromFactory = tableReferenceFactory.get( this, this._processor );
+        this._definitionFactory = definitionFactory.get( this, this._processor );
+        this._manipulationFactory = manipulationFactory.get( this, this._processor );
+        this._dataTypeFactory = dataTypeFactory.get( this, this._processor );
+    }
+
+    /**
+     * Note that exactly one string builder is allocated for each statement.
+     */
+    public String toString( SQLStatement statement )
+    {
+        StringBuilder builder = new StringBuilder();
+        this._processor.process( (Typeable<?>) statement, builder );
+        return builder.toString();
+    }
+
+    public QueryFactory getQueryFactory()
+    {
+        return this._queryFactory;
+    }
+
+    public BooleanFactory getBooleanFactory()
+    {
+        return this._booleanFactory;
+    }
+
+    public TableReferenceFactory getTableReferenceFactory()
+    {
+        return this._fromFactory;
+    }
+
+    public LiteralFactory getLiteralFactory()
+    {
+        return this._literalFactory;
+    }
+
+    public ColumnsFactory getColumnsFactory()
+    {
+        return this._columnsFactory;
+    }
+
+    public ModificationFactory getModificationFactory()
+    {
+        return this._modificationFactory;
+    }
+
+    public DefinitionFactory getDefinitionFactory()
+    {
+        return this._definitionFactory;
+    }
+
+    public ManipulationFactory getManipulationFactory()
+    {
+        return this._manipulationFactory;
+    }
+
+    public DataTypeFactory getDataTypeFactory()
+    {
+        return this._dataTypeFactory;
+    }
+
+    protected SQLProcessorAggregator getProcessor()
+    {
+        return this._processor;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/derby/DerbyVendorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/derby/DerbyVendorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/derby/DerbyVendorImpl.java
new file mode 100644
index 0000000..d7f47a5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/derby/DerbyVendorImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.vendor.derby;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.derby.DerbyProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor;
+import org.apache.polygene.library.sql.generator.vendor.DerbyVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+public class DerbyVendorImpl extends DefaultVendor
+    implements DerbyVendor
+{
+
+    protected static final ProcessorCallback DERBY_PROCESSOR = new ProcessorCallback()
+    {
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new DerbyProcessor( vendor );
+        }
+    };
+
+    public DerbyVendorImpl()
+    {
+        super( DERBY_PROCESSOR );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/h2/H2VendorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/h2/H2VendorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/h2/H2VendorImpl.java
new file mode 100644
index 0000000..c9f1d4a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/h2/H2VendorImpl.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.vendor.h2;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.h2.H2Processor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor;
+import org.apache.polygene.library.sql.generator.vendor.H2Vendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+public class H2VendorImpl extends DefaultVendor
+    implements H2Vendor
+{
+
+    protected static final ProcessorCallback H2_PROCESSOR = new ProcessorCallback()
+    {
+
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new H2Processor( vendor );
+        }
+    };
+
+    public H2VendorImpl()
+    {
+        super( H2_PROCESSOR );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/mysql/MySQLVendorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/mysql/MySQLVendorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/mysql/MySQLVendorImpl.java
new file mode 100644
index 0000000..a497e59
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/mysql/MySQLVendorImpl.java
@@ -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.polygene.library.sql.generator.implementation.vendor.mysql;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.MySQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor;
+import org.apache.polygene.library.sql.generator.vendor.MySQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class MySQLVendorImpl extends DefaultVendor
+    implements MySQLVendor
+{
+
+    protected static final ProcessorCallback MYSQL_PROCESSOR = new ProcessorCallback()
+    {
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new MySQLProcessor( vendor );
+        }
+    };
+
+    private boolean _legacyLimit;
+
+    public MySQLVendorImpl()
+    {
+        super( MYSQL_PROCESSOR );
+
+        this._legacyLimit = false;
+    }
+
+    public boolean legacyLimit()
+    {
+        return this._legacyLimit;
+    }
+
+    public void setLegacyLimit( boolean useLegacyLimit )
+    {
+        this._legacyLimit = useLegacyLimit;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/pgsql/PostgreSQLVendorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/pgsql/PostgreSQLVendorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/pgsql/PostgreSQLVendorImpl.java
new file mode 100644
index 0000000..e663ed9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/pgsql/PostgreSQLVendorImpl.java
@@ -0,0 +1,108 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.vendor.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLDataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLManipulationFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.pgsql.PgSQLDataTypeFactoryImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.pgsql.PgSQLManipulationFactoryImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.factories.pgsql.PgSQLModificationFactoryImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.pgsql.PostgreSQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor;
+import org.apache.polygene.library.sql.generator.vendor.PostgreSQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class PostgreSQLVendorImpl extends DefaultVendor
+    implements PostgreSQLVendor
+{
+    protected static final Callback<PgSQLDataTypeFactory> PG_DATA_TYPE_FACTORY =
+        new Callback<PgSQLDataTypeFactory>()
+        {
+            public PgSQLDataTypeFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+            {
+                return new PgSQLDataTypeFactoryImpl( (PostgreSQLVendor) vendor, processor );
+            }
+        };
+
+    protected static final Callback<PgSQLManipulationFactory> PG_MANIPULATION_FACTORY =
+        new Callback<PgSQLManipulationFactory>()
+        {
+            public PgSQLManipulationFactory
+            get( SQLVendor vendor, SQLProcessorAggregator processor )
+            {
+                return new PgSQLManipulationFactoryImpl( (PostgreSQLVendor) vendor, processor );
+            }
+        };
+
+    protected static final Callback<ModificationFactory> PG_MODIFICATION_FACTORY =
+        new Callback<ModificationFactory>()
+        {
+            public ModificationFactory get( SQLVendor vendor, SQLProcessorAggregator processor )
+            {
+                return new PgSQLModificationFactoryImpl( (PostgreSQLVendor) vendor, processor );
+            }
+        };
+
+    protected static final ProcessorCallback PG_PROCESSOR = new ProcessorCallback()
+    {
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new PostgreSQLProcessor( vendor );
+        }
+    };
+
+    private boolean _legacyOffsetAndLimit;
+
+    public PostgreSQLVendorImpl()
+    {
+        super( PG_PROCESSOR, BOOLEAN_FACTORY, COLUMNS_FACTORY, LITERAL_FACTORY,
+               PG_MODIFICATION_FACTORY, QUERY_FACTORY,
+               TABLE_REFERENCE_FACTORY, DEFINITION_FACTORY, PG_MANIPULATION_FACTORY,
+               PG_DATA_TYPE_FACTORY );
+        this._legacyOffsetAndLimit = false;
+    }
+
+    @Override
+    public PgSQLDataTypeFactory getDataTypeFactory()
+    {
+        return (PgSQLDataTypeFactory) super.getDataTypeFactory();
+    }
+
+    @Override
+    public PgSQLManipulationFactory getManipulationFactory()
+    {
+        return (PgSQLManipulationFactory) super.getManipulationFactory();
+    }
+
+    public boolean legacyOffsetAndLimit()
+    {
+        return this._legacyOffsetAndLimit;
+    }
+
+    public void setLegacyOffsetAndLimit( boolean useLegacyOffsetAndLimit )
+    {
+        this._legacyOffsetAndLimit = useLegacyOffsetAndLimit;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/sqlite/SQLiteVendorImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/sqlite/SQLiteVendorImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/sqlite/SQLiteVendorImpl.java
new file mode 100644
index 0000000..e5f5116
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/vendor/sqlite/SQLiteVendorImpl.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.vendor.sqlite;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.implementation.transformation.sqlite.SQLiteProcessor;
+import org.apache.polygene.library.sql.generator.implementation.vendor.DefaultVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.SQLiteVendor;
+
+public class SQLiteVendorImpl extends DefaultVendor
+    implements SQLiteVendor
+{
+
+    protected static final ProcessorCallback SQLITE_PROCESSOR = new ProcessorCallback()
+    {
+
+        public SQLProcessorAggregator get( SQLVendor vendor )
+        {
+            return new SQLiteProcessor( vendor );
+        }
+    };
+
+    public SQLiteVendorImpl()
+    {
+        super( SQLITE_PROCESSOR );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/DerbyVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/DerbyVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/DerbyVendor.java
new file mode 100644
index 0000000..04c3303
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/DerbyVendor.java
@@ -0,0 +1,25 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+public interface DerbyVendor
+    extends SQLVendor
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/H2Vendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/H2Vendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/H2Vendor.java
new file mode 100644
index 0000000..59e8f5a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/H2Vendor.java
@@ -0,0 +1,25 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+public interface H2Vendor
+    extends SQLVendor
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/MySQLVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/MySQLVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/MySQLVendor.java
new file mode 100644
index 0000000..0cb638c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/MySQLVendor.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+/**
+ * This is vendor for MySQL database. MySQL typically does not understand schema-qualified names, so this vendor doesn't
+ * process any schema name it encounters when creating a SQL string.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface MySQLVendor
+    extends SQLVendor
+{
+
+    /**
+     * <p>
+     * Returns whether the legacy LIMIT expression is used instead of the of the newer LIMIT/OFFSET. In a legacy syntax,
+     * the {@code LIMIT <n> OFFSET <skip>} is written as {@code LIMIT <skip>, <n> } instead. This method is not
+     * thread-safe.
+     * </p>
+     *
+     * @return {@code true} if the legacy LIMIT expressions are used; {@code false} otherwise.
+     */
+    boolean legacyLimit();
+
+    /**
+     * <p>
+     * Sets the switch to use legacy LIMIT expression instead of the newer LIMIT/OFFSET expressions. In a legacy syntax,
+     * the {@code LIMIT <n> OFFSET <skip>} is written as {@code LIMIT <skip>, <n> } instead. Set this to true only if
+     * you really require it. This method is not thread-safe.
+     * </p>
+     *
+     * @param useLegacyLimit Whether to use legacy LIMIT expression instead of the newer LIMIT/OFFSET expressions.
+     */
+    void setLegacyLimit( boolean useLegacyLimit );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/PostgreSQLVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/PostgreSQLVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/PostgreSQLVendor.java
new file mode 100644
index 0000000..8d92eca
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/PostgreSQLVendor.java
@@ -0,0 +1,67 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLDataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.pgsql.PgSQLManipulationFactory;
+
+/**
+ * This is vendor for PostgreSQL database. PostgreSQL provides some extra SQL syntax elements for queries (notably
+ * {@code LIMIT} and {@code OFFSET} clauses), and this vendor gives access to factory, which enables the creation of
+ * these elements.
+ *
+ * @author Stanislav Muhametsin
+ * @see PgSQLQueryFactory
+ * @see LimitClause
+ * @see OffsetClause
+ */
+public interface PostgreSQLVendor
+    extends SQLVendor
+{
+    /**
+     * Returns the data type factory, which knows to create PostgreSQL-specific data types as well as pre-defined
+     * standard ones.
+     */
+    PgSQLDataTypeFactory getDataTypeFactory();
+
+    /**
+     * Returns the manipulation factory, which knows to create PostgreSQL-specific data manipulation statements.
+     */
+    PgSQLManipulationFactory getManipulationFactory();
+
+    /**
+     * Returns whether the legacy (pre-8.4) OFFSET/LIMIT expressions are used instead of the OFFSET/FETCH defined in the
+     * SQL 2008 standard. For more information, see http://www.postgresql.org/docs/8.3/static/sql-select.html#SQL-LIMIT
+     * . This method is not thread-safe.
+     *
+     * @return {@code true} if the legacy OFFSET/LIMIT expressions are used; {@code false} otherwise.
+     */
+    boolean legacyOffsetAndLimit();
+
+    /**
+     * Sets the switch to use legacy LIMIT/OFFSET expressions instead of the OFFSET/FETCH expressions of the SQL 2008
+     * standard. This is necessary only for pre-8.4 PgSQL databases. For more information, see
+     * http://www.postgresql.org/docs/8.3/static/sql-select.html#SQL-LIMIT . This method is not thread-safe.
+     *
+     * @param useLegacyOffsetAndLimit Whether to use legacy LIMIT/OFFSET expressions instead of the OFFSET/FETCH
+     *                                expressions defined in the SQL 2008 standard.
+     */
+    void setLegacyOffsetAndLimit( boolean useLegacyOffsetAndLimit );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendor.java
new file mode 100644
index 0000000..e11da0c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendor.java
@@ -0,0 +1,137 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.DefinitionFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.LiteralFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ManipulationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.ModificationFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory;
+import org.apache.polygene.library.sql.generator.grammar.factories.TableReferenceFactory;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+
+/**
+ * This is the base API interface for all SQLVendors to implement. It gives the means to acquire factories to create SQL
+ * syntax elements. Additionally, the vendor creates the textual representation of these syntax elements so that the
+ * query may be passed directly to database, for example, through JDBC.
+ *
+ * @author Stanislav Muhametsin
+ * @see MySQLVendor
+ * @see PostgreSQLVendor
+ * @see QueryFactory
+ * @see BooleanFactory
+ * @see TableReferenceFactory
+ * @see LiteralFactory
+ * @see ColumnsFactory
+ * @see ModificationFactory
+ * @see #toString(SQLStatement)
+ */
+public interface SQLVendor
+{
+
+    /**
+     * Returns the query factory of this vendor.
+     *
+     * @return The query factory of this vendor.
+     * @see QueryFactory
+     * @see QuerySpecification
+     */
+    QueryFactory getQueryFactory();
+
+    /**
+     * Returns the boolean factory for this vendor.
+     *
+     * @return The boolean factory for this vendor.
+     * @see BooleanFactory
+     */
+    BooleanFactory getBooleanFactory();
+
+    /**
+     * Returns the table reference factory for this vendor.
+     *
+     * @return The table reference factory for this vendor.
+     * @see TableReferenceFactory
+     */
+    TableReferenceFactory getTableReferenceFactory();
+
+    /**
+     * Returns the literal factory for this vendor.
+     *
+     * @return The literal factory for this vendor.
+     * @see LiteralFactory
+     */
+    LiteralFactory getLiteralFactory();
+
+    /**
+     * Returns the columns factory for this vendor.
+     *
+     * @return The columns factory for this vendor.
+     * @see ColumnsFactory
+     */
+    ColumnsFactory getColumnsFactory();
+
+    /**
+     * Returns the factory to create modification statements for this vendor.
+     *
+     * @return The factory to create modification statements for this vendor.
+     * @see ModificationFactory
+     */
+    ModificationFactory getModificationFactory();
+
+    /**
+     * Returns the factory to create definition statements ({@code CREATE SCHEMA/TABLE/VIEW/etc}) for this vendor.
+     *
+     * @return The factory to create definition statements for this vendor.
+     * @see DefinitionFactory
+     */
+    DefinitionFactory getDefinitionFactory();
+
+    /**
+     * Returns the factory to create manipulation statements ({@code DROP/ALTER SCHEMA/TABLE/etc}) for this vendor.
+     *
+     * @return The factory to create manipulation statements.
+     * @see ManipulationFactory
+     */
+    ManipulationFactory getManipulationFactory();
+
+    /**
+     * Returns the factory to create syntax elements for SQL data types compatible with this vendor.
+     *
+     * @return The factory to create syntax elements for SQL data types.
+     * @see DataTypeFactory
+     */
+    DataTypeFactory getDataTypeFactory();
+
+    /**
+     * Takes the {@link SQLStatement} (typically either a query, or a modification statement) and produces a textual SQL
+     * statement out of it.
+     *
+     * @param statement The {@link SQLStatement} to process.
+     * @return The textual SQL statement to be used directly with database.
+     * @throws UnsupportedElementException If during parsing this vendor encounters some SQL syntax element not
+     *                                     understood by this vendor.
+     * @see SQLStatement
+     */
+    String toString( SQLStatement statement );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendorProvider.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendorProvider.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendorProvider.java
new file mode 100644
index 0000000..6a91dc9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLVendorProvider.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+import java.io.IOException;
+import java.util.ServiceLoader;
+
+/**
+ * This class provides easy way of acquiring vendors for specific databases.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class SQLVendorProvider
+{
+    /**
+     * <p>
+     * Creates a new vendor. If one passes {@link SQLVendor} as a parameter, it will return the default vendor-neutral
+     * implementation.
+     * </p>
+     * <p>
+     * Invoking this statement is equivalent to calling {@code new ServiceLoader().firstProvider( vendorClass); }.
+     *
+     * @param <VendorType> The type of the vendor.
+     * @param vendorClass  The class of the vendor.
+     * @return The vendor of a given class.
+     * @throws IOException If {@link ServiceLoader} throws {@link IOException}.
+     * @see ServiceLoader
+     */
+    public static <VendorType extends SQLVendor> VendorType createVendor( Class<VendorType> vendorClass )
+        throws IOException
+    {
+        ServiceLoader<VendorType> load = ServiceLoader.load( vendorClass );
+        return load.iterator().next();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLiteVendor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLiteVendor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLiteVendor.java
new file mode 100644
index 0000000..ba7c961
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/SQLiteVendor.java
@@ -0,0 +1,25 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+public interface SQLiteVendor
+    extends SQLVendor
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/UnsupportedElementException.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/UnsupportedElementException.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/UnsupportedElementException.java
new file mode 100644
index 0000000..f07b7a8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/UnsupportedElementException.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.vendor;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+
+/**
+ * This exception will typically be thrown by
+ * {@link SQLVendor#toString(SQLStatement)} method when the vendor encounters a
+ * SQL syntax element that the vendor doesn't understand.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class UnsupportedElementException extends RuntimeException
+{
+
+    private static final long serialVersionUID = -5331011803322815958L;
+
+    private final Object _element;
+
+    public UnsupportedElementException( String msg )
+    {
+        this( msg, null );
+    }
+
+    public UnsupportedElementException( String msg, Object element )
+    {
+        super( msg );
+        this._element = element;
+    }
+
+    public Object getElement()
+    {
+        return this._element;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/package-info.java
new file mode 100644
index 0000000..1719927
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/vendor/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package provides an API for SQLVendors to implement, and a way to load different vendors dynamically. The vendor will give access to factories in package org.sql.generation.api.grammar.factories , which will enable users to create SQL syntax elements. Vendor is also responsible for creating a textual representation (String) of a SQL syntax structure generated with these factories.
+ */
+package org.apache.polygene.library.sql.generator.vendor;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.DerbyVendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.DerbyVendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.DerbyVendor
new file mode 100644
index 0000000..809d3ec
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.DerbyVendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.derby.DerbyVendorImpl
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.H2Vendor
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.H2Vendor b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.H2Vendor
new file mode 100644
index 0000000..c2f72bb
--- /dev/null
+++ b/libraries/sql-generator/src/main/resources/META-INF/services/org.apache.polygene.library.sql.generator.vendor.H2Vendor
@@ -0,0 +1 @@
+org.apache.polygene.library.sql.generator.implementation.vendor.h2.H2VendorImpl
\ No newline at end of file


[04/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefaultSQLProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefaultSQLProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefaultSQLProcessor.java
new file mode 100644
index 0000000..2a54858
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefaultSQLProcessor.java
@@ -0,0 +1,571 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BinaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression.False;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression.True;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Conjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Disjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.EqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.ExistsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNotNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.MultiPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Negation;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotBetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotEqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotInPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotLikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate.EmptyPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UnaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UniquePredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.DoublePrecision;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Real;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLBoolean;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDate;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInterval;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.UserDefinedType;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.CheckConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.LikeClause;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+import org.apache.polygene.library.sql.generator.grammar.literals.DirectLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.StringLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction.DropDefault;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.SetColumnDefault;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource.Defaults;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ValueSource;
+import org.apache.polygene.library.sql.generator.grammar.query.AsteriskSelect;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement.GrandTotal;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody.EmptyQueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBodyBinary;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.RowDefinition;
+import org.apache.polygene.library.sql.generator.grammar.query.RowSubQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.TableValueConstructor;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.CrossJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinCondition;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NamedColumnsJoin;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NaturalJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.QualifiedJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.UnionJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.BinaryPredicateProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.BooleanTestProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.ConjunctionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.DisjunctionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.MultiPredicateProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.NegationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.UnaryPredicateProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.BooleanExpressionProcessing.UnaryPredicateProcessor.UnaryOperatorOrientation;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ColumnProcessing.ColumnNamesProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ColumnProcessing.ColumnReferenceByExpressionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ColumnProcessing.ColumnReferenceByNameProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.DecimalProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.NumericProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.SQLCharProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.SQLFloatProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.SQLIntervalProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.SQLTimeProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.SQLTimeStampProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DataTypeProcessing.UserDefinedDataTypeProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.CheckConstraintProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ForeignKeyConstraintProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.LikeClauseProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.RegularViewSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.SchemaDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.TableConstraintDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.TableDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.TableElementListProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.UniqueConstraintProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ViewDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.DateTimeLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.DirectLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.NumericLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.SQLFunctionLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.StringLiteralExpressionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.AddColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.AddTableConstraintDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.AlterColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.AlterTableStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropColumnDefaultProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropSchemaStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropTableConstraintDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.DropTableOrViewStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ManipulationProcessing.SetColumnDefaultProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.ColumnSourceByQueryProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.ColumnSourceByValuesProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.DeleteBySearchProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.InsertStatementProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.SetClauseProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.TargetTableProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.UpdateBySearchProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.ModificationProcessing.UpdateSourceByExpressionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.CorrespondingSpecProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.FromProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.GroupByProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.LimitSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.OffsetSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.OrderByProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.OrdinaryGroupingSetProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.QueryExpressionBinaryProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.QueryExpressionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.QuerySpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.RowDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.RowSubQueryProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.SelectColumnsProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.SortSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.TableValueConstructorProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.CrossJoinedTableProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.JoinConditionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.NamedColumnsJoinProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.NaturalJoinedTableProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.QualifiedJoinedTableProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableNameDirectProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableNameFunctionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableReferenceByExpressionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableReferenceByNameProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.UnionJoinedTableProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+import org.apache.polygene.library.sql.generator.vendor.UnsupportedElementException;
+
+/**
+ * This is base class for processing the SQL syntax elements defined in API. It contains the default
+ * processors for nearly all default syntax elements, and a way to easily extend this class in order
+ * to add custom processors, or replace default processors with custom ones.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class DefaultSQLProcessor
+    implements SQLProcessorAggregator
+{
+
+    private static final Map<Class<? extends Typeable<?>>, SQLProcessor> _defaultProcessors;
+
+    private static final Map<Class<? extends UnaryPredicate>, UnaryOperatorOrientation> _defaultUnaryOrientations;
+
+    private static final Map<Class<? extends UnaryPredicate>, String> _defaultUnaryOperators;
+
+    private static final Map<Class<? extends BinaryPredicate>, String> _defaultBinaryOperators;
+
+    private static final Map<Class<? extends MultiPredicate>, String> _defaultMultiOperators;
+
+    private static final Map<Class<? extends MultiPredicate>, String> _defaultMultiSeparators;
+
+    private static final Map<Class<? extends MultiPredicate>, Boolean> _defaultParenthesisPolicies;
+
+    static
+    {
+        Map<Class<? extends UnaryPredicate>, UnaryOperatorOrientation> unaryOrientations =
+            new HashMap<Class<? extends UnaryPredicate>, UnaryOperatorOrientation>();
+        unaryOrientations.put( IsNullPredicate.class, UnaryOperatorOrientation.AFTER_EXPRESSION );
+        unaryOrientations.put( IsNotNullPredicate.class, UnaryOperatorOrientation.AFTER_EXPRESSION );
+        unaryOrientations.put( ExistsPredicate.class, UnaryOperatorOrientation.BEFORE_EXPRESSION );
+        unaryOrientations.put( UniquePredicate.class, UnaryOperatorOrientation.BEFORE_EXPRESSION );
+        _defaultUnaryOrientations = Collections.unmodifiableMap( unaryOrientations );
+
+        Map<Class<? extends UnaryPredicate>, String> unaryOperators =
+            new HashMap<Class<? extends UnaryPredicate>, String>();
+        unaryOperators.put( IsNullPredicate.class, "IS NULL" );
+        unaryOperators.put( IsNotNullPredicate.class, "IS NOT NULL" );
+        unaryOperators.put( ExistsPredicate.class, "EXISTS" );
+        unaryOperators.put( UniquePredicate.class, "UNIQUE" );
+        _defaultUnaryOperators = Collections.unmodifiableMap( unaryOperators );
+
+        Map<Class<? extends BinaryPredicate>, String> binaryOperators =
+            new HashMap<Class<? extends BinaryPredicate>, String>();
+        binaryOperators.put( EqualsPredicate.class, "=" );
+        binaryOperators.put( NotEqualsPredicate.class, "<>" );
+        binaryOperators.put( GreaterOrEqualPredicate.class, ">=" );
+        binaryOperators.put( GreaterThanPredicate.class, ">" );
+        binaryOperators.put( LessOrEqualPredicate.class, "<=" );
+        binaryOperators.put( LessThanPredicate.class, "<" );
+        binaryOperators.put( LikePredicate.class, "LIKE" );
+        binaryOperators.put( NotLikePredicate.class, "NOT LIKE" );
+        _defaultBinaryOperators = Collections.unmodifiableMap( binaryOperators );
+
+        Map<Class<? extends MultiPredicate>, String> multiOperators =
+            new HashMap<Class<? extends MultiPredicate>, String>();
+        multiOperators.put( BetweenPredicate.class, "BETWEEN" );
+        multiOperators.put( InPredicate.class, "IN" );
+        multiOperators.put( NotBetweenPredicate.class, "NOT BETWEEN" );
+        multiOperators.put( NotInPredicate.class, "NOT IN" );
+        _defaultMultiOperators = Collections.unmodifiableMap( multiOperators );
+
+        Map<Class<? extends MultiPredicate>, String> multiSeparators =
+            new HashMap<Class<? extends MultiPredicate>, String>();
+        multiSeparators.put( BetweenPredicate.class, " AND " );
+        multiSeparators.put( InPredicate.class, ", " );
+        multiSeparators.put( NotBetweenPredicate.class, " AND " );
+        multiSeparators.put( NotInPredicate.class, ", " );
+        _defaultMultiSeparators = Collections.unmodifiableMap( multiSeparators );
+
+        Map<Class<? extends MultiPredicate>, Boolean> parenthesisPolicies =
+            new HashMap<Class<? extends MultiPredicate>, Boolean>();
+        parenthesisPolicies.put( BetweenPredicate.class, false );
+        parenthesisPolicies.put( InPredicate.class, true );
+        parenthesisPolicies.put( NotBetweenPredicate.class, false );
+        parenthesisPolicies.put( NotInPredicate.class, true );
+        _defaultParenthesisPolicies = parenthesisPolicies;
+
+        Map<Class<? extends Typeable<?>>, SQLProcessor> processors =
+            new HashMap<Class<? extends Typeable<?>>, SQLProcessor>();
+
+        // Boolean expressions
+        // Constants
+        processors.put( True.class, new ConstantProcessor( "TRUE" ) );
+        processors.put( False.class, new ConstantProcessor( "FALSE" ) );
+        // Unary
+        processors.put(
+            IsNullPredicate.class,
+            new UnaryPredicateProcessor( _defaultUnaryOrientations.get( IsNullPredicate.class ),
+                                         _defaultUnaryOperators
+                                             .get( IsNullPredicate.class ) ) );
+        processors.put( IsNotNullPredicate.class,
+                        new UnaryPredicateProcessor( _defaultUnaryOrientations.get( IsNotNullPredicate.class ),
+                                                     _defaultUnaryOperators.get( IsNotNullPredicate.class ) ) );
+        processors.put(
+            ExistsPredicate.class,
+            new UnaryPredicateProcessor( _defaultUnaryOrientations.get( ExistsPredicate.class ),
+                                         _defaultUnaryOperators
+                                             .get( ExistsPredicate.class ) ) );
+        processors.put(
+            UniquePredicate.class,
+            new UnaryPredicateProcessor( _defaultUnaryOrientations.get( UniquePredicate.class ),
+                                         _defaultUnaryOperators
+                                             .get( UniquePredicate.class ) ) );
+        // Binary
+        processors.put( EqualsPredicate.class,
+                        new BinaryPredicateProcessor( _defaultBinaryOperators.get( EqualsPredicate.class ) ) );
+        processors
+            .put(
+                NotEqualsPredicate.class,
+                new BinaryPredicateProcessor( _defaultBinaryOperators
+                                                  .get( NotEqualsPredicate.class ) ) );
+        processors.put(
+            GreaterOrEqualPredicate.class,
+            new BinaryPredicateProcessor( _defaultBinaryOperators
+                                              .get( GreaterOrEqualPredicate.class ) ) );
+        processors
+            .put(
+                GreaterThanPredicate.class,
+                new BinaryPredicateProcessor( _defaultBinaryOperators
+                                                  .get( GreaterThanPredicate.class ) ) );
+        processors
+            .put(
+                LessOrEqualPredicate.class,
+                new BinaryPredicateProcessor( _defaultBinaryOperators
+                                                  .get( LessOrEqualPredicate.class ) ) );
+        processors.put( LessThanPredicate.class,
+                        new BinaryPredicateProcessor( _defaultBinaryOperators.get( LessThanPredicate.class ) ) );
+        processors.put( LikePredicate.class,
+                        new BinaryPredicateProcessor( _defaultBinaryOperators.get( LikePredicate.class ) ) );
+        processors.put( NotLikePredicate.class,
+                        new BinaryPredicateProcessor( _defaultBinaryOperators.get( NotLikePredicate.class ) ) );
+        // Multi
+        processors.put(
+            BetweenPredicate.class,
+            new MultiPredicateProcessor( _defaultMultiOperators.get( BetweenPredicate.class ),
+                                         _defaultMultiSeparators
+                                             .get( BetweenPredicate.class ), _defaultParenthesisPolicies
+                                             .get( BetweenPredicate.class ) ) );
+        processors.put(
+            InPredicate.class,
+            new MultiPredicateProcessor(
+                _defaultMultiOperators.get( InPredicate.class ), _defaultMultiSeparators
+                .get( InPredicate.class ),
+                _defaultParenthesisPolicies.get( InPredicate.class ) ) );
+        processors.put(
+            NotBetweenPredicate.class,
+            new MultiPredicateProcessor( _defaultMultiOperators.get( NotBetweenPredicate.class ),
+                                         _defaultMultiSeparators.get( NotBetweenPredicate.class ),
+                                         _defaultParenthesisPolicies
+                                             .get( NotBetweenPredicate.class ) ) );
+        processors.put(
+            NotInPredicate.class,
+            new MultiPredicateProcessor( _defaultMultiOperators.get( NotInPredicate.class ),
+                                         _defaultMultiSeparators
+                                             .get( NotInPredicate.class ), _defaultParenthesisPolicies
+                                             .get( NotInPredicate.class ) ) );
+        // Composed
+        processors.put( Conjunction.class, new ConjunctionProcessor() );
+        processors.put( Disjunction.class, new DisjunctionProcessor() );
+        processors.put( Negation.class, new NegationProcessor() );
+        processors.put( BooleanTest.class, new BooleanTestProcessor() );
+        // Empty
+        processors.put( EmptyPredicate.class, new NoOpProcessor() );
+
+        // Column references
+        processors.put( ColumnReferenceByName.class, new ColumnReferenceByNameProcessor() );
+        processors.put( ColumnReferenceByExpression.class,
+                        new ColumnReferenceByExpressionProcessor() );
+        processors.put( ColumnNameList.class, new ColumnNamesProcessor() );
+
+        // Literals
+        processors.put( StringLiteral.class, new StringLiteralExpressionProcessor() );
+        processors.put( TimestampTimeLiteral.class, new DateTimeLiteralProcessor() );
+        processors.put( SQLFunctionLiteral.class, new SQLFunctionLiteralProcessor() );
+        processors.put( NumericLiteral.class, new NumericLiteralProcessor() );
+        processors.put( DirectLiteral.class, new DirectLiteralProcessor() );
+
+        // Queries
+        processors.put( QueryExpressionBodyBinary.class, new QueryExpressionBinaryProcessor() );
+        processors.put( QuerySpecification.class, new QuerySpecificationProcessor() );
+        processors.put( QueryExpression.class, new QueryExpressionProcessor() );
+        processors.put( EmptyQueryExpressionBody.class, new NoOpProcessor() );
+        processors.put( CorrespondingSpec.class, new CorrespondingSpecProcessor() );
+        processors.put( GrandTotal.class, new ConstantProcessor( SQLConstants.OPEN_PARENTHESIS
+                                                                 + SQLConstants.CLOSE_PARENTHESIS ) );
+        processors.put( OrdinaryGroupingSet.class, new OrdinaryGroupingSetProcessor() );
+        processors.put( SortSpecification.class, new SortSpecificationProcessor() );
+        processors.put( GroupByClause.class, new GroupByProcessor() );
+        processors.put( OrderByClause.class, new OrderByProcessor() );
+        processors.put( FromClause.class, new FromProcessor() );
+        SelectColumnsProcessor selectProcessor = new SelectColumnsProcessor();
+        processors.put( AsteriskSelect.class, selectProcessor );
+        processors.put( ColumnReferences.class, selectProcessor );
+        processors.put( TableValueConstructor.class, new TableValueConstructorProcessor() );
+        processors.put( RowDefinition.class, new RowDefinitionProcessor() );
+        processors.put( RowSubQuery.class, new RowSubQueryProcessor() );
+        processors.put( OffsetSpecification.class, new OffsetSpecificationProcessor() );
+        processors.put( LimitSpecification.class, new LimitSpecificationProcessor() );
+
+        // Table references
+        processors.put( TableNameDirect.class, new TableNameDirectProcessor() );
+        processors.put( TableNameFunction.class, new TableNameFunctionProcessor() );
+        processors.put( TableReferenceByName.class, new TableReferenceByNameProcessor() );
+        processors
+            .put( TableReferenceByExpression.class, new TableReferenceByExpressionProcessor() );
+        processors.put( CrossJoinedTable.class, new CrossJoinedTableProcessor() );
+        processors.put( NaturalJoinedTable.class, new NaturalJoinedTableProcessor() );
+        processors.put( QualifiedJoinedTable.class, new QualifiedJoinedTableProcessor() );
+        processors.put( UnionJoinedTable.class, new UnionJoinedTableProcessor() );
+        processors.put( JoinCondition.class, new JoinConditionProcessor() );
+        processors.put( NamedColumnsJoin.class, new NamedColumnsJoinProcessor() );
+
+        // Modification clauses
+        processors.put( ColumnSourceByQuery.class, new ColumnSourceByQueryProcessor() );
+        processors.put( ColumnSourceByValues.class, new ColumnSourceByValuesProcessor() );
+        processors.put( DeleteBySearch.class, new DeleteBySearchProcessor() );
+        processors.put( InsertStatement.class, new InsertStatementProcessor() );
+        processors.put( SetClause.class, new SetClauseProcessor() );
+        processors.put( TargetTable.class, new TargetTableProcessor() );
+        processors.put( UpdateBySearch.class, new UpdateBySearchProcessor() );
+        processors.put( UpdateSourceByExpression.class, new UpdateSourceByExpressionProcessor() );
+        processors.put( ValueSource.Null.class, new ConstantProcessor( "NULL" ) );
+        processors.put( ValueSource.Default.class, new ConstantProcessor( "DEFAULT" ) );
+        processors.put( Defaults.class, new ConstantProcessor( SQLConstants.TOKEN_SEPARATOR
+                                                               + "DEFAULT VALUES" ) );
+
+        // Data definition
+        // First data types
+        processors.put( BigInt.class, new ConstantProcessor( "BIGINT" ) );
+        processors.put( DoublePrecision.class, new ConstantProcessor( "DOUBLE PRECISION" ) );
+        processors.put( Real.class, new ConstantProcessor( "REAL" ) );
+        processors.put( SmallInt.class, new ConstantProcessor( "SMALLINT" ) );
+        processors.put( SQLBoolean.class, new ConstantProcessor( "BOOLEAN" ) );
+        processors.put( SQLDate.class, new ConstantProcessor( "DATE" ) );
+        processors.put( SQLInteger.class, new ConstantProcessor( "INTEGER" ) );
+        processors.put( UserDefinedType.class, new UserDefinedDataTypeProcessor() );
+        processors.put( Decimal.class, new DecimalProcessor() );
+        processors.put( Numeric.class, new NumericProcessor() );
+        processors.put( SQLChar.class, new SQLCharProcessor() );
+        processors.put( SQLFloat.class, new SQLFloatProcessor() );
+        processors.put( SQLInterval.class, new SQLIntervalProcessor() );
+        processors.put( SQLTime.class, new SQLTimeProcessor() );
+        processors.put( SQLTimeStamp.class, new SQLTimeStampProcessor() );
+        // Then statements and clauses
+        processors.put( SchemaDefinition.class, new SchemaDefinitionProcessor() );
+        processors.put( TableDefinition.class, new TableDefinitionProcessor() );
+        processors.put( TableElementList.class, new TableElementListProcessor() );
+        processors.put( ColumnDefinition.class, new ColumnDefinitionProcessor() );
+        processors.put( LikeClause.class, new LikeClauseProcessor() );
+        processors.put( TableConstraintDefinition.class, new TableConstraintDefinitionProcessor() );
+        processors.put( CheckConstraint.class, new CheckConstraintProcessor() );
+        processors.put( UniqueConstraint.class, new UniqueConstraintProcessor() );
+        processors.put( ForeignKeyConstraint.class, new ForeignKeyConstraintProcessor() );
+        processors.put( ViewDefinition.class, new ViewDefinitionProcessor() );
+        processors.put( RegularViewSpecification.class, new RegularViewSpecificationProcessor() );
+
+        // Data manipulation
+        processors.put( AlterTableStatement.class, new AlterTableStatementProcessor() );
+        processors.put( AddColumnDefinition.class, new AddColumnDefinitionProcessor() );
+        processors.put( AddTableConstraintDefinition.class,
+                        new AddTableConstraintDefinitionProcessor() );
+        processors.put( AlterColumnDefinition.class, new AlterColumnDefinitionProcessor() );
+        processors.put( DropDefault.class, new DropColumnDefaultProcessor() );
+        processors.put( SetColumnDefault.class, new SetColumnDefaultProcessor() );
+        processors.put( DropColumnDefinition.class, new DropColumnDefinitionProcessor() );
+        processors.put( DropTableConstraintDefinition.class,
+                        new DropTableConstraintDefinitionProcessor() );
+        processors.put( DropSchemaStatement.class, new DropSchemaStatementProcessor() );
+        processors.put( DropTableOrViewStatement.class, new DropTableOrViewStatementProcessor() );
+
+        _defaultProcessors = Collections.unmodifiableMap( processors );
+    }
+
+    private final Map<Class<? extends Typeable<?>>, SQLProcessor> _processors;
+    private final SQLVendor _vendor;
+
+    public DefaultSQLProcessor( SQLVendor vendor )
+    {
+        this( vendor, _defaultProcessors );
+    }
+
+    public DefaultSQLProcessor( SQLVendor vendor,
+                                Map<Class<? extends Typeable<?>>, SQLProcessor> processors )
+    {
+        Objects.requireNonNull( vendor, "Vendor" );
+        Objects.requireNonNull( processors, "Processors" );
+        this._vendor = vendor;
+        this._processors = new HashMap<>( processors );
+    }
+
+    public void process( Typeable<?> object, StringBuilder builder )
+    {
+        SQLProcessor processor = this._processors.get( object.getImplementedType() );
+        if( processor != null )
+        {
+            processor.process( this, object, builder );
+        }
+        else
+        {
+            throw new UnsupportedElementException( "The vendor " + this.getClass()
+                                                   + " does not know how to handle element of type " + object.getImplementedType()
+                                                   + ".", object );
+        }
+    }
+
+    public SQLVendor getVendor()
+    {
+        return this._vendor;
+    }
+
+    protected Map<Class<? extends Typeable<?>>, SQLProcessor> getProcessors()
+    {
+        return this._processors;
+    }
+
+    public static Map<Class<? extends Typeable<?>>, SQLProcessor> getDefaultProcessors()
+    {
+        return _defaultProcessors;
+    }
+
+    public static Map<Class<? extends BinaryPredicate>, String> getDefaultBinaryOperators()
+    {
+        return _defaultBinaryOperators;
+    }
+
+    public static Map<Class<? extends MultiPredicate>, String> getDefaultMultiOperators()
+    {
+        return _defaultMultiOperators;
+    }
+
+    public static Map<Class<? extends MultiPredicate>, String> getDefaultMultiSeparators()
+    {
+        return _defaultMultiSeparators;
+    }
+
+    public static Map<Class<? extends MultiPredicate>, Boolean> getDefaultParenthesisPolicies()
+    {
+        return _defaultParenthesisPolicies;
+    }
+
+    public static Map<Class<? extends UnaryPredicate>, String> getDefaultUnaryOperators()
+    {
+        return _defaultUnaryOperators;
+    }
+
+    public static Map<Class<? extends UnaryPredicate>, UnaryOperatorOrientation>
+    getDefaultUnaryOrientations()
+    {
+        return _defaultUnaryOrientations;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefinitionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefinitionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefinitionProcessing.java
new file mode 100644
index 0000000..f2a2f90
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/DefinitionProcessing.java
@@ -0,0 +1,516 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.CheckConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.LikeClause;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.MatchType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableScope;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewCheckOption;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefinitionProcessing
+{
+
+    public static class SchemaDefinitionProcessor extends AbstractProcessor<SchemaDefinition>
+    {
+        public SchemaDefinitionProcessor()
+        {
+            super( SchemaDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SchemaDefinition object, StringBuilder builder )
+        {
+            builder.append( SQLConstants.CREATE ).append( SQLConstants.TOKEN_SEPARATOR ).append( "SCHEMA " )
+                   .append( object.getSchemaName() );
+            String charset = object.getSchemaCharset();
+            if( charset != null )
+            {
+                builder.append( " DEFAULT CHARSET " ).append( object.getSchemaCharset() );
+            }
+
+            builder.append( SQLConstants.NEWLINE );
+        }
+
+        protected void processSchemaElements( SQLProcessorAggregator aggregator, SchemaDefinition object,
+                                              StringBuilder builder )
+        {
+            for( SchemaElement el : object.getSchemaElements() )
+            {
+                aggregator.process( el.asTypeable(), builder );
+                builder.append( SQLConstants.NEWLINE );
+            }
+        }
+    }
+
+    public static class TableDefinitionProcessor extends AbstractProcessor<TableDefinition>
+    {
+        private static final Map<TableScope, String> _defaultTableScopes;
+        private static final Map<TableCommitAction, String> _defaultCommitActions;
+
+        static
+        {
+            Map<TableScope, String> operations = new HashMap<TableScope, String>();
+            operations.put( TableScope.GLOBAL_TEMPORARY, "GLOBAL TEMPORARY" );
+            operations.put( TableScope.LOCAL_TEMPORARY, "LOCAL TEMPORARY" );
+            _defaultTableScopes = operations;
+
+            Map<TableCommitAction, String> commitActions = new HashMap<TableCommitAction, String>();
+            commitActions.put( TableCommitAction.ON_COMMIT_DELETE_ROWS, "DELETE ROWS" );
+            commitActions.put( TableCommitAction.ON_COMMIT_PRESERVE_ROWS, "PRESERVE ROWS" );
+            _defaultCommitActions = commitActions;
+        }
+
+        public static Map<TableCommitAction, String> getDefaultCommitActions()
+        {
+            return Collections.unmodifiableMap( _defaultCommitActions );
+        }
+
+        public static Map<TableScope, String> getDefaultTableScopes()
+        {
+            return Collections.unmodifiableMap( _defaultTableScopes );
+        }
+
+        private final Map<TableScope, String> _tableScopes;
+        private final Map<TableCommitAction, String> _commitActions;
+
+        public TableDefinitionProcessor()
+        {
+            this( _defaultTableScopes, _defaultCommitActions );
+        }
+
+        public TableDefinitionProcessor( Map<TableScope, String> tableScopes,
+                                         Map<TableCommitAction, String> commitActions )
+        {
+            super( TableDefinition.class );
+
+            this._tableScopes = tableScopes;
+            this._commitActions = commitActions;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, TableDefinition object, StringBuilder builder )
+        {
+            builder.append( SQLConstants.CREATE );
+            if( object.getTableScope() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( this._tableScopes.get( object.getTableScope() ) );
+            }
+
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "TABLE" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getTableName(), builder );
+
+            builder.append( SQLConstants.NEWLINE );
+            aggregator.process( object.getContents(), builder );
+
+            builder.append( SQLConstants.NEWLINE );
+            if( object.getCommitAction() != null )
+            {
+                builder.append( "ON COMMIT" ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( this._commitActions.get( object.getCommitAction() ) );
+            }
+        }
+    }
+
+    public static class TableElementListProcessor extends AbstractProcessor<TableElementList>
+    {
+
+        public TableElementListProcessor()
+        {
+            super( TableElementList.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, TableElementList object, StringBuilder builder )
+        {
+            Iterator<TableElement> iter = object.getElementList().iterator();
+            builder.append( SQLConstants.OPEN_PARENTHESIS ).append( SQLConstants.NEWLINE );
+            while( iter.hasNext() )
+            {
+                this.processTableElement( aggregator, iter.next(), builder, iter.hasNext() );
+                builder.append( SQLConstants.NEWLINE );
+            }
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+
+        protected void processTableElement( SQLProcessorAggregator aggregator, TableElement object, StringBuilder builder, boolean hasNext )
+        {
+            aggregator.process( object, builder );
+            if( hasNext )
+            {
+                builder.append( SQLConstants.COMMA );
+            }
+        }
+    }
+
+    public static class ColumnDefinitionProcessor extends AbstractProcessor<ColumnDefinition>
+    {
+
+        public ColumnDefinitionProcessor()
+        {
+            super( ColumnDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, ColumnDefinition object, StringBuilder builder )
+        {
+            builder.append( object.getColumnName() ).append( SQLConstants.TOKEN_SEPARATOR );
+
+            this.processDataType( aggregator, object, builder );
+
+            if( object.getDefault() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "DEFAULT" )
+                       .append( SQLConstants.TOKEN_SEPARATOR ).append( object.getDefault() );
+            }
+
+            this.processMayBeNull( object, builder );
+
+            if( object.getAutoGenerationPolicy() != null )
+            {
+                this.processAutoGenerationPolicy( object, builder );
+            }
+        }
+
+        protected void processMayBeNull( ColumnDefinition object, StringBuilder builder )
+        {
+            if( !object.mayBeNull() )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "NOT NULL" );
+            }
+        }
+
+        protected void processDataType( SQLProcessorAggregator aggregator, ColumnDefinition object,
+                                        StringBuilder builder )
+        {
+            aggregator.process( object.getDataType(), builder );
+        }
+
+        protected void processAutoGenerationPolicy( ColumnDefinition object, StringBuilder builder )
+        {
+            builder.append( " GENERATED " );
+            if( AutoGenerationPolicy.ALWAYS.equals( object.getAutoGenerationPolicy() ) )
+            {
+                builder.append( "ALWAYS " );
+            }
+            else if( AutoGenerationPolicy.BY_DEFAULT.equals( object.getAutoGenerationPolicy() ) )
+            {
+                builder.append( "BY DEFAULT " );
+            }
+            else
+            {
+                throw new UnsupportedOperationException( "Unknown auto generation policy: "
+                                                         + object.getAutoGenerationPolicy() + "." );
+            }
+            builder.append( "AS IDENTITY" );
+        }
+    }
+
+    public static class LikeClauseProcessor extends AbstractProcessor<LikeClause>
+    {
+
+        public LikeClauseProcessor()
+        {
+            super( LikeClause.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, LikeClause object, StringBuilder builder )
+        {
+            builder.append( "LIKE" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getTableName(), builder );
+        }
+    }
+
+    public static class TableConstraintDefinitionProcessor extends AbstractProcessor<TableConstraintDefinition>
+    {
+
+        private static final Map<ConstraintCharacteristics, String> _defaultCharacteristics;
+
+        static
+        {
+            Map<ConstraintCharacteristics, String> operations = new HashMap<ConstraintCharacteristics, String>();
+            operations.put( ConstraintCharacteristics.INITIALLY_DEFERRED_DEFERRABLE, "INITIALLY DEFERRED DEFERRABLE" );
+            operations.put( ConstraintCharacteristics.INITIALLY_IMMEDIATE_DEFERRABLE, "INITIALLY IMMEDIATE DEFERRABLE" );
+            operations.put( ConstraintCharacteristics.NOT_DEFERRABLE, "NOT DEFERRABLE" );
+            _defaultCharacteristics = operations;
+        }
+
+        private final Map<ConstraintCharacteristics, String> _characteristics;
+
+        public TableConstraintDefinitionProcessor()
+        {
+            this( _defaultCharacteristics );
+        }
+
+        public TableConstraintDefinitionProcessor( Map<ConstraintCharacteristics, String> characteristics )
+        {
+            super( TableConstraintDefinition.class );
+
+            this._characteristics = characteristics;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, TableConstraintDefinition object,
+                                  StringBuilder builder )
+        {
+            if( object.getConstraintName() != null )
+            {
+                builder.append( "CONSTRAINT" ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( object.getConstraintName() ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+
+            aggregator.process( object.getConstraint(), builder );
+
+            if( object.getCharacteristics() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append(
+                    this._characteristics.get( object.getCharacteristics() ) );
+            }
+        }
+    }
+
+    public static class CheckConstraintProcessor extends AbstractProcessor<CheckConstraint>
+    {
+
+        public CheckConstraintProcessor()
+        {
+            super( CheckConstraint.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, CheckConstraint object, StringBuilder builder )
+        {
+            builder.append( "CHECK" ).append( SQLConstants.TOKEN_SEPARATOR ).append( SQLConstants.OPEN_PARENTHESIS );
+            aggregator.process( object.getCheckCondition(), builder );
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static class UniqueConstraintProcessor extends AbstractProcessor<UniqueConstraint>
+    {
+
+        private static final Map<UniqueSpecification, String> _defaultUniqueSpecs;
+
+        static
+        {
+            Map<UniqueSpecification, String> map = new HashMap<UniqueSpecification, String>();
+            map.put( UniqueSpecification.PRIMARY_KEY, "PRIMARY KEY" );
+            map.put( UniqueSpecification.UNIQUE, "UNIQUE" );
+            _defaultUniqueSpecs = map;
+        }
+
+        private final Map<UniqueSpecification, String> _uniqueSpecs;
+
+        public UniqueConstraintProcessor()
+        {
+            this( _defaultUniqueSpecs );
+        }
+
+        public UniqueConstraintProcessor( Map<UniqueSpecification, String> uniqueSpecs )
+        {
+            super( UniqueConstraint.class );
+
+            this._uniqueSpecs = uniqueSpecs;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, UniqueConstraint object, StringBuilder builder )
+        {
+            this.processUniqueness( aggregator, object, builder );
+        }
+
+        protected void processUniqueness( SQLProcessorAggregator aggregator, UniqueConstraint object, StringBuilder builder )
+        {
+            builder.append( this._uniqueSpecs.get( object.getUniquenessKind() ) );
+            aggregator.process( object.getColumnNameList(), builder );
+        }
+    }
+
+    public static class ForeignKeyConstraintProcessor extends AbstractProcessor<ForeignKeyConstraint>
+    {
+        private static final Map<ReferentialAction, String> _defaultReferentialActions;
+
+        private static final Map<MatchType, String> _defaultMatchTypes;
+
+        static
+        {
+            Map<ReferentialAction, String> map = new HashMap<ReferentialAction, String>();
+            map.put( ReferentialAction.CASCADE, "CASCADE" );
+            map.put( ReferentialAction.NO_ACTION, "NO ACTION" );
+            map.put( ReferentialAction.RESTRICT, "RESTRICT" );
+            map.put( ReferentialAction.SET_DEFAULT, "SET DEFAULT" );
+            map.put( ReferentialAction.SET_NULL, "SET NULL" );
+            _defaultReferentialActions = map;
+
+            Map<MatchType, String> mt = new HashMap<MatchType, String>();
+            mt.put( MatchType.FULL, "FULL" );
+            mt.put( MatchType.PARTIAL, "PARTIAL" );
+            mt.put( MatchType.SIMPLE, "SIMPLE" );
+            _defaultMatchTypes = mt;
+        }
+
+        private final Map<ReferentialAction, String> _referentialActions;
+
+        private final Map<MatchType, String> _matchTypes;
+
+        public ForeignKeyConstraintProcessor()
+        {
+            this( _defaultReferentialActions, _defaultMatchTypes );
+        }
+
+        public ForeignKeyConstraintProcessor( Map<ReferentialAction, String> uniqueSpecs,
+                                              Map<MatchType, String> matchTypes )
+        {
+            super( ForeignKeyConstraint.class );
+
+            this._referentialActions = uniqueSpecs;
+            this._matchTypes = matchTypes;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, ForeignKeyConstraint object, StringBuilder builder )
+        {
+            builder.append( "FOREIGN KEY" );
+            aggregator.process( object.getSourceColumns(), builder );
+            builder.append( SQLConstants.NEWLINE ).append( "REFERENCES" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getTargetTableName(), builder );
+            if( object.getTargetColumns() != null )
+            {
+                aggregator.process( object.getTargetColumns(), builder );
+            }
+
+            if( object.getMatchType() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "MATCH" ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( this._matchTypes.get( object.getMatchType() ) );
+            }
+            builder.append( SQLConstants.NEWLINE );
+
+            this.handleReferentialAction( "ON UPDATE", object.getOnUpdate(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR );
+            this.handleReferentialAction( "ON DELETE", object.getOnDelete(), builder );
+        }
+
+        protected void handleReferentialAction( String prefix, ReferentialAction action, StringBuilder builder )
+        {
+            if( action != null )
+            {
+                builder.append( prefix ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( this._referentialActions.get( action ) );
+            }
+        }
+    }
+
+    public static class ViewDefinitionProcessor extends AbstractProcessor<ViewDefinition>
+    {
+
+        private static final Map<ViewCheckOption, String> _defaultViewCheckOptions;
+
+        static
+        {
+            Map<ViewCheckOption, String> map = new HashMap<ViewCheckOption, String>();
+            map.put( ViewCheckOption.CASCADED, "CASCADED" );
+            map.put( ViewCheckOption.LOCAL, "LOCAL" );
+            _defaultViewCheckOptions = map;
+        }
+
+        private final Map<ViewCheckOption, String> _viewCheckOptions;
+
+        public ViewDefinitionProcessor()
+        {
+            this( _defaultViewCheckOptions );
+        }
+
+        public ViewDefinitionProcessor( Map<ViewCheckOption, String> viewCheckOptions )
+        {
+            super( ViewDefinition.class );
+
+            this._viewCheckOptions = viewCheckOptions;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, ViewDefinition object, StringBuilder builder )
+        {
+            builder.append( SQLConstants.CREATE ).append( SQLConstants.TOKEN_SEPARATOR );
+            if( object.isRecursive() )
+            {
+                builder.append( "RECURSIVE" ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+            builder.append( "VIEW" ).append( SQLConstants.TOKEN_SEPARATOR );
+
+            aggregator.process( object.getViewName(), builder );
+            aggregator.process( object.getViewSpecification(), builder );
+            builder.append( "AS" ).append( SQLConstants.NEWLINE );
+            aggregator.process( object.getViewQuery(), builder );
+
+            if( object.getViewCheckOption() != null )
+            {
+                builder.append( SQLConstants.NEWLINE ).append( "WITH" ).append( SQLConstants.TOKEN_SEPARATOR )
+                       .append( this._viewCheckOptions.get( object.getViewCheckOption() ) )
+                       .append( SQLConstants.TOKEN_SEPARATOR ).append( "CHECK OPTION" );
+            }
+        }
+    }
+
+    public static class RegularViewSpecificationProcessor extends AbstractProcessor<RegularViewSpecification>
+    {
+
+        public RegularViewSpecificationProcessor()
+        {
+            super( RegularViewSpecification.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, RegularViewSpecification object,
+                                  StringBuilder builder )
+        {
+            if( object.getColumns() != null )
+            {
+                aggregator.process( object.getColumns(), builder );
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/LiteralExpressionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/LiteralExpressionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/LiteralExpressionProcessing.java
new file mode 100644
index 0000000..4dbc52d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/LiteralExpressionProcessing.java
@@ -0,0 +1,128 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.DirectLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.StringLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * Currently not thread-safe.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class LiteralExpressionProcessing
+{
+
+    public static class StringLiteralExpressionProcessor extends AbstractProcessor<StringLiteral>
+    {
+        public StringLiteralExpressionProcessor()
+        {
+            super( StringLiteral.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, StringLiteral literal, StringBuilder builder )
+        {
+            String string = literal.getString();
+            builder.append( string == null ? SQLConstants.NULL : "'" + string + "'" );
+        }
+    }
+
+    public static class DirectLiteralProcessor extends AbstractProcessor<DirectLiteral>
+    {
+        public DirectLiteralProcessor()
+        {
+            super( DirectLiteral.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, DirectLiteral literal, StringBuilder builder )
+        {
+            String string = literal.getDirectLiteral();
+            builder.append( string == null ? SQLConstants.NULL : string );
+        }
+    }
+
+    public static class DateTimeLiteralProcessor extends AbstractProcessor<TimestampTimeLiteral>
+    {
+        private final DateFormat _format;
+
+        public DateTimeLiteralProcessor()
+        {
+            super( TimestampTimeLiteral.class );
+            this._format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TimestampTimeLiteral object, StringBuilder builder )
+        {
+            builder.append( "'" + this._format.format( object.getTimestamp() ) + "'" );
+        }
+    }
+
+    public static class SQLFunctionLiteralProcessor extends AbstractProcessor<SQLFunctionLiteral>
+    {
+        public SQLFunctionLiteralProcessor()
+        {
+            super( SQLFunctionLiteral.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, SQLFunctionLiteral object, StringBuilder builder )
+        {
+            builder.append( object.getFunctionName() ).append( SQLConstants.OPEN_PARENTHESIS );
+            Iterator<ValueExpression> iter = object.getParameters().iterator();
+            while( iter.hasNext() )
+            {
+                processor.process( iter.next(), builder );
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static class NumericLiteralProcessor extends AbstractProcessor<NumericLiteral>
+    {
+
+        public NumericLiteralProcessor()
+        {
+            super( NumericLiteral.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, NumericLiteral object, StringBuilder builder )
+        {
+            Number numba = object.getNumber();
+            builder.append( numba == null ? SQLConstants.NULL : numba.toString() );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ManipulationProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ManipulationProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ManipulationProcessing.java
new file mode 100644
index 0000000..853ba67
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ManipulationProcessing.java
@@ -0,0 +1,230 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction.DropDefault;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.SetColumnDefault;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ManipulationProcessing
+{
+
+    public static class AlterTableStatementProcessor extends AbstractProcessor<AlterTableStatement>
+    {
+        public AlterTableStatementProcessor()
+        {
+            super( AlterTableStatement.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, AlterTableStatement object, StringBuilder builder )
+        {
+            builder.append( "ALTER TABLE" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getTableName(), builder );
+            builder.append( SQLConstants.NEWLINE );
+            aggregator.process( object.getAction(), builder );
+        }
+    }
+
+    public static class AddColumnDefinitionProcessor extends AbstractProcessor<AddColumnDefinition>
+    {
+
+        public AddColumnDefinitionProcessor()
+        {
+            super( AddColumnDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, AddColumnDefinition object, StringBuilder builder )
+        {
+            builder.append( "ADD COLUMN" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getColumnDefinition(), builder );
+        }
+    }
+
+    public static class AddTableConstraintDefinitionProcessor extends AbstractProcessor<AddTableConstraintDefinition>
+    {
+
+        public AddTableConstraintDefinitionProcessor()
+        {
+            super( AddTableConstraintDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, AddTableConstraintDefinition object,
+                                  StringBuilder builder )
+        {
+            builder.append( "ADD" ).append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getConstraint(), builder );
+        }
+    }
+
+    public static class AlterColumnDefinitionProcessor extends AbstractProcessor<AlterColumnDefinition>
+    {
+        public AlterColumnDefinitionProcessor()
+        {
+            super( AlterColumnDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, AlterColumnDefinition object, StringBuilder builder )
+        {
+            builder.append( "ALTER COLUMN" ).append( SQLConstants.TOKEN_SEPARATOR ).append( object.getColumnName() )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            aggregator.process( object.getAction(), builder );
+        }
+    }
+
+    public static class DropColumnDefaultProcessor extends AbstractProcessor<DropDefault>
+    {
+        public DropColumnDefaultProcessor()
+        {
+            super( DropDefault.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropDefault object, StringBuilder builder )
+        {
+            builder.append( "DROP DEFAULT" );
+        }
+    }
+
+    public static class SetColumnDefaultProcessor extends AbstractProcessor<SetColumnDefault>
+    {
+        public SetColumnDefaultProcessor()
+        {
+            super( SetColumnDefault.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SetColumnDefault object, StringBuilder builder )
+        {
+            builder.append( "SET" ).append( SQLConstants.TOKEN_SEPARATOR );
+            builder.append( object.getDefault() );
+        }
+    }
+
+    public static class DropColumnDefinitionProcessor extends AbstractProcessor<DropColumnDefinition>
+    {
+        public DropColumnDefinitionProcessor()
+        {
+            super( DropColumnDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropColumnDefinition object, StringBuilder builder )
+        {
+            builder.append( "DROP COLUMN" ).append( SQLConstants.TOKEN_SEPARATOR ).append( object.getColumnName() );
+            ProcessorUtils.processDropBehaviour( object.getDropBehaviour(), builder );
+        }
+    }
+
+    public static class DropTableConstraintDefinitionProcessor extends AbstractProcessor<DropTableConstraintDefinition>
+    {
+        public DropTableConstraintDefinitionProcessor()
+        {
+            super( DropTableConstraintDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropTableConstraintDefinition object,
+                                  StringBuilder builder )
+        {
+            builder.append( "DROP CONSTRAINT" ).append( SQLConstants.TOKEN_SEPARATOR )
+                   .append( object.getConstraintName() );
+            ProcessorUtils.processDropBehaviour( object.getDropBehaviour(), builder );
+        }
+    }
+
+    public static class DropSchemaStatementProcessor extends AbstractProcessor<DropSchemaStatement>
+    {
+        public DropSchemaStatementProcessor()
+        {
+            super( DropSchemaStatement.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropSchemaStatement object, StringBuilder builder )
+        {
+            builder.append( "DROP SCHEMA" ).append( SQLConstants.TOKEN_SEPARATOR ).append( object.getSchemaName() );
+            ProcessorUtils.processDropBehaviour( object.getDropBehaviour(), builder );
+        }
+    }
+
+    public static class DropTableOrViewStatementProcessor extends AbstractProcessor<DropTableOrViewStatement>
+    {
+        private static final Map<ObjectType, String> _defaultObjectTypes;
+
+        static
+        {
+            Map<ObjectType, String> map = new HashMap<ObjectType, String>();
+            map.put( ObjectType.TABLE, "TABLE" );
+            map.put( ObjectType.VIEW, "VIEW" );
+
+            _defaultObjectTypes = map;
+        }
+
+        private final Map<ObjectType, String> _objectTypes;
+
+        public DropTableOrViewStatementProcessor()
+        {
+            this( _defaultObjectTypes );
+        }
+
+        public DropTableOrViewStatementProcessor( Map<ObjectType, String> objectTypes )
+        {
+            super( DropTableOrViewStatement.class );
+
+            this._objectTypes = objectTypes;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, DropTableOrViewStatement object,
+                                  StringBuilder builder )
+        {
+            builder.append( "DROP" ).append( SQLConstants.TOKEN_SEPARATOR )
+                   .append( this._objectTypes.get( object.whatToDrop() ) ).append( SQLConstants.TOKEN_SEPARATOR );
+
+            aggregator.process( object.getTableName(), builder );
+
+            ProcessorUtils.processDropBehaviour( object.getDropBehaviour(), builder );
+        }
+
+        protected Map<ObjectType, String> getObjectTypes()
+        {
+            return this._objectTypes;
+        }
+    }
+}


[06/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateBySearchImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateBySearchImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateBySearchImpl.java
new file mode 100644
index 0000000..de8ae0a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateBySearchImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateStatement;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UpdateBySearchImpl extends SQLSyntaxElementBase<UpdateStatement, UpdateBySearch>
+    implements UpdateBySearch
+{
+
+    private final TargetTable _targetTable;
+
+    private final List<SetClause> _setClauses;
+
+    private final BooleanExpression _where;
+
+    public UpdateBySearchImpl( SQLProcessorAggregator processor, TargetTable targetTable,
+                               List<SetClause> setClauses,
+                               BooleanExpression where )
+    {
+        this( processor, UpdateBySearch.class, targetTable, setClauses, where );
+    }
+
+    protected UpdateBySearchImpl( SQLProcessorAggregator processor,
+                                  Class<? extends UpdateBySearch> expressionClass,
+                                  TargetTable targetTable, List<SetClause> setClauses, BooleanExpression where )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( targetTable, "target table" );
+        Objects.requireNonNull( setClauses, "set clauses" );
+        if( setClauses.isEmpty() )
+        {
+            throw new IllegalArgumentException( "At least one set clause must be present." );
+        }
+        for( SetClause clause : setClauses )
+        {
+            Objects.requireNonNull( clause, "set clause" );
+        }
+
+        this._targetTable = targetTable;
+        this._setClauses = Collections.unmodifiableList( new ArrayList<SetClause>( setClauses ) );
+        this._where = where;
+    }
+
+    public TargetTable getTargetTable()
+    {
+        return this._targetTable;
+    }
+
+    public BooleanExpression getWhere()
+    {
+        return this._where;
+    }
+
+    public List<SetClause> getSetClauses()
+    {
+        return this._setClauses;
+    }
+
+    @Override
+    protected boolean doesEqual( UpdateBySearch another )
+    {
+        return this._targetTable.equals( another.getTargetTable() )
+               && this._setClauses.equals( another.getSetClauses() )
+               && TypeableImpl.bothNullOrEquals( this._where, another.getWhere() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateSourceByExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateSourceByExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateSourceByExpressionImpl.java
new file mode 100644
index 0000000..70d3664
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/UpdateSourceByExpressionImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UpdateSourceByExpressionImpl extends SQLSyntaxElementBase<UpdateSource, UpdateSourceByExpression>
+    implements UpdateSourceByExpression
+{
+
+    private final ValueExpression _valueExpression;
+
+    public UpdateSourceByExpressionImpl( SQLProcessorAggregator processor, ValueExpression valueExpression )
+    {
+        this( processor, UpdateSourceByExpression.class, valueExpression );
+    }
+
+    protected UpdateSourceByExpressionImpl( SQLProcessorAggregator processor,
+                                            Class<? extends UpdateSourceByExpression> expressionClass, ValueExpression valueExpression )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( valueExpression, "expression" );
+        this._valueExpression = valueExpression;
+    }
+
+    public ValueExpression getValueExpression()
+    {
+        return this._valueExpression;
+    }
+
+    @Override
+    protected boolean doesEqual( UpdateSourceByExpression another )
+    {
+        return this._valueExpression.equals( another.getValueExpression() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/pgsql/PgSQLInsertStatementImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/pgsql/PgSQLInsertStatementImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/pgsql/PgSQLInsertStatementImpl.java
new file mode 100644
index 0000000..4c96727
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/modification/pgsql/PgSQLInsertStatementImpl.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.modification.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.pgsql.PgSQLInsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.InsertStatementImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class PgSQLInsertStatementImpl extends InsertStatementImpl implements PgSQLInsertStatement
+{
+
+    private final SelectColumnClause _returning;
+
+    public PgSQLInsertStatementImpl( SQLProcessorAggregator processor,
+                                     TableNameDirect tableName, ColumnSource columnSource, SelectColumnClause returning )
+    {
+        super( processor, PgSQLInsertStatement.class, tableName, columnSource );
+
+        this._returning = returning;
+    }
+
+    public SelectColumnClause getReturningClause()
+    {
+        return this._returning;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/AsteriskSelectImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/AsteriskSelectImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/AsteriskSelectImpl.java
new file mode 100644
index 0000000..53c6e1f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/AsteriskSelectImpl.java
@@ -0,0 +1,42 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.AsteriskSelect;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class AsteriskSelectImpl extends SelectColumnClauseImpl<AsteriskSelect>
+    implements AsteriskSelect
+{
+    public AsteriskSelectImpl( SQLProcessorAggregator processor, SetQuantifier quantifier )
+    {
+        this( processor, AsteriskSelect.class, quantifier );
+    }
+
+    public AsteriskSelectImpl( SQLProcessorAggregator processor, Class<? extends AsteriskSelect> type,
+                               SetQuantifier quantifier )
+    {
+        super( processor, type, quantifier );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByExpressionImpl.java
new file mode 100644
index 0000000..afaf230
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByExpressionImpl.java
@@ -0,0 +1,58 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnReferenceByExpressionImpl extends ColumnReferenceImpl<ColumnReferenceByExpression>
+    implements ColumnReferenceByExpression
+{
+    private final ValueExpression _expression;
+
+    public ColumnReferenceByExpressionImpl( SQLProcessorAggregator processor, ValueExpression expression )
+    {
+        this( processor, ColumnReferenceByExpression.class, expression );
+    }
+
+    protected ColumnReferenceByExpressionImpl( SQLProcessorAggregator processor,
+                                               Class<? extends ColumnReferenceByExpression> implClass, ValueExpression expression )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( expression, "expression" );
+        this._expression = expression;
+    }
+
+    public ValueExpression getExpression()
+    {
+        return this._expression;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnReferenceByExpression another )
+    {
+        return this._expression.equals( another.getExpression() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByNameImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByNameImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByNameImpl.java
new file mode 100644
index 0000000..689c635
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceByNameImpl.java
@@ -0,0 +1,68 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnReferenceByNameImpl extends ColumnReferenceImpl<ColumnReferenceByName>
+    implements ColumnReferenceByName
+{
+
+    private final String _tableName;
+
+    private final String _columnName;
+
+    public ColumnReferenceByNameImpl( SQLProcessorAggregator processor, String tableName, String columnName )
+    {
+        this( processor, ColumnReferenceByName.class, tableName, columnName );
+    }
+
+    protected ColumnReferenceByNameImpl( SQLProcessorAggregator processor,
+                                         Class<? extends ColumnReferenceByName> implClass, String tableName, String columnName )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( columnName, "column name" );
+        this._tableName = tableName;
+        this._columnName = columnName;
+    }
+
+    public String getColumnName()
+    {
+        return this._columnName;
+    }
+
+    public String getTableName()
+    {
+        return this._tableName;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnReferenceByName another )
+    {
+        return this._columnName.equals( another.getColumnName() )
+               && TypeableImpl.bothNullOrEquals( this._tableName, another.getTableName() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceImpl.java
new file mode 100644
index 0000000..22812e4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferenceImpl.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class ColumnReferenceImpl<ColumnReferenceType extends ColumnReference> extends
+                                                                                       NonBooleanExpressionImpl<ColumnReferenceType>
+    implements ColumnReference
+{
+    public ColumnReferenceImpl( SQLProcessorAggregator processor,
+                                Class<? extends ColumnReferenceType> columnReferenceClass )
+    {
+        super( processor, columnReferenceClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferencesImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferencesImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferencesImpl.java
new file mode 100644
index 0000000..7213ad1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/ColumnReferencesImpl.java
@@ -0,0 +1,79 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnReferencesImpl extends SelectColumnClauseImpl<ColumnReferences>
+    implements ColumnReferences
+{
+
+    private final List<ColumnReferenceInfo> _columns;
+
+    public ColumnReferencesImpl( SQLProcessorAggregator processor, SetQuantifier quantifier,
+                                 ColumnReferenceInfo... columns )
+    {
+        this( processor, quantifier, Arrays.asList( columns ) );
+    }
+
+    public ColumnReferencesImpl( SQLProcessorAggregator processor, SetQuantifier quantifier,
+                                 List<ColumnReferenceInfo> columns )
+    {
+        this( processor, ColumnReferences.class, quantifier, columns );
+    }
+
+    public ColumnReferencesImpl( SQLProcessorAggregator processor, Class<? extends ColumnReferences> type,
+                                 SetQuantifier quantifier, List<ColumnReferenceInfo> columns )
+    {
+        super( processor, type, quantifier );
+        Objects.requireNonNull( columns, "columns" );
+        if( columns.isEmpty() )
+        {
+            throw new IllegalArgumentException( "Must have at least one column in column list." );
+        }
+
+        for( ColumnReferenceInfo column : columns )
+        {
+            Objects.requireNonNull( column, "column" );
+        }
+
+        this._columns = Collections.unmodifiableList( columns );
+    }
+
+    public List<ColumnReferenceInfo> getColumns()
+    {
+        return this._columns;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnReferences another )
+    {
+        return super.doesEqual( another ) && this._columns.equals( another.getColumns() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/CorrespondingSpecImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/CorrespondingSpecImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/CorrespondingSpecImpl.java
new file mode 100644
index 0000000..81780f3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/CorrespondingSpecImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class CorrespondingSpecImpl extends SQLSyntaxElementBase<CorrespondingSpec, CorrespondingSpec>
+    implements CorrespondingSpec
+{
+
+    private final ColumnNameList _columnList;
+
+    public CorrespondingSpecImpl( SQLProcessorAggregator processor, ColumnNameList columnNames )
+    {
+        this( processor, CorrespondingSpec.class, columnNames );
+    }
+
+    protected CorrespondingSpecImpl( SQLProcessorAggregator processor, Class<? extends CorrespondingSpec> implClass,
+                                     ColumnNameList columnNames )
+    {
+        super( processor, implClass );
+
+        this._columnList = columnNames;
+    }
+
+    public ColumnNameList getColumnList()
+    {
+        return this._columnList;
+    }
+
+    @Override
+    protected boolean doesEqual( CorrespondingSpec another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._columnList, another.getColumnList() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/FromClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/FromClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/FromClauseImpl.java
new file mode 100644
index 0000000..44f8010
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/FromClauseImpl.java
@@ -0,0 +1,72 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class FromClauseImpl extends SQLSyntaxElementBase<FromClause, FromClause>
+    implements FromClause
+{
+
+    private List<TableReference> _tableReferences;
+
+    public FromClauseImpl( SQLProcessorAggregator processor, TableReference... tableReferences )
+    {
+        this( processor, Arrays.asList( tableReferences ) );
+    }
+
+    public FromClauseImpl( SQLProcessorAggregator processor, List<TableReference> tableReferences )
+    {
+        this( processor, FromClause.class, tableReferences );
+    }
+
+    protected FromClauseImpl( SQLProcessorAggregator processor, Class<? extends FromClause> type,
+                              List<TableReference> tableReferences )
+    {
+        super( processor, type );
+        Objects.requireNonNull( tableReferences, "table references" );
+        for( TableReference ref : tableReferences )
+        {
+            Objects.requireNonNull( ref, "table reference" );
+        }
+        this._tableReferences = Collections.unmodifiableList( tableReferences );
+    }
+
+    public List<TableReference> getTableReferences()
+    {
+        return this._tableReferences;
+    }
+
+    @Override
+    protected boolean doesEqual( FromClause another )
+    {
+        return this._tableReferences.equals( another.getTableReferences() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/GroupByClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/GroupByClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/GroupByClauseImpl.java
new file mode 100644
index 0000000..838b1a2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/GroupByClauseImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class GroupByClauseImpl extends SQLSyntaxElementBase<GroupByClause, GroupByClause>
+    implements GroupByClause
+{
+
+    private final List<GroupingElement> _groupingElements;
+
+    public GroupByClauseImpl( SQLProcessorAggregator processor, List<GroupingElement> groupingElements )
+    {
+        super( processor, GroupByClause.class );
+        Objects.requireNonNull( groupingElements, "grouping elements" );
+        for( GroupingElement element : groupingElements )
+        {
+            Objects.requireNonNull( element, "grouping element" );
+        }
+        this._groupingElements = Collections.unmodifiableList( new ArrayList<GroupingElement>( groupingElements ) );
+    }
+
+    public List<GroupingElement> getGroupingElements()
+    {
+        return this._groupingElements;
+    }
+
+    @Override
+    protected boolean doesEqual( GroupByClause another )
+    {
+        return this._groupingElements.equals( another.getGroupingElements() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/LimitSpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/LimitSpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/LimitSpecificationImpl.java
new file mode 100644
index 0000000..5c074a9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/LimitSpecificationImpl.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class LimitSpecificationImpl extends SQLSyntaxElementBase<LimitSpecification, LimitSpecification>
+    implements LimitSpecification
+{
+
+    private final NonBooleanExpression _count;
+
+    public LimitSpecificationImpl( SQLProcessorAggregator processor, NonBooleanExpression count )
+    {
+        this( processor, LimitSpecification.class, count );
+    }
+
+    protected LimitSpecificationImpl( SQLProcessorAggregator processor,
+                                      Class<? extends LimitSpecification> realImplementingType, NonBooleanExpression count )
+    {
+        super( processor, realImplementingType );
+
+        this._count = count;
+    }
+
+    public NonBooleanExpression getCount()
+    {
+        return this._count;
+    }
+
+    @Override
+    protected boolean doesEqual( LimitSpecification another )
+    {
+        return bothNullOrEquals( this._count, another.getCount() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OffsetSpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OffsetSpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OffsetSpecificationImpl.java
new file mode 100644
index 0000000..0f3e798
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OffsetSpecificationImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class OffsetSpecificationImpl extends SQLSyntaxElementBase<OffsetSpecification, OffsetSpecification>
+    implements OffsetSpecification
+{
+
+    private final NonBooleanExpression _skip;
+
+    public OffsetSpecificationImpl( SQLProcessorAggregator processor, NonBooleanExpression skip )
+    {
+        this( processor, OffsetSpecification.class, skip );
+    }
+
+    protected OffsetSpecificationImpl( SQLProcessorAggregator processor,
+                                       Class<? extends OffsetSpecification> realImplementingType, NonBooleanExpression skip )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( skip, "Skip" );
+        this._skip = skip;
+    }
+
+    public NonBooleanExpression getSkip()
+    {
+        return this._skip;
+    }
+
+    @Override
+    protected boolean doesEqual( OffsetSpecification another )
+    {
+        return this._skip.equals( another.getSkip() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrderByClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrderByClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrderByClauseImpl.java
new file mode 100644
index 0000000..ef56170
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrderByClauseImpl.java
@@ -0,0 +1,62 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class OrderByClauseImpl extends SQLSyntaxElementBase<OrderByClause, OrderByClause>
+    implements OrderByClause
+{
+
+    private List<SortSpecification> _sortSpecs;
+
+    public OrderByClauseImpl( SQLProcessorAggregator processor, List<SortSpecification> sortSpecs )
+    {
+        super( processor, OrderByClause.class );
+        Objects.requireNonNull( sortSpecs, "sort specifications" );
+        for( SortSpecification sortSpec : sortSpecs )
+        {
+            Objects.requireNonNull( sortSpec, "sort specification" );
+        }
+
+        this._sortSpecs = Collections.unmodifiableList( new ArrayList<SortSpecification>( sortSpecs ) );
+    }
+
+    public List<SortSpecification> getOrderingColumns()
+    {
+        return this._sortSpecs;
+    }
+
+    @Override
+    protected boolean doesEqual( OrderByClause another )
+    {
+        return this._sortSpecs.equals( another.getOrderingColumns() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrdinaryGroupingSetImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrdinaryGroupingSetImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrdinaryGroupingSetImpl.java
new file mode 100644
index 0000000..3ebd307
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/OrdinaryGroupingSetImpl.java
@@ -0,0 +1,73 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class OrdinaryGroupingSetImpl extends SQLSyntaxElementBase<GroupingElement, OrdinaryGroupingSet>
+    implements OrdinaryGroupingSet
+{
+    private final List<NonBooleanExpression> _columns;
+
+    public OrdinaryGroupingSetImpl( SQLProcessorAggregator processor, NonBooleanExpression... columns )
+    {
+        this( processor, Arrays.asList( columns ) );
+    }
+
+    public OrdinaryGroupingSetImpl( SQLProcessorAggregator processor, List<NonBooleanExpression> columns )
+    {
+        this( processor, OrdinaryGroupingSet.class, columns );
+    }
+
+    protected OrdinaryGroupingSetImpl( SQLProcessorAggregator processor,
+                                       Class<? extends OrdinaryGroupingSet> implClass, List<NonBooleanExpression> columns )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( columns, "columns" );
+        for( NonBooleanExpression expr : columns )
+        {
+            Objects.requireNonNull( expr, "column" );
+        }
+        this._columns = Collections.unmodifiableList( new ArrayList<NonBooleanExpression>( columns ) );
+    }
+
+    public List<NonBooleanExpression> getColumns()
+    {
+        return this._columns;
+    }
+
+    @Override
+    protected boolean doesEqual( OrdinaryGroupingSet another )
+    {
+        return this._columns.equals( another.getColumns() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyBinaryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyBinaryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyBinaryImpl.java
new file mode 100644
index 0000000..eabbf92
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyBinaryImpl.java
@@ -0,0 +1,105 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBodyBinary;
+import org.apache.polygene.library.sql.generator.grammar.query.SetOperation;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QueryExpressionBodyBinaryImpl extends QueryExpressionBodyImpl<QueryExpressionBodyBinary>
+    implements QueryExpressionBodyBinary
+{
+
+    private final SetOperation _setOperation;
+
+    private final QueryExpressionBody _left;
+
+    private final QueryExpressionBody _right;
+
+    private final SetQuantifier _setQuantifier;
+
+    private final CorrespondingSpec _correspondingColumns;
+
+    public QueryExpressionBodyBinaryImpl( SQLProcessorAggregator processor, SetOperation setOperation,
+                                          QueryExpressionBody left, QueryExpressionBody right, SetQuantifier setQuantifier,
+                                          CorrespondingSpec correspondingColumns )
+    {
+        this( processor, QueryExpressionBodyBinary.class, setOperation, left, right, setQuantifier,
+              correspondingColumns );
+    }
+
+    protected QueryExpressionBodyBinaryImpl( SQLProcessorAggregator processor,
+                                             Class<? extends QueryExpressionBodyBinary> implClass, SetOperation setOperation, QueryExpressionBody left,
+                                             QueryExpressionBody right, SetQuantifier setQuantifier, CorrespondingSpec correspondingColumns )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( setOperation, "set operation" );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( right, "right" );
+        Objects.requireNonNull( setQuantifier, "set quantifier" );
+        this._setOperation = setOperation;
+        this._left = left;
+        this._right = right;
+        this._correspondingColumns = correspondingColumns;
+        this._setQuantifier = setQuantifier;
+    }
+
+    public QueryExpressionBody getLeft()
+    {
+        return this._left;
+    }
+
+    public QueryExpressionBody getRight()
+    {
+        return this._right;
+    }
+
+    public SetOperation getSetOperation()
+    {
+        return this._setOperation;
+    }
+
+    public CorrespondingSpec getCorrespondingColumns()
+    {
+        return this._correspondingColumns;
+    }
+
+    public SetQuantifier getSetQuantifier()
+    {
+        return this._setQuantifier;
+    }
+
+    @Override
+    protected boolean doesEqual( QueryExpressionBodyBinary another )
+    {
+        return this._setOperation.equals( another.getSetOperation() )
+               && this._setQuantifier.equals( another.getSetQuantifier() )
+               && TypeableImpl.bothNullOrEquals( this._correspondingColumns, another.getCorrespondingColumns() )
+               && this._left.equals( another.getLeft() ) && this._right.equals( another.getRight() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyImpl.java
new file mode 100644
index 0000000..700dcac
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionBodyImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class QueryExpressionBodyImpl<ExpressionType extends QueryExpressionBody> extends
+                                                                                          NonBooleanExpressionImpl<ExpressionType>
+{
+
+    public QueryExpressionBodyImpl( SQLProcessorAggregator processor, Class<? extends ExpressionType> expressionClass )
+    {
+        super( processor, expressionClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionImpl.java
new file mode 100644
index 0000000..f2cb8f0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QueryExpressionImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.NonBooleanExpressionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QueryExpressionImpl extends NonBooleanExpressionImpl<QueryExpression>
+    implements QueryExpression
+{
+
+    private final QueryExpressionBody _body;
+
+    public QueryExpressionImpl( SQLProcessorAggregator processor, QueryExpressionBody body )
+    {
+        this( processor, QueryExpression.class, body );
+    }
+
+    protected QueryExpressionImpl( SQLProcessorAggregator processor, Class<? extends QueryExpression> implClass,
+                                   QueryExpressionBody body )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( body, "query expression body" );
+        this._body = body;
+    }
+
+    public QueryExpressionBody getQueryExpressionBody()
+    {
+        return this._body;
+    }
+
+    @Override
+    protected boolean doesEqual( QueryExpression another )
+    {
+        return this._body.equals( another.getQueryExpressionBody() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QuerySpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QuerySpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QuerySpecificationImpl.java
new file mode 100644
index 0000000..812a341
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/QuerySpecificationImpl.java
@@ -0,0 +1,130 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QuerySpecificationImpl extends QueryExpressionBodyImpl<QuerySpecification>
+    implements QuerySpecification
+{
+
+    private final SelectColumnClause _select;
+
+    private final FromClause _from;
+
+    private final BooleanExpression _where;
+
+    private final GroupByClause _groupBy;
+
+    private final BooleanExpression _having;
+
+    private final OrderByClause _orderBy;
+
+    private final OffsetSpecification _offset;
+
+    private final LimitSpecification _limit;
+
+    public QuerySpecificationImpl( SQLProcessorAggregator processor, SelectColumnClause select, FromClause from,
+                                   BooleanExpression where, GroupByClause groupBy, BooleanExpression having, OrderByClause orderBy,
+                                   OffsetSpecification offset, LimitSpecification limit )
+    {
+        this( processor, QuerySpecification.class, select, from, where, groupBy, having, orderBy, offset, limit );
+    }
+
+    protected QuerySpecificationImpl( SQLProcessorAggregator processor, Class<? extends QuerySpecification> queryClass,
+                                      SelectColumnClause select, FromClause from, BooleanExpression where, GroupByClause groupBy,
+                                      BooleanExpression having, OrderByClause orderBy, OffsetSpecification offset, LimitSpecification limit )
+    {
+        super( processor, queryClass );
+        Objects.requireNonNull( select, "select" );
+        this._select = select;
+        this._from = from;
+        this._where = where;
+        this._groupBy = groupBy;
+        this._having = having;
+        this._orderBy = orderBy;
+        this._offset = offset;
+        this._limit = limit;
+    }
+
+    public SelectColumnClause getColumns()
+    {
+        return this._select;
+    }
+
+    public FromClause getFrom()
+    {
+        return this._from;
+    }
+
+    public BooleanExpression getWhere()
+    {
+        return this._where;
+    }
+
+    public GroupByClause getGroupBy()
+    {
+        return this._groupBy;
+    }
+
+    public BooleanExpression getHaving()
+    {
+        return this._having;
+    }
+
+    public OrderByClause getOrderBy()
+    {
+        return this._orderBy;
+    }
+
+    public LimitSpecification getLimitSpecification()
+    {
+        return this._limit;
+    }
+
+    public OffsetSpecification getOffsetSpecification()
+    {
+        return this._offset;
+    }
+
+    @Override
+    protected boolean doesEqual( QuerySpecification another )
+    {
+        return this._select.equals( another.getColumns() )
+               && TypeableImpl.bothNullOrEquals( this._from, another.getFrom() )
+               && TypeableImpl.bothNullOrEquals( this._where, another.getWhere() )
+               && TypeableImpl.bothNullOrEquals( this._groupBy, another.getGroupBy() )
+               && TypeableImpl.bothNullOrEquals( this._having, another.getHaving() )
+               && TypeableImpl.bothNullOrEquals( this._orderBy, another.getOrderBy() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowDefinitionImpl.java
new file mode 100644
index 0000000..51cf107
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowDefinitionImpl.java
@@ -0,0 +1,63 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.RowDefinition;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class RowDefinitionImpl extends SQLSyntaxElementBase<RowValueConstructor, RowDefinition>
+    implements RowDefinition
+{
+
+    private List<ValueExpression> _rowElements;
+
+    public RowDefinitionImpl( SQLProcessorAggregator processor, List<ValueExpression> rowElements )
+    {
+        this( processor, RowDefinition.class, rowElements );
+    }
+
+    protected RowDefinitionImpl( SQLProcessorAggregator processor, Class<? extends RowDefinition> realImplementingType,
+                                 List<ValueExpression> rowElements )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( rowElements, "row elements" );
+        this._rowElements = Collections.unmodifiableList( rowElements );
+    }
+
+    public List<ValueExpression> getRowElements()
+    {
+        return this._rowElements;
+    }
+
+    @Override
+    protected boolean doesEqual( RowDefinition another )
+    {
+        return this._rowElements.equals( another.getRowElements() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowSubQueryImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowSubQueryImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowSubQueryImpl.java
new file mode 100644
index 0000000..ca50e05
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/RowSubQueryImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.RowSubQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class RowSubQueryImpl extends SQLSyntaxElementBase<RowValueConstructor, RowSubQuery>
+    implements RowSubQuery
+{
+    private final QueryExpression _queryExpression;
+
+    public RowSubQueryImpl( SQLProcessorAggregator processor, QueryExpression queryExpression )
+    {
+        this( processor, RowSubQuery.class, queryExpression );
+    }
+
+    protected RowSubQueryImpl( SQLProcessorAggregator processor, Class<? extends RowSubQuery> realImplementingType,
+                               QueryExpression queryExpression )
+    {
+        super( processor, realImplementingType );
+        Objects.requireNonNull( queryExpression, "query expression" );
+        this._queryExpression = queryExpression;
+    }
+
+    public QueryExpression getQueryExpression()
+    {
+        return this._queryExpression;
+    }
+
+    @Override
+    protected boolean doesEqual( RowSubQuery another )
+    {
+        return this._queryExpression.equals( another.getQueryExpression() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SelectColumnClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SelectColumnClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SelectColumnClauseImpl.java
new file mode 100644
index 0000000..8be59aa
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SelectColumnClauseImpl.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class SelectColumnClauseImpl<SelectType extends SelectColumnClause> extends
+                                                                                    SQLSyntaxElementBase<SelectColumnClause, SelectType>
+    implements SelectColumnClause
+{
+
+    private final SetQuantifier _setQuantifier;
+
+    protected SelectColumnClauseImpl( SQLProcessorAggregator processor, Class<? extends SelectType> type,
+                                      SetQuantifier quantifier )
+    {
+        super( processor, type );
+        Objects.requireNonNull( quantifier, "set quantifier" );
+        this._setQuantifier = quantifier;
+    }
+
+    public SetQuantifier getSetQuantifier()
+    {
+        return this._setQuantifier;
+    }
+
+    @Override
+    protected boolean doesEqual( SelectType another )
+    {
+        return this._setQuantifier.equals( another.getSetQuantifier() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SortSpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SortSpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SortSpecificationImpl.java
new file mode 100644
index 0000000..9fbec3a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/SortSpecificationImpl.java
@@ -0,0 +1,71 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SortSpecificationImpl extends SQLSyntaxElementBase<SortSpecification, SortSpecification>
+    implements SortSpecification
+{
+    private final Ordering _ordering;
+
+    private final ValueExpression _expression;
+
+    public SortSpecificationImpl( SQLProcessorAggregator processor, ValueExpression expression, Ordering ordering )
+    {
+        this( processor, SortSpecification.class, expression, ordering );
+    }
+
+    protected SortSpecificationImpl( SQLProcessorAggregator processor, Class<? extends SortSpecification> implClass,
+                                     ValueExpression expression, Ordering ordering )
+    {
+        super( processor, implClass );
+        Objects.requireNonNull( expression, "expression" );
+        Objects.requireNonNull( ordering, "ordering" );
+
+        this._expression = expression;
+        this._ordering = ordering;
+    }
+
+    public Ordering getOrderingSpecification()
+    {
+        return this._ordering;
+    }
+
+    public ValueExpression getValueExpression()
+    {
+        return this._expression;
+    }
+
+    @Override
+    protected boolean doesEqual( SortSpecification another )
+    {
+        return this._ordering.equals( another.getOrderingSpecification() )
+               && this._expression.equals( another.getOrderingSpecification() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableAliasImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableAliasImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableAliasImpl.java
new file mode 100644
index 0000000..04b5b57
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableAliasImpl.java
@@ -0,0 +1,68 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableAliasImpl extends SQLSyntaxElementBase<TableAlias, TableAlias>
+    implements TableAlias
+{
+    private final String _tableAlias;
+
+    private final ColumnNameList _columnAliases;
+
+    public TableAliasImpl( SQLProcessorAggregator processor, String tableAlias, ColumnNameList columnNames )
+    {
+        this( processor, TableAlias.class, tableAlias, columnNames );
+    }
+
+    protected TableAliasImpl( SQLProcessorAggregator processor, Class<? extends TableAlias> implementingClass,
+                              String tableAlias, ColumnNameList columnNames )
+    {
+        super( processor, implementingClass );
+        Objects.requireNonNull( tableAlias, "table alias table name" );
+        this._tableAlias = tableAlias;
+        this._columnAliases = columnNames;
+    }
+
+    public ColumnNameList getColumnAliases()
+    {
+        return this._columnAliases;
+    }
+
+    public String getTableAlias()
+    {
+        return this._tableAlias;
+    }
+
+    @Override
+    protected boolean doesEqual( TableAlias another )
+    {
+        return this._tableAlias.equals( another.getTableAlias() )
+               && bothNullOrEquals( this._columnAliases, another.getColumnAliases() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByExpressionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByExpressionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByExpressionImpl.java
new file mode 100644
index 0000000..9278dad
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByExpressionImpl.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableReferenceByExpressionImpl extends TableReferencePrimaryImpl<TableReferenceByExpression>
+    implements TableReferenceByExpression
+{
+    private final QueryExpression _expression;
+
+    public TableReferenceByExpressionImpl( SQLProcessorAggregator processor, QueryExpression expression,
+                                           TableAlias alias )
+    {
+        this( processor, TableReferenceByExpression.class, expression, alias );
+    }
+
+    protected TableReferenceByExpressionImpl( SQLProcessorAggregator processor,
+                                              Class<? extends TableReferenceByExpression> implClass, QueryExpression expression, TableAlias alias )
+    {
+        super( processor, implClass, alias );
+        Objects.requireNonNull( expression, "collection expression" );
+        this._expression = expression;
+    }
+
+    public QueryExpression getQuery()
+    {
+        return this._expression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByNameImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByNameImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByNameImpl.java
new file mode 100644
index 0000000..2f54001
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/query/TableReferenceByNameImpl.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.query;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableReferenceByNameImpl extends TableReferencePrimaryImpl<TableReferenceByName>
+    implements TableReferenceByName
+{
+    private final TableName _tableName;
+
+    public TableReferenceByNameImpl( SQLProcessorAggregator processor, TableName tableName, TableAlias alias )
+    {
+        this( processor, TableReferenceByName.class, tableName, alias );
+    }
+
+    protected TableReferenceByNameImpl( SQLProcessorAggregator processor,
+                                        Class<? extends TableReferenceByName> implClass, TableName tableName, TableAlias alias )
+    {
+        super( processor, implClass, alias );
+        Objects.requireNonNull( tableName, "table name" );
+        this._tableName = tableName;
+    }
+
+    public TableName getTableName()
+    {
+        return this._tableName;
+    }
+}


[11/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/InPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/InPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/InPredicateImpl.java
new file mode 100644
index 0000000..159c1a2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/InPredicateImpl.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class InPredicateImpl extends MultiPredicateImpl<InPredicate>
+    implements InPredicate
+{
+
+    public InPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                            List<NonBooleanExpression> rights )
+    {
+        this( processor, InPredicate.class, left, rights );
+    }
+
+    protected InPredicateImpl( SQLProcessorAggregator processor, Class<? extends InPredicate> predicateClass,
+                               NonBooleanExpression left, List<NonBooleanExpression> rights )
+    {
+        super( processor, predicateClass, left, rights );
+    }
+
+    public InPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left, NonBooleanExpression... rights )
+    {
+        this( processor, InPredicate.class, left, rights );
+    }
+
+    protected InPredicateImpl( SQLProcessorAggregator processor, Class<? extends InPredicate> predicateClass,
+                               NonBooleanExpression left, NonBooleanExpression... rights )
+    {
+        super( processor, predicateClass, left, rights );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNotNullPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNotNullPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNotNullPredicateImpl.java
new file mode 100644
index 0000000..eff8be0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNotNullPredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNotNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class IsNotNullPredicateImpl extends UnaryPredicateImpl<IsNotNullPredicate>
+    implements IsNotNullPredicate
+{
+
+    public IsNotNullPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression expression )
+    {
+        this( processor, IsNotNullPredicate.class, expression );
+    }
+
+    protected IsNotNullPredicateImpl( SQLProcessorAggregator processor,
+                                      Class<? extends IsNotNullPredicate> predicateClass, NonBooleanExpression expression )
+    {
+        super( processor, predicateClass, expression );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNullPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNullPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNullPredicateImpl.java
new file mode 100644
index 0000000..4dec363
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/IsNullPredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class IsNullPredicateImpl extends UnaryPredicateImpl<IsNullPredicate>
+    implements IsNullPredicate
+{
+
+    public IsNullPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression expression )
+    {
+        this( processor, IsNullPredicate.class, expression );
+    }
+
+    protected IsNullPredicateImpl( SQLProcessorAggregator processor, Class<? extends IsNullPredicate> predicateClass,
+                                   NonBooleanExpression expression )
+    {
+        super( processor, predicateClass, expression );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessOrEqualPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessOrEqualPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessOrEqualPredicateImpl.java
new file mode 100644
index 0000000..31b8f91
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessOrEqualPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class LessOrEqualPredicateImpl extends BinaryPredicateImpl<LessOrEqualPredicate>
+    implements LessOrEqualPredicate
+{
+
+    public LessOrEqualPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                     NonBooleanExpression right )
+    {
+        this( processor, LessOrEqualPredicate.class, left, right );
+    }
+
+    protected LessOrEqualPredicateImpl( SQLProcessorAggregator processor,
+                                        Class<? extends LessOrEqualPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessThanPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessThanPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessThanPredicateImpl.java
new file mode 100644
index 0000000..feb1460
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LessThanPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class LessThanPredicateImpl extends BinaryPredicateImpl<LessThanPredicate>
+    implements LessThanPredicate
+{
+
+    public LessThanPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                  NonBooleanExpression right )
+    {
+        this( processor, LessThanPredicate.class, left, right );
+    }
+
+    protected LessThanPredicateImpl( SQLProcessorAggregator processor,
+                                     Class<? extends LessThanPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LikePredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LikePredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LikePredicateImpl.java
new file mode 100644
index 0000000..a394ea0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/LikePredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.LikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class LikePredicateImpl extends BinaryPredicateImpl<LikePredicate>
+    implements LikePredicate
+{
+
+    public LikePredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        this( processor, LikePredicate.class, left, right );
+    }
+
+    protected LikePredicateImpl( SQLProcessorAggregator processor, Class<? extends LikePredicate> predicateClass,
+                                 NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/MultiPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/MultiPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/MultiPredicateImpl.java
new file mode 100644
index 0000000..ffdb5fc
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/MultiPredicateImpl.java
@@ -0,0 +1,79 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.MultiPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class MultiPredicateImpl<ExpressionType extends MultiPredicate> extends
+                                                                                AbstractBooleanExpression<ExpressionType>
+    implements MultiPredicate
+{
+
+    private final NonBooleanExpression _left;
+
+    private final List<NonBooleanExpression> _rights;
+
+    protected MultiPredicateImpl( SQLProcessorAggregator processor, Class<? extends ExpressionType> expressionClass,
+                                  NonBooleanExpression left, NonBooleanExpression... rights )
+    {
+        this( processor, expressionClass, left, Arrays.asList( rights ) );
+    }
+
+    protected MultiPredicateImpl( SQLProcessorAggregator processor, Class<? extends ExpressionType> expressionClass,
+                                  NonBooleanExpression left, List<NonBooleanExpression> rights )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( left, "left" );
+        Objects.requireNonNull( rights, "rights" );
+
+        for( NonBooleanExpression exp : rights )
+        {
+            Objects.requireNonNull( exp, "right" );
+        }
+
+        this._left = left;
+        this._rights = Collections.unmodifiableList( rights );
+    }
+
+    public NonBooleanExpression getLeft()
+    {
+        return this._left;
+    }
+
+    public List<NonBooleanExpression> getRights()
+    {
+        return this._rights;
+    }
+
+    @Override
+    protected boolean doesEqual( ExpressionType another )
+    {
+        return this._left.equals( another.getLeft() ) && this._rights.equals( another.getRights() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NegationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NegationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NegationImpl.java
new file mode 100644
index 0000000..8e294ec
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NegationImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Negation;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NegationImpl extends ComposedBooleanExpressionImpl<Negation>
+    implements Negation
+{
+
+    private final BooleanExpression _negated;
+
+    public NegationImpl( SQLProcessorAggregator processor, BooleanExpression negated )
+    {
+        this( processor, Negation.class, negated );
+    }
+
+    protected NegationImpl( SQLProcessorAggregator processor, Class<? extends Negation> negationClass,
+                            BooleanExpression negated )
+    {
+        super( processor, negationClass );
+        Objects.requireNonNull( negated, "negated" );
+
+        this._negated = negated;
+    }
+
+    public BooleanExpression getNegated()
+    {
+        return this._negated;
+    }
+
+    public Iterator<BooleanExpression> iterator()
+    {
+        return Arrays.asList( this._negated ).iterator();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotBetweenPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotBetweenPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotBetweenPredicateImpl.java
new file mode 100644
index 0000000..d7b68ae
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotBetweenPredicateImpl.java
@@ -0,0 +1,55 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotBetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NotBetweenPredicateImpl extends MultiPredicateImpl<NotBetweenPredicate>
+    implements NotBetweenPredicate
+{
+
+    public NotBetweenPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                    NonBooleanExpression minimum, NonBooleanExpression maximum )
+    {
+        this( processor, NotBetweenPredicate.class, left, minimum, maximum );
+    }
+
+    protected NotBetweenPredicateImpl( SQLProcessorAggregator processor,
+                                       Class<? extends NotBetweenPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression minimum,
+                                       NonBooleanExpression maximum )
+    {
+        super( processor, predicateClass, left, minimum, maximum );
+    }
+
+    public NonBooleanExpression getMaximum()
+    {
+        return this.getRights().get( 1 );
+    }
+
+    public NonBooleanExpression getMinimum()
+    {
+        return this.getRights().get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotEqualsPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotEqualsPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotEqualsPredicateImpl.java
new file mode 100644
index 0000000..5a7e858
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotEqualsPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotEqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NotEqualsPredicateImpl extends BinaryPredicateImpl<NotEqualsPredicate>
+    implements NotEqualsPredicate
+{
+
+    public NotEqualsPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                   NonBooleanExpression right )
+    {
+        this( processor, NotEqualsPredicate.class, left, right );
+    }
+
+    protected NotEqualsPredicateImpl( SQLProcessorAggregator processor,
+                                      Class<? extends NotEqualsPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotInPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotInPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotInPredicateImpl.java
new file mode 100644
index 0000000..fe3a3af
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotInPredicateImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotInPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NotInPredicateImpl extends MultiPredicateImpl<NotInPredicate>
+    implements NotInPredicate
+{
+
+    public NotInPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                               List<NonBooleanExpression> rights )
+    {
+        this( processor, NotInPredicate.class, left, rights );
+    }
+
+    protected NotInPredicateImpl( SQLProcessorAggregator processor, Class<? extends NotInPredicate> predicateClass,
+                                  NonBooleanExpression left, List<NonBooleanExpression> rights )
+    {
+        super( processor, predicateClass, left, rights );
+    }
+
+    public NotInPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                               NonBooleanExpression... rights )
+    {
+        this( processor, NotInPredicate.class, left, rights );
+    }
+
+    protected NotInPredicateImpl( SQLProcessorAggregator processor, Class<? extends NotInPredicate> predicateClass,
+                                  NonBooleanExpression left, NonBooleanExpression... rights )
+    {
+        super( processor, predicateClass, left, rights );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotLikePredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotLikePredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotLikePredicateImpl.java
new file mode 100644
index 0000000..0b18a78
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotLikePredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotLikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NotLikePredicateImpl extends BinaryPredicateImpl<NotLikePredicate>
+    implements NotLikePredicate
+{
+
+    public NotLikePredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        this( processor, NotLikePredicate.class, left, right );
+    }
+
+    protected NotLikePredicateImpl( SQLProcessorAggregator processor, Class<? extends NotLikePredicate> predicateClass,
+                                    NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotRegexpPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotRegexpPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotRegexpPredicateImpl.java
new file mode 100644
index 0000000..3f86c30
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/NotRegexpPredicateImpl.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotRegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class NotRegexpPredicateImpl extends BinaryPredicateImpl<NotRegexpPredicate>
+    implements NotRegexpPredicate
+{
+
+    public NotRegexpPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left,
+                                   NonBooleanExpression right )
+    {
+        this( processor, NotRegexpPredicate.class, left, right );
+    }
+
+    protected NotRegexpPredicateImpl( SQLProcessorAggregator processor,
+                                      Class<? extends NotRegexpPredicate> predicateClass, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/RegexpPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/RegexpPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/RegexpPredicateImpl.java
new file mode 100644
index 0000000..f725100
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/RegexpPredicateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.RegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class RegexpPredicateImpl extends BinaryPredicateImpl<RegexpPredicate>
+    implements RegexpPredicate
+{
+
+    public RegexpPredicateImpl( SQLProcessorAggregator processor, NonBooleanExpression left, NonBooleanExpression right )
+    {
+        this( processor, RegexpPredicate.class, left, right );
+    }
+
+    protected RegexpPredicateImpl( SQLProcessorAggregator processor, Class<? extends RegexpPredicate> predicateClass,
+                                   NonBooleanExpression left, NonBooleanExpression right )
+    {
+        super( processor, predicateClass, left, right );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UnaryPredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UnaryPredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UnaryPredicateImpl.java
new file mode 100644
index 0000000..3c26361
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UnaryPredicateImpl.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UnaryPredicate;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class UnaryPredicateImpl<ExpressionType extends UnaryPredicate> extends
+                                                                                AbstractBooleanExpression<ExpressionType>
+    implements UnaryPredicate
+{
+
+    private final NonBooleanExpression _expression;
+
+    public UnaryPredicateImpl( SQLProcessorAggregator processor, Class<? extends ExpressionType> expressionClass,
+                               NonBooleanExpression expression )
+    {
+        super( processor, expressionClass );
+        Objects.requireNonNull( expression, "expression" );
+
+        this._expression = expression;
+    }
+
+    public NonBooleanExpression getValueExpression()
+    {
+        return this._expression;
+    }
+
+    @Override
+    protected boolean doesEqual( ExpressionType another )
+    {
+        return this._expression.equals( another.getValueExpression() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UniquePredicateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UniquePredicateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UniquePredicateImpl.java
new file mode 100644
index 0000000..19f96fe
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/booleans/UniquePredicateImpl.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.booleans;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.UniquePredicate;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UniquePredicateImpl extends UnaryPredicateImpl<UniquePredicate>
+    implements UniquePredicate
+{
+
+    public UniquePredicateImpl( SQLProcessorAggregator processor, QueryExpression query )
+    {
+        this( processor, UniquePredicate.class, query );
+    }
+
+    protected UniquePredicateImpl( SQLProcessorAggregator processor, Class<? extends UniquePredicate> predicateClass,
+                                   QueryExpression query )
+    {
+        super( processor, predicateClass, query );
+    }
+
+    @Override
+    public QueryExpression getValueExpression()
+    {
+        return (QueryExpression) super.getValueExpression();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/BooleanBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/BooleanBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/BooleanBuilderImpl.java
new file mode 100644
index 0000000..450e263
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/BooleanBuilderImpl.java
@@ -0,0 +1,83 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.booleans;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class BooleanBuilderImpl extends SQLBuilderBase
+    implements BooleanBuilder
+{
+
+    private BooleanExpression _topLevelExpression;
+
+    private final BooleanFactory _factory;
+
+    public BooleanBuilderImpl( SQLProcessorAggregator processor, BooleanFactory factory )
+    {
+        this( processor, factory, Predicate.EmptyPredicate.INSTANCE );
+    }
+
+    public BooleanBuilderImpl( SQLProcessorAggregator processor, BooleanFactory factory, BooleanExpression expression )
+    {
+        super( processor );
+        Objects.requireNonNull( factory, "boolean expression factory" );
+
+        this._factory = factory;
+        this._topLevelExpression = expression;
+    }
+
+    public BooleanBuilder and( BooleanExpression next )
+    {
+        this._topLevelExpression = this._factory.and( this._topLevelExpression, next );
+        return this;
+    }
+
+    public BooleanBuilder or( BooleanExpression next )
+    {
+        this._topLevelExpression = this._factory.or( this._topLevelExpression, next );
+        return this;
+    }
+
+    public BooleanBuilder not()
+    {
+        this._topLevelExpression = this._factory.not( this._topLevelExpression );
+        return this;
+    }
+
+    public BooleanBuilder reset( BooleanExpression newExpression )
+    {
+        this._topLevelExpression = newExpression;
+        return this;
+    }
+
+    public BooleanExpression createExpression()
+    {
+        return this._topLevelExpression == null ? Predicate.EmptyPredicate.INSTANCE : this._topLevelExpression;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/InBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/InBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/InBuilderImpl.java
new file mode 100644
index 0000000..9c6b290
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/booleans/InBuilderImpl.java
@@ -0,0 +1,69 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.booleans;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.InBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.InPredicateImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class InBuilderImpl extends SQLBuilderBase
+    implements InBuilder
+{
+
+    private final NonBooleanExpression _left;
+
+    private final List<NonBooleanExpression> _expressions;
+
+    public InBuilderImpl( SQLProcessorAggregator processor, NonBooleanExpression left )
+    {
+        super( processor );
+        Objects.requireNonNull( left, "left" );
+
+        this._left = left;
+        this._expressions = new ArrayList<NonBooleanExpression>();
+    }
+
+    public InBuilder addValues( NonBooleanExpression... expressions )
+    {
+        Objects.requireNonNull( expressions, "expressions" );
+        for( NonBooleanExpression exp : expressions )
+        {
+            Objects.requireNonNull( exp, "expression" );
+        }
+
+        this._expressions.addAll( Arrays.asList( expressions ) );
+        return this;
+    }
+
+    public InPredicate createExpression()
+    {
+        return new InPredicateImpl( this.getProcessor(), this._left, this._expressions );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ForeignKeyConstraintBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ForeignKeyConstraintBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ForeignKeyConstraintBuilderImpl.java
new file mode 100644
index 0000000..5d4051e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ForeignKeyConstraintBuilderImpl.java
@@ -0,0 +1,140 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ForeignKeyConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.MatchType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.ForeignKeyConstraintImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ForeignKeyConstraintBuilderImpl extends SQLBuilderBase
+    implements ForeignKeyConstraintBuilder
+{
+
+    private final List<String> _sourceColumns;
+    private final List<String> _targetColumns;
+    private TableNameDirect _targetTable;
+    private MatchType _matchType;
+    private ReferentialAction _onUpdate;
+    private ReferentialAction _onDelete;
+
+    private final ColumnsFactory _c;
+
+    public ForeignKeyConstraintBuilderImpl( SQLProcessorAggregator processor, ColumnsFactory c )
+    {
+        super( processor );
+        Objects.requireNonNull( c, "Columns factory" );
+
+        this._c = c;
+
+        this._sourceColumns = new ArrayList<String>();
+        this._targetColumns = new ArrayList<String>();
+    }
+
+    public ForeignKeyConstraint createExpression()
+    {
+        return new ForeignKeyConstraintImpl( this.getProcessor(), this._c.colNames( this._sourceColumns ),
+                                             this._targetTable, this._targetColumns.size() == 0 ? null : this._c.colNames( this._targetColumns ),
+                                             this._matchType, this._onDelete, this._onUpdate );
+    }
+
+    public ForeignKeyConstraintBuilder addSourceColumns( String... columnNames )
+    {
+        for( String name : columnNames )
+        {
+            this._sourceColumns.add( name );
+        }
+        return this;
+    }
+
+    public ForeignKeyConstraintBuilder addTargetColumns( String... columnNames )
+    {
+        for( String name : columnNames )
+        {
+            this._targetColumns.add( name );
+        }
+        return this;
+    }
+
+    public ForeignKeyConstraintBuilder setTargetTableName( TableNameDirect tableName )
+    {
+        this._targetTable = tableName;
+        return this;
+    }
+
+    public ForeignKeyConstraintBuilder setMatchType( MatchType matchType )
+    {
+        this._matchType = matchType;
+        return this;
+    }
+
+    public ForeignKeyConstraintBuilder setOnUpdate( ReferentialAction action )
+    {
+        this._onUpdate = action;
+        return this;
+    }
+
+    public ForeignKeyConstraintBuilder setOnDelete( ReferentialAction action )
+    {
+        this._onDelete = action;
+        return this;
+    }
+
+    public List<String> getSourceColumns()
+    {
+        return this._sourceColumns;
+    }
+
+    public List<String> getTargetColumns()
+    {
+        return this._targetColumns;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._targetTable;
+    }
+
+    public MatchType getMatchType()
+    {
+        return this._matchType;
+    }
+
+    public ReferentialAction getOnUpdate()
+    {
+        return this._onUpdate;
+    }
+
+    public ReferentialAction getOnDelete()
+    {
+        return this._onDelete;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/SchemaDefinitionBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/SchemaDefinitionBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/SchemaDefinitionBuilderImpl.java
new file mode 100644
index 0000000..f8aa750
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/SchemaDefinitionBuilderImpl.java
@@ -0,0 +1,88 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.SchemaDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.schema.SchemaDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SchemaDefinitionBuilderImpl extends SQLBuilderBase
+    implements SchemaDefinitionBuilder
+{
+
+    private String _schemaName;
+    private String _schemaCharset;
+    private final List<SchemaElement> _elements;
+
+    public SchemaDefinitionBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._elements = new ArrayList<SchemaElement>();
+    }
+
+    public SchemaDefinition createExpression()
+    {
+        return new SchemaDefinitionImpl( this.getProcessor(), this._schemaName, this._schemaCharset, this._elements );
+    }
+
+    public SchemaDefinitionBuilder setSchemaName( String schemaName )
+    {
+        this._schemaName = schemaName;
+        return this;
+    }
+
+    public SchemaDefinitionBuilder setSchemaCharset( String charset )
+    {
+        this._schemaCharset = charset;
+        return this;
+    }
+
+    public SchemaDefinitionBuilder addSchemaElements( SchemaElement... elements )
+    {
+        for( SchemaElement el : elements )
+        {
+            this._elements.add( el );
+        }
+        return this;
+    }
+
+    public String getSchemaName()
+    {
+        return this._schemaName;
+    }
+
+    public String getSchemaCharset()
+    {
+        return this._schemaCharset;
+    }
+
+    public List<SchemaElement> getSchemaElements()
+    {
+        return this._elements;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableDefinitionBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableDefinitionBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableDefinitionBuilderImpl.java
new file mode 100644
index 0000000..d4f5241
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableDefinitionBuilderImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableContentsSource;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableScope;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.TableDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableDefinitionBuilderImpl extends SQLBuilderBase
+    implements TableDefinitionBuilder
+{
+
+    private TableScope _scope;
+    private TableNameDirect _name;
+    private TableCommitAction _commitAction;
+    private TableContentsSource _contents;
+
+    public TableDefinitionBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+    }
+
+    public TableDefinition createExpression()
+    {
+        return new TableDefinitionImpl( this.getProcessor(), this._commitAction, this._contents, this._name,
+                                        this._scope );
+    }
+
+    public TableDefinitionBuilder setTableScope( TableScope scope )
+    {
+        this._scope = scope;
+        return this;
+    }
+
+    public TableDefinitionBuilder setTableName( TableNameDirect tableName )
+    {
+        this._name = tableName;
+        return this;
+    }
+
+    public TableDefinitionBuilder setCommitAction( TableCommitAction commitAction )
+    {
+        this._commitAction = commitAction;
+        return this;
+    }
+
+    public TableDefinitionBuilder setTableContentsSource( TableContentsSource contents )
+    {
+        this._contents = contents;
+        return this;
+    }
+
+    public TableScope getTableScope()
+    {
+        return this._scope;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._name;
+    }
+
+    public TableCommitAction getCommitAction()
+    {
+        return this._commitAction;
+    }
+
+    public TableContentsSource getTableContentsSource()
+    {
+        return this._contents;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableElementListBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableElementListBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableElementListBuilderImpl.java
new file mode 100644
index 0000000..0798a66
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/TableElementListBuilderImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableElementListBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.TableElementListImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableElementListBuilderImpl extends SQLBuilderBase
+    implements TableElementListBuilder
+{
+
+    private final List<TableElement> _elements;
+
+    public TableElementListBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._elements = new ArrayList<TableElement>();
+    }
+
+    public TableElementList createExpression()
+    {
+        return new TableElementListImpl( this.getProcessor(), this._elements );
+    }
+
+    public TableElementListBuilder addTableElement( TableElement element )
+    {
+        this._elements.add( element );
+        return this;
+    }
+
+    public List<TableElement> getTableElements()
+    {
+        return this._elements;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/UniqueConstraintBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/UniqueConstraintBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/UniqueConstraintBuilderImpl.java
new file mode 100644
index 0000000..9668a2c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/UniqueConstraintBuilderImpl.java
@@ -0,0 +1,83 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.UniqueConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.grammar.factories.ColumnsFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.table.UniqueConstraintImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UniqueConstraintBuilderImpl extends SQLBuilderBase
+    implements UniqueConstraintBuilder
+{
+
+    private UniqueSpecification _uniqueness;
+    private final List<String> _columns;
+
+    private final ColumnsFactory _c;
+
+    public UniqueConstraintBuilderImpl( SQLProcessorAggregator processor, ColumnsFactory c )
+    {
+        super( processor );
+        Objects.requireNonNull( c, "Columns factory" );
+
+        this._c = c;
+        this._columns = new ArrayList<String>();
+    }
+
+    public UniqueConstraint createExpression()
+    {
+        return new UniqueConstraintImpl( this.getProcessor(), this._c.colNames( this._columns ), this._uniqueness );
+    }
+
+    public UniqueConstraintBuilder setUniqueness( UniqueSpecification uniqueness )
+    {
+        this._uniqueness = uniqueness;
+        return this;
+    }
+
+    public UniqueConstraintBuilder addColumns( String... columnNames )
+    {
+        for( String col : columnNames )
+        {
+            this._columns.add( col );
+        }
+        return this;
+    }
+
+    public UniqueSpecification getUniqueness()
+    {
+        return this._uniqueness;
+    }
+
+    public List<String> getColumns()
+    {
+        return this._columns;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ViewDefinitionBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ViewDefinitionBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ViewDefinitionBuilderImpl.java
new file mode 100644
index 0000000..f3dd53e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/definition/ViewDefinitionBuilderImpl.java
@@ -0,0 +1,110 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.definition;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ViewDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewCheckOption;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.definition.view.ViewDefinitionImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ViewDefinitionBuilderImpl extends SQLBuilderBase
+    implements ViewDefinitionBuilder
+{
+
+    private Boolean _isRecursive;
+    private TableNameDirect _name;
+    private QueryExpression _query;
+    private ViewCheckOption _viewCheck;
+    private ViewSpecification _viewSpec;
+
+    public ViewDefinitionBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+    }
+
+    public ViewDefinition createExpression()
+    {
+        return new ViewDefinitionImpl( this.getProcessor(), this._name, this._query, this._viewSpec, this._viewCheck,
+                                       this._isRecursive );
+    }
+
+    public ViewDefinitionBuilder setRecursive( Boolean isRecursive )
+    {
+        this._isRecursive = isRecursive;
+        return this;
+    }
+
+    public ViewDefinitionBuilder setViewName( TableNameDirect viewName )
+    {
+        this._name = viewName;
+        return this;
+    }
+
+    public ViewDefinitionBuilder setQuery( QueryExpression query )
+    {
+        this._query = query;
+        return this;
+    }
+
+    public ViewDefinitionBuilder setViewCheckOption( ViewCheckOption viewCheck )
+    {
+        this._viewCheck = viewCheck;
+        return this;
+    }
+
+    public ViewDefinitionBuilder setViewSpecification( ViewSpecification spec )
+    {
+        this._viewSpec = spec;
+        return this;
+    }
+
+    public Boolean isRecursive()
+    {
+        return this._isRecursive;
+    }
+
+    public TableNameDirect getViewName()
+    {
+        return this._name;
+    }
+
+    public QueryExpression getQueryExpression()
+    {
+        return this._query;
+    }
+
+    public ViewCheckOption getViewCheckOption()
+    {
+        return this._viewCheck;
+    }
+
+    public ViewSpecification getViewSpecification()
+    {
+        return this._viewSpec;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/ColumnSourceByValuesBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/ColumnSourceByValuesBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/ColumnSourceByValuesBuilderImpl.java
new file mode 100644
index 0000000..f106dbf
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/ColumnSourceByValuesBuilderImpl.java
@@ -0,0 +1,93 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.modification;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.ColumnSourceByValuesBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.ColumnNameListImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.ColumnSourceByValuesImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnSourceByValuesBuilderImpl extends SQLBuilderBase
+    implements ColumnSourceByValuesBuilder
+{
+
+    private final List<ValueExpression> _values;
+
+    private final List<String> _columnNames;
+
+    public ColumnSourceByValuesBuilderImpl( SQLProcessorAggregator processor )
+    {
+        super( processor );
+        this._values = new ArrayList<ValueExpression>();
+        this._columnNames = new ArrayList<String>();
+    }
+
+    public ColumnSourceByValues createExpression()
+    {
+        ColumnNameList list = null;
+        if( !this._columnNames.isEmpty() )
+        {
+            list = new ColumnNameListImpl( this.getProcessor(), this._columnNames );
+        }
+        return new ColumnSourceByValuesImpl( this.getProcessor(), list, this._values );
+    }
+
+    public ColumnSourceByValuesBuilder addValues( ValueExpression... values )
+    {
+        for( ValueExpression exp : values )
+        {
+            Objects.requireNonNull( exp, "value" );
+            this._values.add( exp );
+        }
+        return this;
+    }
+
+    public List<ValueExpression> getValues()
+    {
+        return Collections.unmodifiableList( this._values );
+    }
+
+    public ColumnSourceByValuesBuilder addColumnNames( String... columnNames )
+    {
+        for( String str : columnNames )
+        {
+            Objects.requireNonNull( str, "column name" );
+            this._columnNames.add( str );
+        }
+
+        return this;
+    }
+
+    public List<String> getColumnNames()
+    {
+        return Collections.unmodifiableList( this._columnNames );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/DeleteBySearchBuilderImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/DeleteBySearchBuilderImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/DeleteBySearchBuilderImpl.java
new file mode 100644
index 0000000..b5dade8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/builders/modification/DeleteBySearchBuilderImpl.java
@@ -0,0 +1,71 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.builders.modification;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.DeleteBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLBuilderBase;
+import org.apache.polygene.library.sql.generator.implementation.grammar.modification.DeleteBySearchImpl;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DeleteBySearchBuilderImpl extends SQLBuilderBase
+    implements DeleteBySearchBuilder
+{
+
+    private final BooleanBuilder _whereBuilder;
+
+    private TargetTable _targetTable;
+
+    public DeleteBySearchBuilderImpl( SQLProcessorAggregator processor, BooleanBuilder whereBuilder )
+    {
+        super( processor );
+        Objects.requireNonNull( whereBuilder, "where builder" );
+        this._whereBuilder = whereBuilder;
+    }
+
+    public DeleteBySearch createExpression()
+    {
+
+        return new DeleteBySearchImpl( this.getProcessor(), this._targetTable, this._whereBuilder.createExpression() );
+    }
+
+    public DeleteBySearchBuilder setTargetTable( TargetTable table )
+    {
+        Objects.requireNonNull( table, "table" );
+        this._targetTable = table;
+        return this;
+    }
+
+    public TargetTable getTargetTable()
+    {
+        return this._targetTable;
+    }
+
+    public BooleanBuilder getWhere()
+    {
+        return this._whereBuilder;
+    }
+}


[15/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElement.java
new file mode 100644
index 0000000..2b54f3e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElement.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is a common interface for table elements in the table element list of table definition. It is usually column
+ * definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ * @see ColumnDefinition
+ */
+public interface TableElement
+    extends Typeable<TableElement>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElementList.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElementList.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElementList.java
new file mode 100644
index 0000000..5de5dbd
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableElementList.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import java.util.List;
+
+/**
+ * This syntax element represents the table element list in table definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ * @see TableElement
+ */
+public interface TableElementList
+    extends TableContentsSource
+{
+    /**
+     * Returns a list of table elements. Will be non-empty.
+     *
+     * @return A list of table elements. Will be non-empty.
+     */
+    List<TableElement> getElementList();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableScope.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableScope.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableScope.java
new file mode 100644
index 0000000..518af9e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/TableScope.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This enum is for table scope in table definition. The scope may be either {@link #GLOBAL_TEMPORARY} or
+ * {@link #LOCAL_TEMPORARY}.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public final class TableScope
+{
+
+    /**
+     * This value represents the {@code GLOBAL TEMPORARY} table.
+     */
+    public static final TableScope GLOBAL_TEMPORARY = new TableScope();
+
+    /**
+     * This value represents the {@code LOCAL TEMPORARY} table.
+     */
+    public static final TableScope LOCAL_TEMPORARY = new TableScope();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueConstraint.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueConstraint.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueConstraint.java
new file mode 100644
index 0000000..1315f27
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueConstraint.java
@@ -0,0 +1,48 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * This constraint defines the columns to be unique ({@code UNIQUE(col1, col2, ...)}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UniqueConstraint
+    extends TableConstraint
+{
+
+    /**
+     * Returns the kind of uniqueness: either primary key constraint ({@code PRIMARY KEY}), or normal uniqueness
+     * constraint ({@code UNIQUE}).
+     *
+     * @return The kind of uniqueness.
+     * @see UniqueSpecification
+     */
+    UniqueSpecification getUniquenessKind();
+
+    /**
+     * Returns the names of columns that are unique.
+     *
+     * @return The names of columns that are unique.
+     */
+    ColumnNameList getColumnNameList();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueSpecification.java
new file mode 100644
index 0000000..8aea72b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/UniqueSpecification.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table;
+
+/**
+ * This syntax element represents the two kind of uniqueness of a column(s): either that the column(s) are
+ * {@code PRIMARY KEY} ({@link #PRIMARY_KEY}), or {@code UNIQUE} ({@link #UNIQUE}).
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class UniqueSpecification
+{
+
+    /**
+     * Represents the primary key uniqueness ({@code PRIMARY KEY(col1, col2, ...)}).
+     */
+    public static final UniqueSpecification PRIMARY_KEY = new UniqueSpecification();
+
+    /**
+     * Represents the normal uniqueness ({@code UNIQUE(col1, col2, ...)}).
+     */
+    public static final UniqueSpecification UNIQUE = new UniqueSpecification();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/package-info.java
new file mode 100644
index 0000000..12745a6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains syntax interfaces for {@code CREATE TABLE} statement.
+ */
+package org.apache.polygene.library.sql.generator.grammar.definition.table;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/pgsql/PgSQLTableCommitAction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/pgsql/PgSQLTableCommitAction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/pgsql/PgSQLTableCommitAction.java
new file mode 100644
index 0000000..04ca291
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/table/pgsql/PgSQLTableCommitAction.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.table.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+
+/**
+ * This class extends the default table commit actions ({@code PRESERVE/DELETE ROWS}) to include third option,
+ * {@code DROP}, supported in PostgreSQL.
+ *
+ * @author Stanislav Muhametsin
+ */
+public class PgSQLTableCommitAction
+{
+    /**
+     * The table commit action to {@code DROP} table when transaction ends.
+     */
+    public static TableCommitAction DROP = new TableCommitAction();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/RegularViewSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/RegularViewSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/RegularViewSpecification.java
new file mode 100644
index 0000000..0c31fb5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/RegularViewSpecification.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.view;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * This syntax element represents the column name list in view definition.
+ *
+ * @author Stanislav Muhametsin
+ * @see ViewDefinition
+ */
+public interface RegularViewSpecification
+    extends ViewSpecification
+{
+
+    /**
+     * Returns the column names of this view. Will be {@code null} if none are specified.
+     *
+     * @return The column names of this view. Will be {@code null} if none are specified.
+     */
+    ColumnNameList getColumns();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewCheckOption.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewCheckOption.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewCheckOption.java
new file mode 100644
index 0000000..4579615
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewCheckOption.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.view;
+
+/**
+ * View check option is typically either {@link #CASCADED} or {@link #LOCAL}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class ViewCheckOption
+{
+
+    /**
+     * This is the cascaded view check option.
+     */
+    public static final ViewCheckOption CASCADED = new ViewCheckOption();
+
+    /**
+     * This is the local view check option.
+     */
+    public static final ViewCheckOption LOCAL = new ViewCheckOption();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewDefinition.java
new file mode 100644
index 0000000..769dfd1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewDefinition.java
@@ -0,0 +1,72 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.view;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaDefinitionStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * This syntax element represents the {@code CREATE VIEW} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ViewDefinition
+    extends SchemaDefinitionStatement, SchemaElement
+{
+
+    /**
+     * Returns {@code true} if the view is defined to be {@code RECURSIVE}, {@code false} otherwise.
+     *
+     * @return {@code true} if the view is defined to be {@code RECURSIVE}, {@code false} otherwise.
+     */
+    Boolean isRecursive();
+
+    /**
+     * Returns the name of this view.
+     *
+     * @return The name of this view.
+     */
+    TableNameDirect getViewName();
+
+    /**
+     * Returns the view specification.
+     *
+     * @return The view specification.
+     * @see ViewSpecification
+     */
+    ViewSpecification getViewSpecification();
+
+    /**
+     * Returns the query defining the contents for this view.
+     *
+     * @return The query defining the contents for this view.
+     */
+    QueryExpression getViewQuery();
+
+    /**
+     * Returns the view check option. Will be {@code null} if none defined.
+     *
+     * @return The view check option. Will be {@code null} if none defined.
+     * @see ViewCheckOption
+     */
+    ViewCheckOption getViewCheckOption();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewSpecification.java
new file mode 100644
index 0000000..71dc8a3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/ViewSpecification.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.definition.view;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This a common interface for view specification (typically column name list).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ViewSpecification
+    extends Typeable<ViewSpecification>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/package-info.java
new file mode 100644
index 0000000..18143ce
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/definition/view/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains syntax interfaces required for {@code CREATE VIEW} statement.
+ */
+package org.apache.polygene.library.sql.generator.grammar.definition.view;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/BooleanFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/BooleanFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/BooleanFactory.java
new file mode 100644
index 0000000..1a99523
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/BooleanFactory.java
@@ -0,0 +1,283 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest.TestType;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanTest.TruthValue;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Conjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Disjunction;
+import org.apache.polygene.library.sql.generator.grammar.booleans.EqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.ExistsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.GreaterThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNotNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.IsNullPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessOrEqualPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LessThanPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.LikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Negation;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotBetweenPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotEqualsPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotInPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotLikePredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.NotRegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.Predicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.RegexpPredicate;
+import org.apache.polygene.library.sql.generator.grammar.booleans.UniquePredicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.InBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory for creating various {@link BooleanExpression}s. This factory is obtainable from {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ */
+public interface BooleanFactory
+{
+
+    /**
+     * Creates new {@link EqualsPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link EqualsPredicate}.
+     */
+    EqualsPredicate eq( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link NotEqualsPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link NotEqualsPredicate}.
+     */
+    NotEqualsPredicate neq( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link LessThanPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link LessThanPredicate}.
+     */
+    LessThanPredicate lt( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link LessOrEqualPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link LessOrEqualPredicate}.
+     */
+    LessOrEqualPredicate leq( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link GreaterThanPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link GreaterThanPredicate}.
+     */
+    GreaterThanPredicate gt( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link GreaterOrEqualPredicate}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link GreaterOrEqualPredicate}.
+     */
+    GreaterOrEqualPredicate geq( NonBooleanExpression left, NonBooleanExpression right );
+
+    /**
+     * Creates new {@link IsNullPredicate}.
+     *
+     * @param what The expression for the predicate.
+     * @return The new {@link IsNullPredicate}.
+     */
+    IsNullPredicate isNull( NonBooleanExpression what );
+
+    /**
+     * Creates new {@link IsNotNullPredicate}.
+     *
+     * @param what The expression for the predicate.
+     * @return The new {@link IsNotNullPredicate}.
+     */
+    IsNotNullPredicate isNotNull( NonBooleanExpression what );
+
+    /**
+     * Creates new {@link Negation}.
+     *
+     * @param what The expression to be negated.
+     * @return The new {@link Negation}.
+     */
+    Negation not( BooleanExpression what );
+
+    /**
+     * Creates new {@link Conjunction}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link Conjunction}.
+     */
+    Conjunction and( BooleanExpression left, BooleanExpression right );
+
+    /**
+     * Creates new {@link Disjunction}.
+     *
+     * @param left  The left-side expression.
+     * @param right The right-side expression.
+     * @return The new {@link Disjunction}.
+     */
+    Disjunction or( BooleanExpression left, BooleanExpression right );
+
+    /**
+     * Creates new {@link BetweenPredicate}.
+     *
+     * @param left    What to be between.
+     * @param minimum The minimum value.
+     * @param maximum The maximum value.
+     * @return The new {@link BetweenPredicate}.
+     */
+    BetweenPredicate between( NonBooleanExpression left, NonBooleanExpression minimum,
+                              NonBooleanExpression maximum );
+
+    /**
+     * Creates new {@link NotBetweenPredicate}.
+     *
+     * @param left    What not to be between.
+     * @param minimum The minimum value
+     * @param maximum The maximum value.
+     * @return The new {@link NotBetweenPredicate}.
+     */
+    NotBetweenPredicate notBetween( NonBooleanExpression left, NonBooleanExpression minimum,
+                                    NonBooleanExpression maximum );
+
+    /**
+     * Creates new {@link InPredicate}.
+     *
+     * @param what   What to be in accepted values.
+     * @param values The accepted values.
+     * @return The new {@link InPredicate}.
+     */
+    InPredicate in( NonBooleanExpression what, NonBooleanExpression... values );
+
+    /**
+     * Returns a builder for {@link InPredicate}.
+     *
+     * @param what What to be in accepted values.
+     * @return The builder for {@link InPredicate}.
+     */
+    InBuilder inBuilder( NonBooleanExpression what );
+
+    /**
+     * Creates new {@link NotInPredicate}.
+     *
+     * @param what   What not to be in values.
+     * @param values The values.
+     * @return The new {@link NotInPredicate}.
+     */
+    NotInPredicate notIn( NonBooleanExpression what, NonBooleanExpression... values );
+
+    /**
+     * Creates new {@link LikePredicate}.
+     *
+     * @param what    What to be like something.
+     * @param pattern The pattern to match.
+     * @return The new {@link LikePredicate}
+     */
+    LikePredicate like( NonBooleanExpression what, NonBooleanExpression pattern );
+
+    /**
+     * Creates new {@link NotLikePredicate}.
+     *
+     * @param what    What not to be like something.
+     * @param pattern The pattern.
+     * @return The new {@link NotLikePredicate}.
+     */
+    NotLikePredicate notLike( NonBooleanExpression what, NonBooleanExpression pattern );
+
+    /**
+     * Creates new {@link RegexpPredicate}.
+     *
+     * @param what    What to match.
+     * @param pattern The pattern to match.
+     * @return The new {@link NotRegexpPredicate}.
+     */
+    RegexpPredicate regexp( NonBooleanExpression what, NonBooleanExpression pattern );
+
+    /**
+     * Creates new {@link NotRegexpPredicate}.
+     *
+     * @param what    What would be not matching the pattern.
+     * @param pattern The pattern to use.
+     * @return The new {@link NotRegexpPredicate}.
+     */
+    NotRegexpPredicate notRegexp( NonBooleanExpression what, NonBooleanExpression pattern );
+
+    /**
+     * Creates new {@link ExistsPredicate}.
+     *
+     * @param query A query to use.
+     * @return The new {@link ExistsPredicate}.
+     */
+    ExistsPredicate exists( QueryExpression query );
+
+    /**
+     * Creates new {@link UniquePredicate}.
+     *
+     * @param query A query to use.
+     * @return The new {@link UniquePredicate}.
+     */
+    UniquePredicate unique( QueryExpression query );
+
+    /**
+     * Creates new {@link BooleanTest}.
+     *
+     * @param expression The expresssion to test.
+     * @param testType   The test type to use.
+     * @param truthValue The truth value to use.
+     * @return The new {@link BooleanTest}.
+     */
+    BooleanTest test( BooleanExpression expression, TestType testType, TruthValue truthValue );
+
+    /**
+     * Returns new {@link BooleanBuilder} with {@link Predicate.EmptyPredicate} as initial value.
+     *
+     * @return The new {@link BooleanBuilder}.
+     */
+    BooleanBuilder booleanBuilder();
+
+    /**
+     * Returns new {@link BooleanBuilder} with given boolean expression as initial value.
+     *
+     * @param first The initial value for boolean expression.
+     * @return The new {@link BooleanBuilder}.
+     */
+    BooleanBuilder booleanBuilder( BooleanExpression first );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ColumnsFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ColumnsFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ColumnsFactory.java
new file mode 100644
index 0000000..7fd5299
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ColumnsFactory.java
@@ -0,0 +1,85 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import java.util.Collection;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferenceByName;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory to create various expressions related to columns. This factory is obtainable from {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ */
+public interface ColumnsFactory
+{
+
+    /**
+     * Creates column reference, which has value of some expression.
+     *
+     * @param expression The expression for the column.
+     * @return The new {@link ColumnReferenceByExpression}.
+     */
+    ColumnReferenceByExpression colExp( ValueExpression expression );
+
+    /**
+     * <p>
+     * Creates column reference, which references column by name, without table name.
+     * </p>
+     * <p>
+     * Calling this method is equivalent in calling {@link #colName(String, String)} and passing {@code null} as first
+     * argument.
+     * </p>
+     *
+     * @param colName The name of the column.
+     * @return The new {@link ColumnReferenceByName}.
+     */
+    ColumnReferenceByName colName( String colName );
+
+    /**
+     * Creates column reference, which reference column by its name and by name of table, to which it belongs.
+     *
+     * @param tableName The name of the table. May be {@code null}.
+     * @param colName   The name of the column.
+     * @return The new {@link ColumnReferenceByName}.
+     */
+    ColumnReferenceByName colName( String tableName, String colName );
+
+    /**
+     * Constructs new {@link ColumnNameList}.
+     *
+     * @param names The column names. At least one element must be present.
+     * @return The new {@link ColumnNameList}.
+     */
+    ColumnNameList colNames( String... names );
+
+    /**
+     * Constructs new {@link ColumnNameList} using specified column names. A new copy of List will be allocated for the
+     * {@link ColumnNameList}.
+     *
+     * @param names The column names. Must contain at least one name.
+     * @return The new {@link ColumnNameList}.
+     */
+    ColumnNameList colNames( Collection<String> names );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DataTypeFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DataTypeFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DataTypeFactory.java
new file mode 100644
index 0000000..85ffeed
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DataTypeFactory.java
@@ -0,0 +1,363 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.BigInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Decimal;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.DoublePrecision;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.IntervalDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Real;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLBoolean;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDate;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInterval;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.UserDefinedType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+
+/**
+ * This is factory for creating SQL data types. Typically required when defining tables.
+ *
+ * @author Stanislav Muhametsin
+ * @see TableDefinition
+ */
+public interface DataTypeFactory
+{
+
+    /**
+     * Creates data type representing {@code BIGINT}.
+     *
+     * @return Data type representing {@code BIGINT}.
+     */
+    BigInt bigInt();
+
+    /**
+     * <p>
+     * Creates plain {@code DECIMAL} type. Calling this method is equivalent to calling
+     * {@link #decimal(Integer, Integer)} and passing {@code null} as both parameters.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @return The new {@code DECIMAL} type.
+     */
+    Decimal decimal();
+
+    /**
+     * <p>
+     * Creates {@code DECIMAL(p)} type, where {@code p} is given precision. Calling this method is equivalent to calling
+     * {@link #decimal(Integer, Integer)} and passing {@code null} as second parameter.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @param precision The precision for this {@code DECIMAL}. May be {@code null} to create plain {@code DECIMAL}
+     *                  type.
+     * @return The new {@code DECIMAL} type.
+     */
+    Decimal decimal( Integer precision );
+
+    /**
+     * <p>
+     * Creates {@code DECIMAL(p,s)} type, where {@code p} is given precision, and {@code s} is given scale.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @param precision The precision for this {@code DECIMAL}. May be {@code null} to create plain {@code DECIMAL}.
+     * @param scale     The scale for this {@code DECIMAL}. Is ignored if {@code precision} is {@code null}.
+     * @return The new {@code DECIMAL} type.
+     */
+    Decimal decimal( Integer precision, Integer scale );
+
+    /**
+     * Creates data type representing {@code DOUBLE PRECISION}.
+     *
+     * @return Data type representing {@code DOUBLE PRECISION}.
+     */
+    DoublePrecision doublePrecision();
+
+    /**
+     * <p>
+     * Creates plain {@code NUMERIC} type. Calling this method is equivalent to calling
+     * {@link #numeric(Integer, Integer)} and passing {@code null} as both parameters.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @return The new {@code NUMERIC} type.
+     */
+    Numeric numeric();
+
+    /**
+     * <p>
+     * Creates {@code NUMERIC(p)} type, where {@code p} is given precision. Calling this method is equivalent to calling
+     * {@link #numeric(Integer, Integer)} and passing {@code null} as second parameter.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @param precision The precision for this {@code NUMERIC}. May be {@code null} to create plain {@code NUMERIC}
+     *                  type.
+     * @return The new {@code NUMERIC} type.
+     */
+    Numeric numeric( Integer precision );
+
+    /**
+     * <p>
+     * Creates {@code NUMERIC(p,s)} type, where {@code p} is given precision, and {@code s} is given scale.
+     * </p>
+     * <p>
+     * The site http://intelligent-enterprise.informationweek.com/000626/celko.jhtml explains difference between
+     * {@code NUMERIC} and {@code DECIMAL}:<br/>
+     * The difference between DECIMAL(s,p) and NUMERIC(s,p) is subtle in the SQL-92 Standard -- DECIMAL(s,p) must be
+     * exactly as precise as declared, while NUMERIC(s,p) must be at least as precise as declared.
+     * </p>
+     *
+     * @param precision The precision for this {@code NUMERIC}. May be {@code null} to create plain {@code NUMERIC}.
+     * @param scale     The scale for this {@code NUMERIC}. Is ignored if {@code precision} is {@code null}.
+     * @return The new {@code NUMERIC} type.
+     */
+    Numeric numeric( Integer precision, Integer scale );
+
+    /**
+     * Creates data type representing {@code REAL}.
+     *
+     * @return Data type representing {@code REAL}.
+     */
+    Real real();
+
+    /**
+     * Creates data type representing {@code SMALLINT}.
+     *
+     * @return Data type representing {@code SMALLINT}.
+     */
+    SmallInt smallInt();
+
+    /**
+     * Creates data type representing {@code BOOLEAN}.
+     *
+     * @return Data type representing {@code BOOLEAN}.
+     */
+    SQLBoolean sqlBoolean();
+
+    /**
+     * Creates a new {@code CHARACTER} type. Calling this method is equivalent to calling {@link #sqlChar(Integer)} and
+     * passing {@code null} as parameter.
+     *
+     * @return New {@code CHARACTER} type.
+     */
+    SQLChar sqlChar();
+
+    /**
+     * Creates a new {@code CHARACTER} type.
+     *
+     * @param length The length for this {@code CHARACTER}. May be {@code null}.
+     * @return New {@code CHARACTER} type.
+     */
+    SQLChar sqlChar( Integer length );
+
+    /**
+     * Creates a new {@code CHARACTER VARYING} type. Calling this method is equivalent to calling
+     * {@link #sqlVarChar(Integer)} and passing {@code null} as parameter.
+     *
+     * @return New {@code CHARACTER VARYING} type.
+     */
+    SQLChar sqlVarChar();
+
+    /**
+     * Creates a new {@code CHARACTER VARYING} type.
+     *
+     * @param length The length for this {@code CHARACTER VARYING}. May be {@code null}.
+     * @return New {@code CHARACTER VARYING} type.
+     */
+    SQLChar sqlVarChar( Integer length );
+
+    /**
+     * Creates a {@code DATE} type.
+     *
+     * @return New {@code DATE} type.
+     */
+    SQLDate date();
+
+    /**
+     * Creates new instance of {@code FLOAT} type. Calling this method is equivalent to calling
+     * {@link #sqlFloat(Integer)} and passing {@code null} as argument.
+     *
+     * @return New {@code FLOAt} type.
+     */
+    SQLFloat sqlFloat();
+
+    /**
+     * Creates new instance of {@code FLOAT} type.
+     *
+     * @param precision The precision for this {@code FLOAT} type. May be {@code null}.
+     * @return New {@code FLOAT} type.
+     */
+    SQLFloat sqlFloat( Integer precision );
+
+    /**
+     * Creates new instance of {@code INTEGER} type.
+     *
+     * @return New {@code INTEGER} type.
+     */
+    SQLInteger integer();
+
+    /**
+     * Creates a new <b>year-month</b> {@code INTERVAL}.
+     *
+     * @param startField          The type of start field for this {@code INTERVAL}. Must be either {@link IntervalDataType#YEAR}
+     *                            or {@link IntervalDataType#MONTH}.
+     * @param startFieldPrecision The precision for the start field. May be {@code null} if none specified.
+     * @param endField            The type of end field for this {@code INTERVAL}. May be {@code null} for single date interval. If
+     *                            it is not {@code null}, must be either {@link IntervalDataType#YEAR} or {@link IntervalDataType#MONTH}
+     *                            .
+     * @return The new {@code INTERVAL} with specified values.
+     * @throws NullPointerException     If {@code startField} is {@code null}.
+     * @throws IllegalArgumentException If requirements for {@code startField} or {@code endField} fail.
+     */
+    SQLInterval yearMonthInterval( IntervalDataType startField, Integer startFieldPrecision,
+                                   IntervalDataType endField );
+
+    /**
+     * Creates a new <b>day-time</b> {@code INTERVAL}.
+     *
+     * @param startField          The type of start field for this {@code INTERVAL}. Must not be {@link IntervalDataType#YEAR}
+     *                            nor {@link IntervalDataType#MONTH}.
+     * @param startFieldPrecision The precision for the start field. May {@code null} if none specified.
+     * @param endField            The type of end field for this {@code INTERVAL}. May be {@code null} for single day-time
+     *                            interval. If it is not {@code null}, it must not be {@link IntervalDataType#YEAR} nor
+     *                            {@link IntervalDataType#MONTH}.
+     * @param secondFracs         The fractional precision for when end field is {@link IntervalDataType#SECOND} or when this is
+     *                            single day-time interval and start field is {@link IntervalDataType#SECOND}. Otherwise this value is
+     *                            ignored.
+     * @return The new {@code INTERVAL}.
+     * @throws NullPointerException     If {@code startField} is {@code null}.
+     * @throws IllegalArgumentException If requirements for {@code startField} or {@code endField} fail, or if when
+     *                                  using single day-time interval with type {@link IntervalDataType#SECOND}, and {@code secondFracs}
+     *                                  is specified, but {@code startFieldPrecision} is not specified.
+     */
+    SQLInterval dayTimeInterval( IntervalDataType startField, Integer startFieldPrecision,
+                                 IntervalDataType endField, Integer secondFracs );
+
+    /**
+     * Creates {@code TIME} type with unspecified precision and unspecified value for including time zone. Calling this
+     * method is equivalent to calling {@link #time(Integer, Boolean)} and pass {@code null} as both parameters.
+     *
+     * @return {@code TIME} type without precision and unspecified value for including time zone.
+     */
+    SQLTime time();
+
+    /**
+     * Creates {@code TIME} type with given precision and unspecified value for including time zone. Calling this method
+     * is equivalent to calling {@link #time(Integer, Boolean)} and pass {@code null} as second parameter.
+     *
+     * @param precision The precision for {@code TIME}. May be {@code null}.
+     * @return {@code TIME} type with given precision and unspecified value for including time zone.
+     */
+    SQLTime time( Integer precision );
+
+    /**
+     * Creates {@code TIME} type with unspecified precision and given value for including time zone. Calling this method
+     * is equivalent to calling {@link #time(Integer, Boolean)} and pass {@code null} as first parameter.
+     *
+     * @param withTimeZone Whether to include time zone. May be {@code null} if no decision is wanted.
+     * @return {@code TIME} type with unspecified precision and given value for including time zone.
+     */
+    SQLTime time( Boolean withTimeZone );
+
+    /**
+     * Creates {@code TIME} type with given precision and whether to include time zone.
+     *
+     * @param precision    The precision for {@code TIME}. May be {@code null}.
+     * @param withTimeZone Whether to include time zone. May be {@code null} if no decision is wanted.
+     * @return {@code TIME} type with given precision and whether to include time zone.
+     */
+    SQLTime time( Integer precision, Boolean withTimeZone );
+
+    /**
+     * Creates {@code TIMESTAMP} type with unspecified precision and unspecified value for including time zone. Calling
+     * this method is equivalent to calling {@link #timeStamp(Integer, Boolean)} and pass {@code null} as both
+     * parameters.
+     *
+     * @return {@code TIMESTAMP} type without precision and unspecified value for including time zone.
+     */
+    SQLTimeStamp timeStamp();
+
+    /**
+     * Creates {@code TIMESTAMP} type with given precision and unspecified value for including time zone. Calling this
+     * method is equivalent to calling {@link #timeStamp(Integer, Boolean)} and pass {@code null} as second parameter.
+     *
+     * @param precision The precision for {@code TIME}. May be {@code null}.
+     * @return {@code TIMESTAMP} type with given precision and unspecified value for including time zone.
+     */
+    SQLTimeStamp timeStamp( Integer precision );
+
+    /**
+     * Creates {@code TIMESTAMP} type with unspecified precision and given value for including time zone. Calling this
+     * method is equivalent to calling {@link #timeStamp(Integer, Boolean)} and pass {@code null} as first parameter.
+     *
+     * @param withTimeZone Whether to include time zone. May be {@code null} if no decision is wanted.
+     * @return {@code TIMESTAMP} type with unspecified precision and given value for including time zone.
+     */
+    SQLTimeStamp timeStamp( Boolean withTimeZone );
+
+    /**
+     * Creates {@code TIMESTAMP} type with given precision and whether to include time zone.
+     *
+     * @param precision    The precision for {@code TIMESTAMP}. May be {@code null}.
+     * @param withTimeZone Whether to include time zone. May be {@code null} if no decision is wanted.
+     * @return {@code TIMESTAMP} type with given precision and whether to include time zone.
+     */
+    SQLTimeStamp timeStamp( Integer precision, Boolean withTimeZone );
+
+    /**
+     * Creates a user-defined type which will be inserted into SQL statement as-such.
+     *
+     * @param textualContent The textual contents for user-defined type.
+     * @return Syntax element for user defined type.
+     */
+    UserDefinedType userDefined( String textualContent );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DefinitionFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DefinitionFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DefinitionFactory.java
new file mode 100644
index 0000000..850cbfe
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/DefinitionFactory.java
@@ -0,0 +1,253 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ForeignKeyConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.SchemaDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.TableElementListBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.UniqueConstraintBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.definition.ViewDefinitionBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.CheckConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.LikeClause;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+
+/**
+ * This is factory for creating builders and syntax elements related to SQL Data Definition (typically {@code CREATE}
+ * statements).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DefinitionFactory
+{
+
+    /**
+     * Creates an empty builder for {@code CREATE SCHEMA} statement.
+     *
+     * @return An empty builder for {@code CREATE SCHEMA} statement.
+     */
+    SchemaDefinitionBuilder createSchemaDefinitionBuilder();
+
+    /**
+     * Creates an empty builder for {@code CREATE TABLE} statement.
+     *
+     * @return An empty builder for {@code CREATE TABLE} statement.
+     */
+    TableDefinitionBuilder createTableDefinitionBuilder();
+
+    /**
+     * Creates an empty builder for defining columns and constraints for {@code CREATE TABLE} statement.
+     *
+     * @return An empty builder for defining columns and constraints for {@code CREATE TABLE} statement.
+     * @see TableDefinition
+     */
+    TableElementListBuilder createTableElementListBuilder();
+
+    /**
+     * Creates a new definition of column with specified name and data type. Invoking this method is equivalent to
+     * invoking {@link #createColumnDefinition(String, String, String, Boolean)} and pass {@code null} and {@code true}
+     * as last two parameters (meaning that there is no default value for column, and it may have {@code NULL} values).
+     *
+     * @param columnName     The name of the column.
+     * @param columnDataType The data type of the column.
+     * @return The syntax element for definition of column with specified name and data type.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     */
+    ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType );
+
+    /**
+     * Creates a new definition of column with specified name, data type, and {@code NULL} value policy. Invoking this
+     * method is equivalent to invoking {@link #createColumnDefinition(String, String, String, Boolean)} and pass
+     * {@code null} and {@code mayBeNull} as last two parameters (meaning that there is no default value for column).
+     *
+     * @param columnName     The name of the column.
+     * @param columnDataType The data type of the column.
+     * @param mayBeNull      The {@code NULL} value policy. Setting this to {@code false} is same as specifying
+     *                       {@code NOT NULL} in column definition in SQL.
+     * @return The syntax element for definition of column with specified name, data type, and {@code NULL} value
+     * policy.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     */
+    ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, Boolean mayBeNull );
+
+    /**
+     * Creates a new definition of column with specified name, data type, default value. Invoking this method is
+     * equivalent to invoking {@link #createColumnDefinition(String, String, String, Boolean)} and pass
+     * {@code columnDefault} and {@code true} as last two parameters (meaning that column may have {@code NULL} values).
+     *
+     * @param columnName     The name of the column.
+     * @param columnDataType The data type of the column.
+     * @param columnDefault  The default value of the column.
+     * @return The syntax element for definition of column with specified name, data type, default value.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     */
+    ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, String columnDefault );
+
+    /**
+     * Creates a new definition of column with specified name, data type, default value, and {@code NULL} value policy.
+     * Invoking this method is equivalent to invoking
+     * {@link #createColumnDefinition(String, SQLDataType, String, Boolean, AutoGenerationPolicy)} and pass {@code null}
+     * as last parameter.
+     *
+     * @param columnName     The name of the column.
+     * @param columnDataType The data type of the column.
+     * @param columnDefault  The default value of the column.
+     * @param mayBeNull      The {@code NULL} value policy for the column. Setting this to {@code false} is same as
+     *                       specifying {@code NOT NULL} in column definition in SQL.
+     * @return The syntax element for definition of column with specified name, data type, default value, and
+     * {@code NULL} value policy.
+     */
+    ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType,
+                                             String columnDefault, Boolean mayBeNull );
+
+    /**
+     * Creates a new definition of column with specified name, data type, {@code NULL} value policy, and auto generation
+     * policy.
+     *
+     * @param columnName           The name of the column.
+     * @param columnDataType       The data type of the column.
+     * @param mayBeNull            The {@code NULL} value policy for the column. Setting this to {@code false} is same as
+     *                             specifying {@code NOT NULL} in column definition in SQL.
+     * @param autoGenerationPolicy The policy for auto generation for this column. Should be {@code null} if the column
+     *                             should not be marked as automatically generated.
+     * @return The syntax element for definition of column with specified name, data type, default value, {@code NULL}
+     * value policy, and auto generation policy.
+     */
+
+    ColumnDefinition createColumnDefinition( String columnName, SQLDataType columnDataType, Boolean mayBeNull,
+                                             AutoGenerationPolicy autoGenerationPolicy );
+
+    /**
+     * Creates a new {@code LIKE
+     * <table name>} clause for {@code CREATE TABLE} statement.
+     *
+     * @param tableName The name of the target table.
+     * @return The syntax element for {@code LIKE
+     * <table name>} clause for {@code CREATE TABLE} statement.
+     */
+    LikeClause createLikeClause( TableNameDirect tableName );
+
+    /**
+     * Creates a new unnamed table constraint without any {@link ConstraintCharacteristics}. Invoking this method is
+     * equivalent to invoking
+     * {@link #createTableConstraintDefinition(String, TableConstraint, ConstraintCharacteristics)} and passing
+     * {@code null}s as first and last parameters.
+     *
+     * @param constraint The constraint for the table.
+     * @return The syntax element for unnamed table constraint without any {@link ConstraintCharacteristics}.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     */
+    TableConstraintDefinition createTableConstraintDefinition( TableConstraint constraint );
+
+    /**
+     * Creates a new, named table constraint without any {@link ConstraintCharacteristics}. Invoking this method is
+     * equivalent to invoking
+     * {@link #createTableConstraintDefinition(String, TableConstraint, ConstraintCharacteristics)} and passing
+     * {@code null} as last parameter.
+     *
+     * @param name       The name for the constraint.
+     * @param constraint The constraint for the table.
+     * @return The syntax element for named table constraint without any {@link ConstraintCharacteristics}.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     */
+    TableConstraintDefinition createTableConstraintDefinition( String name, TableConstraint constraint );
+
+    /**
+     * Creates a new unnamed table constraint with specified {@link ConstraintCharacteristics}. Invoking this method is
+     * equivalent to invoking
+     * {@link #createTableConstraintDefinition(String, TableConstraint, ConstraintCharacteristics)} and passing
+     * {@code null} as first parameter.
+     *
+     * @param constraint      The constraint for the table.
+     * @param characteristics The constraint characteristics for the constraint.
+     * @return The syntax element for unnamed table constraint with specified {@link ConstraintCharacteristics}.
+     * @see #createColumnDefinition(String, String, String, Boolean)
+     * @see ConstraintCharacteristics
+     */
+    TableConstraintDefinition createTableConstraintDefinition( TableConstraint constraint,
+                                                               ConstraintCharacteristics characteristics );
+
+    /**
+     * Creates a new named table constraint with specified {@link ConstraintCharacteristics}.
+     *
+     * @param name            The name for the constraint.
+     * @param constraint      The constraint for the table.
+     * @param characteristics The characteristics for the constraint.
+     * @return The syntax element for named table constraint with specified {@link ConstraintCharacteristics}.
+     * @see ConstraintCharacteristics
+     */
+    TableConstraintDefinition createTableConstraintDefinition( String name, TableConstraint constraint,
+                                                               ConstraintCharacteristics characteristics );
+
+    /**
+     * Creates a {@code CHECK} clause, typically used in {@code CREATE TABLE} statements.
+     *
+     * @param check The boolean expression for check.
+     * @return The syntax element for {@code CHECK} clause, typically used in {@code CREATE TABLE} statements.
+     */
+    CheckConstraint createCheckConstraint( BooleanExpression check );
+
+    /**
+     * Creates an empty builder for unique constraint (either {@code UNIQUE(columns...)} or
+     * {@code PRIMARY KEY(columns...)}), typically used in {@code CREATE TABLE} statements.
+     *
+     * @return An empty builder for unique constraints (either {@code UNIQUE(columns...)} or
+     * {@code PRIMARY KEY(columns...)}).
+     */
+    UniqueConstraintBuilder createUniqueConstraintBuilder();
+
+    /**
+     * Creates an empty builder for {@code FOREIGN KEY} constraint, typically used in {@code CREATE TABLE} statements.
+     *
+     * @return An empty builder for {@code FOREIGN KEY} constraint.
+     * @see ForeignKeyConstraintBuilder
+     * @see ForeignKeyConstraint
+     */
+    ForeignKeyConstraintBuilder createForeignKeyConstraintBuilder();
+
+    /**
+     * Creates an empty builder for {@code CREATE VIEW} statement.
+     *
+     * @return An empty builder for {@code CREATE VIEW} statement.
+     * @see ViewDefinitionBuilder
+     * @see ViewDefinition
+     */
+    ViewDefinitionBuilder createViewDefinitionBuilder();
+
+    /**
+     * Creates a new view specification with given columns. Must have at least one column.
+     *
+     * @param columnNames The names of the columns.
+     * @return A new {@link RegularViewSpecification}.
+     * @see RegularViewSpecification
+     */
+    RegularViewSpecification createRegularViewSpecification( String... columnNames );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/LiteralFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/LiteralFactory.java
new file mode 100644
index 0000000..50feb61
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/LiteralFactory.java
@@ -0,0 +1,88 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import java.sql.Timestamp;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.DirectLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.StringLiteral;
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory to create various literal expressions. This factory is obtainable from {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ */
+public interface LiteralFactory
+{
+
+    /**
+     * Creates new string literal, that is, a string to be enclosed in {@code '} -characters.
+     *
+     * @param stringContents The contents of string literal.
+     * @return The new {@link StringLiteral}
+     */
+    StringLiteral s( String stringContents );
+
+    /**
+     * Returns literal, representing a parameter ({@code ?}) in parameterized SQL statement.
+     *
+     * @return The expression representing parameter ({@code ?}) in parameterized SQL statement.
+     */
+    DirectLiteral param();
+
+    /**
+     * Creates a literal, which has some textual content. This content will be used <b>directly</b> when processing SQL
+     * statement.
+     *
+     * @param literalContents The contents to be used.
+     * @return The new {@link DirectLiteral}.
+     */
+    DirectLiteral l( String literalContents );
+
+    /**
+     * Creates a literal, which has some date as content.
+     *
+     * @param date The date to use.
+     * @return The new {@link TimestampTimeLiteral}.
+     */
+    TimestampTimeLiteral dt( Timestamp date );
+
+    /**
+     * Creates a literal, which has some number as contents.
+     *
+     * @param number The number to use.
+     * @return The new {@link NumericLiteral}.
+     */
+    NumericLiteral n( Number number );
+
+    /**
+     * Creates a literal, which represents a use of SQL function.
+     *
+     * @param name       The name of function.
+     * @param parameters The parameters for function.
+     * @return The new {@link SQLFunctionLiteral}.
+     */
+    SQLFunctionLiteral func( String name, ValueExpression... parameters );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ManipulationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ManipulationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ManipulationFactory.java
new file mode 100644
index 0000000..96149b5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ManipulationFactory.java
@@ -0,0 +1,157 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AddTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnAction.DropDefault;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableAction;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.AlterTableStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.SetColumnDefault;
+
+/**
+ * This is factory for creating builders and syntax elements related to SQL Data Manipulation (typically {@code ALTER}
+ * and {@code DROP} statements).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ManipulationFactory
+{
+
+    /**
+     * Creates the {@code ALTER TABLE} statement with specified parameter.
+     *
+     * @param tableName The name of the table.
+     * @param action    The action to be done to the table.
+     * @return The {@code ALTER TABLE} statement syntax element.
+     * @see AlterTableStatement
+     * @see #createAddColumnDefinition(ColumnDefinition)
+     * @see #createAddTableConstraintDefinition(TableConstraintDefinition)
+     * @see #createAlterColumnDefinition(String, AlterColumnAction)
+     * @see #createDropColumnDefinition(String, DropBehaviour)
+     * @see #createDropTableConstraintDefinition(String, DropBehaviour)
+     */
+    AlterTableStatement createAlterTableStatement( TableNameDirect tableName, AlterTableAction action );
+
+    /**
+     * Creates the syntax element for adding column ({@code ADD COLUMN ...}) in {@code ALTER TABLE} statement.
+     *
+     * @param definition The column to add to table.
+     * @return The syntax element for adding column ({@code ADD COLUMN ...}) in {@code ALTER TABLE} statement.
+     * @see AlterTableStatement
+     */
+    AddColumnDefinition createAddColumnDefinition( ColumnDefinition definition );
+
+    /**
+     * Creates the syntax element for adding table constraint({@code ADD ...}) in {@code ALTER TABLE} statement.
+     *
+     * @param constraintDefinition The table constraint to add to table.
+     * @return The syntax element for adding table constraint ({@code ADD ...}) in {@code ALTER TABLE} statement.
+     * @see AlterTableStatement
+     */
+    AddTableConstraintDefinition createAddTableConstraintDefinition(
+        TableConstraintDefinition constraintDefinition );
+
+    /**
+     * Creates the syntax element for altering column definition ({@code ALTER COLUMN}) in {@code ALTER TABLE}
+     * statement.
+     *
+     * @param columnName The name of the column to alter.
+     * @param action     The way how column should be altered.
+     * @return The syntax element for altering column definition ({@code ALTER COLUMN}) in {@code ALTER TABLE}
+     * statement.
+     * @see AlterColumnAction
+     * @see DropDefault
+     * @see #createSetColumnDefault(String)
+     */
+    AlterColumnDefinition createAlterColumnDefinition( String columnName, AlterColumnAction action );
+
+    /**
+     * Creates the syntax element for setting a new default for column ({@code SET DEFAULT ...}) in {@code ALTER TABLE}
+     * statement.
+     *
+     * @param newDefault The new default value for column.
+     * @return The syntax element for setting a new default for column ({@code SET DEFAULT ...}) in {@code ALTER TABLE}
+     * statement.
+     * @see AlterColumnAction
+     */
+    SetColumnDefault createSetColumnDefault( String newDefault );
+
+    /**
+     * Creates the syntax element for dropping a column definition ({@code DROP COLUMN}) in {@code ALTER TABLE}
+     * statement.
+     *
+     * @param columnName    The name of the column to drop.
+     * @param dropBehaviour The drop behaviour.
+     * @return The syntax element for dropping a column definition ({@code DROP COLUMN}) in {@code ALTER TABLE}
+     * statement.
+     * @see DropBehaviour
+     * @see AlterTableStatement
+     */
+    DropColumnDefinition createDropColumnDefinition( String columnName, DropBehaviour dropBehaviour );
+
+    /**
+     * Creates the syntax element for dropping a table constraint ({@code DROP CONSTRAINT ...}) in {@code ALTER TABLE}
+     * statement.
+     *
+     * @param constraintName The name of the constraint to drop.
+     * @param dropBehaviour  The drop behaviour.
+     * @return The syntax element for dropping a table constraint ({@code DROP CONSTRAINT ...}) in {@code ALTER TABLE}
+     * statement.
+     * @see DropBehaviour
+     * @see AlterTableStatement
+     */
+    DropTableConstraintDefinition createDropTableConstraintDefinition( String constraintName,
+                                                                       DropBehaviour dropBehaviour );
+
+    /**
+     * Creates the statement to drop schema ({@code DROP SCHEMA ...}).
+     *
+     * @param schemaName    The name of the schema to drop.
+     * @param dropBehaviour The drop behaviour.
+     * @return The statement to drop schema ({@code DROP SCHEMA ...}).
+     */
+    DropSchemaStatement createDropSchemaStatement( String schemaName, DropBehaviour dropBehaviour );
+
+    /**
+     * Creates the statement to drop table ({@code DROP TABLE ...}) or view ({@code DROP VIEW ...}).
+     *
+     * @param tableName     The name of the table or view to drop.
+     * @param theType       What to drop. Must be either {@link ObjectType#TABLE} for tables or {@link ObjectType#VIEW} for
+     *                      views.
+     * @param dropBehaviour The drop behaviour.
+     * @return The statement to drop table ({@code DROP TABLE ...}) or view ({@code DROP VIEW ...}).
+     * @see DropBehaviour
+     * @see ObjectType
+     */
+    DropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                             DropBehaviour dropBehaviour );
+}


[09/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DoublePrecisionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DoublePrecisionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DoublePrecisionImpl.java
new file mode 100644
index 0000000..8c68de3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/DoublePrecisionImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.DoublePrecision;
+
+public final class DoublePrecisionImpl
+    implements DoublePrecision
+{
+    public DoublePrecisionImpl()
+    {
+    }
+
+    /**
+     * Returns {@link DoublePrecision}.
+     */
+    public Class<DoublePrecision> getImplementedType()
+    {
+        return DoublePrecision.class;
+    }
+
+    /**
+     * A singleton instance of {@code DOUBLE PRECISION} data type.
+     */
+    public static final DoublePrecision INSTANCE = new DoublePrecisionImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/NumericImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/NumericImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/NumericImpl.java
new file mode 100644
index 0000000..c426231
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/NumericImpl.java
@@ -0,0 +1,73 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Numeric;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class NumericImpl extends TypeableImpl<SQLDataType, Numeric>
+    implements Numeric
+{
+    private final Integer _precision;
+    private final Integer _scale;
+
+    public NumericImpl( Integer precision, Integer scale )
+    {
+        super( Numeric.class );
+        this._precision = precision;
+        this._scale = scale;
+    }
+
+    @Override
+    protected boolean doesEqual( Numeric another )
+    {
+        return bothNullOrEquals( this._precision, another.getPrecision() )
+               && bothNullOrEquals( this._scale, another.getScale() );
+    }
+
+    /**
+     * Returns the precision (first integer) for this {@code NUMERIC}.
+     *
+     * @return The precision for this {@code NUMERIC}.
+     */
+    public Integer getPrecision()
+    {
+        return this._precision;
+    }
+
+    /**
+     * Returns the scale (second integer) for this {@code NUMERIC}.
+     *
+     * @return The precision for this {@code NUMERIC}.
+     */
+    public Integer getScale()
+    {
+        return this._scale;
+    }
+
+    /**
+     * This instance represents {@code NUMERIC} without precision and scale.
+     */
+    public static final Numeric PLAIN_NUMERIC = new NumericImpl( null, null );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/RealImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/RealImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/RealImpl.java
new file mode 100644
index 0000000..19a3bb4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/RealImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.Real;
+
+public final class RealImpl
+    implements Real
+{
+    public RealImpl()
+    {
+    }
+
+    /**
+     * Returns {@link Real}.
+     */
+    public Class<Real> getImplementedType()
+    {
+        return Real.class;
+    }
+
+    /**
+     * A singleton instance of {@code REAL}.
+     */
+    public static final Real INSTANCE = new RealImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLBooleanImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLBooleanImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLBooleanImpl.java
new file mode 100644
index 0000000..081172e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLBooleanImpl.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLBoolean;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class SQLBooleanImpl
+    implements SQLBoolean
+{
+    public SQLBooleanImpl()
+    {
+
+    }
+
+    /**
+     * Returns {@link SQLBoolean}.
+     */
+    public Class<SQLBoolean> getImplementedType()
+    {
+        return SQLBoolean.class;
+    }
+
+    /**
+     * The singleton instance of {@code BOOLEAN}.
+     */
+    public static final SQLBoolean INSTANCE = new SQLBooleanImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLCharImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLCharImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLCharImpl.java
new file mode 100644
index 0000000..e5d3fb0
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLCharImpl.java
@@ -0,0 +1,69 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLChar;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+public final class SQLCharImpl extends TypeableImpl<SQLDataType, SQLChar>
+    implements SQLChar
+{
+    private final Boolean _isVarying;
+    private final Integer _length;
+
+    public SQLCharImpl( Boolean isVarying, Integer length )
+    {
+        super( SQLChar.class );
+        this._isVarying = isVarying;
+        this._length = length;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLChar another )
+    {
+        return this._isVarying.equals( another.isVarying() ) && bothNullOrEquals( this._length, another.getLength() );
+    }
+
+    /**
+     * Returns {@code true} if this is {@code CHARACTER VARYING}; {@code false otherwise}.
+     *
+     * @return {@code true} if this is {@code CHARACTER VARYING}; {@code false otherwise}.
+     */
+    public Boolean isVarying()
+    {
+        return this._isVarying;
+    }
+
+    /**
+     * Returns the length specification for this {@code CHARACTER} or {@code CHARACTER VARYING}. Returns {@code null} if
+     * none specified.
+     *
+     * @return The length for this {@code CHARACTER} or {@code CHARACTER VARYING}.
+     */
+    public Integer getLength()
+    {
+        return this._length;
+    }
+
+    public static final SQLChar PLAIN_FIXED = new SQLCharImpl( false, null );
+
+    public static final SQLChar PLAIN_VARYING = new SQLCharImpl( true, null );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLDateImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLDateImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLDateImpl.java
new file mode 100644
index 0000000..f2a1f8c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLDateImpl.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDate;
+
+public final class SQLDateImpl
+    implements SQLDate
+{
+    public SQLDateImpl()
+    {
+    }
+
+    /**
+     * Returns {@link SQLDate}.
+     */
+    public Class<SQLDate> getImplementedType()
+    {
+        return SQLDate.class;
+    }
+
+    /**
+     * A singleton instance of {@code DATE} data type.
+     */
+    public static final SQLDate INSTANCE = new SQLDateImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLFloatImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLFloatImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLFloatImpl.java
new file mode 100644
index 0000000..2a1bc47
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLFloatImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLFloat;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class SQLFloatImpl extends TypeableImpl<SQLDataType, SQLFloat>
+    implements SQLFloat
+{
+    private final Integer _precision;
+
+    public SQLFloatImpl( Integer precision )
+    {
+        super( SQLFloat.class );
+        this._precision = precision;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLFloat another )
+    {
+        return bothNullOrEquals( this._precision, another.getPrecision() );
+    }
+
+    /**
+     * Returns the precision for this {@code FLOAT}.
+     *
+     * @return The precision for this {@code FLOAT}.
+     */
+    public Integer getPrecision()
+    {
+        return this._precision;
+    }
+
+    /**
+     * This instance represents {@code FLOAT} without precision.
+     */
+    public static final SQLFloat PLAIN_FLOAT = new SQLFloatImpl( null );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntegerImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntegerImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntegerImpl.java
new file mode 100644
index 0000000..e80ed6c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntegerImpl.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInteger;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class SQLIntegerImpl
+    implements SQLInteger
+{
+    public SQLIntegerImpl()
+    {
+    }
+
+    /**
+     * Returns {@link SQLInteger}.
+     */
+    public Class<SQLInteger> getImplementedType()
+    {
+        return SQLInteger.class;
+    }
+
+    /**
+     * The singleton instance of {@code INTEGER}.
+     */
+    public static final SQLInteger INSTANCE = new SQLIntegerImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntervalImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntervalImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntervalImpl.java
new file mode 100644
index 0000000..9b9e239
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLIntervalImpl.java
@@ -0,0 +1,103 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.IntervalDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLInterval;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SQLIntervalImpl extends TypeableImpl<SQLDataType, SQLInterval>
+    implements SQLInterval
+{
+
+    private final IntervalDataType _startField;
+
+    private final Integer _startFieldPrecision;
+
+    private final IntervalDataType _endField;
+
+    private final Integer _secondFracs;
+
+    public SQLIntervalImpl( IntervalDataType startField, Integer startFieldPrecision, IntervalDataType endField,
+                            Integer secondFracs )
+    {
+        super( SQLInterval.class );
+        this._startField = startField;
+        this._startFieldPrecision = startFieldPrecision;
+        this._endField = endField;
+        this._secondFracs = secondFracs;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLInterval another )
+    {
+        return this._startField.equals( another.getStartField() )
+               && bothNullOrEquals( this._startFieldPrecision, another.getStartFieldPrecision() )
+               && bothNullOrEquals( this._endField, another.getEndField() )
+               && bothNullOrEquals( this._secondFracs, another.getSecondFracs() );
+    }
+
+    /**
+     * Returns the start field type for this {@code INTERVAL}.
+     *
+     * @return The start field type for this {@code INTERVAL}.
+     */
+    public IntervalDataType getStartField()
+    {
+        return this._startField;
+    }
+
+    /**
+     * Return the start field precision for this {@code INTERVAL}. May be {@code null} if none specified.
+     *
+     * @return The start field precision for this {@code INTERVAL}.
+     */
+    public Integer getStartFieldPrecision()
+    {
+        return this._startFieldPrecision;
+    }
+
+    /**
+     * Returns the end field precision for this {@code INTERVAL}. Will always be {@code null} for single datetime field
+     * intervals.
+     *
+     * @return The end field precision for this {@code INTERVAL}.
+     */
+    public IntervalDataType getEndField()
+    {
+        return this._endField;
+    }
+
+    /**
+     * Returns the fraction seconds precision for this {@code INTERVAL}. Will always be {@code null} if the end field
+     * type is not {@link IntervalDataType#SECOND}, or if this is single datetime field interval, and its start type is
+     * not {@link IntervalDataType#SECOND}.
+     *
+     * @return The fraction seconds precision for this {@code INTERVAL}.
+     */
+    public Integer getSecondFracs()
+    {
+        return this._secondFracs;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeImpl.java
new file mode 100644
index 0000000..120b074
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeImpl.java
@@ -0,0 +1,74 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTime;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class SQLTimeImpl extends TypeableImpl<SQLDataType, SQLTime>
+    implements SQLTime
+{
+    private final Integer _precision;
+    private final Boolean _withTimeZone;
+
+    public SQLTimeImpl( Integer precision, Boolean withTimeZone )
+    {
+        super( SQLTime.class );
+        this._precision = precision;
+        this._withTimeZone = withTimeZone;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLTime another )
+    {
+        return bothNullOrEquals( this._precision, another.getPrecision() )
+               && bothNullOrEquals( this._withTimeZone, another.isWithTimeZone() );
+    }
+
+    /**
+     * Returns the precision for this {@code TIME}. May be {@code null}.
+     *
+     * @return The precision for this {@code TIME}.
+     */
+    public Integer getPrecision()
+    {
+        return this._precision;
+    }
+
+    /**
+     * Returns whether the {@code TIME} should be with time zone. May be {@code null} if no choice specified.
+     *
+     * @return
+     */
+    public Boolean isWithTimeZone()
+    {
+        return this._withTimeZone;
+    }
+
+    public static final SQLTime PLAIN_TIME = new SQLTimeImpl( null, null );
+
+    public static final SQLTime PLAIN_TIME_WITHOUT_TZ = new SQLTimeImpl( null, false );
+
+    public static final SQLTime PLAIN_TIME_WITH_TZ = new SQLTimeImpl( null, true );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeStampImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeStampImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeStampImpl.java
new file mode 100644
index 0000000..de2b22d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SQLTimeStampImpl.java
@@ -0,0 +1,76 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLTimeStamp;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * This class represents {@code TIMESTAMP} data type.
+ *
+ * @author Stanislav Muhametsin
+ */
+public final class SQLTimeStampImpl extends TypeableImpl<SQLDataType, SQLTimeStamp>
+    implements SQLTimeStamp
+{
+    private final Integer _precision;
+    private final Boolean _withTimeZone;
+
+    public SQLTimeStampImpl( Integer precision, Boolean withTimeZone )
+    {
+        super( SQLTimeStamp.class );
+        this._precision = precision;
+        this._withTimeZone = withTimeZone;
+    }
+
+    @Override
+    protected boolean doesEqual( SQLTimeStamp another )
+    {
+        return bothNullOrEquals( this._precision, another.getPrecision() )
+               && bothNullOrEquals( this._withTimeZone, another.isWithTimeZone() );
+    }
+
+    /**
+     * Returns the precision for this {@code TIMESTAMP}. May be {@code null}.
+     *
+     * @return The precision for this {@code TIMESTAMP}.
+     */
+    public Integer getPrecision()
+    {
+        return this._precision;
+    }
+
+    /**
+     * Returns whether the {@code TIMESTAMP} should be with time zone. May be {@code null} if no choice specified.
+     *
+     * @return
+     */
+    public Boolean isWithTimeZone()
+    {
+        return this._withTimeZone;
+    }
+
+    public static final SQLTimeStamp PLAIN_TIMESTAMP = new SQLTimeStampImpl( null, null );
+
+    public static final SQLTimeStamp PLAIN_TIMESTAMP_WITHOUT_TZ = new SQLTimeStampImpl( null, false );
+
+    public static final SQLTimeStamp PLAIN_TIMESTAMP_WITH_TZ = new SQLTimeStampImpl( null, true );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SmallIntImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SmallIntImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SmallIntImpl.java
new file mode 100644
index 0000000..e931873
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/SmallIntImpl.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SmallInt;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public final class SmallIntImpl
+    implements SmallInt
+{
+    public SmallIntImpl()
+    {
+    }
+
+    /**
+     * Returns {@link SmallInt}.
+     */
+    public Class<SmallInt> getImplementedType()
+    {
+        return SmallInt.class;
+    }
+
+    /**
+     * The singleton instance of {@code SMALLINT}.
+     */
+    public static final SmallInt INSTANCE = new SmallIntImpl();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/UserDefinedTypeImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/UserDefinedTypeImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/UserDefinedTypeImpl.java
new file mode 100644
index 0000000..8a7e119
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/UserDefinedTypeImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.common.datatypes;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.UserDefinedType;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UserDefinedTypeImpl extends TypeableImpl<SQLDataType, UserDefinedType>
+    implements UserDefinedType
+{
+
+    private final String _text;
+
+    public UserDefinedTypeImpl( String textContent )
+    {
+        this( UserDefinedType.class, textContent );
+    }
+
+    protected UserDefinedTypeImpl( Class<? extends UserDefinedType> realImplementingType, String textContent )
+    {
+        super( realImplementingType );
+
+        this._text = textContent;
+    }
+
+    @Override
+    protected boolean doesEqual( UserDefinedType another )
+    {
+        return bothNullOrEquals( this._text, another.getTextualRepresentation() );
+    }
+
+    public String getTextualRepresentation()
+    {
+        return this._text;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/pgsql/TextImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/pgsql/TextImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/pgsql/TextImpl.java
new file mode 100644
index 0000000..0667f16
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/common/datatypes/pgsql/TextImpl.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.common.datatypes.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.pgsql.Text;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TextImpl
+    implements Text
+{
+
+    public TextImpl()
+    {
+    }
+
+    /**
+     * Returns {@link Text}.
+     */
+    public Class<Text> getImplementedType()
+    {
+        return Text.class;
+    }
+
+    /**
+     * A singleton instance of {@code TEXT} data type.
+     */
+    public static Text INSTANCE = new TextImpl();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/schema/SchemaDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/schema/SchemaDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/schema/SchemaDefinitionImpl.java
new file mode 100644
index 0000000..6a376f3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/schema/SchemaDefinitionImpl.java
@@ -0,0 +1,85 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.schema;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaElement;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class SchemaDefinitionImpl extends SQLSyntaxElementBase<SchemaStatement, SchemaDefinition>
+    implements SchemaDefinition
+{
+
+    private final String _charset;
+    private final String _name;
+    private final List<SchemaElement> _elements;
+
+    public SchemaDefinitionImpl( SQLProcessorAggregator processor, String name, String charset,
+                                 List<SchemaElement> elements )
+    {
+        this( processor, SchemaDefinition.class, name, charset, elements );
+    }
+
+    protected SchemaDefinitionImpl( SQLProcessorAggregator processor,
+                                    Class<? extends SchemaDefinition> realImplementingType, String name, String charset,
+                                    List<SchemaElement> elements )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( name, "Schema name" );
+        Objects.requireNonNull( elements, "Elements" );
+
+        this._name = name;
+        this._charset = charset;
+        this._elements = Collections.unmodifiableList( new ArrayList<SchemaElement>( elements ) );
+    }
+
+    @Override
+    protected boolean doesEqual( SchemaDefinition another )
+    {
+        return this._name.equals( another.getSchemaName() ) && this._elements.equals( another.getSchemaElements() )
+               && TypeableImpl.bothNullOrEquals( this._charset, another.getSchemaCharset() );
+    }
+
+    public String getSchemaCharset()
+    {
+        return this._charset;
+    }
+
+    public List<SchemaElement> getSchemaElements()
+    {
+        return this._elements;
+    }
+
+    public String getSchemaName()
+    {
+        return this._name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/CheckConstraintImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/CheckConstraintImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/CheckConstraintImpl.java
new file mode 100644
index 0000000..175744f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/CheckConstraintImpl.java
@@ -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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.CheckConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class CheckConstraintImpl extends SQLSyntaxElementBase<TableConstraint, CheckConstraint>
+    implements CheckConstraint
+{
+
+    private final BooleanExpression _searchCondition;
+
+    public CheckConstraintImpl( SQLProcessorAggregator processor, BooleanExpression searchCondition )
+    {
+        this( processor, CheckConstraint.class, searchCondition );
+    }
+
+    protected CheckConstraintImpl( SQLProcessorAggregator processor,
+                                   Class<? extends CheckConstraint> realImplementingType, BooleanExpression searchCondition )
+    {
+        super( processor, realImplementingType );
+
+        this._searchCondition = searchCondition;
+    }
+
+    @Override
+    protected boolean doesEqual( CheckConstraint another )
+    {
+        return TypeableImpl.bothNullOrEquals( this._searchCondition, another.getCheckCondition() );
+    }
+
+    public BooleanExpression getCheckCondition()
+    {
+        return this._searchCondition;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ColumnDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ColumnDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ColumnDefinitionImpl.java
new file mode 100644
index 0000000..9a19e4f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ColumnDefinitionImpl.java
@@ -0,0 +1,99 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.SQLDataType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ColumnDefinitionImpl extends SQLSyntaxElementBase<TableElement, ColumnDefinition>
+    implements ColumnDefinition
+{
+
+    private final String _name;
+    private final SQLDataType _dataType;
+    private final String _default;
+    private final Boolean _mayBeNull;
+    private final AutoGenerationPolicy _autoGenerationPolicy;
+
+    public ColumnDefinitionImpl( SQLProcessorAggregator processor, String name, SQLDataType dataType,
+                                 String defaultStr, Boolean mayBeNull, AutoGenerationPolicy autoGenerationPolicy )
+    {
+        this( processor, ColumnDefinition.class, name, dataType, defaultStr, mayBeNull, autoGenerationPolicy );
+    }
+
+    protected ColumnDefinitionImpl( SQLProcessorAggregator processor,
+                                    Class<? extends ColumnDefinition> realImplementingType, String name, SQLDataType dataType, String defaultStr,
+                                    Boolean mayBeNull, AutoGenerationPolicy autoGenerationPolicy )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( name, "Column name" );
+        Objects.requireNonNull( dataType, "Column data type" );
+        Objects.requireNonNull( mayBeNull, "Null policy" );
+
+        this._name = name;
+        this._dataType = dataType;
+        this._default = defaultStr;
+        this._mayBeNull = mayBeNull;
+        this._autoGenerationPolicy = autoGenerationPolicy;
+    }
+
+    @Override
+    protected boolean doesEqual( ColumnDefinition another )
+    {
+        return this._name.equals( another.getColumnName() ) && this._dataType.equals( another.getDataType() )
+               && TypeableImpl.bothNullOrEquals( this._default, another.getDefault() )
+               && this._mayBeNull.equals( another.mayBeNull() );
+    }
+
+    public String getColumnName()
+    {
+        return this._name;
+    }
+
+    public SQLDataType getDataType()
+    {
+        return this._dataType;
+    }
+
+    public String getDefault()
+    {
+        return this._default;
+    }
+
+    public Boolean mayBeNull()
+    {
+        return this._mayBeNull;
+    }
+
+    public AutoGenerationPolicy getAutoGenerationPolicy()
+    {
+        return this._autoGenerationPolicy;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ForeignKeyConstraintImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ForeignKeyConstraintImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ForeignKeyConstraintImpl.java
new file mode 100644
index 0000000..e856424
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/ForeignKeyConstraintImpl.java
@@ -0,0 +1,113 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ForeignKeyConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.MatchType;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ReferentialAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ForeignKeyConstraintImpl extends SQLSyntaxElementBase<TableConstraint, ForeignKeyConstraint>
+    implements ForeignKeyConstraint
+{
+
+    private final ColumnNameList _sourceColumns;
+    private final TableNameDirect _targetTableName;
+    private final ColumnNameList _targetColumns;
+    private final MatchType _matchType;
+    private final ReferentialAction _onDelete;
+    private final ReferentialAction _onUpdate;
+
+    public ForeignKeyConstraintImpl( SQLProcessorAggregator processor, ColumnNameList sourceColumns,
+                                     TableNameDirect targetTableName, ColumnNameList targetColumns, MatchType matchType, ReferentialAction onDelete,
+                                     ReferentialAction onUpdate )
+    {
+        this( processor, ForeignKeyConstraint.class, sourceColumns, targetTableName, targetColumns, matchType,
+              onDelete, onUpdate );
+    }
+
+    protected ForeignKeyConstraintImpl( SQLProcessorAggregator processor,
+                                        Class<? extends ForeignKeyConstraint> realImplementingType, ColumnNameList sourceColumns,
+                                        TableNameDirect targetTableName, ColumnNameList targetColumns, MatchType matchType, ReferentialAction onDelete,
+                                        ReferentialAction onUpdate )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( sourceColumns, "Source columns" );
+        Objects.requireNonNull( targetTableName, "Target table name" );
+
+        this._sourceColumns = sourceColumns;
+        this._targetTableName = targetTableName;
+        this._targetColumns = targetColumns;
+        this._matchType = matchType;
+        this._onDelete = onDelete;
+        this._onUpdate = onUpdate;
+    }
+
+    @Override
+    protected boolean doesEqual( ForeignKeyConstraint another )
+    {
+        return this._targetTableName.equals( another.getTargetTableName() )
+               && this._sourceColumns.equals( another.getSourceColumns() )
+               && TypeableImpl.bothNullOrEquals( this._targetColumns, another.getTargetColumns() )
+               && TypeableImpl.bothNullOrEquals( this._matchType, another.getMatchType() )
+               && TypeableImpl.bothNullOrEquals( this._onDelete, another.getOnDelete() )
+               && TypeableImpl.bothNullOrEquals( this._onUpdate, another.getOnUpdate() );
+    }
+
+    public MatchType getMatchType()
+    {
+        return this._matchType;
+    }
+
+    public ReferentialAction getOnDelete()
+    {
+        return this._onDelete;
+    }
+
+    public ReferentialAction getOnUpdate()
+    {
+        return this._onUpdate;
+    }
+
+    public ColumnNameList getSourceColumns()
+    {
+        return this._sourceColumns;
+    }
+
+    public ColumnNameList getTargetColumns()
+    {
+        return this._targetColumns;
+    }
+
+    public TableNameDirect getTargetTableName()
+    {
+        return this._targetTableName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/LikeClauseImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/LikeClauseImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/LikeClauseImpl.java
new file mode 100644
index 0000000..d763b7a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/LikeClauseImpl.java
@@ -0,0 +1,63 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.LikeClause;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class LikeClauseImpl extends SQLSyntaxElementBase<TableElement, LikeClause>
+    implements LikeClause
+{
+
+    private final TableNameDirect _tableName;
+
+    public LikeClauseImpl( SQLProcessorAggregator processor, TableNameDirect tableName )
+    {
+        this( processor, LikeClause.class, tableName );
+    }
+
+    protected LikeClauseImpl( SQLProcessorAggregator processor, Class<? extends LikeClause> realImplementingType,
+                              TableNameDirect tableName )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( tableName, "Table name" );
+
+        this._tableName = tableName;
+    }
+
+    @Override
+    protected boolean doesEqual( LikeClause another )
+    {
+        return this._tableName.equals( another.getTableName() );
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._tableName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableConstraintDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableConstraintDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableConstraintDefinitionImpl.java
new file mode 100644
index 0000000..0998576
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableConstraintDefinitionImpl.java
@@ -0,0 +1,83 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ConstraintCharacteristics;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableConstraintDefinitionImpl extends SQLSyntaxElementBase<TableElement, TableConstraintDefinition>
+    implements TableConstraintDefinition
+{
+
+    private final String _name;
+    private final TableConstraint _constraint;
+    private final ConstraintCharacteristics _characteristics;
+
+    public TableConstraintDefinitionImpl( SQLProcessorAggregator processor, String name, TableConstraint constraint,
+                                          ConstraintCharacteristics characteristics )
+    {
+        this( processor, TableConstraintDefinition.class, name, constraint, characteristics );
+    }
+
+    protected TableConstraintDefinitionImpl( SQLProcessorAggregator processor,
+                                             Class<? extends TableConstraintDefinition> realImplementingType, String name, TableConstraint constraint,
+                                             ConstraintCharacteristics characteristics )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( constraint, "Constraint" );
+
+        this._constraint = constraint;
+        this._name = name;
+        this._characteristics = characteristics;
+    }
+
+    @Override
+    protected boolean doesEqual( TableConstraintDefinition another )
+    {
+        return this._constraint.equals( another.getConstraint() )
+               && TypeableImpl.bothNullOrEquals( this._name, another.getConstraintName() )
+               && TypeableImpl.bothNullOrEquals( this._characteristics, another.getCharacteristics() );
+    }
+
+    public ConstraintCharacteristics getCharacteristics()
+    {
+        return this._characteristics;
+    }
+
+    public TableConstraint getConstraint()
+    {
+        return this._constraint;
+    }
+
+    public String getConstraintName()
+    {
+        return this._name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableDefinitionImpl.java
new file mode 100644
index 0000000..6abed15
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableDefinitionImpl.java
@@ -0,0 +1,99 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableCommitAction;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableContentsSource;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableScope;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableDefinitionImpl extends SQLSyntaxElementBase<SchemaStatement, TableDefinition>
+    implements TableDefinition
+{
+
+    private final TableCommitAction _commitAction;
+    private final TableContentsSource _contents;
+    private final TableNameDirect _name;
+    private final TableScope _scope;
+
+    public TableDefinitionImpl( SQLProcessorAggregator processor, TableCommitAction commitAction,
+                                TableContentsSource contents, TableNameDirect name, TableScope scope )
+    {
+        this( processor, TableDefinition.class, commitAction, contents, name, scope );
+    }
+
+    protected TableDefinitionImpl( SQLProcessorAggregator processor,
+                                   Class<? extends TableDefinition> realImplementingType, TableCommitAction commitAction,
+                                   TableContentsSource contents, TableNameDirect name, TableScope scope )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( name, "Table name" );
+        Objects.requireNonNull( contents, "Table contents" );
+
+        this._name = name;
+        this._contents = contents;
+        this._scope = scope;
+        this._commitAction = commitAction;
+    }
+
+    @Override
+    protected boolean doesEqual( TableDefinition another )
+    {
+        return this._name.equals( another.getTableName() ) && this._contents.equals( another.getContents() )
+               && TypeableImpl.bothNullOrEquals( this._scope, another.getTableScope() )
+               && TypeableImpl.bothNullOrEquals( this._commitAction, another.getCommitAction() );
+    }
+
+    public Typeable<?> asTypeable()
+    {
+        return this;
+    }
+
+    public TableCommitAction getCommitAction()
+    {
+        return this._commitAction;
+    }
+
+    public TableContentsSource getContents()
+    {
+        return this._contents;
+    }
+
+    public TableNameDirect getTableName()
+    {
+        return this._name;
+    }
+
+    public TableScope getTableScope()
+    {
+        return this._scope;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableElementListImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableElementListImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableElementListImpl.java
new file mode 100644
index 0000000..7114482
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/TableElementListImpl.java
@@ -0,0 +1,65 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableContentsSource;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElement;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableElementList;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableElementListImpl extends SQLSyntaxElementBase<TableContentsSource, TableElementList>
+    implements TableElementList
+{
+
+    private final List<TableElement> _elements;
+
+    public TableElementListImpl( SQLProcessorAggregator processor, List<TableElement> elements )
+    {
+        this( processor, TableElementList.class, elements );
+    }
+
+    protected TableElementListImpl( SQLProcessorAggregator processor,
+                                    Class<? extends TableElementList> realImplementingType, List<TableElement> elements )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( elements, "Table elements" );
+
+        this._elements = Collections.unmodifiableList( elements );
+    }
+
+    @Override
+    protected boolean doesEqual( TableElementList another )
+    {
+        return this._elements.equals( another.getElementList() );
+    }
+
+    public List<TableElement> getElementList()
+    {
+        return this._elements;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/UniqueConstraintImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/UniqueConstraintImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/UniqueConstraintImpl.java
new file mode 100644
index 0000000..8a115ba
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/table/UniqueConstraintImpl.java
@@ -0,0 +1,74 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.table;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueConstraint;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.UniqueSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class UniqueConstraintImpl extends SQLSyntaxElementBase<TableConstraint, UniqueConstraint>
+    implements UniqueConstraint
+{
+
+    private final ColumnNameList _columns;
+    private final UniqueSpecification _uniqueness;
+
+    public UniqueConstraintImpl( SQLProcessorAggregator processor, ColumnNameList columns,
+                                 UniqueSpecification uniqueness )
+    {
+        this( processor, UniqueConstraint.class, columns, uniqueness );
+    }
+
+    protected UniqueConstraintImpl( SQLProcessorAggregator processor,
+                                    Class<? extends UniqueConstraint> realImplementingType, ColumnNameList columns, UniqueSpecification uniqueness )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( columns, "Columns" );
+        Objects.requireNonNull( uniqueness, "Uniqueness" );
+
+        this._columns = columns;
+        this._uniqueness = uniqueness;
+    }
+
+    @Override
+    protected boolean doesEqual( UniqueConstraint another )
+    {
+        return this._uniqueness.equals( another.getUniquenessKind() )
+               && this._columns.equals( another.getColumnNameList() );
+    }
+
+    public ColumnNameList getColumnNameList()
+    {
+        return this._columns;
+    }
+
+    public UniqueSpecification getUniquenessKind()
+    {
+        return this._uniqueness;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/RegularViewSpecificationImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/RegularViewSpecificationImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/RegularViewSpecificationImpl.java
new file mode 100644
index 0000000..79aa362
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/RegularViewSpecificationImpl.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.view;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.RegularViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewSpecification;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class RegularViewSpecificationImpl extends SQLSyntaxElementBase<ViewSpecification, RegularViewSpecification>
+    implements RegularViewSpecification
+{
+
+    private final ColumnNameList _columns;
+
+    public RegularViewSpecificationImpl( SQLProcessorAggregator processor, ColumnNameList columns )
+    {
+        this( processor, RegularViewSpecification.class, columns );
+    }
+
+    protected RegularViewSpecificationImpl( SQLProcessorAggregator processor,
+                                            Class<? extends RegularViewSpecification> realImplementingType, ColumnNameList columns )
+    {
+        super( processor, realImplementingType );
+
+        this._columns = columns;
+    }
+
+    @Override
+    protected boolean doesEqual( RegularViewSpecification another )
+    {
+        return this._columns.equals( another.getColumns() );
+    }
+
+    public ColumnNameList getColumns()
+    {
+        return this._columns;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/ViewDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/ViewDefinitionImpl.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/ViewDefinitionImpl.java
new file mode 100644
index 0000000..202ae9c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/definition/view/ViewDefinitionImpl.java
@@ -0,0 +1,108 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.definition.view;
+
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewCheckOption;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.view.ViewSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.TypeableImpl;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLSyntaxElementBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ViewDefinitionImpl extends SQLSyntaxElementBase<SchemaStatement, ViewDefinition>
+    implements ViewDefinition
+{
+
+    private final TableNameDirect _name;
+    private final QueryExpression _query;
+    private final ViewSpecification _spec;
+    private final ViewCheckOption _viewCheck;
+    private final Boolean _isRecursive;
+
+    public ViewDefinitionImpl( SQLProcessorAggregator processor, TableNameDirect name, QueryExpression query,
+                               ViewSpecification spec, ViewCheckOption viewCheck, Boolean isRecursive )
+    {
+        this( processor, ViewDefinition.class, name, query, spec, viewCheck, isRecursive );
+    }
+
+    protected ViewDefinitionImpl( SQLProcessorAggregator processor,
+                                  Class<? extends ViewDefinition> realImplementingType, TableNameDirect name, QueryExpression query,
+                                  ViewSpecification spec, ViewCheckOption viewCheck, Boolean isRecursive )
+    {
+        super( processor, realImplementingType );
+
+        Objects.requireNonNull( name, "View name" );
+        Objects.requireNonNull( query, "View query" );
+        Objects.requireNonNull( isRecursive, "Is recursive" );
+        Objects.requireNonNull( spec, "View specification" );
+
+        this._name = name;
+        this._query = query;
+        this._spec = spec;
+        this._isRecursive = isRecursive;
+        this._viewCheck = viewCheck;
+    }
+
+    @Override
+    protected boolean doesEqual( ViewDefinition another )
+    {
+        return this._name.equals( another.getViewName() ) && this._isRecursive.equals( another.isRecursive() )
+               && this._spec.equals( another.getViewSpecification() ) && this._query.equals( another.getViewQuery() )
+               && TypeableImpl.bothNullOrEquals( this._viewCheck, another.getViewCheckOption() );
+    }
+
+    public Typeable<?> asTypeable()
+    {
+        return this;
+    }
+
+    public ViewCheckOption getViewCheckOption()
+    {
+        return this._viewCheck;
+    }
+
+    public TableNameDirect getViewName()
+    {
+        return this._name;
+    }
+
+    public QueryExpression getViewQuery()
+    {
+        return this._query;
+    }
+
+    public ViewSpecification getViewSpecification()
+    {
+        return this._spec;
+    }
+
+    public Boolean isRecursive()
+    {
+        return this._isRecursive;
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractBooleanFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractBooleanFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractBooleanFactory.java
new file mode 100644
index 0000000..e0ec1a7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/grammar/factories/AbstractBooleanFactory.java
@@ -0,0 +1,51 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.InPredicate;
+import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.factories.BooleanFactory;
+import org.apache.polygene.library.sql.generator.implementation.grammar.common.SQLFactoryBase;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public abstract class AbstractBooleanFactory extends SQLFactoryBase
+    implements BooleanFactory
+{
+
+    protected AbstractBooleanFactory( SQLVendor vendor, SQLProcessorAggregator processor )
+    {
+        super( vendor, processor );
+    }
+
+    public BooleanBuilder booleanBuilder()
+    {
+        return this.booleanBuilder( null );
+    }
+
+    public InPredicate in( NonBooleanExpression what, NonBooleanExpression... values )
+    {
+        return this.inBuilder( what ).addValues( values ).createExpression();
+    }
+}


[13/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/package-info.java
new file mode 100644
index 0000000..f136488
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This is package for syntax elements specific for data manipulation for PostgreSQL databases.
+ */
+package org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSource.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSource.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSource.java
new file mode 100644
index 0000000..7e14967
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSource.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for syntax elements representing the data source for columns in {@code INSERT INTO}
+ * statement.
+ *
+ * @author Stanislav Muhametsin
+ * @see InsertStatement
+ */
+public interface ColumnSource
+    extends Typeable<ColumnSource>
+{
+    /**
+     * This syntax element represents when default values of columns are wanted to be inserted into table.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class Defaults
+        implements ColumnSource
+    {
+        private Defaults()
+        {
+
+        }
+
+        /**
+         * Returns {@link Defaults}.
+         */
+        public Class<? extends ColumnSource> getImplementedType()
+        {
+            return Defaults.class;
+        }
+
+        /**
+         * The singleton reference to object of this class.
+         */
+        public static final Defaults INSTANCE = new Defaults();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByQuery.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByQuery.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByQuery.java
new file mode 100644
index 0000000..c503fcb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByQuery.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+
+/**
+ * This syntax element represents column source acquired by some query, for {@code INSERT INTO} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnSourceByQuery
+    extends DynamicColumnSource
+{
+
+    /**
+     * Returns the query to use as column source.
+     *
+     * @return The query to use as column source.
+     */
+    QueryExpression getQuery();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByValues.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByValues.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByValues.java
new file mode 100644
index 0000000..0bf1bb3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ColumnSourceByValues.java
@@ -0,0 +1,42 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * <p>
+ * This syntax element represents explicitly defined values for column source in {@code INSERT INTO}
+ * statement.
+ * </p>
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnSourceByValues
+    extends DynamicColumnSource
+{
+    /**
+     * Returns the values to use as column source.
+     *
+     * @return The values to use as column source.
+     */
+    List<ValueExpression> getValues();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteBySearch.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteBySearch.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteBySearch.java
new file mode 100644
index 0000000..4e0f1ab
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteBySearch.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+
+/**
+ * This syntax element represents a {@code DELETE FROM} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DeleteBySearch
+    extends DeleteStatement
+{
+    /**
+     * Returns the target table for this {@code DELETE FROM} statement.
+     *
+     * @return The target table for this {@code DELETE FROM} statement.
+     */
+    TargetTable getTargetTable();
+
+    /**
+     * Returns the search condition for rows to delete.
+     *
+     * @return The search condition for rows to delete.
+     */
+    BooleanExpression getWhere();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteStatement.java
new file mode 100644
index 0000000..17dc635
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DeleteStatement.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+
+/**
+ * A common interface for all statements deleting data from tables.
+ *
+ * @author Stanislav Muhametsin
+ * @see DeleteBySearch
+ */
+public interface DeleteStatement
+    extends SQLStatement, Typeable<DeleteStatement>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DynamicColumnSource.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DynamicColumnSource.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DynamicColumnSource.java
new file mode 100644
index 0000000..9fdcea6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/DynamicColumnSource.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * A common interface for column sources with named columns for {@code INSERT INTO} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DynamicColumnSource
+    extends ColumnSource
+{
+
+    /**
+     * Returns the named columns of this column source. May be null if no column names are
+     * specified.
+     *
+     * @return The named columns of this column source.
+     */
+    ColumnNameList getColumnNames();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/InsertStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/InsertStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/InsertStatement.java
new file mode 100644
index 0000000..830cbff
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/InsertStatement.java
@@ -0,0 +1,48 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * This syntax element represents a {@code INSERT INTO} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface InsertStatement
+    extends SQLStatement, Typeable<InsertStatement>
+{
+
+    /**
+     * Returns the table name where to insert.
+     *
+     * @return The table name where to insert.
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Returns the data source for columns.
+     *
+     * @return The data source for columns.
+     */
+    ColumnSource getColumnSource();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/SetClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/SetClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/SetClause.java
new file mode 100644
index 0000000..56f955b
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/SetClause.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This syntax element represents a single {@code SET} element of {@code UPDATE} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SetClause
+    extends Typeable<SetClause>
+{
+
+    /**
+     * Returns the update target, typically a name of the column.
+     *
+     * @return The update target, typically a name of the column.
+     */
+    String getUpdateTarget();
+
+    /**
+     * Returns the update source, that is, data, for the columns.
+     *
+     * @return The data for the columns.
+     */
+    UpdateSource getUpdateSource();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/TargetTable.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/TargetTable.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/TargetTable.java
new file mode 100644
index 0000000..5591608
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/TargetTable.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * This syntax element represents the target table of {@code DELETE FROM} and {@code UPDATE} statements.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TargetTable
+    extends Typeable<TargetTable>
+{
+
+    /**
+     * Returns whether only this table should be updated (and not, for example, inheriting tables).
+     *
+     * @return {@code true} if only this table should be updated; {@code false} otherwise.
+     */
+    Boolean isOnly();
+
+    /**
+     * Returns the table name of the target table.
+     *
+     * @return The table name of the target table.
+     * @see TableName
+     */
+    TableNameDirect getTableName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateBySearch.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateBySearch.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateBySearch.java
new file mode 100644
index 0000000..82398ad
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateBySearch.java
@@ -0,0 +1,56 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+
+/**
+ * This syntax element represents {@code UPDATE} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UpdateBySearch
+    extends UpdateStatement
+{
+
+    /**
+     * Returns the target table of this {@code UPDATE} statement.
+     *
+     * @return The target table of this {@code UPDATE} statement.
+     * @see TargetTable
+     */
+    TargetTable getTargetTable();
+
+    /**
+     * Returns the search condition for the rows to be updated.
+     *
+     * @return The search condition for the rows to be updated.
+     */
+    BooleanExpression getWhere();
+
+    /**
+     * Returns the {@code SET} clauses for columns of the target table.
+     *
+     * @return The {@code SET} clauses for columns of the target table.
+     * @see SetClause
+     */
+    List<SetClause> getSetClauses();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSource.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSource.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSource.java
new file mode 100644
index 0000000..e6982db
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSource.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This syntax element represents the data source for column in {@code SET} clause of {@code UPDATE}
+ * statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UpdateSource
+    extends Typeable<UpdateSource>
+{
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSourceByExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSourceByExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSourceByExpression.java
new file mode 100644
index 0000000..bd6a4e8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateSourceByExpression.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * This syntax element represents the update source having value of whatever expression it holds.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface UpdateSourceByExpression
+    extends UpdateSource
+{
+
+    /**
+     * Returns the value expression to use as value for update source.
+     *
+     * @return The value expression to use as value for update source.
+     */
+    ValueExpression getValueExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateStatement.java
new file mode 100644
index 0000000..bab5554
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/UpdateStatement.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+
+/**
+ * This is common interface for all statements doing updates.
+ *
+ * @author Stanislav Muhametsin
+ * @see UpdateBySearch
+ */
+public interface UpdateStatement
+    extends SQLStatement, Typeable<UpdateStatement>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ValueSource.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ValueSource.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ValueSource.java
new file mode 100644
index 0000000..93c1c06
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/ValueSource.java
@@ -0,0 +1,82 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+public class ValueSource
+{
+
+    /**
+     * This syntax element represents the {@code DEFAULT} keyword as data source for column, meaning
+     * to use the default value for the column.
+     *
+     * @author Stanislav Muhametsin
+     */
+    public static final class Default
+        implements ValueExpression
+    {
+        private Default()
+        {
+
+        }
+
+        /**
+         * Returns {@link Default}.
+         */
+        public Class<? extends ValueExpression> getImplementedType()
+        {
+            return Default.class;
+        }
+
+        /**
+         * Singleton instance of {@link Default}.
+         */
+        public static final Default INSTANCE = new Default();
+    }
+
+    /**
+     * This syntax element represents the {@code NULL} keyword as data source for column, meaning to
+     * use the {@code NULL} value for the column.
+     *
+     * @author Stanislav Muhametsin
+     */
+    public static final class Null
+        implements ValueExpression
+    {
+        private Null()
+        {
+
+        }
+
+        /**
+         * Returns {@link Null}.
+         */
+        public Class<? extends ValueExpression> getImplementedType()
+        {
+            return Null.class;
+        }
+
+        /**
+         * The singleton instance of {@link Null}.
+         */
+        public static final Null INSTANCE = new Null();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/package-info.java
new file mode 100644
index 0000000..302ab4e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains syntax elements relevant to SQL modification clauses ({@code INSERT INTO}, {@code DELETE FROM}, and {@code UPDATE}).
+ */
+package org.apache.polygene.library.sql.generator.grammar.modification;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/PgSQLInsertStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/PgSQLInsertStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/PgSQLInsertStatement.java
new file mode 100644
index 0000000..1f88f99
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/PgSQLInsertStatement.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.modification.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+
+/**
+ * <p>
+ * This interface represents {@code INSERT} statement with PostgreSQL-specific elements.
+ * </p>
+ * <p>
+ * <p>
+ * TODO: {@code WITH RECURSIVE} query
+ * </p>
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface PgSQLInsertStatement extends InsertStatement
+{
+    /**
+     * Gets the columns for the {@code RETURNING} clause. Returns {@code null} if this
+     * {@code INSERT} statement has no {@code RETURNING} clause.
+     *
+     * @return The {@code RETURNING} clause for this statement, or {@code null} if none.
+     */
+    SelectColumnClause getReturningClause();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/package-info.java
new file mode 100644
index 0000000..86ee8d8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/modification/pgsql/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This is package for syntax elements specific for data modification in PostgreSQL databases.
+ */
+package org.apache.polygene.library.sql.generator.grammar.modification.pgsql;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/AsteriskSelect.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/AsteriskSelect.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/AsteriskSelect.java
new file mode 100644
index 0000000..ae995cb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/AsteriskSelect.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This syntax element represents the asterisk in expression {@code SELECT} *.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface AsteriskSelect
+    extends SelectColumnClause
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReference.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReference.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReference.java
new file mode 100644
index 0000000..31472c4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReference.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * Common interface for columns in expression {@code SELECT <column1>, <column2>, ...}.
+ *
+ * @author Stanislav Muhametsin
+ * @see ColumnReferenceByName
+ * @see ColumnReferenceByExpression
+ */
+public interface ColumnReference
+    extends NonBooleanExpression
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByExpression.java
new file mode 100644
index 0000000..78a72ab
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByExpression.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * This syntax element represents the column reference in {@code SELECT <column reference>} clause, where the column
+ * reference is some kind of expression (for example, a constant, or a query).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnReferenceByExpression
+    extends ColumnReference
+{
+
+    /**
+     * Gets the expression for this column reference.
+     *
+     * @return The expression for this column reference.
+     */
+    ValueExpression getExpression();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByName.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByName.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByName.java
new file mode 100644
index 0000000..14ae9f2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferenceByName.java
@@ -0,0 +1,44 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This syntax element represents the column reference in {@code SELECT <column reference>} clause, where the column
+ * reference is column name, either with table name or without.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnReferenceByName
+    extends ColumnReference
+{
+    /**
+     * Gets the table name of this column. Might be {@code null}.
+     *
+     * @return The table name of this column. Might be {@code null}.
+     */
+    String getTableName();
+
+    /**
+     * Gets the column name of this column.
+     *
+     * @return The column name of this column.
+     */
+    String getColumnName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferences.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferences.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferences.java
new file mode 100644
index 0000000..915c4b1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/ColumnReferences.java
@@ -0,0 +1,79 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * This syntax element represents the whole {@code SELECT <column1>, <column2>, ...} clause, up until {@code FROM}. Each
+ * column might have an alias.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface ColumnReferences
+    extends SelectColumnClause
+{
+    /**
+     * A helper class to encapsulate column reference along with its alias.
+     *
+     * @author Stanislav Muhametsin
+     */
+    class ColumnReferenceInfo
+    {
+        private final String _alias;
+        private final ColumnReference _reference;
+
+        public ColumnReferenceInfo( String alias, ColumnReference reference )
+        {
+            Objects.requireNonNull( reference );
+
+            this._alias = alias;
+            this._reference = reference;
+        }
+
+        /**
+         * Returns the alias of this column reference. May be {@code null.}
+         *
+         * @return The alias of this column reference. May be {@code null.}
+         */
+        public String getAlias()
+        {
+            return this._alias;
+        }
+
+        /**
+         * Returns the column reference.
+         *
+         * @return The column reference.
+         */
+        public ColumnReference getReference()
+        {
+            return this._reference;
+        }
+    }
+
+    /**
+     * Returns the list of column references, along with their aliases.
+     *
+     * @return The list of column references, along with their aliases.
+     */
+    List<ColumnReferenceInfo> getColumns();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/CorrespondingSpec.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/CorrespondingSpec.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/CorrespondingSpec.java
new file mode 100644
index 0000000..67d4ee6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/CorrespondingSpec.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+
+/**
+ * This syntax element represents the {@code CORRESPONDING BY} clause in {@code UNION}, {@code INTERSECT}, and
+ * {@code EXCEPT} operations on queries.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface CorrespondingSpec
+    extends Typeable<CorrespondingSpec>
+{
+    /**
+     * Gets the column name correspondence list.
+     *
+     * @return The column name correspondence list.
+     */
+    ColumnNameList getColumnList();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/FromClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/FromClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/FromClause.java
new file mode 100644
index 0000000..9ab567d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/FromClause.java
@@ -0,0 +1,43 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinedTable;
+
+/**
+ * This syntax element represents the {@code FROM} clause in {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface FromClause
+    extends Typeable<FromClause>
+{
+    /**
+     * Gets all the table references. Each table reference may be a simple reference to table name, sub-query, or a
+     * joined table.
+     *
+     * @return The table references for this {@code FROM} clause.
+     * @see TableReference
+     * @see JoinedTable
+     */
+    List<TableReference> getTableReferences();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupByClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupByClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupByClause.java
new file mode 100644
index 0000000..90264f2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupByClause.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This syntax element represents the {@code GROUP BY} clause in {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface GroupByClause
+    extends Typeable<GroupByClause>
+{
+    /**
+     * Returns the grouping elements of this {@code GROUP BY} clause.
+     *
+     * @return The grouping elements of this {@code GROUP BY} clause.
+     * @see GroupingElement
+     */
+    List<GroupingElement> getGroupingElements();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupingElement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupingElement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupingElement.java
new file mode 100644
index 0000000..c5b4f55
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/GroupingElement.java
@@ -0,0 +1,59 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is a common interface for a grouping element of the {@code GROUP BY} clause.
+ *
+ * @author Stanislav Muhametsin
+ * @see GroupByClause
+ */
+public interface GroupingElement
+    extends Typeable<GroupingElement>
+{
+    /**
+     * This syntax element represents the grand total grouping element. It is open parenthesis followed by close
+     * parenthesis.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class GrandTotal
+        implements GroupingElement
+    {
+        private GrandTotal()
+        {
+        }
+
+        /**
+         * Returns {@link GrandTotal}
+         */
+        public Class<? extends GroupingElement> getImplementedType()
+        {
+            return GrandTotal.class;
+        }
+
+        /**
+         * The singleton instance of {@link GrandTotal}.
+         */
+        public static final GrandTotal INSTANCE = new GrandTotal();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/LimitSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/LimitSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/LimitSpecification.java
new file mode 100644
index 0000000..fb8cbe4
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/LimitSpecification.java
@@ -0,0 +1,42 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * This syntax element represents the {@code FETCH FIRST <number> ROWS ONLY} element of the query. This addition has
+ * been defined in SQL 2008 standard.
+ *
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface LimitSpecification
+    extends Typeable<LimitSpecification>
+{
+    /**
+     * Returns the {@code <number>} element in the {@code FETCH FIRST <number> ROWS ONLY} expression. Means the maximum
+     * amounts of rows to be selected.
+     *
+     * @return The maximum amount of rows to be selected. May be {@code null}, in which case the behaviour is
+     * vendor-specific.
+     */
+    NonBooleanExpression getCount();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OffsetSpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OffsetSpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OffsetSpecification.java
new file mode 100644
index 0000000..88b3ecf
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OffsetSpecification.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * This syntax element represents the {@code OFFSET <number> ROWS} element of the query. This addition has been defined
+ * in SQL 2008 standard.
+ *
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface OffsetSpecification
+    extends Typeable<OffsetSpecification>
+{
+    /**
+     * Returns the {@code <number>} element in the {@code OFFSET <number> ROWS} expression. Means the amount of rows to
+     * skip before including them into select.
+     *
+     * @return The amount of rows to be skipped before starting selecting.
+     */
+    NonBooleanExpression getSkip();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrderByClause.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrderByClause.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrderByClause.java
new file mode 100644
index 0000000..b1afbb3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrderByClause.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This syntax element represents the {@code ORDER BY} clause of {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface OrderByClause
+    extends Typeable<OrderByClause>
+{
+
+    /**
+     * Returns the ordering columns of this {@code ORDER BY} clause.
+     *
+     * @return The ordering columns of this {@code ORDER BY} clause.
+     */
+    List<SortSpecification> getOrderingColumns();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/Ordering.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/Ordering.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/Ordering.java
new file mode 100644
index 0000000..01b35cb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/Ordering.java
@@ -0,0 +1,21 @@
+package org.apache.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This is enum for what kind of order will be applied to each ordering column. Can be either {@link #ASCENDING} or
+ * {@link #DESCENDING}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SortSpecification
+ */
+public final class Ordering
+{
+    /**
+     * The ordering will be ascending ({@code ASC}).
+     */
+    public static final Ordering ASCENDING = new Ordering();
+
+    /**
+     * The ordering will be descending ({@code DESC}).
+     */
+    public static final Ordering DESCENDING = new Ordering();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrdinaryGroupingSet.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrdinaryGroupingSet.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrdinaryGroupingSet.java
new file mode 100644
index 0000000..17c9b71
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/OrdinaryGroupingSet.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * This syntax element represents the ordinary grouping set specification. In future there might be {@code CUBE} or
+ * {@code ROLLUP} grouping sets.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface OrdinaryGroupingSet
+    extends GroupingElement
+{
+    /**
+     * Returns the grouping column reference expressions.
+     *
+     * @return The grouping column reference expressions.
+     */
+    List<NonBooleanExpression> getColumns();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpression.java
new file mode 100644
index 0000000..b3807e5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpression.java
@@ -0,0 +1,42 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLStatement;
+
+/**
+ * This syntax element represents the {@link QueryExpressionBody} and, in future, the WithClause ({@code WITH}) to be
+ * used with query.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface QueryExpression
+    extends NonBooleanExpression, SQLStatement
+{
+    /**
+     * Returns the body of this query.
+     *
+     * @return The body of this query.
+     */
+    QueryExpressionBody getQueryExpressionBody();
+
+    // public WithClause getWithClause();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBody.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBody.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBody.java
new file mode 100644
index 0000000..1df2130
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBody.java
@@ -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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinedTable;
+
+/**
+ * This is common interface for a queries and joined tables.
+ *
+ * @author Stanislav Muhametsin
+ * @see QueryExpressionBodyActual
+ * @see JoinedTable
+ */
+public interface QueryExpressionBody
+    extends NonBooleanExpression
+{
+    /**
+     * This syntax element represents the empty query expression body. It is defined for convenience. For example, an
+     * {@code UNION} (or any other set operation) between empty query and another query is always just another query.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class EmptyQueryExpressionBody
+        implements QueryExpressionBody
+    {
+        private EmptyQueryExpressionBody()
+        {
+        }
+
+        /**
+         * Returns {@link EmptyQueryExpressionBody}.
+         */
+        public Class<? extends QueryExpressionBody> getImplementedType()
+        {
+            return EmptyQueryExpressionBody.class;
+        }
+
+        /**
+         * The singleton instance of {@link EmptyQueryExpressionBody}.
+         */
+        public static final EmptyQueryExpressionBody INSTANCE = new EmptyQueryExpressionBody();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyActual.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyActual.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyActual.java
new file mode 100644
index 0000000..857aa16
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyActual.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This is common interface for a query, which is either one {@code SELECT} statement, or many {@code SELECT} statements
+ * joined together with {@link SetOperation}s.
+ *
+ * @author Stanislav Muhametsin
+ * @see QuerySpecification
+ */
+public interface QueryExpressionBodyActual
+    extends QueryExpressionBody
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyBinary.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyBinary.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyBinary.java
new file mode 100644
index 0000000..cc1e211
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyBinary.java
@@ -0,0 +1,71 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+
+/**
+ * This syntax element represents two queries which have a set operation ({@code UNION}, {@code INTERSECT}, or
+ * {@code EXCEPT}) between them.
+ *
+ * @author Stanislav Muhametsin
+ * @see SetOperation
+ */
+public interface QueryExpressionBodyBinary
+    extends QueryExpressionBodyActual
+{
+    /**
+     * Returns the set operation to put between queries.
+     *
+     * @return The set operation to put between queries.
+     * @see SetOperation
+     */
+    SetOperation getSetOperation();
+
+    /**
+     * Returns the correspondence columns.
+     *
+     * @return The correspondence columns.
+     * @see CorrespondingSpec
+     */
+    CorrespondingSpec getCorrespondingColumns();
+
+    /**
+     * Returns the query on the left side of the set operation.
+     *
+     * @return The query on the left side of the set operation.
+     */
+    QueryExpressionBody getLeft();
+
+    /**
+     * Returns the query on the right side of the set operation.
+     *
+     * @return The query on the right side of the set operation.
+     */
+    QueryExpressionBody getRight();
+
+    /**
+     * Returns the set quantifier for the set operation.
+     *
+     * @return The set quantifier for the set operation.
+     * @see SetQuantifier
+     */
+    SetQuantifier getSetQuantifier();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyQuery.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyQuery.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyQuery.java
new file mode 100644
index 0000000..f25637a
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QueryExpressionBodyQuery.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+/**
+ * This syntax element represents the single query (currently only {@code SELECT} statement, represented by
+ * {@link QuerySpecification}.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface QueryExpressionBodyQuery
+    extends QueryExpressionBodyActual
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QuerySpecification.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QuerySpecification.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QuerySpecification.java
new file mode 100644
index 0000000..b35be17
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/QuerySpecification.java
@@ -0,0 +1,95 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+
+/**
+ * This syntax element represents the single {@code SELECT} statement.
+ *
+ * @author Stanislav Muhametsin
+ * @see QuerySpecificationBuilder
+ * @see SelectColumnClause
+ * @see FromClause
+ * @see BooleanExpression
+ * @see GroupByClause
+ * @see OrderByClause
+ */
+public interface QuerySpecification
+    extends QueryExpressionBodyQuery
+{
+
+    /**
+     * Returns the columns in this {@code SELECT} statement.
+     *
+     * @return The columns in this {@code SELECT} statement.
+     */
+    SelectColumnClause getColumns();
+
+    /**
+     * Returns the {@code FROM} clause of this {@code SELECT} statement.
+     *
+     * @return The {@code FROM} clause of this {@code SELECT} statement.
+     */
+    FromClause getFrom();
+
+    /**
+     * Returns the search condition for resulting rows of this {@code SELECT} statement.
+     *
+     * @return The search condition for resulting rows of this {@code SELECT} statement.
+     */
+    BooleanExpression getWhere();
+
+    /**
+     * Returns the {@code GROUP BY} clause of this {@code SELECT} statement.
+     *
+     * @return The {@code GROUP BY} clause of this {@code SELECT} statement.
+     */
+    GroupByClause getGroupBy();
+
+    /**
+     * Returns the grouping condition for {@code GROUP BY} clause of this {@code SELECT} statement.
+     *
+     * @return The grouping condition for {@code GROUP BY} clause of this {@code SELECT} statement.
+     */
+    BooleanExpression getHaving();
+
+    /**
+     * Returns the {@code ORDER BY} clause of this {@code SELECT} statement.
+     *
+     * @return The {@code ORDER BY} clause of this {@code SELECT} statement.
+     */
+    OrderByClause getOrderBy();
+
+    /**
+     * Returns the {@code FETCH FIRST <number> ROWS ONLY} expression for this {@code SELECT} statement.
+     *
+     * @return The {@code FETCH FIRST <number> ROWS ONLY} expression for this {@code SELECT} statement.
+     */
+    LimitSpecification getLimitSpecification();
+
+    /**
+     * Returns the {@code OFFSET <number> ROWS} expression for this {@code SELECT} statement.
+     *
+     * @return The {@code OFFSET <number> ROWS} expression for this {@code SELECT} statement.
+     */
+    OffsetSpecification getOffsetSpecification();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowDefinition.java
new file mode 100644
index 0000000..dcdf6bb
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/query/RowDefinition.java
@@ -0,0 +1,35 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.query;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * This syntax element represents a comma-separated row value definition of {@code VALUES} expression in query.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface RowDefinition
+    extends RowValueConstructor
+{
+
+    List<ValueExpression> getRowElements();
+}


[03/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ModificationProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ModificationProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ModificationProcessing.java
new file mode 100644
index 0000000..835ada1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ModificationProcessing.java
@@ -0,0 +1,291 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.Iterator;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.DynamicColumnSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ModificationProcessing
+{
+
+    public static abstract class DynamicColumnSourceProcessor<SourceType extends DynamicColumnSource>
+        extends
+        AbstractProcessor<SourceType>
+    {
+        public DynamicColumnSourceProcessor( Class<? extends SourceType> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, SourceType object,
+                                  StringBuilder builder )
+        {
+            if( object.getColumnNames() != null )
+            {
+                processor.process( object.getColumnNames(), builder );
+            }
+            this.doProcessColumnSource( processor, object, builder );
+        }
+
+        protected abstract void doProcessColumnSource( SQLProcessorAggregator processor,
+                                                       SourceType object,
+                                                       StringBuilder builder );
+    }
+
+    public static class ColumnSourceByQueryProcessor extends
+                                                     DynamicColumnSourceProcessor<ColumnSourceByQuery>
+    {
+
+        public ColumnSourceByQueryProcessor()
+        {
+            this( ColumnSourceByQuery.class );
+        }
+
+        protected ColumnSourceByQueryProcessor( Class<? extends ColumnSourceByQuery> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcessColumnSource( SQLProcessorAggregator processor,
+                                              ColumnSourceByQuery object,
+                                              StringBuilder builder )
+        {
+            builder.append( SQLConstants.NEWLINE );
+            processor.process( object.getQuery(), builder );
+        }
+    }
+
+    public static class ColumnSourceByValuesProcessor extends
+                                                      DynamicColumnSourceProcessor<ColumnSourceByValues>
+    {
+
+        public ColumnSourceByValuesProcessor()
+        {
+            this( ColumnSourceByValues.class );
+        }
+
+        public ColumnSourceByValuesProcessor( Class<? extends ColumnSourceByValues> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcessColumnSource( SQLProcessorAggregator processor,
+                                              ColumnSourceByValues object,
+                                              StringBuilder builder )
+        {
+            builder.append( SQLConstants.NEWLINE ).append( "VALUES" )
+                   .append( SQLConstants.OPEN_PARENTHESIS );
+            Iterator<ValueExpression> iter = object.getValues().iterator();
+            while( iter.hasNext() )
+            {
+                ValueExpression next = iter.next();
+                boolean needParenthesis = next instanceof QueryExpression;
+                if( needParenthesis )
+                {
+                    builder.append( SQLConstants.OPEN_PARENTHESIS );
+                }
+                processor.process( next, builder );
+                if( needParenthesis )
+                {
+                    builder.append( SQLConstants.CLOSE_PARENTHESIS );
+                }
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static class DeleteBySearchProcessor extends AbstractProcessor<DeleteBySearch>
+    {
+        public DeleteBySearchProcessor()
+        {
+            this( DeleteBySearch.class );
+        }
+
+        public DeleteBySearchProcessor( Class<? extends DeleteBySearch> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, DeleteBySearch object,
+                                  StringBuilder builder )
+        {
+            builder.append( "DELETE FROM" ).append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( object.getTargetTable(), builder );
+            QueryProcessing.processOptionalBooleanExpression( processor, builder,
+                                                              object.getWhere(),
+                                                              SQLConstants.NEWLINE, SQLConstants.WHERE );
+        }
+    }
+
+    public static class InsertStatementProcessor extends AbstractProcessor<InsertStatement>
+    {
+        public InsertStatementProcessor()
+        {
+            this( InsertStatement.class );
+        }
+
+        public InsertStatementProcessor( Class<? extends InsertStatement> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, InsertStatement object,
+                                  StringBuilder builder )
+        {
+            builder.append( "INSERT INTO" ).append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( object.getTableName(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( object.getColumnSource(), builder );
+        }
+    }
+
+    public static class SetClauseProcessor extends AbstractProcessor<SetClause>
+    {
+        public SetClauseProcessor()
+        {
+            this( SetClause.class );
+        }
+
+        public SetClauseProcessor( Class<? extends SetClause> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, SetClause object,
+                                  StringBuilder builder )
+        {
+            builder.append( object.getUpdateTarget() ).append( SQLConstants.TOKEN_SEPARATOR )
+                   .append( "=" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( object.getUpdateSource(), builder );
+        }
+    }
+
+    public static class TargetTableProcessor extends AbstractProcessor<TargetTable>
+    {
+        public TargetTableProcessor()
+        {
+            this( TargetTable.class );
+        }
+
+        protected TargetTableProcessor( Class<? extends TargetTable> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TargetTable object,
+                                  StringBuilder builder )
+        {
+            Boolean isOnly = object.isOnly();
+            if( isOnly )
+            {
+                builder.append( "ONLY" ).append( SQLConstants.OPEN_PARENTHESIS );
+            }
+            processor.process( object.getTableName(), builder );
+            if( isOnly )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+    }
+
+    public static class UpdateBySearchProcessor extends AbstractProcessor<UpdateBySearch>
+    {
+        public UpdateBySearchProcessor()
+        {
+            this( UpdateBySearch.class );
+        }
+
+        protected UpdateBySearchProcessor( Class<? extends UpdateBySearch> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, UpdateBySearch object,
+                                  StringBuilder builder )
+        {
+            builder.append( "UPDATE" ).append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( object.getTargetTable(), builder );
+            builder.append( SQLConstants.NEWLINE ).append( "SET" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            Iterator<SetClause> iter = object.getSetClauses().iterator();
+            while( iter.hasNext() )
+            {
+                processor.process( iter.next(), builder );
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+            QueryProcessing.processOptionalBooleanExpression( processor, builder,
+                                                              object.getWhere(),
+                                                              SQLConstants.NEWLINE, SQLConstants.WHERE );
+        }
+    }
+
+    public static class UpdateSourceByExpressionProcessor extends
+                                                          AbstractProcessor<UpdateSourceByExpression>
+    {
+        public UpdateSourceByExpressionProcessor()
+        {
+            this( UpdateSourceByExpression.class );
+        }
+
+        public UpdateSourceByExpressionProcessor( Class<? extends UpdateSourceByExpression> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor,
+                                  UpdateSourceByExpression object,
+                                  StringBuilder builder )
+        {
+            processor.process( object.getValueExpression(), builder );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/NoOpProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/NoOpProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/NoOpProcessor.java
new file mode 100644
index 0000000..e6bc330
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/NoOpProcessor.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+public class NoOpProcessor
+    implements SQLProcessor
+{
+
+    public void process( SQLProcessorAggregator processor, Typeable<?> object, StringBuilder builder )
+    {
+        // No-op
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ProcessorUtils.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ProcessorUtils.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ProcessorUtils.java
new file mode 100644
index 0000000..15bb6b3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/ProcessorUtils.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class ProcessorUtils
+{
+    public static Boolean notNullAndNotEmpty( String str )
+    {
+        return str != null && str.trim().length() > 0;
+    }
+
+    public static void processSetQuantifier( SetQuantifier quantifier, StringBuilder builder )
+    {
+        if( quantifier == SetQuantifier.ALL )
+        {
+            builder.append( "ALL" );
+        }
+        else
+        {
+            builder.append( "DISTINCT" );
+        }
+    }
+
+    public static void processDropBehaviour( DropBehaviour behaviour, StringBuilder builder )
+    {
+        builder.append( SQLConstants.TOKEN_SEPARATOR );
+        if( behaviour == DropBehaviour.CASCADE )
+        {
+            builder.append( "CASCADE" );
+        }
+        else
+        {
+            builder.append( "RESTRICT" );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/QueryProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/QueryProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/QueryProcessing.java
new file mode 100644
index 0000000..e49bf15
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/QueryProcessing.java
@@ -0,0 +1,615 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.LiteralExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences;
+import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo;
+import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec;
+import org.apache.polygene.library.sql.generator.grammar.query.FromClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBodyBinary;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.RowDefinition;
+import org.apache.polygene.library.sql.generator.grammar.query.RowSubQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause;
+import org.apache.polygene.library.sql.generator.grammar.query.SetOperation;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReference;
+import org.apache.polygene.library.sql.generator.grammar.query.TableValueConstructor;
+import org.apache.polygene.library.sql.generator.implementation.grammar.booleans.BooleanUtils;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class QueryProcessing
+{
+
+    public static void processOptionalBooleanExpression( SQLProcessorAggregator processor,
+                                                         StringBuilder builder,
+                                                         BooleanExpression expression, String prefix, String name )
+    {
+        if( expression != null && !BooleanUtils.isEmpty( expression ) )
+        {
+            processOptional( processor, builder, expression, prefix, name );
+        }
+    }
+
+    public static void processOptional( SQLProcessorAggregator processor, StringBuilder builder,
+                                        Typeable<?> element,
+                                        String prefix, String name )
+    {
+        if( element != null )
+        {
+            builder.append( prefix );
+            if( name != null )
+            {
+                builder.append( name ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+            processor.process( element, builder );
+        }
+    }
+
+    public static class QueryExpressionBinaryProcessor extends
+                                                       AbstractProcessor<QueryExpressionBodyBinary>
+    {
+        private static final Map<SetOperation, String> _defaultSetOperations;
+
+        static
+        {
+            Map<SetOperation, String> operations = new HashMap<SetOperation, String>();
+            operations.put( SetOperation.EXCEPT, "EXCEPT" );
+            operations.put( SetOperation.INTERSECT, "INTERSECT" );
+            operations.put( SetOperation.UNION, "UNION" );
+            _defaultSetOperations = operations;
+        }
+
+        private final Map<SetOperation, String> _setOperations;
+
+        public QueryExpressionBinaryProcessor()
+        {
+            this( _defaultSetOperations );
+        }
+
+        public QueryExpressionBinaryProcessor( Map<SetOperation, String> setOperations )
+        {
+            super( QueryExpressionBodyBinary.class );
+            Objects.requireNonNull( setOperations, "set operations" );
+            this._setOperations = setOperations;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, QueryExpressionBodyBinary body,
+                                  StringBuilder builder )
+        {
+            Boolean leftIsNotEmpty =
+                body.getLeft() != QueryExpressionBody.EmptyQueryExpressionBody.INSTANCE;
+            if( leftIsNotEmpty )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS );
+                processor.process( body.getLeft(), builder );
+                builder.append( SQLConstants.CLOSE_PARENTHESIS ).append( SQLConstants.NEWLINE );
+                this.processSetOperation( body.getSetOperation(), builder );
+
+                builder.append( SQLConstants.TOKEN_SEPARATOR );
+                ProcessorUtils.processSetQuantifier( body.getSetQuantifier(), builder );
+
+                CorrespondingSpec correspondingCols = body.getCorrespondingColumns();
+                if( correspondingCols != null )
+                {
+                    builder.append( SQLConstants.TOKEN_SEPARATOR );
+                    processor.process( correspondingCols, builder );
+                }
+
+                builder.append( SQLConstants.NEWLINE ).append( SQLConstants.OPEN_PARENTHESIS );
+            }
+            processor.process( body.getRight(), builder );
+            if( leftIsNotEmpty )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+        }
+
+        protected void processSetOperation( SetOperation operation, StringBuilder builder )
+        {
+            builder.append( this._setOperations.get( operation ) );
+        }
+    }
+
+    public static class QuerySpecificationProcessor extends AbstractProcessor<QuerySpecification>
+    {
+
+        public QuerySpecificationProcessor()
+        {
+            this( QuerySpecification.class );
+        }
+
+        public QuerySpecificationProcessor( Class<? extends QuerySpecification> queryClass )
+        {
+            super( queryClass );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, QuerySpecification query,
+                                  StringBuilder builder )
+        {
+            builder.append( SQLConstants.SELECT ).append( SQLConstants.TOKEN_SEPARATOR );
+            ProcessorUtils.processSetQuantifier( query.getColumns().getSetQuantifier(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR );
+
+            processor.process( query.getColumns(), builder );
+            processor.process( query.getFrom(), builder );
+            QueryProcessing.processOptionalBooleanExpression( processor, builder, query.getWhere(),
+                                                              SQLConstants.NEWLINE, SQLConstants.WHERE );
+            processor.process( query.getGroupBy(), builder );
+            QueryProcessing.processOptionalBooleanExpression( processor, builder,
+                                                              query.getHaving(),
+                                                              SQLConstants.NEWLINE, SQLConstants.HAVING );
+            processor.process( query.getOrderBy(), builder );
+            Typeable<?> first = null;
+            Typeable<?> second = null;
+            if( this.isOffsetBeforeLimit( processor ) )
+            {
+                first = query.getOffsetSpecification();
+                second = query.getLimitSpecification();
+            }
+            else
+            {
+                first = query.getLimitSpecification();
+                second = query.getOffsetSpecification();
+            }
+
+            if( first != null || second != null )
+            {
+                this.processLimitAndOffset( processor, builder, first, second );
+            }
+
+            if( query.getOrderBy() == null
+                && ( query.getOffsetSpecification() != null || query.getLimitSpecification() != null ) )
+            {
+                LoggerFactory.getLogger( this.getClass().getName() ).warn(
+                    "Spotted query with " + SQLConstants.OFFSET_PREFIX + " and/or "
+                    + SQLConstants.LIMIT_PREFIX
+                    + " clause, but without ORDER BY. The result will be unpredictable!"
+                    + "\n" + "Query: "
+                    + builder.toString() );
+            }
+        }
+
+        protected boolean isOffsetBeforeLimit( SQLProcessorAggregator processor )
+        {
+            return true;
+        }
+
+        protected void processLimitAndOffset( SQLProcessorAggregator processor,
+                                              StringBuilder builder,
+                                              Typeable<?> first, Typeable<?> second )
+        {
+            QueryProcessing.processOptional( processor, builder, first, SQLConstants.NEWLINE, null );
+            QueryProcessing
+                .processOptional( processor, builder, second, SQLConstants.NEWLINE, null );
+        }
+    }
+
+    public static class SelectColumnsProcessor extends AbstractProcessor<SelectColumnClause>
+    {
+        public SelectColumnsProcessor()
+        {
+            super( SelectColumnClause.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SelectColumnClause select,
+                                  StringBuilder builder )
+        {
+            if( select instanceof ColumnReferences )
+            {
+                Iterator<ColumnReferenceInfo> iter =
+                    ( (ColumnReferences) select ).getColumns().iterator();
+                while( iter.hasNext() )
+                {
+                    ColumnReferenceInfo info = iter.next();
+                    aggregator.process( info.getReference(), builder );
+                    String alias = info.getAlias();
+                    if( ProcessorUtils.notNullAndNotEmpty( alias ) )
+                    {
+                        builder.append( SQLConstants.TOKEN_SEPARATOR )
+                               .append( SQLConstants.ALIAS_DEFINER )
+                               .append( SQLConstants.TOKEN_SEPARATOR ).append( alias );
+                    }
+
+                    if( iter.hasNext() )
+                    {
+                        builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                    }
+                }
+            }
+            else
+            {
+                builder.append( SQLConstants.ASTERISK );
+            }
+        }
+    }
+
+    public static class FromProcessor extends AbstractProcessor<FromClause>
+    {
+        public FromProcessor()
+        {
+            super( FromClause.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, FromClause from,
+                                  StringBuilder builder )
+        {
+            if( !from.getTableReferences().isEmpty() )
+            {
+                builder.append( SQLConstants.NEWLINE ).append( SQLConstants.FROM )
+                       .append( SQLConstants.TOKEN_SEPARATOR );
+                Iterator<TableReference> iter = from.getTableReferences().iterator();
+                while( iter.hasNext() )
+                {
+                    aggregator.process( iter.next().asTypeable(), builder );
+                    if( iter.hasNext() )
+                    {
+                        builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                    }
+                }
+            }
+        }
+    }
+
+    public static class QueryExpressionProcessor extends AbstractProcessor<QueryExpression>
+    {
+        public QueryExpressionProcessor()
+        {
+            super( QueryExpression.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, QueryExpression object,
+                                  StringBuilder builder )
+        {
+            processor.process( object.getQueryExpressionBody(), builder );
+        }
+    }
+
+    public static class CorrespondingSpecProcessor extends AbstractProcessor<CorrespondingSpec>
+    {
+        public CorrespondingSpecProcessor()
+        {
+            super( CorrespondingSpec.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, CorrespondingSpec object,
+                                  StringBuilder builder )
+        {
+            builder.append( "CORRESPONDING" );
+            if( object.getColumnList() != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "BY" )
+                       .append( SQLConstants.TOKEN_SEPARATOR );
+                processor.process( object.getColumnList(), builder );
+            }
+        }
+    }
+
+    public static class SortSpecificationProcessor extends AbstractProcessor<SortSpecification>
+    {
+        private static final Map<Ordering, String> _defaultOrderingStrings;
+
+        static
+        {
+            Map<Ordering, String> map = new HashMap<Ordering, String>();
+            map.put( Ordering.ASCENDING, "ASC" );
+            map.put( Ordering.DESCENDING, "DESC" );
+            _defaultOrderingStrings = map;
+        }
+
+        private final Map<Ordering, String> _orderingStrings;
+
+        public SortSpecificationProcessor()
+        {
+            this( _defaultOrderingStrings );
+        }
+
+        public SortSpecificationProcessor( Map<Ordering, String> orderingStrings )
+        {
+            super( SortSpecification.class );
+            Objects.requireNonNull( orderingStrings, "ordering strings" );
+            this._orderingStrings = orderingStrings;
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, SortSpecification object,
+                                  StringBuilder builder )
+        {
+            processor.process( object.getValueExpression(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append(
+                this._orderingStrings.get( object.getOrderingSpecification() ) );
+        }
+    }
+
+    public static class OrdinaryGroupingSetProcessor extends AbstractProcessor<OrdinaryGroupingSet>
+    {
+        public OrdinaryGroupingSetProcessor()
+        {
+            super( OrdinaryGroupingSet.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, OrdinaryGroupingSet object,
+                                  StringBuilder builder )
+        {
+            Iterator<NonBooleanExpression> iter = object.getColumns().iterator();
+            while( iter.hasNext() )
+            {
+                processor.process( iter.next(), builder );
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+        }
+    }
+
+    public static class GroupByProcessor extends AbstractProcessor<GroupByClause>
+    {
+        public GroupByProcessor()
+        {
+            super( GroupByClause.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, GroupByClause groupBy,
+                                  StringBuilder builder )
+        {
+            if( !groupBy.getGroupingElements().isEmpty() )
+            {
+                builder.append( SQLConstants.NEWLINE ).append( SQLConstants.GROUP_BY )
+                       .append( SQLConstants.TOKEN_SEPARATOR );
+                Iterator<GroupingElement> iter = groupBy.getGroupingElements().iterator();
+                while( iter.hasNext() )
+                {
+                    aggregator.process( iter.next(), builder );
+                    if( iter.hasNext() )
+                    {
+                        builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                    }
+                }
+            }
+        }
+    }
+
+    public static class OrderByProcessor extends AbstractProcessor<OrderByClause>
+    {
+        public OrderByProcessor()
+        {
+            super( OrderByClause.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, OrderByClause orderBy,
+                                  StringBuilder builder )
+        {
+            if( !orderBy.getOrderingColumns().isEmpty() )
+            {
+                builder.append( SQLConstants.NEWLINE ).append( SQLConstants.ORDER_BY )
+                       .append( SQLConstants.TOKEN_SEPARATOR );
+                Iterator<SortSpecification> iter = orderBy.getOrderingColumns().iterator();
+                while( iter.hasNext() )
+                {
+                    aggregator.process( iter.next(), builder );
+                    if( iter.hasNext() )
+                    {
+                        builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                    }
+                }
+            }
+        }
+    }
+
+    public static class TableValueConstructorProcessor extends
+                                                       AbstractProcessor<TableValueConstructor>
+    {
+        public TableValueConstructorProcessor()
+        {
+            super( TableValueConstructor.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, TableValueConstructor object,
+                                  StringBuilder builder )
+        {
+            builder.append( "VALUES" ).append( SQLConstants.TOKEN_SEPARATOR );
+            Iterator<RowValueConstructor> iter = object.getRows().iterator();
+            while( iter.hasNext() )
+            {
+                aggregator.process( iter.next(), builder );
+                if( iter.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+        }
+    }
+
+    public static class RowSubQueryProcessor extends AbstractProcessor<RowSubQuery>
+    {
+        public RowSubQueryProcessor()
+        {
+            super( RowSubQuery.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, RowSubQuery object,
+                                  StringBuilder builder )
+        {
+            builder.append( SQLConstants.OPEN_PARENTHESIS );
+            aggregator.process( object.getQueryExpression(), builder );
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static class RowDefinitionProcessor extends AbstractProcessor<RowDefinition>
+    {
+        public RowDefinitionProcessor()
+        {
+            super( RowDefinition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, RowDefinition object,
+                                  StringBuilder builder )
+        {
+            builder.append( SQLConstants.OPEN_PARENTHESIS );
+            Iterator<ValueExpression> vals = object.getRowElements().iterator();
+            while( vals.hasNext() )
+            {
+                aggregator.process( vals.next(), builder );
+                if( vals.hasNext() )
+                {
+                    builder.append( SQLConstants.COMMA ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+            }
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static class OffsetSpecificationProcessor extends AbstractProcessor<OffsetSpecification>
+    {
+
+        public OffsetSpecificationProcessor()
+        {
+            super( OffsetSpecification.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, OffsetSpecification object,
+                                  StringBuilder builder )
+        {
+            String prefix = this.getPrefix( aggregator );
+            if( prefix != null )
+            {
+                builder.append( prefix ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+            NonBooleanExpression skip = object.getSkip();
+            boolean isComplex = !( skip instanceof LiteralExpression );
+            if( isComplex )
+            {
+                builder.append( SQLConstants.OPEN_PARENTHESIS ).append( SQLConstants.NEWLINE );
+            }
+            aggregator.process( skip, builder );
+            if( isComplex )
+            {
+                builder.append( SQLConstants.CLOSE_PARENTHESIS );
+            }
+            String postfix = this.getPostfix( aggregator );
+            if( postfix != null )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( postfix );
+            }
+        }
+
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return SQLConstants.OFFSET_PREFIX;
+        }
+
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return SQLConstants.OFFSET_POSTFIX;
+        }
+    }
+
+    public static class LimitSpecificationProcessor extends AbstractProcessor<LimitSpecification>
+    {
+        public LimitSpecificationProcessor()
+        {
+            super( LimitSpecification.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, LimitSpecification object,
+                                  StringBuilder builder )
+        {
+            NonBooleanExpression count = this.getRealCount( object.getCount() );
+            if( count != null )
+            {
+                String prefix = this.getPrefix( aggregator );
+                if( prefix != null )
+                {
+                    builder.append( prefix ).append( SQLConstants.TOKEN_SEPARATOR );
+                }
+                boolean isComplex = !( count instanceof LiteralExpression );
+                if( isComplex )
+                {
+                    builder.append( SQLConstants.OPEN_PARENTHESIS ).append( SQLConstants.NEWLINE );
+                }
+                aggregator.process( count, builder );
+                if( isComplex )
+                {
+                    builder.append( SQLConstants.CLOSE_PARENTHESIS );
+                }
+                String postfix = this.getPostfix( aggregator );
+                if( postfix != null )
+                {
+                    builder.append( SQLConstants.TOKEN_SEPARATOR ).append( postfix );
+                }
+            }
+        }
+
+        protected NonBooleanExpression getRealCount( NonBooleanExpression limitCount )
+        {
+            return limitCount;
+        }
+
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return SQLConstants.LIMIT_PREFIX;
+        }
+
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return SQLConstants.LIMIT_POSTFIX;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/TableReferenceProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/TableReferenceProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/TableReferenceProcessing.java
new file mode 100644
index 0000000..151b4f7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/TableReferenceProcessing.java
@@ -0,0 +1,354 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferencePrimary;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.CrossJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinCondition;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NamedColumnsJoin;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NaturalJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.QualifiedJoinedTable;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.UnionJoinedTable;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableReferenceProcessing
+{
+
+    public static abstract class AbstractTableNameProcessor<TableNameType extends TableName>
+        extends
+        AbstractProcessor<TableNameType>
+    {
+
+        protected AbstractTableNameProcessor( Class<? extends TableNameType> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TableNameType object,
+                                  StringBuilder builder )
+        {
+            String schemaName = object.getSchemaName();
+            if( ProcessorUtils.notNullAndNotEmpty( schemaName ) )
+            {
+                builder.append( schemaName ).append( SQLConstants.SCHEMA_TABLE_SEPARATOR );
+            }
+            this.doProcessTableName( processor, object, builder );
+        }
+
+        protected abstract void doProcessTableName( SQLProcessorAggregator processor,
+                                                    TableNameType object,
+                                                    StringBuilder builder );
+    }
+
+    public static class TableNameFunctionProcessor extends
+                                                   AbstractTableNameProcessor<TableNameFunction>
+    {
+
+        public TableNameFunctionProcessor()
+        {
+            this( TableNameFunction.class );
+        }
+
+        protected TableNameFunctionProcessor( Class<? extends TableNameFunction> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcessTableName( SQLProcessorAggregator processor,
+                                           TableNameFunction object,
+                                           StringBuilder builder )
+        {
+            processor.process( object.getFunction(), builder );
+        }
+    }
+
+    public static class TableNameDirectProcessor extends
+                                                 AbstractTableNameProcessor<TableNameDirect>
+    {
+
+        public TableNameDirectProcessor()
+        {
+            this( TableNameDirect.class );
+        }
+
+        protected TableNameDirectProcessor( Class<? extends TableNameDirect> realType )
+        {
+            super( realType );
+        }
+
+        @Override
+        protected void doProcessTableName( SQLProcessorAggregator processor,
+                                           TableNameDirect object,
+                                           StringBuilder builder )
+        {
+            builder.append( object.getTableName() );
+        }
+    }
+
+    public static abstract class TableReferencePrimaryProcessor<TableReferenceType extends TableReferencePrimary>
+        extends AbstractProcessor<TableReferenceType>
+    {
+        public TableReferencePrimaryProcessor( Class<TableReferenceType> realType )
+        {
+            super( realType );
+        }
+
+        protected void doProcess( SQLProcessorAggregator processor, TableReferenceType object,
+                                  StringBuilder builder )
+        {
+            this.doProcessTablePrimary( processor, object, builder );
+            if( object.getTableAlias() != null )
+            {
+                this.processTableAlias( processor, object.getTableAlias(), builder );
+            }
+        }
+
+        protected abstract void doProcessTablePrimary( SQLProcessorAggregator processor,
+                                                       TableReferenceType object,
+                                                       StringBuilder builder );
+
+        protected void processTableAlias( SQLProcessorAggregator processor, TableAlias tableAlias,
+                                          StringBuilder builder )
+        {
+            String alias = tableAlias.getTableAlias();
+            if( ProcessorUtils.notNullAndNotEmpty( alias ) )
+            {
+                builder.append( SQLConstants.TOKEN_SEPARATOR ).append( SQLConstants.ALIAS_DEFINER )
+                       .append( SQLConstants.TOKEN_SEPARATOR ).append( alias );
+
+                if( tableAlias.getColumnAliases() != null )
+                {
+                    processor.process( tableAlias.getColumnAliases(), builder );
+                }
+            }
+        }
+    }
+
+    public static class TableReferenceByNameProcessor extends
+                                                      TableReferencePrimaryProcessor<TableReferenceByName>
+    {
+        public TableReferenceByNameProcessor()
+        {
+            super( TableReferenceByName.class );
+        }
+
+        @Override
+        protected void doProcessTablePrimary( SQLProcessorAggregator processor,
+                                              TableReferenceByName object,
+                                              StringBuilder builder )
+        {
+            processor.process( object.getTableName(), builder );
+        }
+    }
+
+    public static class TableReferenceByExpressionProcessor extends
+                                                            TableReferencePrimaryProcessor<TableReferenceByExpression>
+    {
+        public TableReferenceByExpressionProcessor()
+        {
+            super( TableReferenceByExpression.class );
+        }
+
+        @Override
+        protected void doProcessTablePrimary( SQLProcessorAggregator processor,
+                                              TableReferenceByExpression tableRef,
+                                              StringBuilder builder )
+        {
+            builder.append( SQLConstants.OPEN_PARENTHESIS );
+            processor.process( tableRef.getQuery(), builder );
+            builder.append( SQLConstants.CLOSE_PARENTHESIS );
+        }
+    }
+
+    public static abstract class JoinedTableProcessor<JoinedTableType extends JoinedTable> extends
+                                                                                           AbstractProcessor<JoinedTableType>
+    {
+
+        public JoinedTableProcessor( Class<JoinedTableType> realType )
+        {
+            super( realType );
+        }
+
+        protected void doProcess( SQLProcessorAggregator processor, JoinedTableType table,
+                                  StringBuilder builder )
+        {
+            processor.process( table.getLeft().asTypeable(), builder );
+            builder.append( SQLConstants.NEWLINE );
+            this.doProcessJoinedTable( processor, table, builder );
+        }
+
+        protected abstract void doProcessJoinedTable( SQLProcessorAggregator processor,
+                                                      JoinedTableType table,
+                                                      StringBuilder builder );
+
+        protected void processJoinType( JoinType joinType, StringBuilder builder )
+        {
+            if( joinType != null )
+            {
+                if( joinType == JoinType.INNER )
+                {
+                    builder.append( "INNER " );
+                }
+                else
+                {
+                    if( joinType == JoinType.FULL_OUTER )
+                    {
+                        builder.append( "FULL " );
+                    }
+                    else if( joinType == JoinType.LEFT_OUTER )
+                    {
+                        builder.append( "LEFT " );
+                    }
+                    else
+                    // if (joinType == JoinType.RIGHT_OUTER)
+                    {
+                        builder.append( "RIGHT " );
+                    }
+                }
+                builder.append( "JOIN" ).append( SQLConstants.TOKEN_SEPARATOR );
+            }
+        }
+    }
+
+    public static class CrossJoinedTableProcessor extends JoinedTableProcessor<CrossJoinedTable>
+    {
+        public CrossJoinedTableProcessor()
+        {
+            super( CrossJoinedTable.class );
+        }
+
+        @Override
+        protected void doProcessJoinedTable( SQLProcessorAggregator processor,
+                                             CrossJoinedTable table,
+                                             StringBuilder builder )
+        {
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "CROSS JOIN" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( table.getRight().asTypeable(), builder );
+        }
+    }
+
+    public static class NaturalJoinedTableProcessor extends
+                                                    JoinedTableProcessor<NaturalJoinedTable>
+    {
+        public NaturalJoinedTableProcessor()
+        {
+            super( NaturalJoinedTable.class );
+        }
+
+        @Override
+        protected void doProcessJoinedTable( SQLProcessorAggregator processor,
+                                             NaturalJoinedTable table,
+                                             StringBuilder builder )
+        {
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "NATURAL" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            this.processJoinType( table.getJoinType(), builder );
+            builder.append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( table.getRight().asTypeable(), builder );
+        }
+    }
+
+    public static class QualifiedJoinedTableProcessor extends
+                                                      JoinedTableProcessor<QualifiedJoinedTable>
+    {
+        public QualifiedJoinedTableProcessor()
+        {
+            super( QualifiedJoinedTable.class );
+        }
+
+        @Override
+        protected void doProcessJoinedTable( SQLProcessorAggregator processor,
+                                             QualifiedJoinedTable table,
+                                             StringBuilder builder )
+        {
+            this.processJoinType( table.getJoinType(), builder );
+            processor.process( table.getRight().asTypeable(), builder );
+            processor.process( table.getJoinSpecification(), builder );
+        }
+    }
+
+    public static class UnionJoinedTableProcessor extends JoinedTableProcessor<UnionJoinedTable>
+    {
+        public UnionJoinedTableProcessor()
+        {
+            super( UnionJoinedTable.class );
+        }
+
+        @Override
+        protected void doProcessJoinedTable( SQLProcessorAggregator processor,
+                                             UnionJoinedTable table,
+                                             StringBuilder builder )
+        {
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "UNION JOIN" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( table.getRight().asTypeable(), builder );
+        }
+    }
+
+    public static class JoinConditionProcessor extends AbstractProcessor<JoinCondition>
+    {
+        public JoinConditionProcessor()
+        {
+            super( JoinCondition.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, JoinCondition condition,
+                                  StringBuilder builder )
+        {
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "ON" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+            processor.process( condition.getSearchConidition(), builder );
+        }
+    }
+
+    public static class NamedColumnsJoinProcessor extends AbstractProcessor<NamedColumnsJoin>
+    {
+        public NamedColumnsJoinProcessor()
+        {
+            super( NamedColumnsJoin.class );
+        }
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, NamedColumnsJoin join,
+                                  StringBuilder builder )
+        {
+            builder.append( SQLConstants.TOKEN_SEPARATOR ).append( "USING" )
+                   .append( SQLConstants.TOKEN_SEPARATOR );
+
+            processor.process( join.getColumnNames(), builder );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/derby/DerbyProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/derby/DerbyProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/derby/DerbyProcessor.java
new file mode 100644
index 0000000..afc7d35
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/derby/DerbyProcessor.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.derby;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+public class DerbyProcessor extends DefaultSQLProcessor
+{
+
+    public DerbyProcessor( SQLVendor vendor )
+    {
+        super( vendor, DefaultSQLProcessor.getDefaultProcessors() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/h2/H2Processor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/h2/H2Processor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/h2/H2Processor.java
new file mode 100644
index 0000000..8176980
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/h2/H2Processor.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.h2;
+
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+public class H2Processor
+    extends DefaultSQLProcessor
+{
+
+    public H2Processor( SQLVendor vendor )
+    {
+        super( vendor, DefaultSQLProcessor.getDefaultProcessors() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/DefinitionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/DefinitionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/DefinitionProcessing.java
new file mode 100644
index 0000000..3ccc96f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/DefinitionProcessing.java
@@ -0,0 +1,54 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.mysql;
+
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.SchemaDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefinitionProcessing
+{
+
+    public static class MySQLSchemaDefinitionProcessor extends SchemaDefinitionProcessor
+    {
+
+        @Override
+        protected void doProcess( SQLProcessorAggregator aggregator, SchemaDefinition object, StringBuilder builder )
+        {
+            // Just process schema elements
+            this.processSchemaElements( aggregator, object, builder );
+        }
+    }
+
+    public static class MySQLColumnDefinitionProcessor extends ColumnDefinitionProcessor
+    {
+        @Override
+        protected void processAutoGenerationPolicy( ColumnDefinition object, StringBuilder builder )
+        {
+            // MySQL combines both ALWAYS and BY DEFAULT policies.
+            builder.append( " AUTO_INCREMENT" );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/MySQLProcessor.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/MySQLProcessor.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/MySQLProcessor.java
new file mode 100644
index 0000000..dc036f6
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/MySQLProcessor.java
@@ -0,0 +1,81 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.mysql;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.definition.schema.SchemaDefinition;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropSchemaStatement;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefaultSQLProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.NoOpProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.DefinitionProcessing.MySQLColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.DefinitionProcessing.MySQLSchemaDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.QueryProcessing.MySQLLimitSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.QueryProcessing.MySQLOffsetSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.QueryProcessing.MySQLQuerySpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.TableProcessing.MySQLTableNameDirectProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.mysql.TableProcessing.MySQLTableNameFunctionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class MySQLProcessor extends DefaultSQLProcessor
+{
+
+    private static final Map<Class<? extends Typeable<?>>, SQLProcessor> _defaultProcessors;
+
+    static
+    {
+        Map<Class<? extends Typeable<?>>, SQLProcessor> processors = new HashMap<Class<? extends Typeable<?>>, SQLProcessor>(
+            DefaultSQLProcessor.getDefaultProcessors() );
+
+        // MySQL does not understand schema-qualified table names (or anything related to schemas)
+        processors.put( TableNameDirect.class, new MySQLTableNameDirectProcessor() );
+        processors.put( TableNameFunction.class, new MySQLTableNameFunctionProcessor() );
+
+        // Only process schema elements from schema definition, and ignore drop schema statements
+        processors.put( SchemaDefinition.class, new MySQLSchemaDefinitionProcessor() );
+        processors.put( DropSchemaStatement.class, new NoOpProcessor() );
+
+        // Override default column definition support
+        processors.put( ColumnDefinition.class, new MySQLColumnDefinitionProcessor() );
+
+        // Different syntax for OFFSET/FETCH
+        processors.put( QuerySpecification.class, new MySQLQuerySpecificationProcessor() );
+        processors.put( OffsetSpecification.class, new MySQLOffsetSpecificationProcessor() );
+        processors.put( LimitSpecification.class, new MySQLLimitSpecificationProcessor() );
+
+        _defaultProcessors = processors;
+    }
+
+    public MySQLProcessor( SQLVendor vendor )
+    {
+        super( vendor, _defaultProcessors );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/QueryProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/QueryProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/QueryProcessing.java
new file mode 100644
index 0000000..7324418
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/QueryProcessing.java
@@ -0,0 +1,114 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.mysql;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+import org.apache.polygene.library.sql.generator.grammar.common.SQLConstants;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.LimitSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.OffsetSpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.QueryProcessing.QuerySpecificationProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+import org.apache.polygene.library.sql.generator.vendor.MySQLVendor;
+
+/**
+ * @author 2011 Stanislav Muhametsin
+ */
+public class QueryProcessing
+{
+    private static final String MYSQL_LIMIT_PREFIX = "LIMIT";
+    private static final String MYSQL_LIMIT_POSTFIX = null;
+    private static final String MYSQL_OFFSET_PREFIX = "OFFSET";
+    private static final String MYSQL_OFFSET_POSTFIX = null;
+
+    public static class MySQLQuerySpecificationProcessor extends QuerySpecificationProcessor
+    {
+        @Override
+        protected boolean isOffsetBeforeLimit( SQLProcessorAggregator processor )
+        {
+            return false;
+        }
+
+        @Override
+        protected void processLimitAndOffset( SQLProcessorAggregator processor, StringBuilder builder,
+                                              Typeable<?> first, Typeable<?> second )
+        {
+            MySQLVendor vendor = (MySQLVendor) processor.getVendor();
+            if( vendor.legacyLimit() )
+            {
+                // Just do the processing right away, because of the difference of syntax
+                builder.append( SQLConstants.NEWLINE ).append( MYSQL_LIMIT_PREFIX )
+                       .append( SQLConstants.TOKEN_SEPARATOR );
+                if( second != null )
+                {
+                    processor.process( ( (OffsetSpecification) second ).getSkip(), builder );
+                    builder.append( SQLConstants.COMMA );
+                }
+                if( first != null && ( (LimitSpecification) first ).getCount() != null )
+                {
+                    processor.process( ( (LimitSpecification) first ).getCount(), builder );
+                }
+                else if( second != null )
+                {
+                    builder.append( Long.MAX_VALUE );
+                }
+            }
+            else
+            {
+                if( first == null && second != null )
+                {
+                    first = vendor.getQueryFactory().limit( vendor.getLiteralFactory().n( Long.MAX_VALUE ) );
+                }
+                super.processLimitAndOffset( processor, builder, first, second );
+            }
+        }
+    }
+
+    public static class MySQLOffsetSpecificationProcessor extends OffsetSpecificationProcessor
+    {
+        @Override
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return MYSQL_OFFSET_PREFIX;
+        }
+
+        @Override
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return MYSQL_OFFSET_POSTFIX;
+        }
+    }
+
+    public static class MySQLLimitSpecificationProcessor extends LimitSpecificationProcessor
+    {
+        @Override
+        protected String getPrefix( SQLProcessorAggregator processor )
+        {
+            return MYSQL_LIMIT_PREFIX;
+        }
+
+        @Override
+        protected String getPostfix( SQLProcessorAggregator processor )
+        {
+            return MYSQL_LIMIT_POSTFIX;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/TableProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/TableProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/TableProcessing.java
new file mode 100644
index 0000000..e209b07
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/mysql/TableProcessing.java
@@ -0,0 +1,52 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.mysql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableNameDirectProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.TableReferenceProcessing.TableNameFunctionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class TableProcessing
+{
+    public static class MySQLTableNameDirectProcessor extends TableNameDirectProcessor
+    {
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TableNameDirect object, StringBuilder builder )
+        {
+            // MySQL does not understand schema-qualified table names
+            builder.append( object.getTableName() );
+        }
+    }
+
+    public static class MySQLTableNameFunctionProcessor extends TableNameFunctionProcessor
+    {
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TableNameFunction object, StringBuilder builder )
+        {
+            // MySQL does not understand schema-qualified table names
+            processor.process( object.getFunction(), builder );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/package-info.java
new file mode 100644
index 0000000..1560a29
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package contains the default processors for syntax elements defined in API. The vendor uses these processors (or custom processors) to create textual SQL statement out of API syntax elements.
+ */
+package org.apache.polygene.library.sql.generator.implementation.transformation;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/DefinitionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/DefinitionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/DefinitionProcessing.java
new file mode 100644
index 0000000..2eb78fa
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/DefinitionProcessing.java
@@ -0,0 +1,90 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import java.util.Map;
+import java.util.Objects;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.AutoGenerationPolicy;
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+import org.apache.polygene.library.sql.generator.implementation.transformation.DefinitionProcessing.ColumnDefinitionProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class DefinitionProcessing
+{
+    public static class PGColumnDefinitionProcessor extends ColumnDefinitionProcessor
+    {
+        private final Map<Class<?>, String> _dataTypeSerialNames;
+
+        public PGColumnDefinitionProcessor( Map<Class<?>, String> dataTypeSerialNames )
+        {
+            Objects.requireNonNull( dataTypeSerialNames, "Data type serial names" );
+            this._dataTypeSerialNames = dataTypeSerialNames;
+        }
+
+        @Override
+        protected void processDataType( SQLProcessorAggregator aggregator, ColumnDefinition object,
+                                        StringBuilder builder )
+        {
+            AutoGenerationPolicy autoGenPolicy = object.getAutoGenerationPolicy();
+            if( autoGenPolicy == null )
+            {
+                super.processDataType( aggregator, object, builder );
+            }
+            else
+            {
+                // PostgreSQL can't handle the ALWAYS strategy
+                if( AutoGenerationPolicy.BY_DEFAULT.equals( autoGenPolicy ) )
+                {
+                    // Don't produce default data type if auto generated
+                    Class<?> dtClass = object.getDataType().getClass();
+                    Boolean success = false;
+                    for( Map.Entry<Class<?>, String> entry : this._dataTypeSerialNames.entrySet() )
+                    {
+                        success = entry.getKey().isAssignableFrom( dtClass );
+                        if( success )
+                        {
+                            builder.append( entry.getValue() );
+                            break;
+                        }
+                    }
+                    if( !success )
+                    {
+                        throw new UnsupportedOperationException( "Unsupported column data type " + object.getDataType()
+                                                                 + " for auto-generated column." );
+                    }
+                }
+                else
+                {
+                    throw new UnsupportedOperationException( "Unsupported auto generation policy: " + autoGenPolicy
+                                                             + "." );
+                }
+            }
+        }
+
+        @Override
+        protected void processAutoGenerationPolicy( ColumnDefinition object, StringBuilder builder )
+        {
+            // Nothing to do - auto generation policy handled in data type orc
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/LiteralExpressionProcessing.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/LiteralExpressionProcessing.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/LiteralExpressionProcessing.java
new file mode 100644
index 0000000..de1dae7
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/implementation/transformation/pgsql/LiteralExpressionProcessing.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.implementation.transformation.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.literals.TimestampTimeLiteral;
+import org.apache.polygene.library.sql.generator.implementation.transformation.LiteralExpressionProcessing.DateTimeLiteralProcessor;
+import org.apache.polygene.library.sql.generator.implementation.transformation.spi.SQLProcessorAggregator;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public class LiteralExpressionProcessing
+{
+    public static class PGDateTimeLiteralProcessor extends DateTimeLiteralProcessor
+    {
+        @Override
+        protected void doProcess( SQLProcessorAggregator processor, TimestampTimeLiteral object, StringBuilder builder )
+        {
+            builder.append( "timestamp " );
+            super.doProcess( processor, object, builder );
+        }
+    }
+}


[14/19] polygene-java git commit: Bring in Stanislav's sql-generator from GutHub, after his consent in https://lists.apache.org/thread.html/797352ce2ad7aa7b755720a98f545a176e6050e35f56db113ba115fb@%3Cdev.polygene.apache.org%3E

Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ModificationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ModificationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ModificationFactory.java
new file mode 100644
index 0000000..cd71993
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/ModificationFactory.java
@@ -0,0 +1,148 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.ColumnSourceByValuesBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.DeleteBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.modification.UpdateBySearchBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByQuery;
+import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues;
+import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement;
+import org.apache.polygene.library.sql.generator.grammar.modification.SetClause;
+import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSource;
+import org.apache.polygene.library.sql.generator.grammar.modification.UpdateSourceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory, which creates SQL syntax elements related to modification statements ({@code INSERT INTO},
+ * {@code DELETE FROM}, and {@code UPDATE}). This factory is obtainable from {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ */
+public interface ModificationFactory
+{
+
+    /**
+     * Creates a builder to add values as column sources in {@code INSERT INTO} statement.
+     *
+     * @return The new {@link ColumnSourceByValuesBuilder} for {@link ColumnSourceByValues}.
+     */
+    ColumnSourceByValuesBuilder columnSourceByValues();
+
+    /**
+     * <p>
+     * Creates a column source, which uses a query as a source for columns in {@code INSERT INTO} statement.
+     * </p>
+     * <p>
+     * Calling this method is equivalent in calling {@link #columnSourceByQuery(ColumnNameList, QueryExpression)} and
+     * passing {@code null} as first argument.
+     * </p>
+     *
+     * @param query The query to use as source for columns in {@code INSERT INTO} statement.
+     * @return The new {@link ColumnSourceByQuery}.
+     */
+    ColumnSourceByQuery columnSourceByQuery( QueryExpression query );
+
+    /**
+     * Creates a column source, which uses specified target table column names and query as source columns in
+     * {@code INSERT INTO} statement.
+     *
+     * @param columnNames The column names to use in target table.
+     * @param query       The query to use to populate target table.
+     * @return The new {@link ColumnSourceByQuery}.
+     */
+    ColumnSourceByQuery columnSourceByQuery( ColumnNameList columnNames, QueryExpression query );
+
+    /**
+     * Creates builder to create {@link DeleteBySearch} statements.
+     *
+     * @return The new builder for {@link DeleteBySearch}.
+     * @see DeleteBySearchBuilder
+     */
+    DeleteBySearchBuilder deleteBySearch();
+
+    /**
+     * Creates builder to create {@link InsertStatement}s.
+     *
+     * @return The new builder for {@link InsertStatement}.
+     * @see InsertStatementBuilder
+     */
+    InsertStatementBuilder insert();
+
+    /**
+     * Creates builder to create {@link UpdateBySearch} statements.
+     *
+     * @return The new builder for {@link UpdateBySearch} statements.
+     * @see UpdateBySearchBuilder
+     */
+    UpdateBySearchBuilder updateBySearch();
+
+    /**
+     * <p>
+     * Creates new target table to use in modification statements.
+     * </p>
+     * <p>
+     * Calling this method is equivalent for calling {@link #createTargetTable(TableName, Boolean)} and passing
+     * {@code false} as second parameter.
+     *
+     * @param tableName The name of the table.
+     * @return The new {@link TargetTable}.
+     */
+    TargetTable createTargetTable( TableNameDirect tableName );
+
+    /**
+     * Creates new target table to use in modification statements.
+     *
+     * @param tableName The name of the table.
+     * @param isOnly    Whether modification should affect child-tables too.
+     * @return The new {@link TargetTable}.
+     */
+    TargetTable createTargetTable( TableNameDirect tableName, Boolean isOnly );
+
+    /**
+     * Creates a new source for {@code UPDATE} statement. This source will use specified expression as a source for
+     * values.
+     *
+     * @param expression The expression to use.
+     * @return The new {@link UpdateSourceByExpression}.
+     * @see UpdateBySearch
+     */
+    UpdateSourceByExpression updateSourceByExp( ValueExpression expression );
+
+    /**
+     * Creates a new set clause for {@code UPDATE} statement.
+     *
+     * @param updateTarget The target of the update, typically name of the column.
+     * @param updateSource The source for data to be put into that column.
+     * @return The new {@link SetClause}.
+     * @see UpdateBySearch
+     */
+    SetClause setClause( String updateTarget, UpdateSource updateSource );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/QueryFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/QueryFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/QueryFactory.java
new file mode 100644
index 0000000..8872251
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/QueryFactory.java
@@ -0,0 +1,227 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.builders.query.ColumnsBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.FromBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.GroupByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.OrderByBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.QuerySpecificationBuilder;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.SimpleQueryBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause;
+import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.OffsetSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.Ordering;
+import org.apache.polygene.library.sql.generator.grammar.query.OrdinaryGroupingSet;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody.EmptyQueryExpressionBody;
+import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.RowDefinition;
+import org.apache.polygene.library.sql.generator.grammar.query.RowSubQuery;
+import org.apache.polygene.library.sql.generator.grammar.query.RowValueConstructor;
+import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification;
+import org.apache.polygene.library.sql.generator.grammar.query.TableValueConstructor;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory, which creates builders and syntax elements for SQL queries ({@code SELECT} statements). This factory may
+ * be obtained from {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ * @see QueryExpression
+ * @see QuerySpecification
+ */
+public interface QueryFactory
+{
+
+    /**
+     * Creates new query, which has the specified body as an actual query.
+     *
+     * @param body The actual query to use.
+     * @return The new {@link QueryExpression}
+     */
+    QueryExpression createQuery( QueryExpressionBody body );
+
+    /**
+     * Creates a builder to build query specifications ({@code SELECT} expressions).
+     *
+     * @return The new {@link QuerySpecificationBuilder}.
+     */
+    QuerySpecificationBuilder querySpecificationBuilder();
+
+    /**
+     * <p>
+     * Creates a builder for the columns in {@code SELECT} expressions.
+     * </p>
+     * <p>
+     * Calling this method is equivalent to calling {@link #columnsBuilder(SetQuantifier)} and passing
+     * {@link SetQuantifier#ALL} as argument.
+     * </p>
+     *
+     * @return The new {@link ColumnsBuilder}.
+     */
+    ColumnsBuilder columnsBuilder();
+
+    /**
+     * Creates a builder for columns in {@code SELECT} expressions, which has specified set quantifier initially.
+     *
+     * @param setQuantifier The set quantifier to use.
+     * @return The new {@link ColumnsBuilder}.
+     */
+    ColumnsBuilder columnsBuilder( SetQuantifier setQuantifier );
+
+    /**
+     * <p>
+     * Creates a builder to build queries with capability for {@code UNION}, {@code INTERSECT}, and {@code EXCEPT} set
+     * operations.
+     * </p>
+     * <p>
+     * Calling this method is equivalent in calling {@link #queryBuilder(QueryExpressionBody)} and passing
+     * {@link EmptyQueryExpressionBody} as argument.
+     *
+     * @return The new {@link QueryBuilder}.
+     */
+    QueryBuilder queryBuilder();
+
+    /**
+     * Creates a builder to build queries with capability for {@code UNION}, {@code INTERSECT}, and {@code EXCEPT} set
+     * operations.
+     *
+     * @param query The initial query for builder.
+     * @return The new {@link QueryBuilder}.
+     */
+    QueryBuilder queryBuilder( QueryExpressionBody query );
+
+    /**
+     * Creates a builder for {@code GROUP BY} clause.
+     *
+     * @return The new {@link GroupByBuilder}.
+     */
+    GroupByBuilder groupByBuilder();
+
+    /**
+     * Creates a builder for {@code FROM} clause.
+     *
+     * @return The new {@link FromBuilder}.
+     */
+    FromBuilder fromBuilder();
+
+    /**
+     * Creates a new grouping element, which has some expressions as grouping columns.
+     *
+     * @param expressions The expressions to use.
+     * @return The new {@link OrdinaryGroupingSet}.
+     * @see GroupByClause
+     */
+    OrdinaryGroupingSet groupingElement( NonBooleanExpression... expressions );
+
+    /**
+     * Creates a new sort specification for {@code ORDER BY} clause.
+     *
+     * @param expression The expression for column.
+     * @param ordering   The ordering to use.
+     * @return The new {@link SortSpecification}.
+     */
+    SortSpecification sortSpec( ValueExpression expression, Ordering ordering );
+
+    /**
+     * Creates a builder for {@code ORDER BY} clause.
+     *
+     * @return The new {@link OrderByBuilder}.
+     */
+    OrderByBuilder orderByBuilder();
+
+    /**
+     * Creates a builder for simple queries.
+     *
+     * @return The new {@link SimpleQueryBuilder}.
+     */
+    SimpleQueryBuilder simpleQueryBuilder();
+
+    /**
+     * Creates a new {@code VALUES} expression in query.
+     *
+     * @param rows The rows for {@code VALUES} expression.
+     * @return The new {@link TableValueConstructor}.
+     * @see RowValueConstructor
+     * @see RowSubQuery
+     * @see RowDefinition
+     */
+    TableValueConstructor values( RowValueConstructor... rows );
+
+    /**
+     * Creates a new subquery for a row for {@code VALUES} expression in query.
+     *
+     * @param subQuery The query to return the row.
+     * @return The new {@link RowSubQuery}.
+     */
+    RowSubQuery rowSubQuery( QueryExpression subQuery );
+
+    /**
+     * Creates a new row for {@code VALUES} expression in query.
+     *
+     * @param elements The elements for the row.
+     * @return The new {@link RowDefinition}.
+     */
+    RowDefinition row( ValueExpression... elements );
+
+    /**
+     * Returns a query for calling a SQL function with schema. The query is
+     * {@code SELECT * FROM schemaName.functionName(params...)}.
+     *
+     * @param schemaName The name of the schema where SQL function resides.
+     * @param function   The SQL function to call.
+     * @return A query returning the results of calling SQL function.
+     */
+    QueryExpression callFunction( String schemaName, SQLFunctionLiteral function );
+
+    /**
+     * Returns a query for calling a SQL function without a schema. The query is
+     * {@code SELECT * FROM functionName(params...)}. Calling this method is equivalent to calling
+     * {@link #callFunction(String, SQLFunctionLiteral)} and passing {@code null} as first argument.
+     *
+     * @param function The function to call.
+     * @return A query returning the results of calling SQL function.
+     */
+    QueryExpression callFunction( SQLFunctionLiteral function );
+
+    /**
+     * Creates a new {@code OFFSET <n> ROWS} syntax element for query.
+     *
+     * @param offset The offset amount.
+     * @return A new {@code OFFSET <n> ROWS} syntax element.
+     */
+    OffsetSpecification offset( NonBooleanExpression offset );
+
+    /**
+     * Creates a new {@code FETCH FIRST <n> ROWS ONLY} syntax element for query.
+     *
+     * @param count The limit amount.
+     * @return A new {@code FETCH FIRST <n> ROWS ONLY} syntax element.
+     */
+    LimitSpecification limit( NonBooleanExpression count );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/TableReferenceFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/TableReferenceFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/TableReferenceFactory.java
new file mode 100644
index 0000000..252f807
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/TableReferenceFactory.java
@@ -0,0 +1,182 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories;
+
+import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression;
+import org.apache.polygene.library.sql.generator.grammar.builders.query.TableReferenceBuilder;
+import org.apache.polygene.library.sql.generator.grammar.common.ColumnNameList;
+import org.apache.polygene.library.sql.generator.grammar.common.TableName;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameFunction;
+import org.apache.polygene.library.sql.generator.grammar.literals.SQLFunctionLiteral;
+import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableAlias;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByExpression;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferenceByName;
+import org.apache.polygene.library.sql.generator.grammar.query.TableReferencePrimary;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinCondition;
+import org.apache.polygene.library.sql.generator.grammar.query.joins.NamedColumnsJoin;
+import org.apache.polygene.library.sql.generator.vendor.SQLVendor;
+
+/**
+ * A factory for creating builders and syntax elements related to tables. This factory is obtainable from
+ * {@link SQLVendor}.
+ *
+ * @author Stanislav Muhametsin
+ * @see SQLVendor
+ */
+public interface TableReferenceFactory
+{
+    /**
+     * <p>
+     * Creates a new table reference, which uses given table name, without table alias.
+     * </p>
+     * <p>
+     * Calling this method is equivalent to calling {@link #table(TableName, TableAlias)} and passing {@code null} as
+     * second parameter.
+     * </p>
+     *
+     * @param tableName The table name to use.
+     * @return The new {@link TableReferenceByName}.
+     */
+    TableReferenceByName table( TableName tableName );
+
+    /**
+     * Creates a new table references, which uses given table name along with given table alias.
+     *
+     * @param tableName The table name to use.
+     * @param alias     The table alias to use. May be {@code null}.
+     * @return The new {@link TableReferenceByName}.
+     */
+    TableReferenceByName table( TableName tableName, TableAlias alias );
+
+    /**
+     * <p>
+     * Creates a new table name, which isn't schema-qualified.
+     * </p>
+     * <p>
+     * Calling this method is equivalent to calling {@link #tableName(String, String)} and passing {@code null} as first
+     * parameter.
+     * </p>
+     *
+     * @param tableName The name of the table.
+     * @return The new {@link TableName}.
+     */
+    TableNameDirect tableName( String tableName );
+
+    /**
+     * Creates a new table name. If the given schema-name is non-{@code null}, the table name is said to be
+     * schema-qualified.
+     *
+     * @param schemaName The schema name to use. May be {@code null}.
+     * @param tableName  The table name to use.
+     * @return The new {@link TableName}.
+     */
+    TableNameDirect tableName( String schemaName, String tableName );
+
+    /**
+     * Creates a new table name representing a call to SQL function without a schema. This is equivalent to calling
+     * {@link #tableName(String, SQLFunctionLiteral)} and passing {@code null} as first argument.
+     *
+     * @param function The function to call.
+     * @return Table name representing a call to SQL function without a schema.
+     */
+    TableNameFunction tableName( SQLFunctionLiteral function );
+
+    /**
+     * Creates a new table name representing a call to SQL function with schema.
+     *
+     * @param schemaName The schema where function resides.
+     * @param function   The function to call.
+     * @return Table name representing a call to SQL function with schema.
+     */
+    TableNameFunction tableName( String schemaName, SQLFunctionLiteral function );
+
+    /**
+     * <p>
+     * Creates a new alias for table.
+     * </p>
+     * <p>
+     * Calling this method is equivalent to calling {@link #tableAliasWithCols(String, String...)} and not pass anything
+     * to varargs parameter.
+     * </p>
+     *
+     * @param tableNameAlias The alias for table name.
+     * @return The new {@link TableAlias}.
+     */
+    TableAlias tableAlias( String tableNameAlias );
+
+    /**
+     * Creates a new table alias for table, with renamed columns.
+     *
+     * @param tableNameAlias The alias for table name.
+     * @param colNames       The new column names for table.
+     * @return The new {@link TableAlias}.
+     */
+    TableAlias tableAliasWithCols( String tableNameAlias, String... colNames );
+
+    /**
+     * <p>
+     * Creates a new table reference, which will use the values returned by query as if they were values of the table.
+     * </p>
+     * <p>
+     * Calling this method is equivalent to calling {@link #table(QueryExpression, TableAlias)} and passing {@code null}
+     * as second parameter.
+     * </p>
+     *
+     * @param query The query to use.
+     * @return The new {@link TableReferenceByExpression}.
+     */
+    TableReferenceByExpression table( QueryExpression query );
+
+    /**
+     * Creates a new table reference, which will use the values returned by query as if they were values of the table.
+     * Optionally, the table will has a given alias.
+     *
+     * @param query The query to use.
+     * @param alias The table alias to use. May be {@code null} if no alias is needed.
+     * @return The new {@link TableReferenceByExpression}.
+     */
+    TableReferenceByExpression table( QueryExpression query, TableAlias alias );
+
+    /**
+     * Creates a new {@link TableReferenceBuilder} typically used to build joined tables.
+     *
+     * @param firstTable The starting table.
+     * @return The new {@link TableReferenceBuilder}.
+     */
+    TableReferenceBuilder tableBuilder( TableReferencePrimary firstTable );
+
+    /**
+     * Creates a join-condition using specified boolean expression to join tables.
+     *
+     * @param condition The condition to join tables.
+     * @return The new {@link JoinCondition}.
+     */
+    JoinCondition jc( BooleanExpression condition );
+
+    /**
+     * Creates a new named columns join specification, which will use column names to join tables.
+     *
+     * @param columnNames The column names to use to join tables.
+     * @return The new {@link NamedColumnsJoin}.
+     */
+    NamedColumnsJoin nc( ColumnNameList columnNames );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/package-info.java
new file mode 100644
index 0000000..81a4977
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package provides factories to create various builders and SQL syntax elements.
+ */
+package org.apache.polygene.library.sql.generator.grammar.factories;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLDataTypeFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLDataTypeFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLDataTypeFactory.java
new file mode 100644
index 0000000..729173c
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLDataTypeFactory.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.datatypes.pgsql.Text;
+import org.apache.polygene.library.sql.generator.grammar.factories.DataTypeFactory;
+
+/**
+ * This is factory for creating SQL pre-defined types, as well as types specific for PostgreSQL.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface PgSQLDataTypeFactory
+    extends DataTypeFactory
+{
+
+    /**
+     * Creates the data type representing {@code TEXT} data type.
+     *
+     * @return The data type representing {@code TEXT} data type.
+     */
+    Text text();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLManipulationFactory.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLManipulationFactory.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLManipulationFactory.java
new file mode 100644
index 0000000..64acf71
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/PgSQLManipulationFactory.java
@@ -0,0 +1,49 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.factories.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+import org.apache.polygene.library.sql.generator.grammar.factories.ManipulationFactory;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropBehaviour;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.ObjectType;
+import org.apache.polygene.library.sql.generator.grammar.manipulation.pgsql.PgSQLDropTableOrViewStatement;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface PgSQLManipulationFactory
+    extends ManipulationFactory
+{
+
+    PgSQLDropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                                  DropBehaviour dropBehaviour );
+
+    /**
+     * Creates {@code DROP TABLE/VIEW} statement, which may use {@code IF EXISTS} clause before the table name.
+     *
+     * @param tableName     The name of the table/view to drop.
+     * @param theType       What to drop - {@link ObjectType#TABLE} or {@link ObjectType#VIEW}.
+     * @param dropBehaviour Drop behaviour - {@link DropBehaviour#CASCADE} or {@link DropBehaviour#RESTRICT}.
+     * @param useIfExists   {@code true} to append {@code IF EXISTS} before table/view name, {@code false} otherwise.
+     * @return New {@code DROP TABLE/VIEW} statement.
+     */
+    PgSQLDropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
+                                                                  DropBehaviour dropBehaviour, Boolean useIfExists );
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/package-info.java
new file mode 100644
index 0000000..63949b2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/factories/pgsql/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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 to contain PostgreSQL-specific factories enabling creating of PostgreSQL-specific syntax elements.
+ */
+package org.apache.polygene.library.sql.generator.grammar.factories.pgsql;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/DirectLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/DirectLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/DirectLiteral.java
new file mode 100644
index 0000000..9e52571
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/DirectLiteral.java
@@ -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.polygene.library.sql.generator.grammar.literals;
+
+/**
+ * This syntax element encapsulates text to be inserted directly into SQL statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DirectLiteral
+    extends LiteralExpression
+{
+
+    /**
+     * Returns the text to be inserted directly into SQL statement.
+     *
+     * @return The text to be inserted directly into SQL statement.
+     */
+    String getDirectLiteral();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/LiteralExpression.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/LiteralExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/LiteralExpression.java
new file mode 100644
index 0000000..2e6d15d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/LiteralExpression.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression;
+
+/**
+ * This is common interface for all literal expressions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface LiteralExpression
+    extends NonBooleanExpression
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/NumericLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/NumericLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/NumericLiteral.java
new file mode 100644
index 0000000..e61e29d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/NumericLiteral.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+/**
+ * This syntax element encapsulates reference to some number to be inserted into SQL statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface NumericLiteral
+    extends LiteralExpression
+{
+    /**
+     * Returns the number to be inserted into SQL statement.
+     *
+     * @return The number to be inserted into SQL statement.
+     */
+    Number getNumber();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/SQLFunctionLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/SQLFunctionLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/SQLFunctionLiteral.java
new file mode 100644
index 0000000..1db873d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/SQLFunctionLiteral.java
@@ -0,0 +1,47 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+import java.util.List;
+import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression;
+
+/**
+ * This syntax element encapsulates reference to some SQL function to be inserted into SQL statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SQLFunctionLiteral
+    extends LiteralExpression
+{
+
+    /**
+     * Returns the name of the SQL function.
+     *
+     * @return The name of the SQL function.
+     */
+    String getFunctionName();
+
+    /**
+     * The parameters for SQL function.
+     *
+     * @return The parameters for SQL function.
+     */
+    List<ValueExpression> getParameters();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/StringLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/StringLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/StringLiteral.java
new file mode 100644
index 0000000..9006e81
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/StringLiteral.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+/**
+ * This syntax element encapsulates reference to SQL string, that is, some element between {@code '} and {@code '}
+ * characters.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface StringLiteral
+    extends LiteralExpression
+{
+
+    /**
+     * Returns the contents of the string literal, that is, the string to be put between {@code '} and {@code '}.
+     *
+     * @return The contents of the string literal.
+     */
+    String getString();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TemporalLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TemporalLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TemporalLiteral.java
new file mode 100644
index 0000000..8293a4e
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TemporalLiteral.java
@@ -0,0 +1,32 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+/**
+ * This syntax element represents any literal that represents some kind of time.
+ *
+ * @author 2011 Stanislav Muhametsin
+ * @see TimestampTimeLiteral
+ */
+public interface TemporalLiteral
+    extends LiteralExpression
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TimestampTimeLiteral.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TimestampTimeLiteral.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TimestampTimeLiteral.java
new file mode 100644
index 0000000..423594f
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/TimestampTimeLiteral.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.literals;
+
+import java.sql.Timestamp;
+
+/**
+ * This syntax element encapsulates reference to some time stamp to be inserted into SQL statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TimestampTimeLiteral
+    extends TemporalLiteral
+{
+
+    /**
+     * Returns the time stamp to be inserted into SQL statement.
+     *
+     * @return The time stamp to be inserted into SQL statement.
+     */
+    Timestamp getTimestamp();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/package-info.java
new file mode 100644
index 0000000..23fb2e3
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/literals/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * The package for syntax elements representing various literals.
+ */
+package org.apache.polygene.library.sql.generator.grammar.literals;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddColumnDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddColumnDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddColumnDefinition.java
new file mode 100644
index 0000000..48f6b19
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddColumnDefinition.java
@@ -0,0 +1,40 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.definition.table.ColumnDefinition;
+
+/**
+ * This syntax element represents adding a new column to table.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface AddColumnDefinition
+    extends AlterTableAction
+{
+
+    /**
+     * Returns the definition for column to be added.
+     *
+     * @return The definition for column to be added.
+     * @see ColumnDefinition
+     */
+    ColumnDefinition getColumnDefinition();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddTableConstraintDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddTableConstraintDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddTableConstraintDefinition.java
new file mode 100644
index 0000000..24b1eab
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AddTableConstraintDefinition.java
@@ -0,0 +1,38 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.definition.table.TableConstraintDefinition;
+
+/**
+ * This syntax element represents the new table constraint to be added in table alteration statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface AddTableConstraintDefinition
+    extends AlterTableAction
+{
+    /**
+     * Returns the table constraint to be added.
+     *
+     * @return The table constraint to be added.
+     */
+    TableConstraintDefinition getConstraint();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnAction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnAction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnAction.java
new file mode 100644
index 0000000..1f2b2a5
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnAction.java
@@ -0,0 +1,53 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for column alteration actions.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface AlterColumnAction
+    extends Typeable<AlterColumnAction>
+{
+
+    /**
+     * This syntax element represents dropping column default in table alteration statement.
+     *
+     * @author Stanislav Muhametsin
+     */
+    final class DropDefault
+        implements AlterColumnAction
+    {
+        private DropDefault()
+        {
+
+        }
+
+        public Class<? extends AlterColumnAction> getImplementedType()
+        {
+            return DropDefault.class;
+        }
+
+        public static final DropDefault INSTANCE = new DropDefault();
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnDefinition.java
new file mode 100644
index 0000000..26616fa
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterColumnDefinition.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * This syntax element represents the alteration of column.
+ *
+ * @author Stanislav Muhametsin
+ * @see AlterTableAction
+ */
+public interface AlterColumnDefinition
+    extends AlterTableAction
+{
+
+    /**
+     * Returns the name of the column to be altered.
+     *
+     * @return The name of the column to be altered.
+     */
+    String getColumnName();
+
+    /**
+     * Returns the action to be done on column.
+     *
+     * @return The action to be done on column.
+     * @see AlterColumnAction
+     */
+    AlterColumnAction getAction();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterStatement.java
new file mode 100644
index 0000000..d807954
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterStatement.java
@@ -0,0 +1,33 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaManipulationStatement;
+
+/**
+ * This is a common interface for all {@code ALTER} statements.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface AlterStatement
+    extends SchemaManipulationStatement
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableAction.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableAction.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableAction.java
new file mode 100644
index 0000000..0ee5866
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableAction.java
@@ -0,0 +1,34 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.Typeable;
+
+/**
+ * This is common interface for actions altering table.
+ *
+ * @author Stanislav Muhametsin
+ * @see AlterTableStatement
+ */
+public interface AlterTableAction
+    extends Typeable<AlterTableAction>
+{
+
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableStatement.java
new file mode 100644
index 0000000..ad5158d
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/AlterTableStatement.java
@@ -0,0 +1,45 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface AlterTableStatement
+    extends AlterStatement
+{
+
+    /**
+     * Returns the name of the table to be altered.
+     *
+     * @return The name of the table to be altered.
+     */
+    TableNameDirect getTableName();
+
+    /**
+     * Returns the action to perform in order to alter table.
+     *
+     * @return The action to perform in order to alter table.
+     * @see AlterTableAction
+     */
+    AlterTableAction getAction();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviour.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviour.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviour.java
new file mode 100644
index 0000000..bb57cdf
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviour.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * The drop behaviour for generalized {@code DROP} statement. Typically one of {@link #CASCADE} or {@link #RESTRICT}.
+ *
+ * @author Stanislav Muhametsin
+ * @see DropStatement
+ */
+public final class DropBehaviour
+{
+
+    /**
+     * The drop behaviour which means to {@code CASCADE} the {@code DROP} through all depending elements.
+     */
+    public static final DropBehaviour CASCADE = new DropBehaviour();
+
+    /**
+     * The drop behaviour which means to {@code RESTRICT} the {@code DROP} if any elements depend on the object to be
+     * dropped.
+     */
+    public static final DropBehaviour RESTRICT = new DropBehaviour();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviourContainer.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviourContainer.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviourContainer.java
new file mode 100644
index 0000000..9f61bed
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropBehaviourContainer.java
@@ -0,0 +1,36 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * A generic drop behaviour container (for any {@code DROP} clause and statement).
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropBehaviourContainer
+{
+
+    /**
+     * Returns the drop behaviour for this clause or statement.
+     *
+     * @return The drop behaviour for this clause or statement.
+     */
+    DropBehaviour getDropBehaviour();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropColumnDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropColumnDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropColumnDefinition.java
new file mode 100644
index 0000000..59cd0e2
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropColumnDefinition.java
@@ -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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * This syntax element represents dropping a column from a table in table alteration statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropColumnDefinition
+    extends AlterTableAction, DropBehaviourContainer
+{
+
+    /**
+     * Returns the name of the column to be dropped.
+     *
+     * @return The name of the column to be dropped.
+     */
+    String getColumnName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropSchemaStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropSchemaStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropSchemaStatement.java
new file mode 100644
index 0000000..5b57453
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropSchemaStatement.java
@@ -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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * This syntax element represents the {@code DROP SCHEMA} statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropSchemaStatement
+    extends DropStatement
+{
+
+    /**
+     * Returns the name of the schema to be dropped.
+     *
+     * @return The name of the schema to be dropped.
+     */
+    String getSchemaName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropStatement.java
new file mode 100644
index 0000000..0ca5010
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropStatement.java
@@ -0,0 +1,41 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.SchemaManipulationStatement;
+
+/**
+ * This is a common interface for {@code DROP} statements.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropStatement
+    extends SchemaManipulationStatement, DropBehaviourContainer
+{
+
+    /**
+     * Returns the object type to drop. Typically either {@link ObjectType#SCHEMA}, {@link ObjectType#TABLE}, or
+     * {@link ObjectType#VIEW}.
+     *
+     * @return The object type to drop.
+     * @see ObjectType
+     */
+    ObjectType whatToDrop();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableConstraintDefinition.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableConstraintDefinition.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableConstraintDefinition.java
new file mode 100644
index 0000000..a6a1cc1
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableConstraintDefinition.java
@@ -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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * This syntax element represents dropping a table constraint in table alteration statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropTableConstraintDefinition
+    extends AlterTableAction, DropBehaviourContainer
+{
+
+    /**
+     * Returns the constraint name to be dropped.
+     *
+     * @return The constraint name to be dropped.
+     */
+    String getConstraintName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableOrViewStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableOrViewStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableOrViewStatement.java
new file mode 100644
index 0000000..1872743
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/DropTableOrViewStatement.java
@@ -0,0 +1,39 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect;
+
+/**
+ * This is generalized statement to drop tables and views.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface DropTableOrViewStatement
+    extends DropStatement
+{
+
+    /**
+     * Returns the name of the table or view to be deleted.
+     *
+     * @return The name of the table or view to be deleted.
+     */
+    TableNameDirect getTableName();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/ObjectType.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/ObjectType.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/ObjectType.java
new file mode 100644
index 0000000..33275c8
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/ObjectType.java
@@ -0,0 +1,46 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * Object type is used in generalized {@code DROP} statement to define what to drop. It is usually one of
+ * {@link #SCHEMA}, {@link #TABLE}, or {@link #VIEW}.
+ *
+ * @author Stanislav Muhametsin
+ * @see DropStatement
+ */
+public final class ObjectType
+{
+
+    /**
+     * The object type which means to {@code DROP SCHEMA}.
+     */
+    public static final ObjectType SCHEMA = new ObjectType();
+
+    /**
+     * The object type which means to {@code DROP TABLE}.
+     */
+    public static final ObjectType TABLE = new ObjectType();
+
+    /**
+     * The object type which means to {@code DROP VIEW}.
+     */
+    public static final ObjectType VIEW = new ObjectType();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/SetColumnDefault.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/SetColumnDefault.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/SetColumnDefault.java
new file mode 100644
index 0000000..4998f80
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/SetColumnDefault.java
@@ -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.polygene.library.sql.generator.grammar.manipulation;
+
+/**
+ * This syntax element represents setting a new default for a column in table alteration statement.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface SetColumnDefault
+    extends AlterColumnAction
+{
+
+    /**
+     * Returns the new default value for this column.
+     *
+     * @return The new default value for this column.
+     */
+    String getDefault();
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/package-info.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/package-info.java
new file mode 100644
index 0000000..6ff9718
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/package-info.java
@@ -0,0 +1,23 @@
+/*
+ *  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.
+ *
+ *
+ */
+/**
+ * This package provides syntax elements for {@code DROP} and {@code ALTER} statements.
+ */
+package org.apache.polygene.library.sql.generator.grammar.manipulation;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatement.java
----------------------------------------------------------------------
diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatement.java
new file mode 100644
index 0000000..2b916b9
--- /dev/null
+++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatement.java
@@ -0,0 +1,31 @@
+/*
+ *  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.polygene.library.sql.generator.grammar.manipulation.pgsql;
+
+import org.apache.polygene.library.sql.generator.grammar.manipulation.DropTableOrViewStatement;
+
+/**
+ * @author Stanislav Muhametsin
+ */
+public interface PgSQLDropTableOrViewStatement extends DropTableOrViewStatement
+{
+
+    Boolean useIfExists();
+}