Search in sources :

Example 6 with LiteralFactory

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

the class AbstractSQLIndexing method createInsertStatement.

protected InsertStatement createInsertStatement(String schemaName, String tableName, Integer amountOfColumns, SQLVendor vendor) {
    ModificationFactory m = vendor.getModificationFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    ColumnSourceByValuesBuilder columnBuilder = m.columnSourceByValues();
    for (Integer x = 0; x < amountOfColumns; ++x) {
        columnBuilder.addValues(l.param());
    }
    return m.insert().setTableName(t.tableName(schemaName, tableName)).setColumnSource(columnBuilder.createExpression()).createExpression();
}
Also used : ModificationFactory(org.sql.generation.api.grammar.factories.ModificationFactory) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) ColumnSourceByValuesBuilder(org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 7 with LiteralFactory

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

the class AbstractSQLIndexing method createPropertyInsert.

protected InsertStatement createPropertyInsert(QNameInfo qNameInfo, SQLVendor vendor) {
    String tableName = qNameInfo.getTableName();
    ModificationFactory m = vendor.getModificationFactory();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    ColumnSourceByValuesBuilder columnBuilder = m.columnSourceByValues().addValues(l.param(), l.param(), l.param());
    if (qNameInfo.getCollectionDepth() > 0) {
        columnBuilder.addValues(l.func("text2ltree", l.param()));
    }
    columnBuilder.addValues(l.param());
    return m.insert().setTableName(t.tableName(this._state.schemaName().get(), tableName)).setColumnSource(columnBuilder.createExpression()).createExpression();
}
Also used : ModificationFactory(org.sql.generation.api.grammar.factories.ModificationFactory) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) ColumnSourceByValuesBuilder(org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Example 8 with LiteralFactory

use of org.sql.generation.api.grammar.factories.LiteralFactory 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 9 with LiteralFactory

use of org.sql.generation.api.grammar.factories.LiteralFactory 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 10 with LiteralFactory

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

the class AbstractSQLStartup method createInsertStatementForQNameInfo.

private InsertStatement createInsertStatementForQNameInfo(Connection connection, String schemaName, SQLVendor vendor) {
    ModificationFactory m = vendor.getModificationFactory();
    TableReferenceFactory t = vendor.getTableReferenceFactory();
    LiteralFactory l = vendor.getLiteralFactory();
    return m.insert().setTableName(t.tableName(schemaName, USED_QNAMES_TABLE_NAME)).setColumnSource(m.columnSourceByValues().addValues(l.param(), l.param()).createExpression()).createExpression();
}
Also used : ModificationFactory(org.sql.generation.api.grammar.factories.ModificationFactory) TableReferenceFactory(org.sql.generation.api.grammar.factories.TableReferenceFactory) LiteralFactory(org.sql.generation.api.grammar.factories.LiteralFactory)

Aggregations

LiteralFactory (org.sql.generation.api.grammar.factories.LiteralFactory)12 TableReferenceFactory (org.sql.generation.api.grammar.factories.TableReferenceFactory)11 ColumnsFactory (org.sql.generation.api.grammar.factories.ColumnsFactory)8 ModificationFactory (org.sql.generation.api.grammar.factories.ModificationFactory)8 BooleanFactory (org.sql.generation.api.grammar.factories.BooleanFactory)6 QueryFactory (org.sql.generation.api.grammar.factories.QueryFactory)4 ColumnSourceByValuesBuilder (org.sql.generation.api.grammar.builders.modification.ColumnSourceByValuesBuilder)3 QuerySpecificationBuilder (org.sql.generation.api.grammar.builders.query.QuerySpecificationBuilder)3 QNameInfo (org.qi4j.index.sql.support.common.QNameInfo)2 SQLVendor (org.sql.generation.api.vendor.SQLVendor)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 BigInteger (java.math.BigInteger)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 EntityDescriptor (org.qi4j.api.entity.EntityDescriptor)1 Property (org.qi4j.api.property.Property)1