Java 类org.hibernate.JDBCException 实例源码

项目:lams    文件:CacheSQLExceptionConversionDelegate.java   
/**
 * Convert the given SQLException into Hibernate's JDBCException hierarchy.
 *
 * @param sqlException The SQLException to be converted.
 * @param message     An optional error message.
 * @param sql         Optionally, the sql being performed when the exception occurred.
 * @return The resulting JDBCException; returns null if it could not be converted.
 */
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    String sqlStateClassCode = JdbcExceptionHelper.extractSqlStateClassCode( sqlException );
    if ( sqlStateClassCode != null ) {
        Integer errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
        if ( INTEGRITY_VIOLATION_CATEGORIES.contains( errorCode ) ) {
            String constraintName =
                    getConversionContext()
                            .getViolatedConstraintNameExtracter()
                            .extractConstraintName( sqlException );
            return new ConstraintViolationException( message, sqlException, sql, constraintName );
        }
        else if ( DATA_CATEGORIES.contains( sqlStateClassCode ) ) {
            return new DataException( message, sqlException, sql );
        }
    }
    return null; // allow other delegates the chance to look
}
项目:lams    文件:IteratorImpl.java   
public void close() throws JDBCException {
    if (ps!=null) {
        LOG.debug("Closing iterator");
        session.getTransactionCoordinator().getJdbcCoordinator().release( ps );
        ps = null;
        rs = null;
        hasNext = false;
        try {
            session.getPersistenceContext().getLoadContexts().cleanup( rs );
        }
        catch( Throwable ignore ) {
            // ignore this error for now
               LOG.debugf("Exception trying to cleanup load context : %s", ignore.getMessage());
        }
    }
}
项目:lams    文件:SybaseASE157Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
            if("JZ0TO".equals( sqlState ) || "JZ006".equals( sqlState )){
                throw new LockTimeoutException( message, sqlException, sql );
            }
            if ( 515 == errorCode && "ZZZZZ".equals( sqlState ) ) {
                // Attempt to insert NULL value into column; column does not allow nulls.
                final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException );
                return new ConstraintViolationException( message, sqlException, sql, constraintName );
            }
            return null;
        }
    };
}
项目:lams    文件:SQLServer2005Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
            final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
            if ( "HY008".equals( sqlState ) ) {
                throw new QueryTimeoutException( message, sqlException, sql );
            }
            if (1222 == errorCode ) {
                throw new LockTimeoutException( message, sqlException, sql );
            }
            return null;
        }
    };
}
项目:lams    文件:PostgreSQL81Dialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );

            if ( "40P01".equals( sqlState ) ) {
                // DEADLOCK DETECTED
                return new LockAcquisitionException( message, sqlException, sql );
            }

            if ( "55P03".equals( sqlState ) ) {
                // LOCK NOT AVAILABLE
                return new PessimisticLockException( message, sqlException, sql );
            }

            // returning null allows other delegates to operate
            return null;
        }
    };
}
项目:hibernate4-sqlite-dialect    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = org.hibernate.internal.util.JdbcExceptionHelper.extractErrorCode(sqlException);
            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);
        }
    };
}
项目:vsDiaryWriter    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
            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;
        }
    };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
        return new SQLExceptionConverter() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
        return new SQLExceptionConversionDelegate() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
  return new SQLExceptionConverter() {
    @Override
    public JDBCException convert(SQLException sqlException, String message,
        String sql) {
      final String sqlState = JDBCExceptionHelper
          .extractSqlState(sqlException);
      if (sqlState != null) {
        if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
          return new SQLGrammarException(message, sqlException, sql);
        }
        else if (DATA_CATEGORIES.contains(sqlState)) {
          return new DataException(message, sqlException, sql);
        }
        else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
          return new LockAcquisitionException(message, sqlException, sql);
        }
      }
      return null;
    }
  };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
  return new SQLExceptionConverter() {
    @Override
    public JDBCException convert(SQLException sqlException, String message,
        String sql) {
      final String sqlState = JDBCExceptionHelper
          .extractSqlState(sqlException);
      if (sqlState != null) {
        if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
          return new SQLGrammarException(message, sqlException, sql);
        }
        else if (DATA_CATEGORIES.contains(sqlState)) {
          return new DataException(message, sqlException, sql);
        }
        else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
          return new LockAcquisitionException(message, sqlException, sql);
        }
      }
      return null;
    }
  };
}
项目:cacheonix-core    文件:SchemaExport.java   
private void importScript(Reader importFileReader, Statement statement)
        throws IOException {
    log.info( "Executing import script: " + importFile );
    BufferedReader reader = new BufferedReader( importFileReader );
    for ( String sql = reader.readLine(); sql != null; sql = reader.readLine() ) {
        try {
            String trimmedSql = sql.trim();
            if ( trimmedSql.length() == 0 ||
                 trimmedSql.startsWith( "--" ) ||
                 trimmedSql.startsWith( "//" ) ||
                 trimmedSql.startsWith( "/*" ) ) {
                continue;
            }
            else {
                if ( trimmedSql.endsWith( ";" ) ) {
                    trimmedSql = trimmedSql.substring( 0, trimmedSql.length() - 1 );
                }
                log.debug( trimmedSql );
                statement.execute( trimmedSql );
            }
        }
        catch ( SQLException e ) {
            throw new JDBCException( "Error during import script execution", e );
        }
    }
}
项目:cacheonix-core    文件:SchemaExport.java   
private void create(boolean script, boolean export, Writer fileOutput, Statement statement)
        throws IOException {
    for ( int j = 0; j < createSQL.length; j++ ) {
        try {
            execute( script, export, fileOutput, statement, createSQL[j] );
        }
        catch ( SQLException e ) {
            if ( haltOnError ) {
                throw new JDBCException( "Error during DDL export", e );
            }
            exceptions.add( e );
            log.error( "Unsuccessful: " + createSQL[j] );
            log.error( e.getMessage() );
        }
    }
}
项目:cacheonix-core    文件:CacheSQLStateConverter.java   
/**
 * Convert the given SQLException into Hibernate's JDBCException hierarchy.
 *
 * @param sqlException The SQLException to be converted.
 * @param message     An optional error message.
 * @param sql         Optionally, the sql being performed when the exception occurred.
 * @return The resulting JDBCException.
 */
