Search in sources :

Example 46 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertChangedItemPaths.

private void insertChangedItemPaths(JdbcSession jdbcSession, MAuditEventRecord auditRow) {
    if (auditRow.changedItemPaths != null && !auditRow.changedItemPaths.isEmpty()) {
        QAuditItem qAuditItem = QAuditItemMapping.get().defaultAlias();
        SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditItem);
        for (String changedItemPath : auditRow.changedItemPaths) {
            insertBatch.set(qAuditItem.recordId, auditRow.id).set(qAuditItem.changedItemPath, changedItemPath).addBatch();
        }
        insertBatch.setBatchToBulk(true);
        insertBatch.execute();
    }
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 47 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertAuditEventRecord.

/**
 * Inserts audit event record aggregate root without any subentities.
 *
 * @return ID of created audit event record
 */
private MAuditEventRecord insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecordType record) {
    QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
    QAuditEventRecord aer = aerMapping.defaultAlias();
    MAuditEventRecord row = aerMapping.toRowObject(record);
    SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
    Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
    for (AuditEventRecordCustomColumnPropertyType property : record.getCustomColumnProperty()) {
        String propertyName = property.getName();
        if (!customColumns.containsKey(propertyName)) {
            throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + propertyName);
        }
        // Like insert.set, but that one is too parameter-type-safe for our generic usage here.
        insert.columns(aer.getPath(propertyName)).values(property.getValue());
    }
    Long returnedId = insert.executeWithKey(aer.id);
    // If returned ID is null, it was provided. If not, it fails, something went bad.
    row.id = returnedId != null ? returnedId : record.getRepoId();
    return row;
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 48 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertAuditEventRecord.

/**
 * Inserts audit event record aggregate root without any subentities.
 *
 * @return ID of created audit event record
 */
private Long insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecord record) {
    QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
    QAuditEventRecord aer = aerMapping.defaultAlias();
    MAuditEventRecord aerBean = aerMapping.toRowObject(record);
    SQLInsertClause insert = jdbcSession.newInsert(aer).populate(aerBean);
    Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
    for (Entry<String, String> property : record.getCustomColumnProperty().entrySet()) {
        String propertyName = property.getKey();
        if (!customColumns.containsKey(propertyName)) {
            throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + propertyName);
        }
        // Like insert.set, but that one is too parameter-type-safe for our generic usage here.
        insert.columns(aer.getPath(propertyName)).values(property.getValue());
    }
    Long returnedId = insert.executeWithKey(aer.id);
    // If returned ID is null, it was provided. If not, it fails, something went bad.
    return returnedId != null ? returnedId : record.getRepoId();
}
Also used : ColumnMetadata(com.querydsl.sql.ColumnMetadata) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 49 with SQLInsertClause

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

the class SqaleAuditService method insertAuditEventRecord.

/**
 * Inserts audit event record aggregate root without any subentities.
 * Traditional Sqale "insert root first, then insert children" is not optimal here,
 * because to insert root we need to collect some information from children anyway.
 * So we prepare the subentities in collections, gather the needed information
 * (e.g. changed item paths) and then insert root entity.
 * Subentities are inserted later out of this method.
 *
 * @return inserted row with transient deltas prepared for insertion
 */
private MAuditEventRecord insertAuditEventRecord(JdbcSession jdbcSession, AuditEventRecord record) {
    QAuditEventRecordMapping aerMapping = QAuditEventRecordMapping.get();
    QAuditEventRecord aer = aerMapping.defaultAlias();
    MAuditEventRecord row = aerMapping.toRowObject(record);
    Collection<MAuditDelta> deltaRows = prepareDeltas(record.getDeltas());
    row.deltas = deltaRows;
    Set<String> changedItemPaths = collectChangedItemPaths(deltaRows);
    row.changedItemPaths = changedItemPaths.isEmpty() ? null : changedItemPaths.toArray(String[]::new);
    SQLInsertClause insert = jdbcSession.newInsert(aer).populate(row);
    Map<String, ColumnMetadata> customColumns = aerMapping.getExtensionColumns();
    for (Map.Entry<String, String> property : record.getCustomColumnProperty().entrySet()) {
        String propertyName = property.getKey();
        if (!customColumns.containsKey(propertyName)) {
            throw new IllegalArgumentException("Audit event record table doesn't" + " contains column for property " + propertyName);
        }
        // Like insert.set, but that one is too parameter-type-safe for our generic usage here.
        insert.columns(aer.getPath(propertyName)).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 : ColumnMetadata(com.querydsl.sql.ColumnMetadata) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause)

Example 50 with SQLInsertClause

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

the class SqaleAuditService method insertAuditDeltas.

private void insertAuditDeltas(JdbcSession jdbcSession, MAuditEventRecord auditRow) {
    if (!auditRow.deltas.isEmpty()) {
        SQLInsertClause insertBatch = jdbcSession.newInsert(QAuditDeltaMapping.get().defaultAlias());
        for (MAuditDelta deltaRow : auditRow.deltas) {
            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