use of java.sql.SQLException in project hibernate-orm by hibernate.
the class JdbcTimestampCustomSessionLevelTimeZoneTest method testTimeZone.
@Test
public void testTimeZone() {
connectionProvider.clear();
doInHibernateSessionBuilder(() -> {
return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
}, s -> {
Person person = new Person();
person.id = 1L;
s.persist(person);
});
assertEquals(1, connectionProvider.getPreparedStatements().size());
PreparedStatement ps = connectionProvider.getPreparedStatements().get(0);
try {
ArgumentCaptor<Calendar> calendarArgumentCaptor = ArgumentCaptor.forClass(Calendar.class);
verify(ps, times(1)).setTimestamp(anyInt(), any(Timestamp.class), calendarArgumentCaptor.capture());
assertEquals(TIME_ZONE, calendarArgumentCaptor.getValue().getTimeZone());
} catch (SQLException e) {
fail(e.getMessage());
}
connectionProvider.clear();
doInHibernateSessionBuilder(() -> {
return sessionFactory().withOptions().jdbcTimeZone(TIME_ZONE);
}, s -> {
s.doWork(connection -> {
try (Statement st = connection.createStatement()) {
try (ResultSet rs = st.executeQuery("select createdOn from Person")) {
while (rs.next()) {
Timestamp timestamp = rs.getTimestamp(1);
int offsetDiff = TimeZone.getDefault().getOffset(0) - TIME_ZONE.getOffset(0);
assertEquals(Math.abs(Long.valueOf(offsetDiff).longValue()), Math.abs(timestamp.getTime()));
}
}
}
});
Person person = s.find(Person.class, 1L);
assertEquals(0, person.createdOn.getTime());
});
}
use of java.sql.SQLException in project hibernate-orm by hibernate.
the class XaTransactionImpl method commit.
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
if (status == Status.STATUS_MARKED_ROLLBACK) {
log.trace("on commit, status was marked for rollback-only");
rollback();
} else {
status = Status.STATUS_PREPARING;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.beforeCompletion();
}
}
if (!runXaResourcePrepare()) {
status = Status.STATUS_ROLLING_BACK;
} else {
status = Status.STATUS_PREPARED;
}
status = Status.STATUS_COMMITTING;
if (connection != null) {
try {
connection.commit();
connectionProvider.closeConnection(connection);
connection = null;
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
runXaResourceCommitTx();
status = Status.STATUS_COMMITTED;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
}
use of java.sql.SQLException in project hibernate-orm by hibernate.
the class DualNodeJtaTransactionImpl method commit.
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
if (status == Status.STATUS_MARKED_ROLLBACK) {
log.trace("on commit, status was marked for rollback-only");
rollback();
} else {
status = Status.STATUS_PREPARING;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.beforeCompletion();
}
}
if (!runXaResourcePrepare()) {
status = Status.STATUS_ROLLING_BACK;
} else {
status = Status.STATUS_PREPARED;
}
status = Status.STATUS_COMMITTING;
if (connection != null) {
try {
connection.commit();
connection.close();
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
runXaResourceCommitTx();
status = Status.STATUS_COMMITTED;
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
}
use of java.sql.SQLException in project hibernate-orm by hibernate.
the class DualNodeJtaTransactionImpl method rollback.
public void rollback() throws IllegalStateException, SystemException {
status = Status.STATUS_ROLLING_BACK;
runXaResourceRollback();
status = Status.STATUS_ROLLEDBACK;
if (connection != null) {
try {
connection.rollback();
connection.close();
} catch (SQLException sqle) {
status = Status.STATUS_UNKNOWN;
throw new SystemException();
}
}
if (synchronizations != null) {
for (int i = 0; i < synchronizations.size(); i++) {
Synchronization s = (Synchronization) synchronizations.get(i);
s.afterCompletion(status);
}
}
// status = Status.STATUS_NO_TRANSACTION;
jtaTransactionManager.endCurrent(this);
}
use of java.sql.SQLException in project Openfire by igniterealtime.
the class DbRuleManager method getRuleByOrderId.
public Rule getRuleByOrderId(int order) {
Rule rule = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GET_RULE_BY_ORDER_ID);
pstmt.setInt(1, order);
rs = pstmt.executeQuery();
while (rs.next()) {
rule.setOrder(rs.getInt(1));
String ruleType = rs.getString(2);
if (ruleType.equals(Reject.class.getName())) {
rule = new Reject();
} else if (ruleType.equals(Pass.class.getName())) {
rule = new Pass();
} else if (ruleType.equals(Drop.class.getName())) {
rule = new Drop();
}
rule.setRuleId(rs.getString(3));
rule.setPacketType(Rule.PacketType.valueOf(rs.getString(4)));
rule.setDestination(rs.getString(5));
rule.setSource(rs.getString(6));
rule.isDisabled(rs.getBoolean(7));
rule.doLog(rs.getBoolean(8));
rule.setDescription(rs.getString(9));
rule.setSourceType(Rule.SourceDestType.valueOf(rs.getString(10)));
rule.setDestType(Rule.SourceDestType.valueOf(rs.getString(11)));
}
} catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
} finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return rule;
}
Aggregations