public JDBCException convert(SQLException sqlException, String message, String sql) {
    String sqlStateClassCode = JDBCExceptionHelper.extractSqlStateClassCode( sqlException );
    Integer errorCode = new Integer( JDBCExceptionHelper.extractErrorCode( sqlException ) );
    if ( sqlStateClassCode != null ) {
        if ( SQL_GRAMMAR_CATEGORIES.contains( sqlStateClassCode ) ) {
            return new SQLGrammarException( message, sqlException, sql );
        }
        else if ( INTEGRITY_VIOLATION_CATEGORIES.contains( errorCode ) ) {
            String constraintName = extracter.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 );
        }
    }
    return handledNonSpecificException( sqlException, message, sql );
}
项目:cacheonix-core    文件:CustomInsertSQLWithIdentityColumnTest.java   
public void testBadInsertionFails() {
    Session session = openSession();
    session.beginTransaction();
    Organization org = new Organization( "hola!" );
    try {
        session.save( org );
        session.delete( org );
        fail( "expecting bad custom insert statement to fail" );
    }
    catch( JDBCException e ) {
        // expected failure
    }

    session.getTransaction().rollback();
    session.close();
}
项目:cacheonix-core    文件:ResultCheckStyleTest.java   
public void testInsertionFailureWithExceptionChecking() {
    Session s = openSession();
    s.beginTransaction();
    ExceptionCheckingEntity e = new ExceptionCheckingEntity();
    e.setName( "dummy" );
    s.save( e );
    try {
        s.flush();
        fail( "expection flush failure!" );
    }
    catch( JDBCException ex ) {
        // these should specifically be JDBCExceptions...
    }
    s.clear();
    s.getTransaction().commit();
    s.close();
}
项目:cacheonix-core    文件:ResultCheckStyleTest.java   
public void testUpdateFailureWithExceptionChecking() {
    Session s = openSession();
    s.beginTransaction();
    ExceptionCheckingEntity e = new ExceptionCheckingEntity();
    e.setId( new Long( 1 ) );
    e.setName( "dummy" );
    s.update( e );
    try {
        s.flush();
        fail( "expection flush failure!" );
    }
    catch( JDBCException ex ) {
        // these should specifically be JDBCExceptions...
    }
    s.clear();
    s.getTransaction().commit();
    s.close();
}
项目:cacheonix-core    文件:ResultCheckStyleTest.java   
public void testDeleteWithExceptionChecking() {
    Session s = openSession();
    s.beginTransaction();
    ExceptionCheckingEntity e = new ExceptionCheckingEntity();
    e.setId( new Long( 1 ) );
    e.setName( "dummy" );
    s.delete( e );
    try {
        s.flush();
        fail( "expection flush failure!" );
    }
    catch( JDBCException ex ) {
        // these should specifically be JDBCExceptions...
    }
    s.clear();
    s.getTransaction().commit();
    s.close();
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
        return new SQLExceptionConverter() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
        return new SQLExceptionConversionDelegate() {
                @Override
                public JDBCException convert(SQLException sqlException,
                                String message, String sql) {
                        final String sqlState = JdbcExceptionHelper
                                        .extractSqlState(sqlException);
                        if (sqlState != null) {
                                if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
                                        return new SQLGrammarException(message, sqlException,
                                                        sql);
                                } else if (DATA_CATEGORIES.contains(sqlState)) {
                                        return new DataException(message, sqlException, sql);
                                } else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
                                        return new LockAcquisitionException(message,
                                                        sqlException, sql);
                                }
                        }
                        return null;
                }
        };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
  return new SQLExceptionConverter() {
    @Override
    public JDBCException convert(SQLException sqlException, String message,
        String sql) {
      final String sqlState = JDBCExceptionHelper
          .extractSqlState(sqlException);
      if (sqlState != null) {
        if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
          return new SQLGrammarException(message, sqlException, sql);
        }
        else if (DATA_CATEGORIES.contains(sqlState)) {
          return new DataException(message, sqlException, sql);
        }
        else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
          return new LockAcquisitionException(message, sqlException, sql);
        }
      }
      return null;
    }
  };
}
项目:gemfirexd-oss    文件:GemFireXDDialect.java   
@Override
public SQLExceptionConverter buildSQLExceptionConverter() {
  return new SQLExceptionConverter() {
    @Override
    public JDBCException convert(SQLException sqlException, String message,
        String sql) {
      final String sqlState = JDBCExceptionHelper
          .extractSqlState(sqlException);
      if (sqlState != null) {
        if (SQL_GRAMMAR_CATEGORIES.contains(sqlState)) {
          return new SQLGrammarException(message, sqlException, sql);
        }
        else if (DATA_CATEGORIES.contains(sqlState)) {
          return new DataException(message, sqlException, sql);
        }
        else if (LOCK_ACQUISITION_CATEGORIES.contains(sqlState)) {
          return new LockAcquisitionException(message, sqlException, sql);
        }
      }
      return null;
    }
  };
}
项目:spletne-seje    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
    return new SQLExceptionConversionDelegate() {
        @Override
        public JDBCException convert(SQLException sqlException, String message, String sql) {
            final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
            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 null;
        }
    };
}
项目:aseguradora-dbs    文件:MedicoVentana.java   
private void eliminarMedico() {
    int row = tablaMedico.getSelectedRow();
    try {

        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        Medico medico = new Medico();
        Short cod_m = (row == -1) ? Short.parseShort(etCodMedico.getText().toString()) : Short.parseShort(tablaMedico.getModel().getValueAt(row, 0).toString());
        medico = (Medico) session.load(Medico.class, cod_m);
        session.delete(medico);
        tx.commit();
        session.close();
            cargarMedico();
        } catch (JDBCException e) {
            System.out.println("aqui");
            e.printStackTrace();
            if (e.getMessage().contains(""+ERROR_EDITAR_CLAVE_AJENA)){
                JOptionPane.showMessageDialog(rootPane, "No puedes borrar este medico, restricción clave primeria/ajena");
            }
        }
}
项目:Lucee4    文件:CommonUtil.java   
public static PageException toPageException(Throwable t) {
    lucee.commons.lang.ExceptionUtil.rethrowIfNecessary(t);
    PageException pe = caster().toPageException(t);;
    if (t instanceof org.hibernate.HibernateException) {
        org.hibernate.HibernateException he = (org.hibernate.HibernateException)t;
        Throwable cause = he.getCause();
        if(cause != null) {
            pe = caster().toPageException( cause );
            ExceptionUtil.setAdditional(pe, CommonUtil.createKey("hibernate exception"), t );
        }
    }
    if ( t instanceof JDBCException ) {
        JDBCException je = (JDBCException)t;
        ExceptionUtil.setAdditional(pe, CommonUtil.createKey("sql"), je.getSQL());
    }
    if( t instanceof ConstraintViolationException) {
        ConstraintViolationException cve = (ConstraintViolationException)t;
        if(!Util.isEmpty(cve.getConstraintName())) {
            ExceptionUtil.setAdditional(pe, CommonUtil.createKey("constraint name"), cve.getConstraintName());
        }
    }
    return pe;

}
项目:Introspect-Framework    文件:SQLiteDialect.java   
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
  return new SQLExceptionConversionDelegate() {
    @Override
    public JDBCException convert(SQLException sqlException, String message, String sql) {
      final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
      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;
    }
  };
}
项目:ZawodyWeb    文件:RequestBean.java   
@HttpAction(name = "dellanguage", pattern = "del/{id}/language")
public String deleteLanguage(@Param(name = "id", encode = true) int id) {
    if (rolesBean.canEditAnyProblem()) {
        try {
            languagesDAO.deleteById(id);
            HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
            HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
        } catch (JDBCException e) {
            e.printStackTrace();
            SQLException ex = e.getSQLException();
            while ((ex = ex.getNextException()) != null) {
                ex.printStackTrace();
            }
        }

        return "/admin/listlanguages";
    } else {
        return "/error/404";
    }
}
项目:ZawodyWeb    文件:RequestBean.java   
@HttpAction(name = "delseries", pattern = "del/{id}/series")
public String deleteSeries(@Param(name = "id", encode = true) int id) {
    Series s = seriesDAO.getById(id);
    if (s != null && rolesBean.canDeleteSeries(s.getContests().getId(), id)) {
        try {
            seriesDAO.delete(s);
            HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
            HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
        } catch (JDBCException e) {
            e.printStackTrace();
            SQLException ex = e.getSQLException();
            while ((ex = ex.getNextException()) != null) {
                ex.printStackTrace();
            }
        }
        return "problems";
    } else {
        return "/error/404";
    }
}
项目:CarSalesWebService    文件:TestSpringHibernateSessionFactory.java   
public static void main(String[] args) {
    // TODO Auto-generated method stub
    //ApplicationContext applicationContext = null;
    //ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();  


    AutoService autoService = (AutoService) ctx.getBean("autoService");
    Auto araba = new Auto();


    //auto.setCarid(2);
    try{

        //autoService.getAuto(1);
         araba = autoService.getAuto("16");
    }catch (JDBCException jdbce) {
        jdbce.getSQLException().getNextException().printStackTrace();
    }
    System.out.println(araba.getAutoname());
    System.out.println(araba.getAutofuel().getAutofuelname());


    System.out.println("************** ENDING PROGRAM *****************");
}
项目:yeti    文件:SQLiteDialect.java   
@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);
        }
    };
}
项目:open-cyclos    文件:DirectLockHandlerFactory.java   
@Override
public void lock(final Account... accounts) throws LockingException {
    if (ArrayUtils.isEmpty(accounts)) {
        return;
    }
    Long[] ids = EntityHelper.toIds(accounts);
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    try {
        session
                .createQuery("select l.id from AccountLock l where l.id in (:ids)")
                .setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE))
                .setParameterList("ids", ids)
                .list();
    } catch (JDBCException e) {
        handleException(e);
    }
}
项目:dcp-api    文件:JpaHibernateContentPersistenceService.java   
/**
 * Check if table exists in DB for given table name and create it if not.
 * 
 * @param tableName to check/create
 */
