|
|
|
|
@ -701,6 +701,15 @@ public class JdbcTemplateTests {
@@ -701,6 +701,15 @@ public class JdbcTemplateTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testBatchUpdateWithEmptyList() throws Exception { |
|
|
|
|
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; |
|
|
|
|
JdbcTemplate template = new JdbcTemplate(this.dataSource, false); |
|
|
|
|
|
|
|
|
|
int[] actualRowsAffected = template.batchUpdate(sql, Collections.emptyList()); |
|
|
|
|
assertTrue("executed 0 updates", actualRowsAffected.length == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testBatchUpdateWithListOfObjectArrays() throws Exception { |
|
|
|
|
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; |
|
|
|
|
@ -711,11 +720,9 @@ public class JdbcTemplateTests {
@@ -711,11 +720,9 @@ public class JdbcTemplateTests {
|
|
|
|
|
|
|
|
|
|
given(this.preparedStatement.executeBatch()).willReturn(rowsAffected); |
|
|
|
|
mockDatabaseMetaData(true); |
|
|
|
|
|
|
|
|
|
JdbcTemplate template = new JdbcTemplate(this.dataSource, false); |
|
|
|
|
|
|
|
|
|
int[] actualRowsAffected = template.batchUpdate(sql, ids); |
|
|
|
|
|
|
|
|
|
assertTrue("executed 2 updates", actualRowsAffected.length == 2); |
|
|
|
|
assertEquals(rowsAffected[0], actualRowsAffected[0]); |
|
|
|
|
assertEquals(rowsAffected[1], actualRowsAffected[1]); |
|
|
|
|
@ -738,10 +745,9 @@ public class JdbcTemplateTests {
@@ -738,10 +745,9 @@ public class JdbcTemplateTests {
|
|
|
|
|
|
|
|
|
|
given(this.preparedStatement.executeBatch()).willReturn(rowsAffected); |
|
|
|
|
mockDatabaseMetaData(true); |
|
|
|
|
|
|
|
|
|
this.template = new JdbcTemplate(this.dataSource, false); |
|
|
|
|
int[] actualRowsAffected = this.template.batchUpdate(sql, ids, sqlTypes); |
|
|
|
|
|
|
|
|
|
int[] actualRowsAffected = this.template.batchUpdate(sql, ids, sqlTypes); |
|
|
|
|
assertTrue("executed 2 updates", actualRowsAffected.length == 2); |
|
|
|
|
assertEquals(rowsAffected[0], actualRowsAffected[0]); |
|
|
|
|
assertEquals(rowsAffected[1], actualRowsAffected[1]); |
|
|
|
|
@ -780,19 +786,20 @@ public class JdbcTemplateTests {
@@ -780,19 +786,20 @@ public class JdbcTemplateTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCouldntGetConnectionForOperationOrExceptionTranslator() throws SQLException { |
|
|
|
|
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException { |
|
|
|
|
SQLException sqlException = new SQLException("foo", "07xxx"); |
|
|
|
|
this.dataSource = mock(DataSource.class); |
|
|
|
|
given(this.dataSource.getConnection()).willThrow(sqlException); |
|
|
|
|
JdbcTemplate template = new JdbcTemplate(this.dataSource, false); |
|
|
|
|
RowCountCallbackHandler rcch = new RowCountCallbackHandler(); |
|
|
|
|
|
|
|
|
|
this.thrown.expect(CannotGetJdbcConnectionException.class); |
|
|
|
|
this.thrown.expect(exceptionCause(sameInstance(sqlException))); |
|
|
|
|
template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCouldntGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException { |
|
|
|
|
public void testCouldNotGetConnectionForOperationWithLazyExceptionTranslator() throws SQLException { |
|
|
|
|
SQLException sqlException = new SQLException("foo", "07xxx"); |
|
|
|
|
this.dataSource = mock(DataSource.class); |
|
|
|
|
given(this.dataSource.getConnection()).willThrow(sqlException); |
|
|
|
|
@ -800,30 +807,31 @@ public class JdbcTemplateTests {
@@ -800,30 +807,31 @@ public class JdbcTemplateTests {
|
|
|
|
|
this.template.setDataSource(this.dataSource); |
|
|
|
|
this.template.afterPropertiesSet(); |
|
|
|
|
RowCountCallbackHandler rcch = new RowCountCallbackHandler(); |
|
|
|
|
|
|
|
|
|
this.thrown.expect(CannotGetJdbcConnectionException.class); |
|
|
|
|
this.thrown.expect(exceptionCause(sameInstance(sqlException))); |
|
|
|
|
this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() |
|
|
|
|
public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedViaBeanProperty() |
|
|
|
|
throws SQLException { |
|
|
|
|
|
|
|
|
|
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(true); |
|
|
|
|
doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCouldntGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() |
|
|
|
|
public void testCouldNotGetConnectionInOperationWithExceptionTranslatorInitializedInAfterPropertiesSet() |
|
|
|
|
throws SQLException { |
|
|
|
|
|
|
|
|
|
doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(false); |
|
|
|
|
doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* If beanProperty is true, initialize via exception translator bean property; |
|
|
|
|
* if false, use afterPropertiesSet(). |
|
|
|
|
*/ |
|
|
|
|
private void doTestCouldntGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty) |
|
|
|
|
private void doTestCouldNotGetConnectionInOperationWithExceptionTranslatorInitialized(boolean beanProperty) |
|
|
|
|
throws SQLException { |
|
|
|
|
|
|
|
|
|
SQLException sqlException = new SQLException("foo", "07xxx"); |
|
|
|
|
@ -883,7 +891,7 @@ public class JdbcTemplateTests {
@@ -883,7 +891,7 @@ public class JdbcTemplateTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCouldntClose() throws Exception { |
|
|
|
|
public void testCouldNotClose() throws Exception { |
|
|
|
|
SQLException sqlException = new SQLException("bar"); |
|
|
|
|
given(this.connection.createStatement()).willReturn(this.statement); |
|
|
|
|
given(this.resultSet.next()).willReturn(false); |
|
|
|
|
|