use of org.springframework.dao.DataAccessException in project spring-framework by spring-projects.
the class NamedParameterJdbcTemplateTests method testQueryWithResultSetExtractorNoParameters.
@Test
public void testQueryWithResultSetExtractorNoParameters() throws SQLException {
given(resultSet.next()).willReturn(true);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Customer cust = namedParameterTemplate.query(SELECT_NO_PARAMETERS, new ResultSetExtractor<Customer>() {
@Override
public Customer extractData(ResultSet rs) throws SQLException, DataAccessException {
rs.next();
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
});
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
verify(connection).prepareStatement(SELECT_NO_PARAMETERS);
verify(preparedStatement).close();
verify(connection).close();
}
use of org.springframework.dao.DataAccessException in project spring-framework by spring-projects.
the class SQLExceptionCustomTranslatorTests method badSqlGrammarException.
@Test
public void badSqlGrammarException() {
SQLException badSqlGrammarExceptionEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 1);
DataAccessException dae = sext.translate("task", "SQL", badSqlGrammarExceptionEx);
assertEquals(badSqlGrammarExceptionEx, dae.getCause());
assertThat(dae, instanceOf(BadSqlGrammarException.class));
}
use of org.springframework.dao.DataAccessException in project spring-security-oauth by spring-projects.
the class JdbcApprovalStore method purgeExpiredApprovals.
public boolean purgeExpiredApprovals() {
logger.debug("Purging expired approvals from database");
try {
int deleted = jdbcTemplate.update(deleteApprovalStatment + " where expiresAt <= ?", new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setTimestamp(1, new Timestamp(new Date().getTime()));
}
});
logger.debug(deleted + " expired approvals deleted");
} catch (DataAccessException ex) {
logger.error("Error purging expired approvals", ex);
return false;
}
return true;
}
use of org.springframework.dao.DataAccessException in project spring-boot by spring-projects.
the class AbstractDataSourcePoolMetadataTests method getPoolSizeTwoConnections.
@Test
public void getPoolSizeTwoConnections() {
final JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
assertThat(getDataSourceMetadata().getActive()).isEqualTo(2);
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(1.0f);
return null;
}
});
return null;
}
});
}
use of org.springframework.dao.DataAccessException in project spring-boot by spring-projects.
the class AbstractDataSourcePoolMetadataTests method getPoolSizeNoConnection.
@Test
public void getPoolSizeNoConnection() {
// Make sure the pool is initialized
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
return null;
}
});
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(0));
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0));
}
Aggregations