org.springframework.jdbc.UncategorizedSQLException Java Examples

The following examples show how to use org.springframework.jdbc.UncategorizedSQLException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractFallbackSQLExceptionTranslator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
 * {@link #getFallbackTranslator() fallback translator} if necessary.
 */
@Override
@NonNull
public DataAccessException translate(String task, @Nullable String sql, SQLException ex) {
	Assert.notNull(ex, "Cannot translate a null SQLException");

	DataAccessException dae = doTranslate(task, sql, ex);
	if (dae != null) {
		// Specific exception match found.
		return dae;
	}

	// Looking for a fallback...
	SQLExceptionTranslator fallback = getFallbackTranslator();
	if (fallback != null) {
		dae = fallback.translate(task, sql, ex);
		if (dae != null) {
			// Fallback exception match found.
			return dae;
		}
	}

	// We couldn't identify it more precisely.
	return new UncategorizedSQLException(task, sql, ex);
}
 
Example #2
Source File: JdbcTemplateTests.java    From effectivejava with Apache License 2.0 6 votes vote down vote up
@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"));
	}
}
 
Example #3
Source File: JdbcTemplateTests.java    From effectivejava with Apache License 2.0 6 votes vote down vote up
@Test
public void testBogusUpdate() throws Exception {
	final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
	final int idParam = 6666;

	// It's because Integers aren't canonical
	SQLException sqlException = new SQLException("bad update");
	given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

	Dispatcher d = new Dispatcher(idParam, sql);
	this.thrown.expect(UncategorizedSQLException.class);
	this.thrown.expect(exceptionCause(equalTo(sqlException)));
	try {
		this.template.update(d);
	}
	finally {
		verify(this.preparedStatement).setInt(1, idParam);
		verify(this.preparedStatement).close();
		verify(this.connection, atLeastOnce()).close();
	}
}
 
Example #4
Source File: AbstractFallbackSQLExceptionTranslator.java    From effectivejava with Apache License 2.0 6 votes vote down vote up
/**
 * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
 * {@link #getFallbackTranslator() fallback translator} if necessary.
 */
@Override
public DataAccessException translate(String task, String sql, SQLException ex) {
	Assert.notNull(ex, "Cannot translate a null SQLException");
	if (task == null) {
		task = "";
	}
	if (sql == null) {
		sql = "";
	}

	DataAccessException dex = doTranslate(task, sql, ex);
	if (dex != null) {
		// Specific exception match found.
		return dex;
	}
	// Looking for a fallback...
	SQLExceptionTranslator fallback = getFallbackTranslator();
	if (fallback != null) {
		return fallback.translate(task, sql, ex);
	}
	// We couldn't identify it more precisely.
	return new UncategorizedSQLException(task, sql, ex);
}
 
Example #5
Source File: HibernateSqlViewStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String testSqlGrammar( String sql )
{
    String viewName = SqlView.PREFIX_VIEWNAME + System.currentTimeMillis();

    sql = "CREATE VIEW " + viewName + " AS " + sql;

    log.debug( "Test view SQL: " + sql );

    try
    {
        jdbcTemplate.execute( sql );

        jdbcTemplate.execute( "DROP VIEW IF EXISTS " + viewName );
    }
    catch ( BadSqlGrammarException | UncategorizedSQLException ex )
    {
        return ex.getCause().getMessage();
    }

    return null;
}
 
Example #6
Source File: JdbcTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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"));
	}
}
 
Example #7
Source File: JdbcTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testBogusUpdate() throws Exception {
	final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
	final int idParam = 6666;

	// It's because Integers aren't canonical
	SQLException sqlException = new SQLException("bad update");
	given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

	Dispatcher d = new Dispatcher(idParam, sql);
	this.thrown.expect(UncategorizedSQLException.class);
	this.thrown.expect(exceptionCause(equalTo(sqlException)));
	try {
		this.template.update(d);
	}
	finally {
		verify(this.preparedStatement).setInt(1, idParam);
		verify(this.preparedStatement).close();
		verify(this.connection, atLeastOnce()).close();
	}
}
 
