Search in sources :

Example 51 with SQLInsertClause

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

the class AuditInsertion method insertAuditEventRecord.

private MAuditEventRecord insertAuditEventRecord(MAuditEventRecord row) {
    QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
    QAuditEventRecord aer = aerMapping.defaultAlias();
    SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
    // Custom columns, this better be replaced by some extension container later
    Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
    for (AuditEventRecordCustomColumnPropertyType property : record.getCustomColumnProperty()) {
        if (!customColumns.containsKey(property.getName())) {
            throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + property.getName());
        }
        // Like insert.set, but that one is too parameter-type-safe for our generic usage here.
        insert.columns(aer.getPath(property.getName())).values(property.getValue());
    }
    Long returnedId = insert.executeWithKey(aer.id);
    // If returned ID is null, it was likely provided, so we use that one.
    row.id = returnedId != null ? returnedId : record.getRepoId();
    return row;
}
Also used : AuditEventRecordCustomColumnPropertyType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordCustomColumnPropertyType) ColumnMetadata(com.querydsl.sql.ColumnMetadata) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 52 with SQLInsertClause

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

the class AuditInsertion method insertAuditDeltas.

private void insertAuditDeltas(MAuditEventRecord auditRow, Collection<MAuditDelta> deltaRows) {
    if (deltaRows != null && !deltaRows.isEmpty()) {
        SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
        for (MAuditDelta deltaRow : deltaRows) {
            deltaRow.recordId = auditRow.id;
            deltaRow.timestamp = auditRow.timestamp;
            // NULLs are important to keep the value count consistent during the batch
            insertBatch.populate(deltaRow, DefaultMapper.WITH_NULL_BINDINGS).addBatch();
        }
        insertBatch.setBatchToBulk(true);
        insertBatch.execute();
    }
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause)

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