Java Code Examples for org.hibernate.JDBCException

The following are top voted examples for showing how to use org.hibernate.JDBCException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: CacheSQLExceptionConversionDelegate.java   Source Code and License 7 votes vote down vote up
/**
 * 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
}
 
Example 2
Project: lams   File: SybaseASE157Dialect.java   Source Code and License 7 votes vote down vote up
@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;
		}
	};
}
 
Example 3
Project: lams   File: IteratorImpl.java   Source Code and License 6 votes vote down vote up
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());
		}
	}
}
 
Example 4
Project: lams   File: SQLServer2005Dialect.java   Source Code and License 6 votes vote down vote up
@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;
		}
	};
}
 
Example 5
Project: lams   File: PostgreSQL81Dialect.java   Source Code and License 6 votes vote down vote up
@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;
		}
	};
}
 
Example 6
Project: hibernate4-sqlite-dialect   File: SQLiteDialect.java   Source Code and License 6 votes vote down vote up
@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);
        }
    };
}
 
Example 7
Project: vsDiaryWriter   File: SQLiteDialect.java   Source Code and License 6 votes vote down vote up
@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;
		}
	};
}
 
Example 8
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
                }
        };
}
 
Example 9
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
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;
                }
        };
}
 
Example 10
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
    }
  };
}
 
Example 11
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
    }
  };
}
 
Example 12
Project: cacheonix-core   File: SchemaExport.java   Source Code and License 6 votes vote down vote up
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 );
		}
	}
}
 
Example 13
Project: cacheonix-core   File: SchemaExport.java   Source Code and License 6 votes vote down vote up
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() );
		}
	}
}
 
Example 14
Project: cacheonix-core   File: CacheSQLStateConverter.java   Source Code and License 6 votes vote down vote up
/**
 * 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 );
}
 
Example 15
Project: cacheonix-core   File: CustomInsertSQLWithIdentityColumnTest.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 16
Project: cacheonix-core   File: ResultCheckStyleTest.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 17
Project: cacheonix-core   File: ResultCheckStyleTest.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 18
Project: cacheonix-core   File: ResultCheckStyleTest.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 19
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
                }
        };
}
 
Example 20
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
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;
                }
        };
}
 
Example 21
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
    }
  };
}
 
Example 22
Project: gemfirexd-oss   File: GemFireXDDialect.java   Source Code and License 6 votes vote down vote up
@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;
    }
  };
}
 
Example 23
Project: spletne-seje   File: SQLiteDialect.java   Source Code and License 6 votes vote down vote up
@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;
		}
	};
}
 
Example 24
Project: aseguradora-dbs   File: MedicoVentana.java   Source Code and License 6 votes vote down vote up
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");
            }
        }
}
 
Example 25
Project: Lucee4   File: CommonUtil.java   Source Code and License 6 votes vote down vote up
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;
	
}
 
Example 26
Project: Introspect-Framework   File: SQLiteDialect.java   Source Code and License 6 votes vote down vote up
@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;
    }
  };
}
 
Example 27
Project: ZawodyWeb   File: RequestBean.java   Source Code and License 6 votes vote down vote up
@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";
    }
}
 
Example 28
Project: ZawodyWeb   File: RequestBean.java   Source Code and License 6 votes vote down vote up
@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";
    }
}
 
Example 29
Project: CarSalesWebService   File: TestSpringHibernateSessionFactory.java   Source Code and License 6 votes vote down vote up
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 *****************");
}
 
Example 30
Project: yeti   File: SQLiteDialect.java   Source Code and License 6 votes vote down vote up
@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 31
Project: open-cyclos   File: DirectLockHandlerFactory.java   Source Code and License 6 votes vote down vote up
@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);
    }
}
 
Example 32
Project: dcp-api   File: JpaHibernateContentPersistenceService.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
			}
		}
	}
}
 
Example 33
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegate.java   Source Code and License 5 votes vote down vote up
@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);
}
 
Example 34
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 35
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 36
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 37
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 38
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 39
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 40
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@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());
}
 
Example 41
Project: sqlite-dialect   File: SQLiteSQLExceptionConversionDelegateTest.java   Source Code and License 5 votes vote down vote up
@Test
public void returnsGenericJDBCExceptionForEverythingElse() {
    when(JdbcExceptionHelper.extractErrorCode(sqlException)).thenReturn(41);

    JDBCException exception = conversionDelegate.convert(sqlException, "message", "sql");
    assertTrue(exception instanceof GenericJDBCException);
    assertEquals("message", exception.getMessage());
    assertEquals("sql", exception.getSQL());
}
 
Example 42
Project: OpenDiabetes   File: HSQLDialect.java   Source Code and License 5 votes vote down vote up
public void lock(Serializable id, Object version, Object object, int timeout, SessionImplementor session)
                throws StaleObjectStateException, JDBCException {
        if ( getLockMode().greaterThan( LockMode.READ ) ) {
                log.warn( "HSQLDB supports only READ_UNCOMMITTED isolation" );
        }
        super.lock( id, version, object, timeout, session );
}
 
Example 43
Project: OpenDiabetes   File: HSQLDialect.java   Source Code and License 5 votes vote down vote up
public void lock(Serializable id, Object version, Object object, SessionImplementor session)
		throws StaleObjectStateException, JDBCException {
	if ( getLockMode().greaterThan( LockMode.READ ) ) {
		log.warn( "HSQLDB supports only READ_UNCOMMITTED isolation" );
	}
	super.lock( id, version, object, session );
}
 
Example 44
Project: lams   File: SpringSessionSynchronization.java   Source Code and License 5 votes vote down vote up
private DataAccessException translateException(HibernateException ex) {
	if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
		JDBCException jdbcEx = (JDBCException) ex;
		return this.jdbcExceptionTranslator.translate(
				"Hibernate flushing: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
	}
	return SessionFactoryUtils.convertHibernateAccessException(ex);
}
 
Example 45
Project: lams   File: BasicConnectionCreator.java   Source Code and License 5 votes vote down vote up
protected JDBCException convertSqlException(String message, SQLException e) {
	// if JdbcServices#getSqlExceptionHelper is available, use it...
	final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
	if ( jdbcServices != null && jdbcServices.getSqlExceptionHelper() != null ) {
		return jdbcServices.getSqlExceptionHelper().convert( e, message, null );
	}

	// likely we are still in the process of initializing the ServiceRegistry, so use the simplified
	// SQLException conversion
	return simpleConverterAccess.getValue().convert( e, message, null );
}
 
Example 46
Project: lams   File: LogicalConnectionImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Physically opens a JDBC Connection.
 *
 * @throws org.hibernate.JDBCException Indicates problem opening a connection
 */
