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 );
+}

Reply via email to