Search in sources :

Example 41 with SQLInsertClause

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

the class MySQLQueryFactoryTest method insertIgnore.

@Test
public void insertIgnore() {
    SQLInsertClause clause = queryFactory.insertIgnore(QSurvey.survey);
    assertEquals("insert ignore into SURVEY\nvalues ()", clause.toString());
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Test(org.junit.Test)

Example 42 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, List<AuditEventRecordPropertyType> properties) {
    if (properties.isEmpty()) {
        return;
    }
    QAuditPropertyValue qAuditPropertyValue = QAuditPropertyValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditPropertyValue);
    for (AuditEventRecordPropertyType propertySet : properties) {
        for (String value : propertySet.getValue()) {
            // id will be generated, but we're not interested in those here
            insertBatch.set(qAuditPropertyValue.recordId, recordId).set(qAuditPropertyValue.name, propertySet.getName()).set(qAuditPropertyValue.value, value).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)

Example 43 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertReferences.

private void insertReferences(JdbcSession jdbcSession, long recordId, List<AuditEventRecordReferenceType> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qAuditRefValue = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditRefValue);
    for (AuditEventRecordReferenceType refSet : references) {
        for (AuditEventRecordReferenceValueType refValue : refSet.getValue()) {
            // id will be generated, but we're not interested in those here
            PolyStringType targetName = refValue.getTargetName();
            insertBatch.set(qAuditRefValue.recordId, recordId).set(qAuditRefValue.name, refSet.getName()).set(qAuditRefValue.oid, refValue.getOid()).set(qAuditRefValue.type, RUtil.qnameToString(refValue.getType())).set(qAuditRefValue.targetNameOrig, PolyString.getOrig(targetName)).set(qAuditRefValue.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
        }
    }
    if (insertBatch.getBatchCount() == 0) {
        // strange, no values anywhere?
        return;
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause)

Example 44 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertReferences.

private void insertReferences(JdbcSession jdbcSession, long recordId, Map<String, Set<AuditReferenceValue>> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qAuditRefValue = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditRefValue);
    for (String refName : references.keySet()) {
        for (AuditReferenceValue refValue : references.get(refName)) {
            // id will be generated, but we're not interested in those here
            PolyString targetName = refValue.getTargetName();
            insertBatch.set(qAuditRefValue.recordId, recordId).set(qAuditRefValue.name, refName).set(qAuditRefValue.oid, refValue.getOid()).set(qAuditRefValue.type, RUtil.qnameToString(refValue.getType())).set(qAuditRefValue.targetNameOrig, PolyString.getOrig(targetName)).set(qAuditRefValue.targetNameNorm, PolyString.getNorm(targetName)).addBatch();
        }
    }
    if (insertBatch.getBatchCount() == 0) {
        // strange, no values anywhere?
        return;
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue)

Example 45 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertAuditDeltas.

private void insertAuditDeltas(JdbcSession jdbcSession, MAuditEventRecord auditRow, List<ObjectDeltaOperationType> deltas) {
    // we want to keep only unique deltas, checksum is also part of PK
    Map<String, MAuditDelta> deltasByChecksum = new HashMap<>();
    for (ObjectDeltaOperationType delta : deltas) {
        if (delta == null) {
            continue;
        }
        MAuditDelta mAuditDelta = convertDelta(delta, auditRow);
        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();
    }
}
Also used : MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) 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