use of cn.taketoday.jdbc.datasource.SingleConnectionDataSource in project today-infrastructure by TAKETODAY.
the class JdbcTemplateTests method testLeaveConnectionOpenOnRequest.
@Test
public void testLeaveConnectionOpenOnRequest() throws Exception {
String sql = "SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3";
given(this.resultSet.next()).willReturn(false);
given(this.connection.isClosed()).willReturn(false);
given(this.connection.createStatement()).willReturn(this.preparedStatement);
// if close is called entire test will fail
willThrow(new RuntimeException()).given(this.connection).close();
SingleConnectionDataSource scf = new SingleConnectionDataSource(this.dataSource.getConnection(), false);
this.template = new JdbcTemplate(scf, false);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
this.template.query(sql, rcch);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
}
use of cn.taketoday.jdbc.datasource.SingleConnectionDataSource in project today-infrastructure by TAKETODAY.
the class RowMapperTests method setUp.
@BeforeEach
public void setUp() throws SQLException {
given(connection.createStatement()).willReturn(statement);
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
given(statement.executeQuery(anyString())).willReturn(resultSet);
given(preparedStatement.executeQuery()).willReturn(resultSet);
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getString(1)).willReturn("tb1", "tb2");
given(resultSet.getInt(2)).willReturn(1, 2);
template.setDataSource(new SingleConnectionDataSource(connection, false));
template.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
template.afterPropertiesSet();
}
use of cn.taketoday.jdbc.datasource.SingleConnectionDataSource in project today-framework by TAKETODAY.
the class JdbcTemplateTests method testLeaveConnectionOpenOnRequest.
@Test
public void testLeaveConnectionOpenOnRequest() throws Exception {
String sql = "SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3";
given(this.resultSet.next()).willReturn(false);
given(this.connection.isClosed()).willReturn(false);
given(this.connection.createStatement()).willReturn(this.preparedStatement);
// if close is called entire test will fail
willThrow(new RuntimeException()).given(this.connection).close();
SingleConnectionDataSource scf = new SingleConnectionDataSource(this.dataSource.getConnection(), false);
this.template = new JdbcTemplate(scf, false);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
this.template.query(sql, rcch);
verify(this.resultSet).close();
verify(this.preparedStatement).close();
}
use of cn.taketoday.jdbc.datasource.SingleConnectionDataSource in project today-framework by TAKETODAY.
the class RowMapperTests method setUp.
@BeforeEach
public void setUp() throws SQLException {
given(connection.createStatement()).willReturn(statement);
given(connection.prepareStatement(anyString())).willReturn(preparedStatement);
given(statement.executeQuery(anyString())).willReturn(resultSet);
given(preparedStatement.executeQuery()).willReturn(resultSet);
given(resultSet.next()).willReturn(true, true, false);
given(resultSet.getString(1)).willReturn("tb1", "tb2");
given(resultSet.getInt(2)).willReturn(1, 2);
template.setDataSource(new SingleConnectionDataSource(connection, false));
template.setExceptionTranslator(new SQLStateSQLExceptionTranslator());
template.afterPropertiesSet();
}
Aggregations