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

Reply via email to