protected static Function<DatabaseMetaData,Boolean> productNameEqualsIgnorecaseMatcher(final String name){ return new Function<DatabaseMetaData,Boolean>() { @Override public Boolean apply(DatabaseMetaData dm) { try { return dm.getDatabaseProductName().equalsIgnoreCase(name); } catch (SQLException e) { throw new NestedSQLException(e); } } }; }
public static void wrapAndThrow(String message,SQLException e){ throw new NestedSQLException(message,e); }
public static NestedSQLException wrap(SQLException e){ return new NestedSQLException(e); }
public static void wrapAndThrow(SQLException e){ throw new NestedSQLException(e); }
public static NestedSQLException wrap(String message,SQLException e){ return new NestedSQLException(message,e); }
protected Connection fetchConnectionFromDataSource() { try { return dataSource.getConnection(); } catch (SQLException e) { throw new NestedSQLException(e); } }
@Override public Boolean apply(DatabaseMetaData dm) { try { return dm.getDatabaseProductName().equalsIgnoreCase(name); } catch (SQLException e) { throw new NestedSQLException(e); } } };
protected static Function<DatabaseMetaData,Boolean> productNameContainsIgnorecaseMatcher(final String name){ return dm -> { try { return Strings.containsIgnoreCase(dm.getDatabaseProductName(), name); } catch (SQLException e) { throw new NestedSQLException(e); } }; } }
protected void setConnection(Connection connection) { try { this.originalAutoCommit = connection.getAutoCommit(); connection.setAutoCommit(false); } catch (SQLException e) { tp.returnConnectionToDataSource(connection); throw new NestedSQLException("Error setting connection's 'autoCommit'" + e.getMessage(), e); } if (isolation != TransactionDefinition.Isolation.DEFAULT.getValue()) { try { this.originalIsolationLevel = connection.getTransactionIsolation(); if (this.isolation != this.originalIsolationLevel) { connection.setTransactionIsolation(this.isolation); } } catch (SQLException e) { tp.returnConnectionToDataSource(connection); throw new NestedSQLException("Error setting connection's transaction isolation" + e.getMessage(), e); } } this.connection = connection; }
throw new NestedSQLException("Unable to get driver for JDBC URL " + jdbcUrl, e);
@Override public DbSchemaName[] readSchemaNames(Connection connection) { ResultSet rs = null; try{ rs = getSchemas(connection, connection.getMetaData()); List<DbSchemaName> schemas = new ArrayList<DbSchemaName>(); while(rs.next()){ String catalog = getSchemaCatalog(rs); String schema = getSchemaName(rs); if(!dialect.isSystemSchema(schema)){ schemas.add(new DbSchemaName(catalog, schema)); } } return schemas.toArray(new DbSchemaName[schemas.size()]); }catch(SQLException e){ throw new NestedSQLException("Error reading schema names : " + e.getMessage(),e); }finally{ JDBC.closeResultSetAndStatement(rs); } }
@Override public <T> T executeWithResult(ConnectionCallbackWithResult<T> callback) throws NestedSQLException { try { DataSource contextDataSource = getContextDataSource(); if(null == contextDataSource && null != tp) { return tp.executeWithResult(callback); }else{ Connection conn = null; try { conn = null != contextDataSource ? contextDataSource.getConnection() : dataSource.getConnection(); return callback.execute(conn); }catch(SQLException e) { throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeConnection(conn); } } } finally { SqlExecutionContext.clean(); } }
throw new NestedSQLException("Error creating Db instance : " + e.getMessage(),e); }finally{ JDBC.closeConnection(connection);
@Override public void execute(ConnectionCallback callback) throws NestedSQLException { try { DataSource contextDataSource = getContextDataSource(); if(null == contextDataSource && null != tp) { tp.execute(callback); }else{ Connection conn = null; try { conn = null != contextDataSource ? contextDataSource.getConnection() : dataSource.getConnection(); callback.execute(conn); }catch(SQLException e) { throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeConnection(conn); } } } finally { SqlExecutionContext.clean(); } }
throw new NestedSQLException(e); }else{ log.warn("Statement [{}] failed, error : {} \n SQL -> \n {}",nrOfExecuted,e.getMessage(),sql, e); throw new NestedSQLException("Error executing this execution : " + e.getMessage(), e); }finally{ JDBC.closeStatementOnly(stmt);
.build(); } catch (SQLException e) { throw new NestedSQLException("Error reading schema : " + e.getMessage(),e);
throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeStatementOnly(ps);
throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeResultSetOnly(rs);
throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeStatementOnly(ps);