Java Code Examples for org.hibernate.util.JDBCExceptionReporter#logExceptions()

The following examples show how to use org.hibernate.util.JDBCExceptionReporter#logExceptions() . 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: LocalDataSourceConnectionProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 2
Source File: LocalDataSourceConnectionProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 3
Source File: LocalDataSourceConnectionProvider.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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 4
Source File: LocalDataSourceConnectionProvider.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: Expectations.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 6
Source File: AbstractBatcher.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 7
Source File: SQLExceptionConversionTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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 8
Source File: JDBCExceptionHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 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 );
}