use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class StandardDialectResolverTest method runDialectTest.
private static void runDialectTest(String productName, int majorVersion, int minorVersion, Class<? extends Dialect> expectedDialect) {
TestingDialectResolutionInfo info = TestingDialectResolutionInfo.forDatabaseInfo(productName, majorVersion, minorVersion);
Dialect dialect = StandardDialectResolver.INSTANCE.resolveDialect(info);
StringBuilder builder = new StringBuilder(productName).append(" ").append(majorVersion);
if (minorVersion > 0) {
builder.append(".").append(minorVersion);
}
String dbms = builder.toString();
assertNotNull("Dialect for " + dbms + " should not be null", dialect);
assertTrue("Dialect for " + dbms + " should be " + expectedDialect.getSimpleName(), expectedDialect.isInstance(dialect));
}
use of org.hibernate.dialect.Dialect in project hibernate-orm by hibernate.
the class DialectFactoryTest method testDetermination.
private void testDetermination(final String databaseName, final int majorVersion, final int minorVersion, Class expected, DialectResolver resolver) {
dialectFactory.setDialectResolver(resolver);
Dialect resolved = dialectFactory.buildDialect(new Properties(), new DialectResolutionInfoSource() {
@Override
public DialectResolutionInfo getDialectResolutionInfo() {
return TestingDialectResolutionInfo.forDatabaseInfo(databaseName, majorVersion, minorVersion);
}
});
assertEquals(expected, resolved.getClass());
}
use of org.hibernate.dialect.Dialect in project uPortal by Jasig.
the class DelayedValidationQueryResolverImpl method getValidationQuery.
protected String getValidationQuery(DataSource dataSource) {
final Dialect dialect = this.resolveDialect(dataSource);
if (dialect == null) {
return null;
}
final Class<? extends Dialect> dialectType = dialect.getClass();
return resolveValidationQuery(dialectType);
}
use of org.hibernate.dialect.Dialect in project midpoint by Evolveum.
the class SqlAuditServiceImpl method cleanupAuditMaxAge.
private void cleanupAuditMaxAge(CleanupPolicyType policy, OperationResult parentResult) {
final String operation = "deletingMaxAge";
SqlPerformanceMonitor pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart("cleanupAuditMaxAge");
int attempt = 1;
if (policy.getMaxAge() == null) {
return;
}
Duration duration = policy.getMaxAge();
if (duration.getSign() > 0) {
duration = duration.negate();
}
Date minValue = new Date();
duration.addTo(minValue);
// factored out because it produces INFO-level message
Dialect dialect = Dialect.getDialect(baseHelper.getSessionFactoryBean().getHibernateProperties());
checkTemporaryTablesSupport(dialect);
long start = System.currentTimeMillis();
boolean first = true;
Holder<Integer> totalCountHolder = new Holder<>(0);
try {
while (true) {
try {
LOGGER.info("{} audit cleanup, deleting up to {} (duration '{}'), batch size {}{}.", first ? "Starting" : "Continuing with ", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
first = false;
int count;
do {
// the following method may restart due to concurrency
// (or any other) problem - in any iteration
long batchStart = System.currentTimeMillis();
LOGGER.debug("Starting audit cleanup batch, deleting up to {} (duration '{}'), batch size {}, up to now deleted {} entries.", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
count = batchDeletionAttempt((session, tempTable) -> selectRecordsByMaxAge(session, tempTable, minValue, dialect), totalCountHolder, batchStart, dialect, parentResult);
} while (count > 0);
return;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
pm.registerOperationNewTrial(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
LOGGER.info("Audit cleanup based on age finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
}
}
use of org.hibernate.dialect.Dialect in project midpoint by Evolveum.
the class SqlAuditServiceImpl method cleanupAuditMaxRecords.
private void cleanupAuditMaxRecords(CleanupPolicyType policy, OperationResult parentResult) {
final String operation = "deletingMaxRecords";
SqlPerformanceMonitor pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart("cleanupAuditMaxRecords");
int attempt = 1;
if (policy.getMaxRecords() == null) {
return;
}
Integer recordsToKeep = policy.getMaxRecords();
// factored out because it produces INFO-level message
Dialect dialect = Dialect.getDialect(baseHelper.getSessionFactoryBean().getHibernateProperties());
checkTemporaryTablesSupport(dialect);
long start = System.currentTimeMillis();
boolean first = true;
Holder<Integer> totalCountHolder = new Holder<>(0);
try {
while (true) {
try {
LOGGER.info("{} audit cleanup, keeping at most {} records, batch size {}{}.", first ? "Starting" : "Continuing with ", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
first = false;
int count;
do {
// the following method may restart due to concurrency
// (or any other) problem - in any iteration
long batchStart = System.currentTimeMillis();
LOGGER.debug("Starting audit cleanup batch, keeping at most {} records, batch size {}, up to now deleted {} entries.", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
count = batchDeletionAttempt((session, tempTable) -> selectRecordsByNumberToKeep(session, tempTable, recordsToKeep, dialect), totalCountHolder, batchStart, dialect, parentResult);
} while (count > 0);
return;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
pm.registerOperationNewTrial(opHandle, attempt);
}
}
} finally {
pm.registerOperationFinish(opHandle, attempt);
LOGGER.info("Audit cleanup based on record count finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
}
}
Aggregations