Search in sources :

Example 1 with SybaseASEDialect

use of org.hibernate.dialect.SybaseASEDialect in project hibernate-orm by hibernate.

the class ValidityAuditStrategyRevEndTsTest method verifyRevEndTimeStamps.

private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
    for (Map<String, Object> revisionEntity : revisionEntities) {
        Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
        SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND");
        if (revendTimestamp == null) {
            Assert.assertNull(revEnd);
        } else {
            final Dialect dialect = getDialect();
            if (dialect instanceof MySQLDialect && dialect.getVersion().isBefore(5, 7) && !(dialect instanceof MariaDBDialect)) {
                // MySQL5 DATETIME column type does not contain milliseconds.
                // MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that
                // the column is defined as DATETIME(6).
                Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
            } else if (dialect instanceof SybaseASEDialect) {
                // Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity".
                Assert.assertEquals(revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0);
            } else {
                Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
            }
        }
    }
}
Also used : MySQLDialect(org.hibernate.dialect.MySQLDialect) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) MySQLDialect(org.hibernate.dialect.MySQLDialect) MariaDBDialect(org.hibernate.dialect.MariaDBDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) Dialect(org.hibernate.dialect.Dialect) Date(java.util.Date)

Example 2 with SybaseASEDialect

use of org.hibernate.dialect.SybaseASEDialect in project hibernate-orm by hibernate.

the class TransactionUtil method setJdbcTimeout.

/**
 * Set Session or Statement timeout
 * @param session Hibernate Session
 */
public static void setJdbcTimeout(Session session, long millis) {
    final Dialect dialect = session.getSessionFactory().unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect();
    session.doWork(connection -> {
        if (dialect instanceof PostgreSQLDialect) {
            try (Statement st = connection.createStatement()) {
                // Prepared Statements fail for SET commands
                st.execute(String.format("SET statement_timeout TO %d", millis / 10));
            }
        } else if (dialect instanceof MySQLDialect) {
            try (PreparedStatement st = connection.prepareStatement("SET SESSION innodb_lock_wait_timeout = ?")) {
                st.setLong(1, TimeUnit.MILLISECONDS.toSeconds(millis));
                st.execute();
            }
        } else if (dialect instanceof H2Dialect) {
            try (PreparedStatement st = connection.prepareStatement("SET LOCK_TIMEOUT ?")) {
                st.setLong(1, millis / 10);
                st.execute();
            }
        } else if (dialect instanceof SQLServerDialect) {
            try (Statement st = connection.createStatement()) {
                // Prepared Statements fail for SET commands
                st.execute(String.format("SET LOCK_TIMEOUT %d", millis / 10));
            }
        } else if (dialect instanceof AbstractHANADialect) {
            try (Statement st = connection.createStatement()) {
                // Prepared Statements fail for SET commands
                st.execute(String.format("SET TRANSACTION LOCK WAIT TIMEOUT %d", millis));
            }
        } else if (dialect instanceof SybaseASEDialect) {
            try (Statement st = connection.createStatement()) {
                // Prepared Statements fail for SET commands
                st.execute(String.format("SET LOCK WAIT %d", millis / 1000));
            }
        } else {
            try {
                connection.setNetworkTimeout(Executors.newSingleThreadExecutor(), (int) millis);
            } catch (Throwable ignore) {
            }
        }
    });
}
Also used : AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) H2Dialect(org.hibernate.dialect.H2Dialect) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) H2Dialect(org.hibernate.dialect.H2Dialect) AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) PostgreSQLDialect(org.hibernate.dialect.PostgreSQLDialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) SybaseASEDialect(org.hibernate.dialect.SybaseASEDialect) SQLServerDialect(org.hibernate.dialect.SQLServerDialect) Dialect(org.hibernate.dialect.Dialect) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Dialect (org.hibernate.dialect.Dialect)2 MySQLDialect (org.hibernate.dialect.MySQLDialect)2 SybaseASEDialect (org.hibernate.dialect.SybaseASEDialect)2 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 AbstractHANADialect (org.hibernate.dialect.AbstractHANADialect)1 H2Dialect (org.hibernate.dialect.H2Dialect)1 MariaDBDialect (org.hibernate.dialect.MariaDBDialect)1 PostgreSQLDialect (org.hibernate.dialect.PostgreSQLDialect)1 SQLServerDialect (org.hibernate.dialect.SQLServerDialect)1 SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)1