Java 类org.hibernate.util.JDBCExceptionReporter 实例源码
项目:cacheonix-core
文件:SchemaExport.java
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() );
}
}
}
项目:cacheonix-core
文件:AbstractBatcher.java
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"
);
}
}
项目:cacheonix-core
文件:ConnectionManager.java
/**
* 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"
);
}
}
项目:lams
文件:LocalDataSourceConnectionProvider.java
/**
* 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;
}
}
项目:lams
文件:LocalDataSourceConnectionProvider.java
/**
* 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;
}
}
项目:spring4-understanding
文件:LocalDataSourceConnectionProvider.java
/**
* 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;
}
}
项目:spring4-understanding
文件:LocalDataSourceConnectionProvider.java
/**
* 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;
}
}
项目:communote-server
文件:C3P0DataSourceConnectionProvider.java
/**
* {@inheritDoc}
*/
@Override
public void closeConnection(Connection con) throws SQLException {
// simply call Connection.close
try {
con.close();
} catch (SQLException ex) {
JDBCExceptionReporter.logExceptions(ex);
throw ex;
}
}
项目:cacheonix-core
文件:ManagedProviderConnectionHelper.java
public void release() throws SQLException {
if ( connection != null ) {
try {
JDBCExceptionReporter.logAndClearWarnings( connection );
connectionProvider.closeConnection( connection );
}
finally {
connectionProvider.close();
}
}
connection = null;
}
项目:cacheonix-core
文件:SuppliedConnectionProviderConnectionHelper.java
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;
}
}
项目:cacheonix-core
文件:SuppliedConnectionHelper.java
public void release() throws SQLException {
JDBCExceptionReporter.logAndClearWarnings( connection );
if ( toggleAutoCommit ) {
connection.setAutoCommit( false );
}
connection = null;
}
项目:cacheonix-core
文件:Expectations.java
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 );
}
}
项目:cacheonix-core
文件:AbstractBatcher.java
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;
}
}
项目:class-guard
文件:LocalDataSourceConnectionProvider.java
/**
* This implementation delegates to the underlying DataSource.
* @see javax.sql.DataSource#getConnection()
*/
public Connection getConnection() throws SQLException {
try {
return this.dataSourceToUse.getConnection();
}
catch (SQLException ex) {
JDBCExceptionReporter.logExceptions(ex);
throw ex;
}
}
项目:class-guard
文件:LocalDataSourceConnectionProvider.java
/**
* This implementation calls {@link DataSourceUtils#doCloseConnection},
* checking against a {@link org.springframework.jdbc.datasource.SmartDataSource}.
*/
public void closeConnection(Connection con) throws SQLException {
try {
DataSourceUtils.doCloseConnection(con, this.dataSourceToUse);
}
catch (SQLException ex) {
JDBCExceptionReporter.logExceptions(ex);
throw ex;
}
}
项目:cacheonix-core
文件:SQLExceptionConversionTest.java
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();
}
项目:cacheonix-core
文件:JDBCExceptionHelper.java
/**
* 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 );
}