use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleAuditService method executeCleanupAuditMaxRecords.
private void executeCleanupAuditMaxRecords(int maxRecords) {
long opHandle = registerOperationStart(OP_CLEANUP_AUDIT_MAX_RECORDS);
long start = System.currentTimeMillis();
long deletedCount = 0;
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
logger.info("Audit cleanup, deleting to leave only {} records.", maxRecords);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
Long deleteFromId = jdbcSession.newQuery().select(qae.id).from(qae).orderBy(qae.id.desc()).offset(maxRecords).fetchFirst();
if (deleteFromId == null) {
logger.info("Nothing to delete from audit, {} entries allowed.", maxRecords);
return;
}
deletedCount = jdbcSession.newDelete(qae).where(qae.id.loe(deleteFromId)).execute();
jdbcSession.commit();
} finally {
registerOperationFinish(opHandle);
logger.info("Audit cleanup based on record count finished; deleted {} entries in {} seconds.", deletedCount, (System.currentTimeMillis() - start) / 1000L);
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleAuditService method executeCleanupAuditMaxAge.
private void executeCleanupAuditMaxAge(Duration maxAge) {
long opHandle = registerOperationStart(OP_CLEANUP_AUDIT_MAX_AGE);
if (maxAge.getSign() > 0) {
maxAge = maxAge.negate();
}
// This is silly, it mutates the Date, but there seems to be no other way to do it!
Date minValue = new Date();
maxAge.addTo(minValue);
Instant olderThan = Instant.ofEpochMilli(minValue.getTime());
long start = System.currentTimeMillis();
long deletedCount = 0;
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
logger.info("Audit cleanup, deleting records older than {}.", olderThan);
QAuditEventRecord qae = QAuditEventRecordMapping.get().defaultAlias();
deletedCount = jdbcSession.newDelete(qae).where(qae.timestamp.lt(olderThan)).execute();
jdbcSession.commit();
} finally {
registerOperationFinish(opHandle);
logger.info("Audit cleanup based on age finished; deleted {} entries in {} seconds.", deletedCount, (System.currentTimeMillis() - start) / 1000L);
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleAuditService method executeAudit.
private void executeAudit(AuditEventRecord record) {
long opHandle = registerOperationStart(OP_AUDIT);
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
// we want DB to assign the ID
record.setRepoId(null);
MAuditEventRecord auditRow = insertAuditEventRecord(jdbcSession, record);
record.setRepoId(auditRow.id);
insertAuditDeltas(jdbcSession, auditRow);
insertReferences(jdbcSession, auditRow, record.getReferences());
jdbcSession.commit();
} finally {
registerOperationFinish(opHandle);
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class SqaleAuditService method executeAudit.
private void executeAudit(AuditEventRecordType record) {
long opHandle = registerOperationStart(OP_AUDIT);
try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
// plenty of parameters, but it's better to have a short-lived stateful worker for it
new AuditInsertion(record, jdbcSession, sqlRepoContext, escapeIllegalCharacters, logger).execute();
jdbcSession.commit();
} finally {
registerOperationFinish(opHandle);
}
}
use of com.evolveum.midpoint.repo.sqlbase.JdbcSession in project midpoint by Evolveum.
the class CleanupTest method cleanup.
@AfterMethod
public void cleanup() {
try (JdbcSession jdbcSession = createJdbcSession().startTransaction()) {
jdbcSession.newDelete(QAuditDeltaMapping.get().defaultAlias()).execute();
jdbcSession.newDelete(QAuditItemMapping.get().defaultAlias()).execute();
jdbcSession.newDelete(QAuditPropertyValueMapping.get().defaultAlias()).execute();
jdbcSession.newDelete(QAuditResourceMapping.get().defaultAlias()).execute();
jdbcSession.newDelete(QAuditRefValueMapping.get().defaultAlias()).execute();
jdbcSession.newDelete(QAuditEventRecordMapping.get().defaultAlias()).execute();
jdbcSession.commit();
}
}
Aggregations