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();
}
}
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;
}
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();
}
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;
}
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();
}
}
Aggregations