private void obtainConnection() throws JDBCException {
	LOG.debug( "Obtaining JDBC connection" );
	try {
		physicalConnection = jdbcConnectionAccess.obtainConnection();
		for ( ConnectionObserver observer : observers ) {
			observer.physicalConnectionObtained( physicalConnection );
		}
		LOG.debug( "Obtained JDBC connection" );
	}
	catch ( SQLException sqle) {
		throw getJdbcServices().getSqlExceptionHelper().convert( sqle, "Could not open connection" );
	}
}
 
Example 47
Project: lams   File: LogicalConnectionImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Physically closes the JDBC Connection.
 *
 * @throws JDBCException Indicates problem closing a connection
 */
@Override
public void releaseConnection() throws JDBCException {
	LOG.debug( "Releasing JDBC connection" );
	if ( physicalConnection == null ) {
		return;
	}
	try {
		if ( !physicalConnection.isClosed() ) {
			getJdbcServices().getSqlExceptionHelper().logAndClearWarnings( physicalConnection );
		}
		if ( !isUserSuppliedConnection ) {
			jdbcConnectionAccess.releaseConnection( physicalConnection );
		}
	}
	catch (SQLException e) {
		throw getJdbcServices().getSqlExceptionHelper().convert( e, "Could not close connection" );
	}
	finally {
		physicalConnection = null;
	}
	LOG.debug( "Released JDBC connection" );
	for ( ConnectionObserver observer : observers ) {
		observer.physicalConnectionReleased();
	}
	releaseNonDurableObservers();
}
 
Example 48
Project: lams   File: ContextualLobCreator.java   Source Code and License 5 votes vote down vote up
@Override
public Blob createBlob(byte[] bytes) {
	try {
		final Blob blob = createBlob();
		blob.setBytes( 1, bytes );
		return blob;
	}
	catch ( SQLException e ) {
		throw new JDBCException( "Unable to set BLOB bytes after creation", e );
	}
}
 
Example 49
Project: lams   File: ContextualLobCreator.java   Source Code and License 5 votes vote down vote up
@Override
public Clob createClob(String string) {
	try {
		final Clob clob = createClob();
		clob.setString( 1, string );
		return clob;
	}
	catch ( SQLException e ) {
		throw new JDBCException( "Unable to set CLOB string after creation", e );
	}
}
 
