org.hibernate.exception.JDBCConnectionException Java Examples
The following examples show how to use
org.hibernate.exception.JDBCConnectionException.
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: SQLiteDialect.java From md_blockchain with Apache License 2.0 | 6 votes |
@Override public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() { return new SQLExceptionConversionDelegate() { @Override public JDBCException convert(SQLException sqlException, String message, String sql) { final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException) & 0xFF; if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) { return new DataException(message, sqlException, sql); } else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) { return new LockAcquisitionException(message, sqlException, sql); } else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) { return new JDBCConnectionException(message, sqlException, sql); } // returning null allows other delegates to operate return null; } }; }
Example #2
Source File: HibernateEngine.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
public List execQuery(String queryString) { List result = null; Transaction tx = null; try { Session session = _factory.getCurrentSession(); tx = session.beginTransaction(); Query query = session.createQuery(queryString); if (query != null) result = query.list(); } catch (JDBCConnectionException jce) { _log.error("Caught Exception: Couldn't connect to datasource - " + "starting with an empty dataset"); } catch (HibernateException he) { _log.error("Caught Exception: Error executing query: " + queryString, he); if (tx != null) tx.rollback(); } return result; }
Example #3
Source File: HibernateEngine.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
/** * executes a Query object based on the hql string passed * @param queryString - the hibernate query to execute * @return the List of objects returned, or null if the query has some problem */ public List execQuery(String queryString) { List result = null; Transaction tx = null; try { tx = getOrBeginTransaction(); Query query = getSession().createQuery(queryString); if (query != null) result = query.list(); } catch (JDBCConnectionException jce) { _log.error("Caught Exception: Couldn't connect to datasource - " + "continuing with an empty dataset"); if (tx != null) tx.rollback(); } catch (HibernateException he) { _log.error("Caught Exception: Error executing query: " + queryString, he); if (tx != null) tx.rollback(); } return result; }
Example #4
Source File: HibernateEngine.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
/** * executes a plain SQL Query * @param queryString - the SQL query to execute * @return the List of objects returned, or null if the query has some problem */ public List execSQLQuery(String queryString) { List result = null; Transaction tx = null; try { tx = getOrBeginTransaction(); Query query = getSession().createSQLQuery(queryString); if (query != null) result = query.list(); commit(); } catch (JDBCConnectionException jce) { _log.error("Caught Exception: Couldn't connect to datasource - " + "starting with an empty dataset"); if (tx != null) tx.rollback(); } catch (HibernateException he) { _log.error("Caught Exception: Error executing query: " + queryString, he); rollback(); } return result; }
Example #5
Source File: HibernateEngine.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
public int execUpdate(String queryString, boolean commit) { int result = -1; Transaction tx = null; try { tx = getOrBeginTransaction(); result = getSession().createQuery(queryString).executeUpdate(); if (commit) commit(); } catch (JDBCConnectionException jce) { _log.error("Caught Exception: Couldn't connect to datasource - " + "starting with an empty dataset"); } catch (HibernateException he) { _log.error("Caught Exception: Error executing query: " + queryString, he); if (tx != null) tx.rollback(); } return result; }
Example #6
Source File: DataDbLogger.java From core with GNU General Public License v3.0 | 6 votes |
/** * Returns true if the exception indicates that there is a problem connecting * to the database as opposed to with the SQL. * * @param e * @return */ private boolean shouldKeepTryingBecauseConnectionException(HibernateException e) { // Need to know if it is a problem with the database not // being accessible or if there is a problem with the SQL/data. // If there is a problem accessibility of the database then // want to keep trying writing the old data. But if it is // a problem with the SQL/data then only want to try to write // the good data from the batch a single time to make sure // all good data is written. // From javadocs for for org.hivernate.exception at // http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/exception/package-frame.html // can see that there are a couple of different exception types. // From looking at documentation and testing found out that // bad SQL is indicated by // ConstraintViolationException // DataException // SQLGrammarException // Appears that for bad connection could get: // JDBCConnectionException (was not able to verify experimentally) // GenericJDBCException (obtained when committing transaction with db turned off) // So if exception is JDBCConnectionException or JDBCGenericException // then should keep retrying until successful. boolean keepTryingTillSuccessfull = e instanceof JDBCConnectionException || e instanceof GenericJDBCException; return keepTryingTillSuccessfull; }
Example #7
Source File: SQLiteDialect.java From yeti with MIT License | 6 votes |
@Override public SQLExceptionConverter buildSQLExceptionConverter() { return new SQLExceptionConverter() { @Override public JDBCException convert(SQLException sqlException, String message, String sql) { final int errorCode = sqlException.getErrorCode(); if (errorCode == SQLITE_CONSTRAINT) { final String constraintName = EXTRACTER.extractConstraintName(sqlException); return new ConstraintViolationException(message, sqlException, sql, constraintName); } else if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) { return new DataException(message, sqlException, sql); } else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) { return new LockAcquisitionException(message, sqlException, sql); } else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) { return new JDBCConnectionException(message, sqlException, sql); } return new GenericJDBCException(message, sqlException, sql); } }; }
Example #8
Source File: SQLExceptionTypeDelegate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public JDBCException convert(SQLException sqlException, String message, String sql) { if ( SQLClientInfoException.class.isInstance( sqlException ) || SQLInvalidAuthorizationSpecException.class.isInstance( sqlException ) || SQLNonTransientConnectionException.class.isInstance( sqlException ) || SQLTransientConnectionException.class.isInstance( sqlException ) ) { return new JDBCConnectionException( message, sqlException, sql ); } else if ( DataTruncation.class.isInstance( sqlException ) || SQLDataException.class.isInstance( sqlException ) ) { throw new DataException( message, sqlException, sql ); } else if ( SQLIntegrityConstraintViolationException.class.isInstance( sqlException ) ) { return new ConstraintViolationException( message, sqlException, sql, getConversionContext().getViolatedConstraintNameExtracter().extractConstraintName( sqlException ) ); } else if ( SQLSyntaxErrorException.class.isInstance( sqlException ) ) { return new SQLGrammarException( message, sqlException, sql ); } else if ( SQLTimeoutException.class.isInstance( sqlException ) ) { return new QueryTimeoutException( message, sqlException, sql ); } else if ( SQLTransactionRollbackException.class.isInstance( sqlException ) ) { // Not 100% sure this is completely accurate. The JavaDocs for SQLTransactionRollbackException state that // it indicates sql states starting with '40' and that those usually indicate that: // <quote> // the current statement was automatically rolled back by the database because of deadlock or // other transaction serialization failures. // </quote> return new LockAcquisitionException( message, sqlException, sql ); } return null; // allow other delegates the chance to look }
Example #9
Source File: SQLStateConversionDelegate.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public JDBCException convert(SQLException sqlException, String message, String sql) { final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException ); final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException ); if ( sqlState != null ) { String sqlStateClassCode = JdbcExceptionHelper.determineSqlStateClassCode( sqlState ); if ( sqlStateClassCode != null ) { if ( SQL_GRAMMAR_CATEGORIES.contains( sqlStateClassCode ) ) { return new SQLGrammarException( message, sqlException, sql ); } else if ( INTEGRITY_VIOLATION_CATEGORIES.contains( sqlStateClassCode ) ) { final String constraintName = getConversionContext() .getViolatedConstraintNameExtracter() .extractConstraintName( sqlException ); return new ConstraintViolationException( message, sqlException, sql, constraintName ); } else if ( CONNECTION_CATEGORIES.contains( sqlStateClassCode ) ) { return new JDBCConnectionException( message, sqlException, sql ); } else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) { return new DataException( message, sqlException, sql ); } } if ( "40001".equals( sqlState ) ) { return new LockAcquisitionException( message, sqlException, sql ); } if ( "40XL1".equals( sqlState ) || "40XL2".equals( sqlState )) { // Derby "A lock could not be obtained within the time requested." return new PessimisticLockException( message, sqlException, sql ); } // MySQL Query execution was interrupted if ( "70100".equals( sqlState ) || // Oracle user requested cancel of current operation ( "72000".equals( sqlState ) && errorCode == 1013 ) ) { throw new QueryTimeoutException( message, sqlException, sql ); } } return null; }