Search in sources :

Example 6 with BooleanFactory

use of org.sql.generation.api.grammar.factories.BooleanFactory 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();
}
Also used : ModificationFactory(org.sql.generation.api.grammar.factories.ModificationFactory) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) QueryFactory(org.sql.generation.api.grammar.factories.QueryFactory) ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) QuerySpecificationBuilder(org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 7 with BooleanFactory

use of org.sql.generation.api.grammar.factories.BooleanFactory in project qi4j-sdk by Qi4j.

the class AbstractSQLIndexing method createUpdateEntityTableStatement.

protected UpdateStatement createUpdateEntityTableStatement(String schemaName, SQLVendor vendor) {
    ModificationFactory m = vendor.getModificationFactory();
    BooleanFactory b = vendor.getBooleanFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    ColumnsFactory c = vendor.getColumnsFactory();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    // "UPDATE " + "%s" + "." + ENTITY_TABLE_NAME + "\n" + //
    // "SET " + ENTITY_TABLE_IDENTITY_COLUMN_NAME + " = ?, " + //
    // ENTITY_TABLE_MODIFIED_COLUMN_NAME + " = ?, " + //
    // ENTITY_TABLE_VERSION_COLUMN_NAME + " = ?, " + //
    // ENTITY_TABLE_APPLICATION_VERSION_COLUMN_NAME + " = ?" + "\n" + //
    // "WHERE " + ENTITY_TABLE_PK_COLUMN_NAME + " = ?" + "\n" + //
    // ";" //
    UpdateSourceByExpression paramSource = m.updateSourceByExp(l.param());
    UpdateBySearchBuilder builder = m.updateBySearch();
    builder.setTargetTable(m.createTargetTable(t.tableName(schemaName, DBNames.ENTITY_TABLE_NAME))).addSetClauses(m.setClause(DBNames.ENTITY_TABLE_IDENTITY_COLUMN_NAME, paramSource), m.setClause(DBNames.ENTITY_TABLE_MODIFIED_COLUMN_NAME, paramSource), m.setClause(DBNames.ENTITY_TABLE_VERSION_COLUMN_NAME, paramSource), m.setClause(DBNames.ENTITY_TABLE_APPLICATION_VERSION_COLUMN_NAME, paramSource)).getWhereBuilder().reset(b.eq(c.colName(DBNames.ENTITY_TABLE_PK_COLUMN_NAME), l.param()));
    return builder.createExpression();
}
Also used : UpdateSourceByExpression(org.sql.generation.api.grammar.modification.UpdateSourceByExpression) ModificationFactory(org.sql.generation.api.grammar.factories.ModificationFactory) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) UpdateBySearchBuilder(org.sql.generation.api.grammar.builders.modification.UpdateBySearchBuilder) ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 8 with BooleanFactory

use of org.sql.generation.api.grammar.factories.BooleanFactory in project qi4j-sdk by Qi4j.

the class AbstractSQLQuerying method createTypeCondition.

protected org.sql.generation.api.grammar.booleans.BooleanExpression createTypeCondition(Class<?> resultType, SQLVendor vendor) {
    BooleanFactory b = vendor.getBooleanFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    ColumnsFactory c = vendor.getColumnsFactory();
    List<Integer> typeIDs = this.getEntityTypeIDs(resultType);
    InBuilder in = b.inBuilder(c.colName(TABLE_NAME_PREFIX + TYPE_TABLE_SUFFIX, DBNames.ENTITY_TYPES_TABLE_PK_COLUMN_NAME));
    for (Integer i : typeIDs) {
        in.addValues(l.n(i));
    }
    return in.createExpression();
}
Also used : ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) InBuilder(org.sql.generation.api.grammar.builders.booleans.InBuilder) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 9 with BooleanFactory

use of org.sql.generation.api.grammar.factories.BooleanFactory in project qi4j-sdk by Qi4j.

the class AbstractSQLQuerying method traverseAssociationPath.

