use of org.springframework.jdbc.UncategorizedSQLException in project spring-framework by spring-projects.
the class DataSourceTransactionManagerTests method testTransactionAwareDataSourceProxy.
@Test
public void testTransactionAwareDataSourceProxy() throws Exception {
given(con.getAutoCommit()).willReturn(true);
TransactionTemplate tt = new TransactionTemplate(tm);
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
assertEquals(con, DataSourceUtils.getConnection(ds));
TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
try {
assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
// should be ignored
dsProxy.getConnection().close();
} catch (SQLException ex) {
throw new UncategorizedSQLException("", "", ex);
}
}
});
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).commit();
ordered.verify(con).setAutoCommit(true);
verify(con).close();
}
use of org.springframework.jdbc.UncategorizedSQLException in project spring-framework by spring-projects.
the class JdbcTemplateTests method testBatchUpdateWithBatchFailure.
@Test
public void testBatchUpdateWithBatchFailure() throws Exception {
final String[] sql = { "A", "B", "C", "D" };
given(this.statement.executeBatch()).willThrow(new BatchUpdateException(new int[] { 1, Statement.EXECUTE_FAILED, 1, Statement.EXECUTE_FAILED }));
mockDatabaseMetaData(true);
given(this.connection.createStatement()).willReturn(this.statement);
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
try {
template.batchUpdate(sql);
} catch (UncategorizedSQLException ex) {
assertThat(ex.getSql(), equalTo("B; D"));
}
}
use of org.springframework.jdbc.UncategorizedSQLException in project uPortal by Jasig.
the class DataSourceSchemaExport method perform.
private void perform(String[] sqlCommands, boolean executeSql, String outputFile, boolean append, boolean failFast) {
final PrintWriter sqlWriter = getSqlWriter(outputFile, append);
try {
for (final String sqlCommand : sqlCommands) {
final String formatted = formatter.format(sqlCommand);
sqlWriter.println(formatted);
if (executeSql) {
try {
jdbcOperations.execute(sqlCommand);
logger.info(sqlCommand);
} catch (BadSqlGrammarException | UncategorizedSQLException e) {
// Needed until Hibernate 5. See https://hibernate.atlassian.net/browse/HHH-7002.
if (sqlCommand.contains("drop constraint")) {
logger.info("Failed to execute (probably ignorable): {}, error message {}", sqlCommand, e.getMessage());
} else {
handleSqlException(failFast, sqlCommand, e);
}
} catch (Exception e) {
handleSqlException(failFast, sqlCommand, e);
}
}
}
} finally {
IOUtils.closeQuietly(sqlWriter);
}
}
Aggregations