use of org.springframework.jdbc.BadSqlGrammarException in project dhis2-core by dhis2.
the class JdbcEventAnalyticsManager method getEventCount.
@Override
public long getEventCount(EventQueryParams params) {
String sql = "select count(psi) ";
sql += getFromClause(params);
sql += getWhereClause(params);
long count = 0;
try {
log.debug("Analytics event count SQL: " + sql);
if (params.analyzeOnly()) {
executionPlanStore.addExecutionPlan(params.getExplainOrderId(), sql);
} else {
count = jdbcTemplate.queryForObject(sql, Long.class);
}
} catch (BadSqlGrammarException ex) {
log.info(AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex);
} catch (DataAccessResourceFailureException ex) {
log.warn(E7131.getMessage(), ex);
throw new QueryRuntimeException(E7131, ex);
} catch (DataIntegrityViolationException ex) {
log.warn(E7132.getMessage(), ex);
throw new QueryRuntimeException(E7132, ex);
}
return count;
}
use of org.springframework.jdbc.BadSqlGrammarException in project spring-framework by spring-projects.
the class SQLErrorCodeSQLExceptionTranslatorTests method errorCodeTranslation.
@Test
public void errorCodeTranslation() {
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
SQLException badSqlEx = new SQLException("", "", 1);
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", badSqlEx);
assertThat(bsgex.getSql()).isEqualTo("SQL");
assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
SQLException invResEx = new SQLException("", "", 4);
InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) sext.translate("task", "SQL", invResEx);
assertThat(irsex.getSql()).isEqualTo("SQL");
assertThat((Object) irsex.getSQLException()).isEqualTo(invResEx);
checkTranslation(sext, 5, DataAccessResourceFailureException.class);
checkTranslation(sext, 6, DataIntegrityViolationException.class);
checkTranslation(sext, 7, CannotAcquireLockException.class);
checkTranslation(sext, 8, DeadlockLoserDataAccessException.class);
checkTranslation(sext, 9, CannotSerializeTransactionException.class);
checkTranslation(sext, 10, DuplicateKeyException.class);
SQLException dupKeyEx = new SQLException("", "", 10);
DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
assertThat(dksex).isInstanceOf(DataIntegrityViolationException.class);
// Test fallback. We assume that no database will ever return this error code,
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
SQLException sex = new SQLException("", "07xxx", 666666666);
BadSqlGrammarException bsgex2 = (BadSqlGrammarException) sext.translate("task", "SQL2", sex);
assertThat(bsgex2.getSql()).isEqualTo("SQL2");
assertThat((Object) bsgex2.getSQLException()).isEqualTo(sex);
}
use of org.springframework.jdbc.BadSqlGrammarException in project spring-framework by spring-projects.
the class SQLErrorCodeSQLExceptionTranslatorTests method batchExceptionTranslation.
@Test
public void batchExceptionTranslation() {
SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES);
SQLException badSqlEx = new SQLException("", "", 1);
BatchUpdateException batchUpdateEx = new BatchUpdateException();
batchUpdateEx.setNextException(badSqlEx);
BadSqlGrammarException bsgex = (BadSqlGrammarException) sext.translate("task", "SQL", batchUpdateEx);
assertThat(bsgex.getSql()).isEqualTo("SQL");
assertThat((Object) bsgex.getSQLException()).isEqualTo(badSqlEx);
}
use of org.springframework.jdbc.BadSqlGrammarException 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) {
// 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);
}
}
use of org.springframework.jdbc.BadSqlGrammarException in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsManager method getAggregatedEventData.
// -------------------------------------------------------------------------
// EnrollmentAnalyticsManager implementation
// -------------------------------------------------------------------------
@Override
public Grid getAggregatedEventData(EventQueryParams params, Grid grid, int maxLimit) {
// ---------------------------------------------------------------------
// Select
// ---------------------------------------------------------------------
String countClause = getAggregateClause(params);
String sql = "select " + countClause + " as value," + StringUtils.join(getSelectColumns(params), ",") + " ";
// ---------------------------------------------------------------------
// Criteria
// ---------------------------------------------------------------------
sql += getFromWhereClause(params, Lists.newArrayList("psi"));
// ---------------------------------------------------------------------
// Group by
// ---------------------------------------------------------------------
sql += "group by " + StringUtils.join(getSelectColumns(params), ",") + " ";
if (params.hasSortOrder()) {
sql += "order by value " + params.getSortOrder().toString().toLowerCase() + " ";
}
if (params.hasLimit()) {
sql += "limit " + params.getLimit();
} else if (maxLimit > 0) {
sql += "limit " + (maxLimit + 1);
}
try {
getAggregatedEventData(grid, params, sql);
} catch (BadSqlGrammarException ex) {
log.info(QUERY_ERR_MSG, ex);
}
return grid;
}
Aggregations