protected Integer traverseAssociationPath(TraversedAssoOrManyAssoRef reference, Integer lastTableIndex, Integer nextAvailableIndex, SQLVendor vendor, TableReferenceBuilder builder, JoinType joinStyle, Boolean includeLastTable) {
    Stack<QualifiedName> qNameStack = new Stack<>();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    BooleanFactory b = vendor.getBooleanFactory();
    ColumnsFactory c = vendor.getColumnsFactory();
    String schemaName = this._state.schemaName().get();
    while (reference._hasRefs) {
        qNameStack.add(QualifiedName.fromAccessor(reference.getAccessor()));
        reference = reference.getTraversedAssociation();
    }
    while (!qNameStack.isEmpty()) {
        QualifiedName qName = qNameStack.pop();
        QNameInfo info = this._state.qNameInfos().get().get(qName);
        if (info == null) {
            throw new InternalError("No qName info found for qName [" + qName + "].");
        }
        // @formatter:off
        builder.addQualifiedJoin(joinStyle, t.table(t.tableName(schemaName, info.getTableName()), t.tableAlias(TABLE_NAME_PREFIX + nextAvailableIndex)), t.jc(b.eq(c.colName(TABLE_NAME_PREFIX + lastTableIndex, DBNames.ENTITY_TABLE_PK_COLUMN_NAME), c.colName(TABLE_NAME_PREFIX + nextAvailableIndex, DBNames.ENTITY_TABLE_PK_COLUMN_NAME))));
        lastTableIndex = nextAvailableIndex;
        ++nextAvailableIndex;
        if (includeLastTable || !qNameStack.isEmpty()) {
            builder.addQualifiedJoin(joinStyle, t.table(t.tableName(schemaName, DBNames.ENTITY_TABLE_NAME), t.tableAlias(TABLE_NAME_PREFIX + nextAvailableIndex)), t.jc(b.eq(c.colName(TABLE_NAME_PREFIX + lastTableIndex, DBNames.QNAME_TABLE_VALUE_COLUMN_NAME), c.colName(TABLE_NAME_PREFIX + nextAvailableIndex, DBNames.ENTITY_TABLE_PK_COLUMN_NAME))));
            lastTableIndex = nextAvailableIndex;
            ++nextAvailableIndex;
        }
    // @formatter:on
    }
    return lastTableIndex;
}
Also used : TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) QualifiedName(org.qi4j.api.common.QualifiedName) ColumnsFactory(org.sql.generation.api.grammar.factories.ColumnsFactory) QNameInfo(org.qi4j.index.sql.support.common.QNameInfo) BooleanFactory(org.sql.generation.api.grammar.factories.BooleanFactory) Stack(java.util.Stack)

Aggregations

BooleanFactory (org.sql.generation.api.grammar.factories.BooleanFactory)9 ColumnsFactory (org.sql.generation.api.grammar.factories.ColumnsFactory)9 TableReferenceFactory (org.sql.generation.api.grammar.factories.TableReferenceFactory)8 LiteralFactory (org.sql.generation.api.grammar.factories.LiteralFactory)6 QNameInfo (org.qi4j.index.sql.support.common.QNameInfo)3 ModificationFactory (org.sql.generation.api.grammar.factories.ModificationFactory)3 QueryFactory (org.sql.generation.api.grammar.factories.QueryFactory)3 Stack (java.util.Stack)2 QualifiedName (org.qi4j.api.common.QualifiedName)2 QuerySpecificationBuilder (org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 ResultSet (java.sql.ResultSet)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Property (org.qi4j.api.property.Property)1 PropertyFunction (org.qi4j.api.query.grammar.PropertyFunction)1 Variable (org.qi4j.api.query.grammar.Variable)1 ValueComposite (org.qi4j.api.value.ValueComposite)1 BooleanBuilder (org.sql.generation.api.grammar.builders.booleans.BooleanBuilder)1 InBuilder (org.sql.generation.api.grammar.builders.booleans.InBuilder)1