Example #8
Source File: AbstractFallbackSQLExceptionTranslator.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
 * {@link #getFallbackTranslator() fallback translator} if necessary.
 */
@Override
public DataAccessException translate(String task, String sql, SQLException ex) {
	Assert.notNull(ex, "Cannot translate a null SQLException");
	if (task == null) {
		task = "";
	}
	if (sql == null) {
		sql = "";
	}

	DataAccessException dex = doTranslate(task, sql, ex);
	if (dex != null) {
		// Specific exception match found.
		return dex;
	}
	// Looking for a fallback...
	SQLExceptionTranslator fallback = getFallbackTranslator();
	if (fallback != null) {
		return fallback.translate(task, sql, ex);
	}
	// We couldn't identify it more precisely.
	return new UncategorizedSQLException(task, sql, ex);
}
 
Example #9
Source File: JdbcTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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"));
	}
}
 
Example #10
Source File: JdbcTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testBogusUpdate() throws Exception {
	final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
	final int idParam = 6666;

	// It's because Integers aren't canonical
	SQLException sqlException = new SQLException("bad update");
	given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

	Dispatcher d = new Dispatcher(idParam, sql);
	this.thrown.expect(UncategorizedSQLException.class);
	this.thrown.expect(exceptionCause(equalTo(sqlException)));
	try {
		this.template.update(d);
	}
	finally {
		verify(this.preparedStatement).setInt(1, idParam);
		verify(this.preparedStatement).close();
		verify(this.connection, atLeastOnce()).close();
	}
}
 
Example #11
Source File: AbstractFallbackSQLExceptionTranslator.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
 * {@link #getFallbackTranslator() fallback translator} if necessary.
 */
@Override
@NonNull
public DataAccessException translate(String task, @Nullable String sql, SQLException ex) {
	Assert.notNull(ex, "Cannot translate a null SQLException");

	DataAccessException dae = doTranslate(task, sql, ex);
	if (dae != null) {
		// Specific exception match found.
		return dae;
	}

	// Looking for a fallback...
	SQLExceptionTranslator fallback = getFallbackTranslator();
	if (fallback != null) {
		dae = fallback.translate(task, sql, ex);
		if (dae != null) {
			// Fallback exception match found.
			return dae;
		}
	}

	// We couldn't identify it more precisely.
	return new UncategorizedSQLException(task, sql, ex);
}
 
Example #12
Source File: JdbcTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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"));
	}
}
 
Example #13
Source File: JdbcTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testBogusUpdate() throws Exception {
	final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
	final int idParam = 6666;

	// It's because Integers aren't canonical
	SQLException sqlException = new SQLException("bad update");
	given(this.preparedStatement.executeUpdate()).willThrow(sqlException);

	Dispatcher d = new Dispatcher(idParam, sql);
	assertThatExceptionOfType(UncategorizedSQLException.class).isThrownBy(() ->
			this.template.update(d))
		.withCause(sqlException);
	verify(this.preparedStatement).setInt(1, idParam);
	verify(this.preparedStatement).close();
	verify(this.connection, atLeastOnce()).close();
}
 
