Permalink
Browse files

Added support for calling SQL functions as query.

  • Loading branch information...
Stanislav Muhametsin
Stanislav Muhametsin committed Sep 11, 2011
1 parent 07940fe commit 38bab95cf969b983728b685107bf4cbc9d342f3a
Showing with 542 additions and 229 deletions.
  1. +6 −3 .gitignore
  2. +3 −3 ...src/main/java/org/sql/generation/api/grammar/builders/definition/ForeignKeyConstraintBuilder.java
  3. +3 −3 api/src/main/java/org/sql/generation/api/grammar/builders/definition/TableDefinitionBuilder.java
  4. +3 −3 api/src/main/java/org/sql/generation/api/grammar/builders/definition/ViewDefinitionBuilder.java
  5. +3 −3 api/src/main/java/org/sql/generation/api/grammar/builders/modification/InsertStatementBuilder.java
  6. +9 −2 api/src/main/java/org/sql/generation/api/grammar/builders/query/SimpleQueryBuilder.java
  7. +2 −2 api/src/main/java/org/sql/generation/api/grammar/builders/query/pgsql/PgSQLSimpleQueryBuilder.java
  8. +6 −13 api/src/main/java/org/sql/generation/api/grammar/common/{TableName.java → TableNameAbstract.java}
  9. +32 −0 api/src/main/java/org/sql/generation/api/grammar/common/TableNameDirect.java
  10. +33 −0 api/src/main/java/org/sql/generation/api/grammar/common/TableNameFunction.java
  11. +2 −2 api/src/main/java/org/sql/generation/api/grammar/definition/table/ForeignKeyConstraint.java
  12. +2 −2 api/src/main/java/org/sql/generation/api/grammar/definition/table/LikeClause.java
  13. +2 −2 api/src/main/java/org/sql/generation/api/grammar/definition/table/TableDefinition.java
  14. +2 −2 api/src/main/java/org/sql/generation/api/grammar/definition/view/ViewDefinition.java
  15. +0 −1 api/src/main/java/org/sql/generation/api/grammar/factories/ColumnsFactory.java
  16. +2 −2 api/src/main/java/org/sql/generation/api/grammar/factories/DefinitionFactory.java
  17. +3 −3 api/src/main/java/org/sql/generation/api/grammar/factories/ManipulationFactory.java
  18. +3 −3 api/src/main/java/org/sql/generation/api/grammar/factories/ModificationFactory.java
  19. +23 −2 api/src/main/java/org/sql/generation/api/grammar/factories/QueryFactory.java
  20. +26 −5 api/src/main/java/org/sql/generation/api/grammar/factories/TableReferenceFactory.java
  21. +3 −3 api/src/main/java/org/sql/generation/api/grammar/factories/pgsql/PgSQLManipulationFactory.java
  22. +2 −2 api/src/main/java/org/sql/generation/api/grammar/manipulation/AlterTableStatement.java
  23. +2 −2 api/src/main/java/org/sql/generation/api/grammar/manipulation/DropTableOrViewStatement.java
  24. +2 −2 api/src/main/java/org/sql/generation/api/grammar/modification/InsertStatement.java
  25. +2 −2 api/src/main/java/org/sql/generation/api/grammar/modification/TargetTable.java
  26. +2 −2 api/src/main/java/org/sql/generation/api/grammar/query/TableReferenceByName.java
  27. +4 −4 ...rg/sql/generation/implementation/grammar/builders/definition/ForeignKeyConstraintBuilderImpl.java
  28. +4 −4 ...ava/org/sql/generation/implementation/grammar/builders/definition/TableDefinitionBuilderImpl.java
  29. +4 −4 ...java/org/sql/generation/implementation/grammar/builders/definition/ViewDefinitionBuilderImpl.java
  30. +4 −4 ...a/org/sql/generation/implementation/grammar/builders/modification/InsertStatementBuilderImpl.java
  31. +29 −13 ...rc/main/java/org/sql/generation/implementation/grammar/builders/query/SimpleQueryBuilderImpl.java
  32. +2 −2 ...a/org/sql/generation/implementation/grammar/builders/query/pgsql/PgSQLSimpleQueryBuilderImpl.java
  33. +47 −0 ...ntation/src/main/java/org/sql/generation/implementation/grammar/common/TableNameAbstractImpl.java
  34. +9 −20 .../org/sql/generation/implementation/grammar/common/{TableNameImpl.java → TableNameDirectImpl.java}
  35. +56 −0 ...ntation/src/main/java/org/sql/generation/implementation/grammar/common/TableNameFunctionImpl.java
  36. +1 −2 ...ntation/src/main/java/org/sql/generation/implementation/grammar/common/datatypes/SQLTimeImpl.java
  37. +1 −2 ...src/main/java/org/sql/generation/implementation/grammar/common/datatypes/UserDefinedTypeImpl.java
  38. +6 −6 ...ain/java/org/sql/generation/implementation/grammar/definition/table/ForeignKeyConstraintImpl.java
  39. +5 −5 ...tion/src/main/java/org/sql/generation/implementation/grammar/definition/table/LikeClauseImpl.java
  40. +5 −5 ...src/main/java/org/sql/generation/implementation/grammar/definition/table/TableDefinitionImpl.java
  41. +5 −5 ...n/src/main/java/org/sql/generation/implementation/grammar/definition/view/ViewDefinitionImpl.java
  42. +2 −2 ...rc/main/java/org/sql/generation/implementation/grammar/factories/AbstractModificationFactory.java
  43. +6 −0 ...ation/src/main/java/org/sql/generation/implementation/grammar/factories/AbstractQueryFactory.java
  44. +11 −3 ...on/src/main/java/org/sql/generation/implementation/grammar/factories/AbstractTableRefFactory.java
  45. +0 −1 ...tion/src/main/java/org/sql/generation/implementation/grammar/factories/DefaultColumnsFactory.java
  46. +2 −2 ...n/src/main/java/org/sql/generation/implementation/grammar/factories/DefaultDefinitionFactory.java
  47. +3 −3 ...src/main/java/org/sql/generation/implementation/grammar/factories/DefaultManipulationFactory.java
  48. +2 −2 ...src/main/java/org/sql/generation/implementation/grammar/factories/DefaultModificationFactory.java
  49. +7 −0 ...tation/src/main/java/org/sql/generation/implementation/grammar/factories/DefaultQueryFactory.java
  50. +14 −5 ...ion/src/main/java/org/sql/generation/implementation/grammar/factories/DefaultTableRefFactory.java
  51. +0 −1 ...main/java/org/sql/generation/implementation/grammar/factories/pgsql/PgSQLDataTypeFactoryImpl.java
  52. +3 −3 .../java/org/sql/generation/implementation/grammar/factories/pgsql/PgSQLManipulationFactoryImpl.java
  53. +1 −2 ...java/org/sql/generation/implementation/grammar/manipulation/AddTableConstraintDefinitionImpl.java
  54. +6 −6 ...src/main/java/org/sql/generation/implementation/grammar/manipulation/AlterTableStatementImpl.java
  55. +5 −5 ...ain/java/org/sql/generation/implementation/grammar/manipulation/DropTableOrViewStatementImpl.java
  56. +3 −3 ...g/sql/generation/implementation/grammar/manipulation/pgsql/PgSQLDropTableOrViewStatementImpl.java
  57. +5 −5 ...ion/src/main/java/org/sql/generation/implementation/grammar/modification/InsertStatementImpl.java
  58. +5 −5 ...ntation/src/main/java/org/sql/generation/implementation/grammar/modification/TargetTableImpl.java
  59. +6 −5 ...ation/src/main/java/org/sql/generation/implementation/grammar/query/TableReferenceByNameImpl.java
  60. +6 −3 ...mentation/src/main/java/org/sql/generation/implementation/transformation/DefaultSQLProcessor.java
  61. +57 −20 ...tion/src/main/java/org/sql/generation/implementation/transformation/TableReferenceProcessing.java
  62. +6 −3 ...entation/src/main/java/org/sql/generation/implementation/transformation/mysql/MySQLProcessor.java
  63. +16 −4 ...on/src/main/java/org/sql/generation/implementation/transformation/mysql/MySQLTableProcessing.java
  64. +1 −1 .../src/main/java/org/sql/generation/implementation/transformation/pgsql/ManipulationProcessing.java
  65. +15 −0 implementation/src/test/java/org/sql/generation/implementation/AbstractQueryTest.java