protected synchronized void ensureTableExists(String tableName) {
    if (!checkTableExists(tableName)) {
        try {
            doDatabaseWork(new CreateTableWork(tableName));
            synchronized (TABLES_EXISTS) {
                TABLES_EXISTS.put(tableName, Boolean.TRUE);
            }
        } catch (JDBCException e) {
            // in case of exception we are not sure if table exists or not, so recheck it and throw exception out if not
            // created
            synchronized (TABLES_EXISTS) {
                TABLES_EXISTS.remove(tableName);
            }
            if (!checkTableExists(tableName)) {
                throw e;
            }
        }
    }
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegate.java   
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
    final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
    if (errorCode == SQLITE_CONSTRAINT) {
        final String constraintName = EXTRACTER.extractConstraintName(sqlException);
        return new ConstraintViolationException(message, sqlException, sql, constraintName);
    } else if (errorCode == SQLITE_TOO_BIG || 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_IO_ERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOT_ADB) {
        return new JDBCConnectionException(message, sqlException, sql);
    }
    return new GenericJDBCException(message, sqlException, sql);
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsConstraintViolationException() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(19);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof ConstraintViolationException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsDataExceptionForSqliteTooBigError() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(18);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof DataException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsDataExceptionForSqliteMismatch() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(20);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof DataException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsLockAcquisitionExceptionForSqliteBusy() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(5);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof LockAcquisitionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsLockAcquisitionExceptionForSqliteLocked() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(6);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof LockAcquisitionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsJDBCConnectionExceptionForSqliteCorrupt() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(11);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof JDBCConnectionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
项目:sqlite-dialect    文件:SQLiteSQLExceptionConversionDelegateTest.java   
@Test
public void returnsJDBCConnectionExceptionForSqliteNotAbd() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(26);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof JDBCConnectionException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}