Example #14
Source File: AbstractFallbackSQLExceptionTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Pre-checks the arguments, calls {@link #doTranslate}, and invokes the
 * {@link #getFallbackTranslator() fallback translator} if necessary.
 */
@Override
public DataAccessException translate(String task, String sql, SQLException ex) {
	Assert.notNull(ex, "Cannot translate a null SQLException");
	if (task == null) {
		task = "";
	}
	if (sql == null) {
		sql = "";
	}

	DataAccessException dae = doTranslate(task, sql, ex);
	if (dae != null) {
		// Specific exception match found.
		return dae;
	}

	// Looking for a fallback...
	SQLExceptionTranslator fallback = getFallbackTranslator();
	if (fallback != null) {
		dae = fallback.translate(task, sql, ex);
		if (dae != null) {
			// Fallback exception match found.
			return dae;
		}
	}

	// We couldn't identify it more precisely.
	return new UncategorizedSQLException(task, sql, ex);
}
 
Example #15
Source File: DataSourceTransactionManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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();
}
 
Example #16
Source File: SQLStateExceptionTranslatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void invalidSqlStateCode() {
	SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #17
Source File: SQLStateExceptionTranslatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void testMalformedSqlStateCode(SQLException sex) {
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #18
Source File: SQLStateExceptionTranslatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void invalidSqlStateCode() {
	SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #19
Source File: DataSourceTransactionManagerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
				assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
				// 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();
}
 
Example #20
Source File: DataSourceTransactionManagerTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
@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());
				assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
				// 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();
}
 
Example #21
Source File: SQLStateExceptionTranslatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testMalformedSqlStateCode(SQLException sex) {
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #22
Source File: SQLStateExceptionTranslatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testMalformedSqlStateCode(SQLException sex) {
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #23
Source File: SQLStateExceptionTranslatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void invalidSqlStateCode() {
	SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #24
Source File: SQLStateExceptionTranslatorTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
public void testInvalidSqlStateCode() {
	String sql = "SELECT FOO FROM BAR";
	SQLException sex = new SQLException("Message", "NO SUCH CODE", 1);
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #25
Source File: DataSourceTransactionManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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();
}
 
Example #26
Source File: SQLStateExceptionTranslatorTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
private void testMalformedSqlStateCode(SQLException sex) {
	String sql = "SELECT FOO FROM BAR";
	try {
		throw this.trans.translate("task", sql, sex);
	}
	catch (UncategorizedSQLException ex) {
		// OK
		assertTrue("SQL is correct", sql.equals(ex.getSql()));
		assertTrue("Exception matches", sex.equals(ex.getSQLException()));
	}
}
 
Example #27
Source File: SQLStateSQLExceptionTranslatorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testTranslateUncategorized() throws Exception {
	doTest("00000000", UncategorizedSQLException.class);
}
 
Example #28
Source File: SQLStateSQLExceptionTranslatorTests.java    From effectivejava with Apache License 2.0 4 votes vote down vote up
@Test
public void testTranslateUncategorized() throws Exception {
	doTest("00000000", UncategorizedSQLException.class);
}
 
Example #29
Source File: DataSourceTransactionManagerTests.java    From effectivejava with Apache License 2.0 4 votes vote down vote up
private void doTestTransactionCommitRestoringAutoCommit(
		boolean autoCommit, boolean lazyConnection, final boolean createStatement)
		throws Exception {
	if (lazyConnection) {
		given(con.getAutoCommit()).willReturn(autoCommit);
		given(con.getTransactionIsolation()).willReturn(Connection.TRANSACTION_READ_COMMITTED);
	}

	if (!lazyConnection || createStatement) {
		given(con.getAutoCommit()).willReturn(autoCommit);
	}

	final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy(ds) : ds);
	tm = new DataSourceTransactionManager(dsToUse);
	TransactionTemplate tt = new TransactionTemplate(tm);
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
	assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive());

	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
			assertTrue("Synchronization active", TransactionSynchronizationManager.isSynchronizationActive());
			assertTrue("Is new transaction", status.isNewTransaction());
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			Connection tCon = DataSourceUtils.getConnection(dsToUse);
			try {
				if (createStatement) {
					tCon.createStatement();
					assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(tCon));
				}
			}
			catch (SQLException ex) {
				throw new UncategorizedSQLException("", "", ex);
			}
		}
	});

	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
	assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive());

	if(autoCommit && (!lazyConnection || createStatement)) {
		InOrder ordered = inOrder(con);
		ordered.verify(con).setAutoCommit(false);
		ordered.verify(con).commit();
		ordered.verify(con).setAutoCommit(true);
	}
	if (createStatement) {
		verify(con, times(2)).close();
	}
	else {
		verify(con).close();
	}
}
 
Example #30
Source File: JdbcTemplate.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * for Spring 4.x
 */
protected DataAccessException translateException(String task, String sql, SQLException ex) {
    DataAccessException dae = getExceptionTranslator().translate(task, sql, ex);
    return (dae != null ? dae : new UncategorizedSQLException(task, sql, ex));
}