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