List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:com.edu.rodriguez.dao.ContactoDao.java
private void manejaExcepcion(HibernateException he) throws HibernateException { tx.rollback();/*from w ww .j av a2s.c o m*/ throw new HibernateException("Ocurrip un error en la capa de acceso a datos", he); }
From source file:com.enonic.cms.store.hibernate.type.BinaryColumnReader.java
License:Open Source License
public static byte[] readBinary(String columnName, ResultSet resultSet) throws SQLException { if (Environment.useStreamsForBinary()) { InputStream inputStream = resultSet.getBinaryStream(columnName); if (inputStream == null) { return null; }//from w w w . j a va2 s .c o m ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048); byte[] buffer = new byte[2048]; try { while (true) { int amountRead = inputStream.read(buffer); if (amountRead == -1) { break; } outputStream.write(buffer, 0, amountRead); } inputStream.close(); outputStream.close(); } catch (IOException e) { throw new HibernateException("Failed to read xml from stream", e); } return outputStream.toByteArray(); } else { return resultSet.getBytes(columnName); } }
From source file:com.ephesoft.dcma.core.hibernate.DynamicHibernateDao.java
License:Open Source License
/** * Constructor.//from w w w . j ava 2s . co m * * @param cfgLocation String */ public DynamicHibernateDao(String cfgLocation) { Configuration configuration = new Configuration().configure(cfgLocation); String filePath = META_INF + File.separator + FOLDER_NAME + File.separator + FILE_NAME + ".properties"; Properties properties; InputStream propertyInStream = null; try { propertyInStream = new ClassPathResource(filePath).getInputStream(); properties = new Properties(); properties.load(propertyInStream); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new HibernateException(e.getMessage(), e); } finally { if (propertyInStream != null) { try { propertyInStream.close(); } catch (IOException ioe) { LOG.info("Could not close property input stream in Dynamic Hibernate Dao."); } } } for (Object propertyKey : properties.keySet()) { String propertyKeyString = (String) propertyKey; if (!propertyKeyString.equalsIgnoreCase(PASSWORD)) { configuration.setProperty(propertyKeyString, properties.getProperty(propertyKeyString)); } else { PasswordDecryptor passwordDecryptor = new PasswordDecryptor( properties.getProperty(propertyKeyString)); try { configuration.setProperty(propertyKeyString, passwordDecryptor.getDecryptedString()); } catch (CryptographyException e) { LOG.error(e.getMessage(), e); throw new HibernateException(e.getMessage(), e); } } } try { if (sessionFactory != null) { sessionFactory.close(); } } catch (Exception e) { LOG.error("Could not close session factory", e); } sessionFactory = configuration.buildSessionFactory(); }
From source file:com.es.lib.entity.type.iface.IJsonType.java
License:Apache License
@Override default Object copyObject(Object o, Class<?> returnedClass) { try {//from w ww . j a v a2s . c o m return asObject(asString(o), returnedClass); } catch (IOException e) { throw new HibernateException("Error copy JSON", e); } }
From source file:com.es.lib.entity.type.iface.IJsonType.java
License:Apache License
@Override default Object getObject(ResultSet rs, String[] names, Class<?> returnedClass) throws SQLException { if (rs.getObject(names[0]) == null) { return null; }//from w w w .j a v a2 s .c o m PGobject pGobject = (PGobject) rs.getObject(names[0]); try { return asObject(pGobject.getValue(), returnedClass); } catch (IOException e) { throw new HibernateException("Error read JSON", e); } }
From source file:com.es.lib.entity.type.iface.IJsonType.java
License:Apache License
@Override default void setObject(PreparedStatement ps, Object value, int index) throws SQLException { if (value == null) { ps.setNull(index, Types.NULL); return;//from w w w.j ava2 s .c om } String jsonString; try { jsonString = asString(value); } catch (IOException e) { throw new HibernateException("Error save JSON", e); } PGobject pGobject = new PGobject(); pGobject.setType(getDbType().getValue()); pGobject.setValue(jsonString); ps.setObject(index, pGobject); }
From source file:com.example.app.hibernate.PeriodUserType.java
License:Open Source License
@Nullable @Override/*from ww w .j a va 2 s . c o m*/ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { final String period = rs.getString(names[0]); if (rs.wasNull()) { return null; } try { return Period.parse(period); } catch (DateTimeParseException e) { throw new HibernateException("Unexpected value: " + period, e); } }
From source file:com.example.app.model.DemoUserProfileDAO.java
License:Open Source License
/** * Delete the specified user profiles.// ww w . j av a2 s . com * * @param qlBuilder a QL builder that will return UserProfiles to delete. */ public void deleteUserProfiles(QLBuilder qlBuilder) { beginTransaction(); boolean success = false; try { final Session session = getSession(); final QLResolver queryResolver = qlBuilder.getQueryResolver(); final QLResolverOptions options = new QLResolverOptions(); final int atATime = 200; options.setFetchSize(atATime); queryResolver.setOptions(options); try (CloseableIterator<DemoUserProfile> it = queryResolver.iterate()) { int count = 0; while (it.hasNext()) { DemoUserProfile demoUserProfile = it.next(); session.delete(demoUserProfile); if (++count > atATime) { count = 0; session.flush(); // May need to clear action queues as well to free up memory. } } } catch (Exception e) { throw new HibernateException("Unable to iterate over query results.", e); } success = true; } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:com.example.app.model.UserProfileDAO.java
License:Open Source License
/** * Delete the specified user profiles.//ww w. j a v a2 s . com * * @param qlBuilder a QL builder that will return UserProfiles to delete. */ public void deleteUserProfiles(QLBuilder qlBuilder) { beginTransaction(); boolean success = false; try { final Session session = getSession(); final QLResolver queryResolver = qlBuilder.getQueryResolver(); final QLResolverOptions options = new QLResolverOptions(); final int atATime = 200; options.setFetchSize(atATime); queryResolver.setOptions(options); try (CloseableIterator<UserProfile> it = queryResolver.iterate()) { int count = 0; while (it.hasNext()) { UserProfile userProfile = it.next(); session.delete(userProfile); if (++count > atATime) { count = 0; session.flush(); // May need to clear action queues as well to free up memory. } } } catch (Exception e) { throw new HibernateException("Unable to iterate over query results.", e); } success = true; } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:com.facultyshowcase.app.model.ProfessorProfileDAO.java
License:Open Source License
/** * Delete the specified user profiles.// w w w . j a v a 2s. c o m * * @param qlBuilder a QL builder that will return ProfessorProfiles to delete. */ @WithTransaction public void deleteProfessorProfiles(QLBuilder qlBuilder) { final Session session = getSession(); final QLResolver queryResolver = qlBuilder.getQueryResolver(); final QLResolverOptions options = new QLResolverOptions(); final int atATime = 200; options.setFetchSize(atATime); queryResolver.setOptions(options); try (CloseableIterator<ProfessorProfile> it = queryResolver.iterate()) { int count = 0; while (it.hasNext()) { ProfessorProfile ProfessorProfile = it.next(); session.delete(ProfessorProfile); if (++count > atATime) { count = 0; session.flush(); // May need to clear action queues as well to free up memory. } } } catch (Exception e) { throw new HibernateException("Unable to iterate over query results.", e); } }