Search in sources :

Example 21 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertResourceOids.

private void insertResourceOids(JdbcSession jdbcSession, long recordId, Collection<String> resourceOids) {
    if (resourceOids.isEmpty()) {
        return;
    }
    QAuditResource qAuditResource = QAuditResourceMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditResource);
    for (String resourceOid : resourceOids) {
        insertBatch.set(qAuditResource.recordId, recordId).set(qAuditResource.resourceOid, resourceOid).addBatch();
    }
    insertBatch.setBatchToBulk(true);
    insertBatch.execute();
}
Also used : SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 22 with SQLInsertClause

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

the class SqlAuditServiceImpl method insertChangedItemPaths.

private void insertChangedItemPaths(JdbcSession jdbcSession, long recordId, Collection<MAuditDelta> deltas) {
    Set<String> changedItemPaths = new HashSet<>();
    for (MAuditDelta delta : deltas) {
        try {
            ObjectDeltaType deltaBean = schemaService.parserFor(delta.serializedDelta).parseRealValue(ObjectDeltaType.class);
            for (ItemDeltaType itemDelta : deltaBean.getItemDelta()) {
                ItemPath path = itemDelta.getPath().getItemPath();
                CanonicalItemPath canonical = schemaService.createCanonicalItemPath(path, deltaBean.getObjectType());
                for (int i = 0; i < canonical.size(); i++) {
                    changedItemPaths.add(canonical.allUpToIncluding(i).asString());
                }
            }
        } catch (SchemaException | SystemException e) {
            // See MID-6446 - we want to throw in tests, old ones should be fixed by now
            if (InternalsConfig.isConsistencyChecks()) {
                throw new SystemException("Problem during audit delta parse", e);
            }
            LOGGER.warn("Serialized audit delta for recordId={} cannot be parsed." + " No changed items were created. This may cause problem later, but is not" + " critical for storing the audit record.", recordId, e);
        }
    }
    if (!changedItemPaths.isEmpty()) {
        QAuditItem qAuditItem = QAuditItemMapping.get().defaultAlias();
        SQLInsertClause insertBatch = jdbcSession.newInsert(qAuditItem);
        for (String changedItemPath : changedItemPaths) {
            insertBatch.set(qAuditItem.recordId, recordId).set(qAuditItem.changedItemPath, changedItemPath).addBatch();
        }
        insertBatch.setBatchToBulk(true);
        insertBatch.execute();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SystemException(com.evolveum.midpoint.util.exception.SystemException) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with SQLInsertClause

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

the class SqaleAuditService method insertReferences.

private void insertReferences(JdbcSession jdbcSession, MAuditEventRecord auditRow, Map<String, Set<AuditReferenceValue>> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qr = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qr);
    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(qr.recordId, auditRow.id).set(qr.timestamp, auditRow.timestamp).set(qr.name, refName).set(qr.targetOid, SqaleUtils.oidToUUid(refValue.getOid())).set(qr.targetType, refValue.getType() != null ? MObjectType.fromTypeQName(refValue.getType()) : null).set(qr.targetNameOrig, PolyString.getOrig(targetName)).set(qr.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 24 with SQLInsertClause

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

the class AuditInsertion method insertReferences.

private void insertReferences(MAuditEventRecord auditRow, List<AuditEventRecordReferenceType> references) {
    if (references.isEmpty()) {
        return;
    }
    QAuditRefValue qr = QAuditRefValueMapping.get().defaultAlias();
    SQLInsertClause insertBatch = jdbcSession.newInsert(qr);
    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(qr.recordId, auditRow.id).set(qr.timestamp, auditRow.timestamp).set(qr.name, refSet.getName()).set(qr.targetOid, SqaleUtils.oidToUUid(refValue.getOid())).set(qr.targetType, refValue.getType() != null ? MObjectType.fromTypeQName(refValue.getType()) : null).set(qr.targetNameOrig, PolyString.getOrig(targetName)).set(qr.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) AuditEventRecordReferenceType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceType) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) AuditEventRecordReferenceValueType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordReferenceValueType)

Example 25 with SQLInsertClause

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

the class TweetRepository method save.

@Transactional
public Long save(Tweet tweet, Long... mentions) {
    Long tweetId = save(tweet);
    SQLInsertClause insert = insert(tweetUser);
    for (Long mentionsId : mentions) {
        TweetUser tu = new TweetUser();
        tu.setTweetId(tweetId);
        tu.setMentionsId(mentionsId);
        insert.populate(tu).addBatch();
    }
    insert.execute();
    return tweetId;
}
Also used : TweetUser(com.querydsl.example.sql.model.TweetUser) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) Transactional(com.querydsl.example.sql.guice.Transactional)

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