use of org.sql.generation.api.grammar.factories.QueryFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLIndexing method createAssoInsert.
protected InsertStatement createAssoInsert(QNameInfo qNameInfo, SQLVendor vendor, Integer amountOfParams) {
ModificationFactory m = vendor.getModificationFactory();
LiteralFactory l = vendor.getLiteralFactory();
ColumnsFactory c = vendor.getColumnsFactory();
QueryFactory q = vendor.getQueryFactory();
TableReferenceFactory t = vendor.getTableReferenceFactory();
BooleanFactory b = vendor.getBooleanFactory();
String schemaName = this._state.schemaName().get();
// "INSERT INTO " + "%s" + "." + "%s" + "\n" + //
// "SELECT " + "?, " + "?, " + ENTITY_TABLE_PK_COLUMN_NAME + "\n" + // <-- here is 4 params
// when many-asso
// "FROM " + "%s" + "." + ENTITY_TABLE_NAME + "\n" + //
// "WHERE " + ENTITY_TABLE_IDENTITY_COLUMN_NAME + " = " + "?";
QuerySpecificationBuilder qBuilder = q.querySpecificationBuilder();
for (Integer x = 0; x < amountOfParams; ++x) {
qBuilder.getSelect().addUnnamedColumns(c.colExp(l.param()));
}
qBuilder.getSelect().addUnnamedColumns(c.colName(DBNames.ENTITY_TABLE_PK_COLUMN_NAME));
qBuilder.getFrom().addTableReferences(t.tableBuilder(t.table(t.tableName(schemaName, DBNames.ENTITY_TABLE_NAME))));
qBuilder.getWhere().reset(b.eq(c.colName(DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME), l.param()));
return m.insert().setTableName(t.tableName(schemaName, qNameInfo.getTableName())).setColumnSource(m.columnSourceByQuery(q.createQuery(qBuilder.createExpression()))).createExpression();
}
use of org.sql.generation.api.grammar.factories.QueryFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLStartup method getNextPK.
protected Long getNextPK(Statement stmt, String schemaName, String columnName, String tableName, Long defaultPK) throws SQLException {
ResultSet rs = null;
Long result = defaultPK;
try {
SQLVendor vendor = this._vendor;
QueryFactory q = vendor.getQueryFactory();
// Let's cheat a bit on SQL functions, so we won't need to use heavy query builder.
// Also, currently there are no arithmetic statements
rs = stmt.executeQuery(vendor.toString(q.simpleQueryBuilder().select("COUNT(" + columnName + ")", "MAX(" + columnName + ") + 1").from(vendor.getTableReferenceFactory().tableName(schemaName, tableName)).createExpression()));
if (rs.next()) {
Long count = rs.getLong(1);
if (count > 0) {
result = rs.getLong(2);
}
}
} finally {
SQLUtil.closeQuietly(rs);
}
return result;
}
use of org.sql.generation.api.grammar.factories.QueryFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method processBooleanExpression.
protected QueryBuilder processBooleanExpression(Specification<Composite> expression, Boolean negationActive, SQLVendor vendor, org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, Map<String, Object> variables, List<Object> values, List<Integer> valueSQLTypes) {
QueryBuilder result = null;
if (expression == null) {
QueryFactory q = vendor.getQueryFactory();
result = q.queryBuilder(this.selectAllEntitiesOfCorrectType(vendor, entityTypeCondition).createExpression());
} else {
if (EXPRESSION_PROCESSORS.containsKey(expression.getClass())) {
result = EXPRESSION_PROCESSORS.get(expression.getClass()).processBooleanExpression(this, expression, negationActive, vendor, entityTypeCondition, variables, values, valueSQLTypes);
} else {
throw new UnsupportedOperationException("Expression " + expression + " of type " + expression.getClass() + " is not supported");
}
}
return result;
}
use of org.sql.generation.api.grammar.factories.QueryFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method finalizeContainsQuery.
protected QueryBuilder finalizeContainsQuery(SQLVendor vendor, QuerySpecification contains, org.sql.generation.api.grammar.booleans.BooleanExpression entityTypeCondition, Boolean negationActive) {
QueryFactory q = vendor.getQueryFactory();
QueryBuilder result;
if (negationActive) {
result = q.queryBuilder(this.selectAllEntitiesOfCorrectType(vendor, entityTypeCondition).createExpression()).except(contains);
} else {
result = q.queryBuilder(contains);
}
return result;
}
use of org.sql.generation.api.grammar.factories.QueryFactory in project qi4j-sdk by Qi4j.
the class AbstractSQLQuerying method getBuilderForPredicate.
protected QuerySpecificationBuilder getBuilderForPredicate(SQLVendor vendor, String tableAlias) {
QueryFactory q = vendor.getQueryFactory();
ColumnsFactory c = vendor.getColumnsFactory();
QuerySpecificationBuilder result = q.querySpecificationBuilder();
result.getSelect().setSetQuantifier(SetQuantifier.DISTINCT).addUnnamedColumns(c.colName(tableAlias, DBNames.ENTITY_TABLE_PK_COLUMN_NAME), c.colName(tableAlias, DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME));
return result;
}
Aggregations