Search in sources :

Example 21 with Dialect

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));
}
Also used : TestingDialectResolutionInfo(org.hibernate.dialect.resolver.TestingDialectResolutionInfo) SQLServer2012Dialect(org.hibernate.dialect.SQLServer2012Dialect) SQLServer2005Dialect(org.hibernate.dialect.SQLServer2005Dialect) SQLServer2008Dialect(org.hibernate.dialect.SQLServer2008Dialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) PostgreSQL9Dialect(org.hibernate.dialect.PostgreSQL9Dialect) Dialect(org.hibernate.dialect.Dialect) PostgreSQL82Dialect(org.hibernate.dialect.PostgreSQL82Dialect)

Example 22 with 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());
}
Also used : DialectResolutionInfoSource(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource) SybaseAnywhereDialect(org.hibernate.dialect.SybaseAnywhereDialect) DerbyTenSevenDialect(org.hibernate.dialect.DerbyTenSevenDialect) H2Dialect(org.hibernate.dialect.H2Dialect) IngresDialect(org.hibernate.dialect.IngresDialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) Oracle8iDialect(org.hibernate.dialect.Oracle8iDialect) InformixDialect(org.hibernate.dialect.InformixDialect) DB2Dialect(org.hibernate.dialect.DB2Dialect) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) PostgreSQL9Dialect(org.hibernate.dialect.PostgreSQL9Dialect) PostgreSQL82Dialect(org.hibernate.dialect.PostgreSQL82Dialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) Oracle10gDialect(org.hibernate.dialect.Oracle10gDialect) Oracle9iDialect(org.hibernate.dialect.Oracle9iDialect) DerbyDialect(org.hibernate.dialect.DerbyDialect) HSQLDialect(org.hibernate.dialect.HSQLDialect) DerbyTenFiveDialect(org.hibernate.dialect.DerbyTenFiveDialect) PostgresPlusDialect(org.hibernate.dialect.PostgresPlusDialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) DB2400Dialect(org.hibernate.dialect.DB2400Dialect) Dialect(org.hibernate.dialect.Dialect) MySQL5Dialect(org.hibernate.dialect.MySQL5Dialect) DerbyTenSixDialect(org.hibernate.dialect.DerbyTenSixDialect) Properties(java.util.Properties) DialectResolutionInfo(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)

Example 23 with Dialect

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);
}
Also used : Dialect(org.hibernate.dialect.Dialect)

Example 24 with Dialect

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);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) BiFunction(java.util.function.BiFunction) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) GetObjectResult(com.evolveum.midpoint.repo.sql.util.GetObjectResult) Map(java.util.Map) Query(org.hibernate.Query) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) AuditService(com.evolveum.midpoint.audit.api.AuditService) Holder(com.evolveum.midpoint.util.Holder) ScrollableResults(org.hibernate.ScrollableResults) Timestamp(java.sql.Timestamp) Set(java.util.Set) FlushMode(org.hibernate.FlushMode) MiscUtil(com.evolveum.midpoint.util.MiscUtil) RowSelection(org.hibernate.engine.spi.RowSelection) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Projections(org.hibernate.criterion.Projections) Task(com.evolveum.midpoint.task.api.Task) LimitHandler(org.hibernate.dialect.pagination.LimitHandler) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) com.evolveum.midpoint.repo.sql.data.audit(com.evolveum.midpoint.repo.sql.data.audit) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) Dialect(org.hibernate.dialect.Dialect) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) Statement(java.sql.Statement) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Types(java.sql.Types) Holder(com.evolveum.midpoint.util.Holder) Duration(javax.xml.datatype.Duration) Date(java.util.Date) Dialect(org.hibernate.dialect.Dialect)

Example 25 with Dialect

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);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) BiFunction(java.util.function.BiFunction) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) GetObjectResult(com.evolveum.midpoint.repo.sql.util.GetObjectResult) Map(java.util.Map) Query(org.hibernate.Query) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) AuditService(com.evolveum.midpoint.audit.api.AuditService) Holder(com.evolveum.midpoint.util.Holder) ScrollableResults(org.hibernate.ScrollableResults) Timestamp(java.sql.Timestamp) Set(java.util.Set) FlushMode(org.hibernate.FlushMode) MiscUtil(com.evolveum.midpoint.util.MiscUtil) RowSelection(org.hibernate.engine.spi.RowSelection) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Projections(org.hibernate.criterion.Projections) Task(com.evolveum.midpoint.task.api.Task) LimitHandler(org.hibernate.dialect.pagination.LimitHandler) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) com.evolveum.midpoint.repo.sql.data.audit(com.evolveum.midpoint.repo.sql.data.audit) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) Dialect(org.hibernate.dialect.Dialect) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) Statement(java.sql.Statement) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Types(java.sql.Types) Holder(com.evolveum.midpoint.util.Holder) Dialect(org.hibernate.dialect.Dialect)

Aggregations

Dialect (org.hibernate.dialect.Dialect)45 HibernateException (org.hibernate.HibernateException)9 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)7 PostgreSQL81Dialect (org.hibernate.dialect.PostgreSQL81Dialect)4 RowSelection (org.hibernate.engine.spi.RowSelection)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 H2Dialect (org.hibernate.dialect.H2Dialect)3 DialectResolutionInfo (org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo)3 Column (org.hibernate.mapping.Column)3 SpatialDialect (org.hibernate.spatial.SpatialDialect)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)2 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2