Example 50
Project: lams   File: ContextualLobCreator.java   Source Code and License 5 votes vote down vote up
@Override
public NClob createNClob(String string) {
	try {
		final NClob nclob = createNClob();
		nclob.setString( 1, string );
		return nclob;
	}
	catch ( SQLException e ) {
		throw new JDBCException( "Unable to set NCLOB string after creation", e );
	}
}
 
Example 51
Project: lams   File: SQLExceptionConverterFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Builds a minimal converter.  The instance returned here just always converts to
 * {@link org.hibernate.exception.GenericJDBCException}.
 *
 * @return The minimal converter.
 */
public static SQLExceptionConverter buildMinimalSQLExceptionConverter() {
	return new SQLExceptionConverter() {
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			return new GenericJDBCException( message, sqlException, sql );
		}
	};
}
 
Example 52
Project: lams   File: StandardSQLExceptionConverter.java   Source Code and License 5 votes vote down vote up
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
	for ( SQLExceptionConversionDelegate delegate : delegates ) {
		final JDBCException jdbcException = delegate.convert( sqlException, message, sql );
		if ( jdbcException != null ) {
			return jdbcException;
		}
	}
	return new GenericJDBCException( message, sqlException, sql );
}
 
Example 53
Project: lams   File: SQLExceptionTypeDelegate.java   Source Code and License 5 votes vote down vote up
@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 54
Project: lams   File: HSQLDialect.java   Source Code and License 5 votes vote down vote up
public void lock(Serializable id, Object version, Object object, int timeout, SessionImplementor session)
		throws StaleObjectStateException, JDBCException {
	if ( getLockMode().greaterThan( LockMode.READ ) ) {
		LOG.hsqldbSupportsOnlyReadCommittedIsolation();
	}
	super.lock( id, version, object, timeout, session );
}
 
Example 55
Project: lams   File: DB2Dialect.java   Source Code and License 5 votes vote down vote up
@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( -952 == errorCode && "57014".equals( sqlState )){
				throw new LockTimeoutException( message, sqlException, sql );
			}
			return null;
		}
	};
}
 
Example 56
Project: lams   File: OutputsImpl.java   Source Code and License 5 votes vote down vote up
protected JDBCException convert(SQLException e, String message) {
	return context.getSession().getFactory().getSQLExceptionHelper().convert(
			e,
			message,
			context.getSql()
	);
}
 
Example 57
Project: dev-courses   File: HSQLDialect.java   Source Code and License 5 votes vote down vote up
public void lock(Serializable id, Object version, Object object, int timeout, SessionImplementor session)
                throws StaleObjectStateException, JDBCException {
        if ( getLockMode().greaterThan( LockMode.READ ) ) {
                log.warn( "HSQLDB supports only READ_UNCOMMITTED isolation" );
        }
        super.lock( id, version, object, timeout, session );
}
 
Example 58
Project: dev-courses   File: HSQLDialect.java   Source Code and License 5 votes vote down vote up
public void lock(Serializable id, Object version, Object object, SessionImplementor session)
		throws StaleObjectStateException, JDBCException {
	if ( getLockMode().greaterThan( LockMode.READ ) ) {
		log.warn( "HSQLDB supports only READ_UNCOMMITTED isolation" );
	}
	super.lock( id, version, object, session );
}
 
Example 59
Project: spring4-understanding   File: SpringSessionSynchronization.java   Source Code and License 5 votes vote down vote up
private DataAccessException translateException(HibernateException ex) {
	if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
		JDBCException jdbcEx = (JDBCException) ex;
		return this.jdbcExceptionTranslator.translate(
				"Hibernate flushing: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
	}
	return SessionFactoryUtils.convertHibernateAccessException(ex);
}
 
Example 60
Project: cacheonix-core   File: SQLExceptionConverterFactory.java   Source Code and License 5 votes vote down vote up
/**
 * Builds a minimal converter.  The instance returned here just always converts to
 * {@link GenericJDBCException}.
 *
 * @return The minimal converter.
 */
public static SQLExceptionConverter buildMinimalSQLExceptionConverter() {
	return new SQLExceptionConverter() {
		public JDBCException convert(SQLException sqlException, String message, String sql) {
			return new GenericJDBCException( message, sqlException, sql );
		}
	};
}