View
@@ -1,4 +1,7 @@
-api/target
-implementation/target
-api.qi4j/target
+# Ignore default maven target folders
target
+
+# Ignore Eclipse files and folders
+.settings
+.project
+.classpath
@@ -17,7 +17,7 @@
import java.util.List;
import org.sql.generation.api.grammar.builders.AbstractBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.table.ForeignKeyConstraint;
import org.sql.generation.api.grammar.definition.table.MatchType;
import org.sql.generation.api.grammar.definition.table.ReferentialAction;
@@ -53,7 +53,7 @@
* @param tableName The target table name for this foreign key constraint.
* @return This builder.
*/
- public ForeignKeyConstraintBuilder setTargetTableName( TableName tableName );
+ public ForeignKeyConstraintBuilder setTargetTableName( TableNameDirect tableName );
/**
* Sets the match type for this foreign key constraint.
@@ -101,7 +101,7 @@
*
* @return The target table name for this foreign key constraint.
*/
- public TableName getTableName();
+ public TableNameDirect getTableName();
/**
* Returns the match type for this foreign key constraint.
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.builders.definition;
import org.sql.generation.api.grammar.builders.AbstractBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.table.TableCommitAction;
import org.sql.generation.api.grammar.definition.table.TableContentsSource;
import org.sql.generation.api.grammar.definition.table.TableDefinition;
@@ -47,7 +47,7 @@
* @return This builder.
* @see TableName
*/
- public TableDefinitionBuilder setTableName( TableName tableName );
+ public TableDefinitionBuilder setTableName( TableNameDirect tableName );
/**
* Sets the commit action for this table.
@@ -80,7 +80,7 @@
*
* @return The name for this table.
*/
- public TableName getTableName();
+ public TableNameDirect getTableName();
/**
* Returns the commit action for this table.
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.builders.definition;
import org.sql.generation.api.grammar.builders.AbstractBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.view.RegularViewSpecification;
import org.sql.generation.api.grammar.definition.view.ViewCheckOption;
import org.sql.generation.api.grammar.definition.view.ViewDefinition;
@@ -46,7 +46,7 @@
* @param viewName The name for this view.
* @return This builder.
*/
- public ViewDefinitionBuilder setViewName( TableName viewName );
+ public ViewDefinitionBuilder setViewName( TableNameDirect viewName );
/**
* Sets the query for this view.
@@ -86,7 +86,7 @@
*
* @return The name of the view.
*/
- public TableName getViewName();
+ public TableNameDirect getViewName();
/**
* Returns the query for the view.
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.builders.modification;
import org.sql.generation.api.grammar.builders.AbstractBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.modification.ColumnSource;
import org.sql.generation.api.grammar.modification.InsertStatement;
@@ -37,14 +37,14 @@
* @param tableName The table name for this {@code INSERT} statement.
* @return This builder.
*/
- public InsertStatementBuilder setTableName( TableName tableName );
+ public InsertStatementBuilder setTableName( TableNameDirect tableName );
/**
* Returns the table name for this {@code INSERT} statement.
*
* @return The table name for this {@code INSERT} statement.
*/
- public TableName getTableName();
+ public TableNameDirect getTableName();
/**
* Sets the source for the columns for this {@code INSERT} statement.
@@ -16,7 +16,7 @@
import org.sql.generation.api.grammar.booleans.BooleanExpression;
import org.sql.generation.api.grammar.builders.AbstractBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameAbstract;
import org.sql.generation.api.grammar.common.ValueExpression;
import org.sql.generation.api.grammar.factories.QueryFactory;
import org.sql.generation.api.grammar.query.QueryExpression;
@@ -47,6 +47,13 @@
*/
public SimpleQueryBuilder select( ValueExpression... expressions );
+ /**
+ * Selects all columns ({@code SELECT *}).
+ *
+ * @return This builder.
+ */
+ public SimpleQueryBuilder selectAllColumns();
+
/**
* Adds alias to the most recently added column.
*
@@ -61,7 +68,7 @@
* @param tableNames The table names to add.
* @return This builder.
*/
- public SimpleQueryBuilder from( TableName... tableNames );
+ public SimpleQueryBuilder from( TableNameAbstract... tableNames );
/**
* Sets the search condition ({@code WHERE} clause) for this query.
@@ -16,7 +16,7 @@
import org.sql.generation.api.grammar.booleans.BooleanExpression;
import org.sql.generation.api.grammar.builders.query.SimpleQueryBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameAbstract;
/**
* This builder extends {@link SimpleQueryBuilder} functionality with PostgreSQL-specific elements.
@@ -48,7 +48,7 @@
public PgSQLSimpleQueryBuilder as( String columnAlias );
- public PgSQLSimpleQueryBuilder from( TableName... tableNames );
+ public PgSQLSimpleQueryBuilder from( TableNameAbstract... tableNames );
public PgSQLSimpleQueryBuilder where( BooleanExpression searchCondition );
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ * Copyright (c) 2011, Stanislav Muhametsin. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,26 +17,19 @@
import org.atp.api.Typeable;
/**
- * A table name may be just table name, or schema-qualified table name.
+ * This is common interface for table names. Table name may be either {@link TableNameDirect} or
+ * {@link TableNameFunction}.
*
- * @author Stanislav Muhametsin
+ * @author 2011 Stanislav Muhametsin
*/
-public interface TableName
- extends Typeable<TableName>
+public interface TableNameAbstract
+ extends Typeable<TableNameAbstract>
{
-
/**
* Gets the schema name. Returns {@code null} if this is not schema-qualified table name.
*
* @return Schema name of the schema-qualified table name, or {@code null} if this is not a schema-qualified table
* name.
*/
public String getSchemaName();
-
- /**
- * Gets name of the table. Returns always non-{@code null}.
- *
- * @return The name of the table. Always non-{@code null}.
- */
- public String getTableName();
}
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.sql.generation.api.grammar.common;
+
+/**
+ * A direct table name may be just table name, or schema-qualified table name.
+ *
+ * @author Stanislav Muhametsin
+ */
+public interface TableNameDirect
+ extends TableNameAbstract
+{
+
+ /**
+ * Gets name of the table. Returns always non-{@code null}.
+ *
+ * @return The name of the table. Always non-{@code null}.
+ */
+ public String getTableName();
+}
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Stanislav Muhametsin. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.sql.generation.api.grammar.common;
+
+import org.sql.generation.api.grammar.literals.SQLFunctionLiteral;
+
+/**
+ * A table name function serves as a function call when selecting data.
+ *
+ * @author 2011 Stanislav Muhametsin
+ */
+public interface TableNameFunction
+ extends TableNameAbstract
+{
+ /**
+ * Returns the function to call.
+ *
+ * @return The function to call.
+ */
+ public SQLFunctionLiteral getFunction();
+}
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.definition.table;
import org.sql.generation.api.grammar.common.ColumnNameList;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
/**
* This syntax element represents the {@code FOREIGN KEY(col1, col2, ...) ...} table constraint in table definition.
@@ -40,7 +40,7 @@
*
* @return The name of the table where the columns in this table are referencing to.
*/
- public TableName getTargetTableName();
+ public TableNameDirect getTargetTableName();
/**
* Returns the list of column names in target table. Will be {@code null} if none specified.
@@ -14,7 +14,7 @@
package org.sql.generation.api.grammar.definition.table;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
/**
* This syntax element represents the {@code LIKE
@@ -32,5 +32,5 @@
*
* @return The name of the table for this {@code LIKE} clause.
*/
- public TableName getTableName();
+ public TableNameDirect getTableName();
}
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.definition.table;
import org.sql.generation.api.grammar.common.SchemaDefinitionStatement;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.schema.SchemaElement;
/**
@@ -40,7 +40,7 @@
* @return The name for this table.
* @see TableName
*/
- public TableName getTableName();
+ public TableNameDirect getTableName();
/**
* Returns the commit action for this table. May be {@code null} if no commit action defined.
@@ -15,7 +15,7 @@
package org.sql.generation.api.grammar.definition.view;
import org.sql.generation.api.grammar.common.SchemaDefinitionStatement;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.schema.SchemaElement;
import org.sql.generation.api.grammar.query.QueryExpression;
@@ -40,7 +40,7 @@
*
* @return The name of this view.
*/
- public TableName getViewName();
+ public TableNameDirect getViewName();
/**
* Returns the view specification.
@@ -15,7 +15,6 @@
package org.sql.generation.api.grammar.factories;
import java.util.Collection;
-import java.util.List;
import org.sql.generation.api.grammar.common.ColumnNameList;
import org.sql.generation.api.grammar.common.ValueExpression;
@@ -21,7 +21,7 @@
import org.sql.generation.api.grammar.builders.definition.TableElementListBuilder;
import org.sql.generation.api.grammar.builders.definition.UniqueConstraintBuilder;
import org.sql.generation.api.grammar.builders.definition.ViewDefinitionBuilder;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.common.datatypes.SQLDataType;
import org.sql.generation.api.grammar.definition.table.CheckConstraint;
import org.sql.generation.api.grammar.definition.table.ColumnDefinition;
@@ -127,7 +127,7 @@ public ColumnDefinition createColumnDefinition( String columnName, SQLDataType c
* @return The syntax element for {@code LIKE
* <table name>} clause for {@code CREATE TABLE} statement.
*/
- public LikeClause createLikeClause( TableName tableName );
+ public LikeClause createLikeClause( TableNameDirect tableName );
/**
* Creates a new unnamed table constraint without any {@link ConstraintCharacteristics}. Invoking this method is
@@ -14,7 +14,7 @@
package org.sql.generation.api.grammar.factories;
-import org.sql.generation.api.grammar.common.TableName;
+import org.sql.generation.api.grammar.common.TableNameDirect;
import org.sql.generation.api.grammar.definition.table.ColumnDefinition;
import org.sql.generation.api.grammar.definition.table.TableConstraintDefinition;
import org.sql.generation.api.grammar.manipulation.AddColumnDefinition;
@@ -54,7 +54,7 @@
* @see #createDropColumnDefinition(String, DropBehaviour)
* @see #createDropTableConstraintDefinition(String, DropBehaviour)
*/
- public AlterTableStatement createAlterTableStatement( TableName tableName, AlterTableAction action );
+ public AlterTableStatement createAlterTableStatement( TableNameDirect tableName, AlterTableAction action );
/**
* Creates the syntax element for adding column ({@code ADD COLUMN ...}) in {@code ALTER TABLE} statement.
@@ -147,7 +147,7 @@ public DropTableConstraintDefinition createDropTableConstraintDefinition( String
* @see DropBehaviour
* @see ObjectType
*/
- public DropTableOrViewStatement createDropTableOrViewStatement( TableName tableName, ObjectType theType,
+ public DropTableOrViewStatement createDropTableOrViewStatement( TableNameDirect tableName, ObjectType theType,
DropBehaviour dropBehaviour );
}
Oops, something went wrong.

0 comments on commit 38bab95

Please sign in to comment.