public static void logExceptions(SQLException ex) { logExceptions(ex, null); }
/** * This implementation simply calls <code>Connection.close</code>. * * @see java.sql.Connection#close() */ public void closeConnection(Connection con) throws SQLException { try { con.close(); } catch (SQLException ex) { JDBCExceptionReporter.logExceptions(ex); throw ex; } }
/** * This implementation delegates to the underlying DataSource. * * @see javax.sql.DataSource#getConnection() */ public Connection getConnection() throws SQLException { try { return this.dataSource.getConnection(); } catch (SQLException ex) { JDBCExceptionReporter.logExceptions(ex); throw ex; } }
/** * This implementation delegates to the underlying DataSource. * @see javax.sql.DataSource#getConnection() */ @Override public Connection getConnection() throws SQLException { try { return this.dataSourceToUse.getConnection(); } catch (SQLException ex) { JDBCExceptionReporter.logExceptions(ex); throw ex; } }
public void abortBatch(SQLException sqle) { try { if (batchUpdate!=null) closeStatement(batchUpdate); } catch (SQLException e) { //noncritical, swallow and let the other propagate! JDBCExceptionReporter.logExceptions(e); } finally { batchUpdate=null; batchUpdateSQL=null; } }
/** * Converts the given SQLException into Hibernate's JDBCException hierarchy, as well as performing * appropriate logging. * * @param converter The converter to use. * @param sqlException The exception to convert. * @param message An optional error message. * @return The converted JDBCException. */ public static JDBCException convert(SQLExceptionConverter converter, SQLException sqlException, String message, String sql) { JDBCExceptionReporter.logExceptions( sqlException, message + " [" + sql + "]" ); return converter.convert( sqlException, message, sql ); }
/** * Converts the given SQLException into Hibernate's JDBCException hierarchy, as well as performing * appropriate logging. * * @param converter The converter to use. * @param sqlException The exception to convert. * @param message An optional error message. * @return The converted JDBCException. */ public static JDBCException convert(SQLExceptionConverter converter, SQLException sqlException, String message, String sql) { JDBCExceptionReporter.logExceptions( sqlException, message + " [" + sql + "]" ); return converter.convert( sqlException, message, sql ); }
public void abortBatch(SQLException sqle) { try { if (batchUpdate!=null) closeStatement(batchUpdate); } catch (SQLException e) { //noncritical, swallow and let the other propagate! JDBCExceptionReporter.logExceptions(e); } finally { batchUpdate=null; batchUpdateSQL=null; } }
/** * This implementation calls {@link DataSourceUtils#doCloseConnection}, * checking against a {@link org.springframework.jdbc.datasource.SmartDataSource}. */ @Override public void closeConnection(Connection con) throws SQLException { try { DataSourceUtils.doCloseConnection(con, this.dataSourceToUse); } catch (SQLException ex) { JDBCExceptionReporter.logExceptions(ex); throw ex; } }
public static void logExceptions(SQLException ex, String message) { if ( log.isErrorEnabled() ) { if ( log.isDebugEnabled() ) { message = StringHelper.isNotEmpty(message) ? message : DEFAULT_EXCEPTION_MSG; log.debug( message, ex ); } while (ex != null) { StringBuffer buf = new StringBuffer(30) .append( "SQL Error: " ) .append( ex.getErrorCode() ) .append( ", SQLState: " ) .append( ex.getSQLState() ); log.warn( buf.toString() ); log.error( ex.getMessage() ); ex = ex.getNextException(); } } }
public void createSchema() { try { execute(getCreateSql()); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to create schema"); } }
public void dropSchema() { try { execute(getDropSql()); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to drop schema"); } }
public void updateSchema() { try { execute(getUpdateSql()); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to update schema"); } }
public void cleanSchema() { try { execute(getCleanSql()); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to clean schema"); } }
public void createTable(String tableName) { Table table = findTableMapping(tableName); String sql = sqlCreateString(table); try { execute(new String[] { sql }); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to create table"); } }
private void execute(String sql, Statement statement) { try { statement.executeUpdate(sql); SQLWarning warning = statement.getWarnings(); if (warning != null) { JDBCExceptionReporter.logWarnings(warning); statement.clearWarnings(); } } catch (SQLException e) { JDBCExceptionReporter.logExceptions(e, "failed to execute update"); exceptions.add(e); } }
public boolean tableExists(String tableName) { Connection connection = null; try { connection = createConnection(); DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData .getTables(getDefaultCatalog(), getDefaultSchema(), tableName, TABLE_TYPES); try { return resultSet.next(); } finally { resultSet.close(); } } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "could not determine whether table exists"); return false; } finally { closeConnection(connection); } }
private void closeConnection(Connection connection) { if (connectionProvider != null) { try { if (connection != null) { JDBCExceptionReporter.logAndClearWarnings(connection); connectionProvider.closeConnection(connection); } } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e); } finally { connectionProvider.close(); connectionProvider = null; } } }
public Set getExistingTables() { Connection connection = null; try { connection = createConnection(); Set existingTables = new HashSet(); DatabaseMetaData metaData = connection.getMetaData(); boolean storesLowerCaseIdentifiers = metaData.storesLowerCaseIdentifiers(); ResultSet resultSet = metaData .getTables(getDefaultCatalog(), getDefaultSchema(), null, TABLE_TYPES); try { while (resultSet.next()) { String tableName = resultSet.getString("TABLE_NAME"); if (storesLowerCaseIdentifiers) tableName = tableName.toUpperCase(); existingTables.add(tableName); } } finally { resultSet.close(); } return existingTables; } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "could not get available table names"); return Collections.EMPTY_SET; } finally { closeConnection(connection); } }
public String[] getUpdateSql() { Connection connection = null; try { connection = createConnection(); return configuration .generateSchemaUpdateScript(getDialect(), getDatabaseMetadata(connection)); } catch (SQLException e) { exceptions.add(e); JDBCExceptionReporter.logExceptions(e, "failed to generate update sql"); return EMPTY_STRING_ARRAY; } finally { closeConnection(connection); } }