org.hibernate.util.JDBCExceptionReporter Java Examples
The following examples show how to use
org.hibernate.util.JDBCExceptionReporter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaExport.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql) throws IOException, SQLException { String formatted = format( sql ); if ( delimiter != null ) { formatted += delimiter; } if ( script ) { System.out.println( formatted ); } log.debug( formatted ); if ( outputFile != null ) { fileOutput.write( formatted + "\n" ); } if ( export ) { statement.executeUpdate( sql ); SQLWarning warnings = statement.getWarnings(); if ( warnings != null) { JDBCExceptionReporter.logAndClearWarnings( connectionHelper.getConnection() ); } } }
Example #2
Source File: AbstractBatcher.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void closeConnection(Connection conn) throws HibernateException { if ( log.isDebugEnabled() ) { log.debug( "closing JDBC connection" + preparedStatementCountsToString() + resultSetCountsToString() ); } try { if ( !conn.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings(conn); } factory.getConnectionProvider().closeConnection(conn); } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" ); } }
Example #3
Source File: ConnectionManager.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Physically closes the JDBC Connection. */ private void closeConnection() { if ( log.isDebugEnabled() ) { log.debug( "releasing JDBC connection [" + batcher.openResourceStatsAsString() + "]" ); } try { if ( !connection.isClosed() ) { JDBCExceptionReporter.logAndClearWarnings( connection ); } factory.getConnectionProvider().closeConnection( connection ); connection = null; } catch (SQLException sqle) { throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot release connection" ); } }
Example #4
Source File: LocalDataSourceConnectionProvider.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #5
Source File: LocalDataSourceConnectionProvider.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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; } }
Example #6
Source File: LocalDataSourceConnectionProvider.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #7
Source File: LocalDataSourceConnectionProvider.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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; } }
Example #8
Source File: ManagedProviderConnectionHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void release() throws SQLException { if ( connection != null ) { try { JDBCExceptionReporter.logAndClearWarnings( connection ); connectionProvider.closeConnection( connection ); } finally { connectionProvider.close(); } } connection = null; }
Example #9
Source File: SuppliedConnectionProviderConnectionHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void release() throws SQLException { // we only release the connection if ( connection != null ) { JDBCExceptionReporter.logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } provider.closeConnection( connection ); connection = null; } }
Example #10
Source File: SuppliedConnectionHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void release() throws SQLException { JDBCExceptionReporter.logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } connection = null; }
Example #11
Source File: Expectations.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
protected int determineRowCount(int reportedRowCount, PreparedStatement statement) { try { return toCallableStatement( statement ).getInt( parameterPosition ); } catch( SQLException sqle ) { JDBCExceptionReporter.logExceptions( sqle, "could not extract row counts from CallableStatement" ); throw new GenericJDBCException( "could not extract row counts from CallableStatement", sqle ); } }
Example #12
Source File: AbstractBatcher.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
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; } }
Example #13
Source File: SQLExceptionConversionTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void testIntegrityViolation() throws Exception { if ( getDialect() instanceof MySQLMyISAMDialect ) { reportSkip( "MySQL (ISAM) does not support FK violation checking", "exception conversion" ); return; } SQLExceptionConverter converter = getDialect().buildSQLExceptionConverter(); Session session = openSession(); session.beginTransaction(); Connection connection = session.connection(); // Attempt to insert some bad values into the T_MEMBERSHIP table that should // result in a constraint violation PreparedStatement ps = null; try { ps = connection.prepareStatement("INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)"); ps.setLong(1, 52134241); // Non-existent user_id ps.setLong(2, 5342); // Non-existent group_id ps.executeUpdate(); fail("INSERT should have failed"); } catch(SQLException sqle) { JDBCExceptionReporter.logExceptions(sqle, "Just output!!!!"); JDBCException jdbcException = converter.convert(sqle, null, null); assertEquals( "Bad conversion [" + sqle.getMessage() + "]", ConstraintViolationException.class , jdbcException.getClass() ); ConstraintViolationException ex = (ConstraintViolationException) jdbcException; System.out.println("Violated constraint name: " + ex.getConstraintName()); } finally { if ( ps != null ) { try { ps.close(); } catch( Throwable ignore ) { // ignore... } } } session.getTransaction().rollback(); session.close(); }
Example #14
Source File: JDBCExceptionHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 2 votes |
/** * 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 ); }