http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java new file mode 100644 index 0000000..d438ea9 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/definition/package-info.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +/** + * This is package containing builders for syntax elements used in SQL Data Definition statements (typically {@code CREATE} statements). + */ +package org.apache.polygene.library.sql.generator.grammar.builders.definition; \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java new file mode 100644 index 0000000..dc3a709 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/ColumnSourceByValuesBuilder.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression; +import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSourceByValues; + +/** + * This builder builds the {@link ColumnSourceByValues} syntax element. + * + * @author Stanislav Muhametsin + */ +public interface ColumnSourceByValuesBuilder + extends AbstractBuilder<ColumnSourceByValues> +{ + /** + * Adds the expressions as values to columns. + * + * @param values The value expressions to add. + * @return This builder. + */ + ColumnSourceByValuesBuilder addValues( ValueExpression... values ); + + /** + * Returns the value expressions for the columns. + * + * @return The value expressions for the columns. + */ + List<ValueExpression> getValues(); + + /** + * Adds the names for the columns. + * + * @param columnNames The names for columns. + * @return This builder. + */ + ColumnSourceByValuesBuilder addColumnNames( String... columnNames ); + + /** + * Returns the names for the columns. + * + * @return The names for the columns. + */ + List<String> getColumnNames(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java new file mode 100644 index 0000000..4d1ca4a --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/DeleteBySearchBuilder.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification; + +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder; +import org.apache.polygene.library.sql.generator.grammar.modification.DeleteBySearch; +import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable; + +/** + * This builder builds statements deleting rows matching search condition ({@code DELETE FROM} table {@code [WHERE} + * searchCondition {@code ]}). + * + * @author Stanislav Muhametsin + * @see TargetTable + * @see BooleanBuilder + */ +public interface DeleteBySearchBuilder + extends AbstractBuilder<DeleteBySearch> +{ + /** + * Sets the target table for this {@code DELETE} statement. + * + * @param table The target table for this {@code DELETE} statement. + * @return This builder. + */ + DeleteBySearchBuilder setTargetTable( TargetTable table ); + + /** + * Retrieves the target table for this {@code DELETE} statement. + * + * @return The target table for this {@code DELETE} statement. + */ + TargetTable getTargetTable(); + + /** + * Returns the builder for search condition for this {@code DELETE} statement (boolean expression after + * {@code WHERE}). The search condition is optional. + * + * @return The builder for search condition for this {@code DELETE} statement. + */ + BooleanBuilder getWhere(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java new file mode 100644 index 0000000..c404bc5 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/InsertStatementBuilder.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification; + +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.TableName; +import org.apache.polygene.library.sql.generator.grammar.common.TableNameDirect; +import org.apache.polygene.library.sql.generator.grammar.modification.ColumnSource; +import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement; + +/** + * This builder builds statements inserting rows to tables ({@code INSERT INTO } tableName {@code [(} column names + * {@code )]} expression). + * + * @author Stanislav Muhametsin + * @see TableName + * @see ColumnSource + */ +public interface InsertStatementBuilder + extends AbstractBuilder<InsertStatement> +{ + + /** + * Sets the table name for this {@code INSERT} statement. + * + * @param tableName The table name for this {@code INSERT} statement. + * @return This builder. + */ + InsertStatementBuilder setTableName( TableNameDirect tableName ); + + /** + * Returns the table name for this {@code INSERT} statement. + * + * @return The table name for this {@code INSERT} statement. + */ + TableNameDirect getTableName(); + + /** + * Sets the source for the columns for this {@code INSERT} statement. + * + * @param source The source for columns for this {@code INSERT} statement. + * @return This builder. + */ + InsertStatementBuilder setColumnSource( ColumnSource source ); + + /** + * Returns the source for the columns for this {@code INSERT} statement. + * + * @return The source for the columns for this {@code INSERT} statement. + */ + ColumnSource getColumnSource(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java new file mode 100644 index 0000000..c82087c --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/UpdateBySearchBuilder.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder; +import org.apache.polygene.library.sql.generator.grammar.modification.SetClause; +import org.apache.polygene.library.sql.generator.grammar.modification.TargetTable; +import org.apache.polygene.library.sql.generator.grammar.modification.UpdateBySearch; + +/** + * This builder builds statements updating rows matching search condition ({@code UPDATE} table {@code SET} set-clauses + * {@code [WHERE} searchCondition {@code ]}). + * + * @author Stanislav Muhametsin + * @see SetClause + * @see BooleanBuilder + */ +public interface UpdateBySearchBuilder + extends AbstractBuilder<UpdateBySearch> +{ + /** + * Sets the target table for this {@code UPDATE} statement. + * + * @param table The target table for this {@code UPDATE} statement. + * @return This builder. + */ + UpdateBySearchBuilder setTargetTable( TargetTable table ); + + /** + * Returns the builder for search condition for this {@code UPDATE} statement (boolean expression after + * {@code WHERE}). The search condition is optional. + * + * @return The builder for search condition for this {@code UPDATE} statement. + */ + BooleanBuilder getWhereBuilder(); + + /** + * Adds the clause to the set-clause list of this {@code UPDATE} statement. + * + * @param clauses The set-clauses for this {@code UPDATE} statement. + * @return This builder. + */ + UpdateBySearchBuilder addSetClauses( SetClause... clauses ); + + /** + * Returns the list of set clauses which has been added to this builder. + * + * @return The list of set clauses which has been added to this builder. + */ + List<SetClause> getSetClauses(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java new file mode 100644 index 0000000..181488c --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/package-info.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +/** + * Package to hold builders common for SQL modification clauses ({@code INSERT}, {@code UPDATE}, and {@code DELETE}). + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java new file mode 100644 index 0000000..38cbca3 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/PgSQLInsertStatementBuilder.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql; + +import org.apache.polygene.library.sql.generator.grammar.builders.modification.InsertStatementBuilder; +import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause; + +/** + * This build is used for creating {@code INSERT} statements specific for PostgreSQL databases. + * + * @author Stanislav Muhametsin + */ +public interface PgSQLInsertStatementBuilder extends InsertStatementBuilder +{ + + /** + * Sets the {@code RETURNING} clause for this {@code INSERT} statement. + * + * @param clause The {@code RETURNING} clause. May be {@code null} if no {@code RETURNING} + * clause is desired. + * @return This builder. + */ + PgSQLInsertStatementBuilder setReturningClause( SelectColumnClause clause ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java new file mode 100644 index 0000000..359bfff --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/modification/pgsql/package-info.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +/** + * This package contains modification statement ( {@code UPDATE}, {@code INSERT} or {@code DELETE}) + * builders specific for PostgreSQL database. + */ +package org.apache.polygene.library.sql.generator.grammar.builders.modification.pgsql; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java new file mode 100644 index 0000000..dc3e00c --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/package-info.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +/** + * A package containing builders for common elements of SQL syntax. + */ +package org.apache.polygene.library.sql.generator.grammar.builders; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java new file mode 100644 index 0000000..86a1b2e --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/AbstractQueryBuilder.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression; +import org.apache.polygene.library.sql.generator.grammar.literals.NumericLiteral; +import org.apache.polygene.library.sql.generator.grammar.query.LimitSpecification; + +/** + * @author 2011 Stanislav Muhametsin + */ +public interface AbstractQueryBuilder<ExpressionType> + extends AbstractBuilder<ExpressionType> +{ + /** + * Adds the {@code FETCH FIRST ROW ONLY} expression for this query. The resulting {@link LimitSpecification} will + * have its count as {@code null}. + * + * @return This builder. + */ + AbstractQueryBuilder<ExpressionType> limit(); + + /** + * Adds the {@code FETCH FIRST <number> ROWS ONLY} expression for this query. Calling this method is equivalent of + * calling {@link #limit(NonBooleanExpression)} and passing the {@link NumericLiteral} representing the given number + * as the parameter. + * + * @param max The maximum amount of rows for this query to return. Use {@code null} to remove the + * {@code FETCH FIRST <number> ROWS ONLY} expression. + * @return This builder. + */ + AbstractQueryBuilder<ExpressionType> limit( Integer max ); + + /** + * Adds the {@code FETCH FIRST <number> ROWS ONLY} expression for this query. + * + * @param max The maximum amount of rows for this query to return. May be subquery or something else that evaluates + * to number or {@code NULL}. Use {@code null} to remove the {@code FETCH FIRST <number> ROWS ONLY} + * expression. + * @return This builder. + */ + AbstractQueryBuilder<ExpressionType> limit( NonBooleanExpression max ); + + /** + * Adds the {@code OFFSET <number> ROWS} expression for this query. Calling this method is equivalen of calling + * {@link #offset(NonBooleanExpression)} and passing the {@link NumericLiteral} representing the given number as the + * parameter. + * + * @param skip The amount of rows to skip before starting to include them into this query. Use {@code null} to + * remove the {@code OFFSET <number> ROWS} expression. + * @return This builder. + */ + AbstractQueryBuilder<ExpressionType> offset( Integer skip ); + + /** + * Adds the {@code OFFSET <number> ROWS} expression for this query. + * + * @param skip The amount of rows to skip before starting to include them into this query. May be subquery or + * something else that evaluates to number or {@code NULL}. Use {@code null} to remove the + * {@code OFFSET <number> ROWS} expression. + * @return This builder. + */ + AbstractQueryBuilder<ExpressionType> offset( NonBooleanExpression skip ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java new file mode 100644 index 0000000..e11a70b --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/ColumnsBuilder.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier; +import org.apache.polygene.library.sql.generator.grammar.query.ColumnReference; +import org.apache.polygene.library.sql.generator.grammar.query.ColumnReferences.ColumnReferenceInfo; +import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification; +import org.apache.polygene.library.sql.generator.grammar.query.SelectColumnClause; + +/** + * This builder builds the columns for {@code SELECT} statement. + * + * @author Stanislav Muhametsin + * @see SelectColumnClause + * @see QuerySpecification + * @see ColumnReference + */ +public interface ColumnsBuilder + extends AbstractBuilder<SelectColumnClause> +{ + /** + * Adds columns without aliases to this {@code SELECT} statement. + * + * @param columns Columns without aliases to add to this {@code SELECT} statement. + * @return This builder. + */ + ColumnsBuilder addUnnamedColumns( ColumnReference... columns ); + + /** + * Add columns with aliases to this {@code SELECT} statement. + * + * @param namedColumns Columns with aliases to add to this {@code SELECT} statement. + * @return + */ + ColumnsBuilder addNamedColumns( ColumnReferenceInfo... namedColumns ); + + /** + * Sets the set quantifier ({@code ALL} or {@code DISTINCT}) for this {@code SELECT} statement. + * + * @param newSetQuantifier The new set quantifier. + * @return This builder. + * @see SetQuantifier + */ + ColumnsBuilder setSetQuantifier( SetQuantifier newSetQuantifier ); + + /** + * Marks that all columns should be selected ({@literal SELECT} *). This will empty a list of columns to select. + * + * @return This builder. + */ + ColumnsBuilder selectAll(); + + /** + * Returns the columns of this {@code SELECT} statement. It returns empty by default, or after calling + * {@link #selectAll()} method. + * + * @return A list of columns of this {@code SELECT} statement. Might be empty. + */ + List<ColumnReferenceInfo> getColumns(); + + /** + * Returns the set quantifier ({@code ALL} or {@code DISTINCT}) of this {@code SELECT} statement. + * + * @return The set quantifier of this {@code SELECT} statement. + */ + SetQuantifier getSetQuantifier(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java new file mode 100644 index 0000000..cbed912 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/FromBuilder.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.query.FromClause; +import org.apache.polygene.library.sql.generator.grammar.query.TableReference; + +/** + * The builder that builds the {@code FROM} clause in SQL {@code SELECT} query. It treats {@code FROM} clause as a list + * of {@link TableReference}s, and acts as aggregator for {@link TableReferenceBuilder}s. + * + * @author Stanislav Muhametsin + * @see TableReference + * @see TableReferenceBuilder + */ +public interface FromBuilder + extends AbstractBuilder<FromClause> +{ + + /** + * Adds table reference builders to this {@code FROM} clause. When {@link #createExpression()} method will be called + * on this builder, it will build all table references from builders that were added through this method. + * + * @param tableRefs Table reference builders to add to this {@code FROM} clause. + * @return This builder. + */ + FromBuilder addTableReferences( TableReferenceBuilder... tableRefs ); + + /** + * Returns a list of table reference builders in this builder. + * + * @return A list of table reference builders in this builder. Might be empty. + */ + List<TableReferenceBuilder> getTableReferences(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java new file mode 100644 index 0000000..102d379 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/GroupByBuilder.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.query.GroupByClause; +import org.apache.polygene.library.sql.generator.grammar.query.GroupingElement; + +/** + * The builder that builds the {@code GROUP BY} clause in SQL {@code SELECT} query. + * + * @author Stanislav Muhametsin + * @see GroupByClause + * @see GroupingElement + */ +public interface GroupByBuilder + extends AbstractBuilder<GroupByClause> +{ + + /** + * Adds grouping elements to this {@code GROUP BY} clause. + * + * @param elements The grouping elements for this {@code GROUP BY} clause. + * @return This builder. + */ + GroupByBuilder addGroupingElements( GroupingElement... elements ); + + /** + * Returns the list of added grouping elements. + * + * @return The list of added grouping elements. + */ + List<GroupingElement> getGroupingElements(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java new file mode 100644 index 0000000..49cbaa3 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/OrderByBuilder.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import java.util.List; +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.query.OrderByClause; +import org.apache.polygene.library.sql.generator.grammar.query.SortSpecification; + +/** + * The builder that builds the {@code ORDER BY} clause in SQL {@code SELECT} query. + * + * @author Stanislav Muhametsin + * @see OrderByClause + * @see SortSpecification + */ +public interface OrderByBuilder + extends AbstractBuilder<OrderByClause> +{ + + /** + * Adds sort specifications to this {@code ORDER BY} clause. + * + * @param specs The sort specifications for this {@code ORDER BY} clause. + * @return This builder. + */ + OrderByBuilder addSortSpecs( SortSpecification... specs ); + + /** + * Returns the list of added sort specifications. + * + * @return The added sort specifications. + */ + List<SortSpecification> getSortSpecs(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java new file mode 100644 index 0000000..3ae57b3 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QueryBuilder.java @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.SetQuantifier; +import org.apache.polygene.library.sql.generator.grammar.query.CorrespondingSpec; +import org.apache.polygene.library.sql.generator.grammar.query.QueryExpressionBody; +import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification; + +/** + * The builder that builds the SQL queries having {@code UNION}, {@code INTERSECT}, or {@code EXCEPT} between the + * {@code SELECT} statements. + * + * @author Stanislav Muhametsin + * @see QueryExpressionBody + * @see QuerySpecification + * @see QuerySpecificationBuilder + * @see CorrespondingSpec + */ +public interface QueryBuilder + extends AbstractBuilder<QueryExpressionBody> +{ + /** + * <p> + * Adds {@code UNION} between current query and the given query. Then makes resulting query the current query. + * </p> + * <p> + * This is equivalent on calling {@link #union(SetQuantifier, QueryExpressionBody)} and giving + * {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param another The query to perform {@code UNION} with. + * @return This builder. + */ + QueryBuilder union( QueryExpressionBody another ); + + /** + * <p> + * Adds {@code UNION <setQuantifier>} between current query and the given query. Then makes resulting query the + * current query. + * </p> + * <p> + * This is equivalent on calling {@link #union(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving + * {@code null} as second parameter. + * </p> + * + * @param setQuantifier The set quantifier for this union. + * @param another The query to perform {@code UNION} with. + * @return This builder. + */ + QueryBuilder union( SetQuantifier setQuantifier, QueryExpressionBody another ); + + /** + * <p> + * Adds {@code UNION <correspondingSpec>} between current query and the given query. Then makes resulting query the + * current query. + * </p> + * <p> + * This is equivalent on calling {@link #union(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving + * {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param correspondingSpec The column correspondence specification. + * @param another The query to perform {@code UNION} with. + * @return This builder. + */ + QueryBuilder union( CorrespondingSpec correspondingSpec, QueryExpressionBody another ); + + /** + * Adds {@code UNION <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes + * resulting query the current query. + * + * @param setQuantifier The set quantifier for this union. + * @param correspondingSpec The column correspondence specification. May be {@code null}. + * @param another The query to perform {@code UNION} with. + * @return This builder. + */ + QueryBuilder union( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec, + QueryExpressionBody another ); + + /** + * <p> + * Adds {@code INTERSECT} between current query and the given query. Then makes resulting query the current query. + * </p> + * <p> + * This is equivalent on calling {@link #intersect(SetQuantifier, QueryExpressionBody)} and giving + * {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param another The query to perform {@code INTERSECT} with. + * @return This builder. + */ + QueryBuilder intersect( QueryExpressionBody another ); + + /** + * <p> + * Adds {@code INTERSECT <setQuantifier>} between current query and the given query. Then makes resulting query the + * current query. + * </p> + * <p> + * This is equivalent on calling {@link #intersect(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and + * giving {@code null} as second parameter. + * </p> + * + * @param setQuantifier The set quantifier for this union. + * @param another The query to perform {@code INTERSECT} with. + * @return This builder. + */ + QueryBuilder intersect( SetQuantifier setQuantifier, QueryExpressionBody another ); + + /** + * <p> + * Adds {@code INTERSECT <correspondingSpec>} between current query and the given query. Then makes resulting query + * the current query. + * </p> + * <p> + * This is equivalent on calling {@link #intersect(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and + * giving {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param correspondingSpec The column correspondence specification. + * @param another The query to perform {@code INTERSECT} with. + * @return This builder. + */ + QueryBuilder intersect( CorrespondingSpec correspondingSpec, QueryExpressionBody another ); + + /** + * Adds {@code INTERSECT <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes + * resulting query the current query. + * + * @param setQuantifier The set quantifier for this union. + * @param correspondingSpec The column correspondence specification. May be {@code null}. + * @param another The query to perform {@code INTERSECT} with. + * @return This builder. + */ + QueryBuilder intersect( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec, + QueryExpressionBody another ); + + /** + * <p> + * Adds {@code EXCEPT} between current query and the given query. Then makes resulting query the current query. + * </p> + * <p> + * This is equivalent on calling {@link #except(SetQuantifier, QueryExpressionBody)} and giving + * {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param another The query to perform {@code EXCEPT} with. + * @return This builder. + */ + QueryBuilder except( SetQuantifier setQuantifier, CorrespondingSpec correspondingSpec, + QueryExpressionBody another ); + + /** + * <p> + * Adds {@code EXCEPT <setQuantifier>} between current query and the given query. Then makes resulting query the + * current query. + * </p> + * <p> + * This is equivalent on calling {@link #except(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving + * {@code null} as second parameter. + * </p> + * + * @param setQuantifier The set quantifier for this union. + * @param another The query to perform {@code EXCEPT} with. + * @return This builder. + */ + QueryBuilder except( QueryExpressionBody another ); + + /** + * <p> + * Adds {@code EXCEPT <correspondingSpec>} between current query and the given query. Then makes resulting query the + * current query. + * </p> + * <p> + * This is equivalent on calling {@link #except(SetQuantifier, CorrespondingSpec, QueryExpressionBody)} and giving + * {@link SetQuantifier#DISTINCT} as first parameter. + * </p> + * + * @param correspondingSpec The column correspondence specification. + * @param another The query to perform {@code EXCEPT} with. + * @return This builder. + */ + QueryBuilder except( SetQuantifier setQuantifier, QueryExpressionBody another ); + + /** + * Adds {@code EXCEPT <setQuantifier> <correspondingSpec>} between current query and the given query. Then makes + * resulting query the current query. + * + * @param setQuantifier The set quantifier for this union. + * @param correspondingSpec The column correspondence specification. May be {@code null}. + * @param another The query to perform {@code EXCEPT} with. + * @return This builder. + */ + QueryBuilder except( CorrespondingSpec correspondingSpec, QueryExpressionBody another ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java new file mode 100644 index 0000000..3be9d71 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/QuerySpecificationBuilder.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import org.apache.polygene.library.sql.generator.grammar.builders.booleans.BooleanBuilder; +import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression; +import org.apache.polygene.library.sql.generator.grammar.query.QuerySpecification; + +/** + * This builder builds a single {@code SELECT} query. It acts as an aggregator for {@link ColumnsBuilder} for columns in + * {@code SELECT}, {@link FromBuilder} for tables in {@code FROM} clause, {@link BooleanBuilder} for search condition in + * {@code WHERE} clause, {@link GroupByBuilder} for {@code GROUP BY} clause, another {@link BooleanBuilder} for grouping + * conditions in {@code HAVING} clause, and finally {@link OrderByBuilder} for {@code ORDER BY} clause. + * + * @author Stanislav Muhametsin + * @see QuerySpecification + */ +public interface QuerySpecificationBuilder + extends AbstractQueryBuilder<QuerySpecification> +{ + + /** + * Gets the builder for columns in this {@code SELECT} statement. + * + * @return The builder for columns in this {@code SELECT} statement. + */ + ColumnsBuilder getSelect(); + + /** + * Gets the builder for {@code FROM} clause of this {@code SELECT} statement. + * + * @return The builder for {@code FROM} clause of this {@code SELECT} statement. + */ + FromBuilder getFrom(); + + /** + * Gets the builder for search condition in {@code WHERE} clause of this {@code SELECT} statement. + * + * @return The builder for search condition in {@code WHERE} clause of this {@code SELECT} statement. + */ + BooleanBuilder getWhere(); + + /** + * Gets the builder for {@code GROUP BY} clause of this {@code SELECT} statement. + * + * @return The builder for {@code GROUP BY} clause of this {@code SELECT} statement. + */ + GroupByBuilder getGroupBy(); + + /** + * Gets the builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement. + * + * @return The builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement. + */ + BooleanBuilder getHaving(); + + /** + * Gets the builder for {@code ORDER BY} clause of this {@code SELECT} statement. + * + * @return The builder for {@code ORDER BY} clause of this {@code SELECT} statement. + */ + OrderByBuilder getOrderBy(); + + /** + * Checks that all selected columns are in {@code GROUP BY} clause. If they are not, it adds them as last columns of + * {@code GROUP BY} clause. + * + * @return This builder. + */ + QuerySpecificationBuilder trimGroupBy(); + + /** + * Sets the builder for columns in {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setSelect( ColumnsBuilder builder ); + + /** + * Sets the builder for {@code FROM} clause of this {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setFrom( FromBuilder builder ); + + /** + * Sets the builder for search condition in {@code WHERE} clause of this {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setWhere( BooleanBuilder builder ); + + /** + * Sets the builder for {@code GROUP BY} clause of this {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setGroupBy( GroupByBuilder builder ); + + /** + * Sets the builder for grouping condition in {@code HAVING} clause of this {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setHaving( BooleanBuilder builder ); + + /** + * Sets the builder for {@code ORDER BY} clause of this {@code SELECT} statement. + * + * @return This builder. + */ + QuerySpecificationBuilder setOrderBy( OrderByBuilder builder ); + + QuerySpecificationBuilder limit(); + + QuerySpecificationBuilder limit( Integer max ); + + QuerySpecificationBuilder limit( NonBooleanExpression max ); + + QuerySpecificationBuilder offset( Integer skip ); + + QuerySpecificationBuilder offset( NonBooleanExpression skip ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java new file mode 100644 index 0000000..e3907dd --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/SimpleQueryBuilder.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import org.apache.polygene.library.sql.generator.grammar.booleans.BooleanExpression; +import org.apache.polygene.library.sql.generator.grammar.common.NonBooleanExpression; +import org.apache.polygene.library.sql.generator.grammar.common.TableName; +import org.apache.polygene.library.sql.generator.grammar.common.ValueExpression; +import org.apache.polygene.library.sql.generator.grammar.factories.QueryFactory; +import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression; + +/** + * This is builder to quickly create simple queries, without the generic and not-so-easy-to-use methods of traditional + * {@link QuerySpecificationBuilder} + {@link QueryFactory} style. Using this builder is generally not thread-safe. + * + * @author Stanislav Muhametsin + */ +public interface SimpleQueryBuilder + extends AbstractQueryBuilder<QueryExpression> +{ + + /** + * Adds the specified columns to the {@code SELECT} list. + * + * @param columnNames The names of the columns. + * @return This builder. + */ + SimpleQueryBuilder select( String... columnNames ); + + /** + * Adds the specified column expressions to the {@code SELECT} list. + * + * @param expressions The value expressions for columns. + * @return This builder. + */ + SimpleQueryBuilder select( ValueExpression... expressions ); + + /** + * Selects all columns ({@code SELECT *}). + * + * @return This builder. + */ + SimpleQueryBuilder selectAllColumns(); + + /** + * Adds alias to the most recently added column. + * + * @param columnAlias The alias for most recently added column; + * @return This builder. + */ + SimpleQueryBuilder as( String columnAlias ); + + /** + * Adds table names for {@code FROM} clause of this query. + * + * @param tableNames The table names to add. + * @return This builder. + */ + SimpleQueryBuilder from( TableName... tableNames ); + + /** + * Sets the search condition ({@code WHERE} clause) for this query. + * + * @param searchCondition The search condition for this query. + * @return This builder. + */ + SimpleQueryBuilder where( BooleanExpression searchCondition ); + + /** + * Adds {@code GROUP BY} columns for this query. + * + * @param columns The column names for {@code GROUP BY} clause. + * @return This builder. + */ + SimpleQueryBuilder groupBy( String... columns ); + + /** + * Adds {@code HAVING} grouping condition for this query. + * + * @param groupingCondition The grouping condition for this query. + * @return This builder. + */ + SimpleQueryBuilder having( BooleanExpression groupingCondition ); + + /** + * Adds {@code ORDER BY} columns for this query, with {@code ASC} as ordering specification. + * + * @param columns The column names for {@code ORDER BY}. + * @return This builder. + */ + SimpleQueryBuilder orderByAsc( String... columns ); + + /** + * Adds {@code ORDER BY} columns for this query, with {@code DESC} as ordering specification. + * + * @param columns The column names for {@code ORDER BY}. + * @return This builder. + */ + SimpleQueryBuilder orderByDesc( String... columns ); + + SimpleQueryBuilder limit(); + + SimpleQueryBuilder limit( Integer max ); + + SimpleQueryBuilder limit( NonBooleanExpression max ); + + SimpleQueryBuilder offset( Integer skip ); + + SimpleQueryBuilder offset( NonBooleanExpression skip ); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java new file mode 100644 index 0000000..1365809 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/TableReferenceBuilder.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; + +import org.apache.polygene.library.sql.generator.grammar.builders.AbstractBuilder; +import org.apache.polygene.library.sql.generator.grammar.query.TableReference; +import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinSpecification; +import org.apache.polygene.library.sql.generator.grammar.query.joins.JoinType; + +/** + * The builder to build joined tables. A joined table contains 0 or more joins. + * + * @author Stanislav Muhametsin + * @see TableReference + */ +public interface TableReferenceBuilder + extends AbstractBuilder<TableReference> +{ + /** + * Adds a qualified join ({@code JOIN}) to whatever current table of builder, and overwrites the current table with + * the result. + * + * @param joinType The join type. + * @param right The table on the right side of the join. + * @param joinSpec The join specification. + * @return This builder + * @see JoinType + * @see JoinSpecification + */ + TableReferenceBuilder addQualifiedJoin( JoinType joinType, TableReference right, JoinSpecification joinSpec ); + + /** + * Adds a cross join ({@code CROSS JOIN}) to whatever current table of builder, and overwrites the current table + * with the result. + * + * @param right The table on the right side of the join. + * @return This builder. + */ + TableReferenceBuilder addCrossJoin( TableReference right ); + + /** + * Adds a natural join ({@code NATURAL JOIN}) to whatever current table of builder, and overwrites the current table + * with the result. + * + * @param joinType The join type. + * @param right The table on the right side of the join. + * @return This builder. + */ + TableReferenceBuilder addNaturalJoin( JoinType joinType, TableReference right ); + + /** + * Adds an union join ({@code UNION JOIN}) to whatever current table of builder, and overwrites the current table + * with the result. + * + * @param right The table on the right side of the join. + * @return This builder + */ + TableReferenceBuilder addUnionJoin( TableReference right ); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java new file mode 100644 index 0000000..a3d21fe --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/builders/query/package-info.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +/** + * Package to hold builders for SQL queries ({@code SELECT} -statements). + */ +package org.apache.polygene.library.sql.generator.grammar.builders.query; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java new file mode 100644 index 0000000..53b0b12 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/ColumnNameList.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +import java.util.List; +import org.apache.polygene.library.sql.generator.Typeable; + +/** + * This interface presents a non-empty list of plain-text column names. + * + * @author Stanislav Muhametsin + */ +public interface ColumnNameList extends Typeable<ColumnNameList> +{ + /** + * Returns the list of column names. This list will be always non-empty. + * + * @return The non-empty list of column names. + */ + List<String> getColumnNames(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java new file mode 100644 index 0000000..4ecc86b --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/NonBooleanExpression.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * A common interface for all expressions, which return non-boolean value. + * + * @author Stanislav Muhametsin + */ +public interface NonBooleanExpression + extends ValueExpression +{ + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java new file mode 100644 index 0000000..57f1402 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLConstants.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * A container for common textual constants of SQL language. + * + * @author Stanislav Muhametsin + */ +public interface SQLConstants +{ + String SELECT = "SELECT"; + + String FROM = "FROM"; + + String WHERE = "WHERE"; + + String GROUP_BY = "GROUP BY"; + + String HAVING = "HAVING"; + + String ORDER_BY = "ORDER BY"; + + String TABLE_COLUMN_SEPARATOR = "."; + + String SCHEMA_TABLE_SEPARATOR = "."; + + String TOKEN_SEPARATOR = " "; + + String AND = "AND"; + + String OR = "OR"; + + String NOT = "NOT"; + + String ASTERISK = "*"; + + String COMMA = ","; + + String PERIOD = "."; + + String QUESTION_MARK = "?"; + + String OPEN_PARENTHESIS = "("; + + String CLOSE_PARENTHESIS = ")"; + + String ALIAS_DEFINER = "AS"; + + String NEWLINE = "\n"; + + String NULL = "NULL"; + + String IS = "IS"; + + String CREATE = "CREATE"; + + String OFFSET_PREFIX = "OFFSET"; + + String OFFSET_POSTFIX = "ROWS"; + + String LIMIT_PREFIX = "FETCH FIRST"; + + String LIMIT_POSTFIX = "ROWS ONLY"; +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java new file mode 100644 index 0000000..06a644f --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLFunctions.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * A container for textual names of default SQL functions. + * + * @author Stanislav Muhametsin + */ +public interface SQLFunctions +{ + + String AVG = "AVG"; + + String MAX = "MAX"; + + String MIN = "MIN"; + + String SUM = "SUM"; + + String EVERY = "EVERY"; + + String ANY = "ANY"; + + String COUNT = "COUNT"; +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java new file mode 100644 index 0000000..d9120c9 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SQLStatement.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +import org.apache.polygene.library.sql.generator.grammar.modification.DeleteStatement; +import org.apache.polygene.library.sql.generator.grammar.modification.InsertStatement; +import org.apache.polygene.library.sql.generator.grammar.modification.UpdateStatement; +import org.apache.polygene.library.sql.generator.grammar.query.QueryExpression; + +/** + * A single SQL statement, which is to be sent to database. + * + * @author Stanislav Muhametsin + * @see QueryExpression + * @see DeleteStatement + * @see UpdateStatement + * @see InsertStatement + */ +public interface SQLStatement +{ + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java new file mode 100644 index 0000000..23ecde5 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaDefinitionStatement.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +import org.apache.polygene.library.sql.generator.grammar.definition.table.TableDefinition; + +/** + * This is a common interface for all definition ({@code CREATE}) clauses. + * + * @author Stanislav Muhametsin + * @see TableDefinition + */ +public interface SchemaDefinitionStatement + extends SchemaStatement +{ + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java new file mode 100644 index 0000000..d27c4c3 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaManipulationStatement.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * @author Stanislav Muhametsin + */ +public interface SchemaManipulationStatement + extends SchemaStatement +{ + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java new file mode 100644 index 0000000..10560b8 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SchemaStatement.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +import org.apache.polygene.library.sql.generator.Typeable; + +/** + * @author Stanislav Muhametsin + */ +public interface SchemaStatement + extends Typeable<SchemaStatement>, SQLStatement +{ + +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java new file mode 100644 index 0000000..524bc61 --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/SetQuantifier.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * Set quantifer, can be either {@link #ALL} or {@link #DISTINCT}. + * + * @author Stanislav Muhametsin + */ +public final class SetQuantifier +{ + + /** + * Set quantifier for {@code DISTINCT} element. + */ + public static final SetQuantifier DISTINCT = new SetQuantifier(); + + /** + * Set quantifier for {@code ALL} element. + */ + public static final SetQuantifier ALL = new SetQuantifier(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java new file mode 100644 index 0000000..8cbd2cb --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableName.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +import org.apache.polygene.library.sql.generator.Typeable; + +/** + * This is common interface for table names. Table name may be either {@link TableNameDirect} or + * {@link TableNameFunction}. + * + * @author 2011 Stanislav Muhametsin + */ +public interface TableName + extends Typeable<TableName> +{ + /** + * Gets the schema name. Returns {@code null} if this is not schema-qualified table name. + * + * @return Schema name of the schema-qualified table name, or {@code null} if this is not a schema-qualified table + * name. + */ + String getSchemaName(); +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a36086b6/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java ---------------------------------------------------------------------- diff --git a/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java new file mode 100644 index 0000000..7936c7a --- /dev/null +++ b/libraries/sql-generator/src/main/java/org/apache/polygene/library/sql/generator/grammar/common/TableNameDirect.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ +package org.apache.polygene.library.sql.generator.grammar.common; + +/** + * A direct table name may be just table name, or schema-qualified table name. + * + * @author Stanislav Muhametsin + */ +public interface TableNameDirect + extends TableName +{ + + /** + * Gets name of the table. Returns always non-{@code null}. + * + * @return The name of the table. Always non-{@code null}. + */ + String getTableName(); +}
