Search in sources :

Example 16 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_batch.

@Test
public void insert_batch() {
    SQLInsertClause insert = insert(survey).set(survey.id, 5).set(survey.name, "55").addBatch();
    assertEquals(1, insert.getBatchCount());
    insert.set(survey.id, 6).set(survey.name, "66").addBatch();
    assertEquals(2, insert.getBatchCount());
    assertEquals(2, insert.execute());
    assertEquals(1L, query().from(survey).where(survey.name.eq("55")).fetchCount());
    assertEquals(1L, query().from(survey).where(survey.name.eq("66")).fetchCount());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 17 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class InsertBase method insert_with_keys_OverriddenColumn.

@Test(expected = QueryException.class)
@IncludeIn({ DERBY, HSQLDB })
public void insert_with_keys_OverriddenColumn() throws SQLException {
    String originalColumnName = ColumnMetadata.getName(survey.id);
    try {
        configuration.registerColumnOverride(survey.getSchemaName(), survey.getTableName(), originalColumnName, "wrongColumnName");
        SQLInsertClause sqlInsertClause = new SQLInsertClause(connection, configuration, survey);
        sqlInsertClause.addListener(new TestLoggingListener());
        Object id = sqlInsertClause.set(survey.name, "Hello you").executeWithKey(survey.id);
        assertNotNull(id);
    } finally {
        configuration.registerColumnOverride(survey.getSchemaName(), survey.getTableName(), originalColumnName, originalColumnName);
    }
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test) IncludeIn(com.querydsl.core.testutil.IncludeIn)

Example 18 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project querydsl by querydsl.

the class AbstractBaseTest method insert.

protected SQLInsertClause insert(RelationalPath<?> e) {
    SQLInsertClause sqlInsertClause = new SQLInsertClause(connection, configuration, e);
    sqlInsertClause.addListener(new TestLoggingListener());
    return sqlInsertClause;
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause)

Example 19 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project midpoint by Evolveum.

the class SqlAuditServiceImpl method insertAuditDeltas.

private Collection<MAuditDelta> insertAuditDeltas(JdbcSession jdbcSession, long recordId, Collection<ObjectDeltaOperation<?>> deltas) {
    // we want to keep only unique deltas, checksum is also part of PK
    Map<String, MAuditDelta> deltasByChecksum = new HashMap<>();
    for (ObjectDeltaOperation<?> deltaOperation : deltas) {
        if (deltaOperation == null) {
            continue;
        }
        MAuditDelta mAuditDelta = convertDelta(deltaOperation, recordId);
        deltasByChecksum.put(mAuditDelta.checksum, mAuditDelta);
    }
    if (!deltasByChecksum.isEmpty()) {
        SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
        for (MAuditDelta value : deltasByChecksum.values()) {
            // NULLs are important to keep the value count consistent during the batch
            insertBatch.populate(value, DefaultMapper.WITH_NULL_BINDINGS).addBatch();
        }
        insertBatch.setBatchToBulk(true);
        insertBatch.execute();
    }
    return deltasByChecksum.values();
}
Also used : MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 20 with SQLInsertClause

use of com.querydsl.sql.dml.SQLInsertClause in project midpoint by Evolveum.

the class SqlAuditServiceImpl method insertProperties.

private void insertProperties(JdbcSession jdbcSession, long recordId, Map<String, Set<String>> properties) {
    if (properties.isEmpty()) {
        return;
    }
    QAuditPropertyValue qAuditPropertyValue = QAuditPropertyValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditPropertyValue);
    for (String propertyName : properties.keySet()) {
        for (String propertyValue : properties.get(propertyName)) {
            // id will be generated, but we're not interested in those here
            insertBatch.set(qAuditPropertyValue.recordId, recordId).set(qAuditPropertyValue.name, propertyName).set(qAuditPropertyValue.value, propertyValue).addBatch();
        }
    }
    if (insertBatch.getBatchCount() == 0) {
        // strange, no values anywhere?
        return;
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

SQLInsertClause (com.querydsl.sql.dml.SQLInsertClause)52 Test (org.junit.Test)25 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)13 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)6 ColumnMetadata (com.querydsl.sql.ColumnMetadata)4 MAuditDelta (com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta)3 IncludeIn (com.querydsl.core.testutil.IncludeIn)3 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 MAuditEventRecord (com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord)2 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)2 H2Templates (com.querydsl.sql.H2Templates)2 QGeneratedKeysEntity (com.querydsl.sql.QGeneratedKeysEntity)2 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 AuditEventRecordCustomColumnPropertyType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType)1 AuditEventRecordReferenceType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType)1 AuditEventRecordReferenceValueType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceValueType)1 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)1