/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * <p>Will automatically apply a specified SQLExceptionTranslator to a * Hibernate JDBCException, else rely on Hibernate's default translation. * @param ex the HibernateException that occurred * @return a corresponding DataAccessException * @see SessionFactoryUtils#convertHibernateAccessException */ protected DataAccessException convertHibernateAccessException(HibernateException ex) { return SessionFactoryUtils.convertHibernateAccessException(ex); }
/** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. * <p>Will automatically apply a specified SQLExceptionTranslator to a * Hibernate JDBCException, else rely on Hibernate's default translation. * @param ex the HibernateException that occurred * @return a corresponding DataAccessException * @see SessionFactoryUtils#convertHibernateAccessException */ protected DataAccessException convertHibernateAccessException(HibernateException ex) { return SessionFactoryUtils.convertHibernateAccessException(ex); }
@Deprecated @Override public void closeIterator(Iterator<?> it) throws DataAccessException { try { Hibernate.close(it); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } }
@Override public void initialize(Object proxy) throws DataAccessException { try { Hibernate.initialize(proxy); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } }
/** * Trigger a flush on the given Hibernate Session, converting regular * {@link HibernateException} instances as well as Hibernate 5.2's * {@link PersistenceException} wrappers accordingly. * @param session the Hibernate Session to flush * @param synch whether this flush is triggered by transaction synchronization * @throws DataAccessException in case of flush failures * @since 4.3.2 */ static void flush(Session session, boolean synch) throws DataAccessException { if (synch) { logger.debug("Flushing Hibernate Session on transaction synchronization"); } else { logger.debug("Flushing Hibernate Session on explicit request"); } try { session.flush(); } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } catch (PersistenceException ex) { if (ex.getCause() instanceof HibernateException) { throw convertHibernateAccessException((HibernateException) ex.getCause()); } throw ex; } }
@Override public void initialize(Object proxy) throws DataAccessException { try { Hibernate.initialize(proxy); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } }
@Deprecated @Override public void closeIterator(Iterator<?> it) throws DataAccessException { try { Hibernate.close(it); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } }
/** * Trigger a flush on the given Hibernate Session, converting regular * {@link HibernateException} instances as well as Hibernate 5.2's * {@link PersistenceException} wrappers accordingly. * @param session the Hibernate Session to flush * @param synch whether this flush is triggered by transaction synchronization * @throws DataAccessException in case of flush failures * @since 4.3.2 */ static void flush(Session session, boolean synch) throws DataAccessException { if (synch) { logger.debug("Flushing Hibernate Session on transaction synchronization"); } else { logger.debug("Flushing Hibernate Session on explicit request"); } try { session.flush(); } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } catch (PersistenceException ex) { if (ex.getCause() instanceof HibernateException) { throw convertHibernateAccessException((HibernateException) ex.getCause()); } throw ex; } }
/** * Convert the given HibernateException to an appropriate exception from the * {@code org.springframework.dao} hierarchy. * <p>Will automatically apply a specified SQLExceptionTranslator to a * Hibernate JDBCException, otherwise rely on Hibernate's default translation. * @param ex the HibernateException that occurred * @return a corresponding DataAccessException * @see SessionFactoryUtils#convertHibernateAccessException */ protected DataAccessException convertHibernateAccessException(HibernateException ex) { if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) { JDBCException jdbcEx = (JDBCException) ex; DataAccessException dae = this.jdbcExceptionTranslator.translate( "Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException()); if (dae != null) { throw dae; } } return SessionFactoryUtils.convertHibernateAccessException(ex); }
throw SessionFactoryUtils.convertHibernateAccessException(ex); throw SessionFactoryUtils.convertHibernateAccessException((HibernateException) ex.getCause());
/** * Convert the given HibernateException to an appropriate exception from the * {@code org.springframework.dao} hierarchy. * <p>Will automatically apply a specified SQLExceptionTranslator to a * Hibernate JDBCException, otherwise rely on Hibernate's default translation. * @param ex the HibernateException that occurred * @return a corresponding DataAccessException * @see SessionFactoryUtils#convertHibernateAccessException */ protected DataAccessException convertHibernateAccessException(HibernateException ex) { if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) { JDBCException jdbcEx = (JDBCException) ex; DataAccessException dae = this.jdbcExceptionTranslator.translate( "Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException()); if (dae != null) { throw dae; } } return SessionFactoryUtils.convertHibernateAccessException(ex); }
throw SessionFactoryUtils.convertHibernateAccessException(ex); throw SessionFactoryUtils.convertHibernateAccessException((HibernateException) ex.getCause());
@Override public void initialize(Object proxy) throws DataAccessException { try { Hibernate.initialize(proxy); } catch (HibernateException ex) { throw SessionFactoryUtils.convertHibernateAccessException(ex); } }
@Override @Nullable public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof HibernateException) { return convertHibernateAccessException((HibernateException) ex); } if (ex instanceof PersistenceException) { if (ex.getCause() instanceof HibernateException) { return convertHibernateAccessException((HibernateException) ex.getCause()); } return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex); } return null; }
@Override public ContentItem findEventByIcalUid(String uid, CollectionItem calendar) { if (!(calendar instanceof HibCollectionItem)) { // External collections cannot be queried. return null; } try { TypedQuery<ContentItem> query = this.em.createNamedQuery("event.by.calendar.icaluid", ContentItem.class); query.setParameter("calendar", calendar); query.setParameter("uid", uid); List<ContentItem> resultList = query.getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return null; } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
@Override public ContentItem findEventByIcalUid(String uid, CollectionItem calendar) { if (!(calendar instanceof HibCollectionItem)) { // External collections cannot be queried. return null; } try { TypedQuery<ContentItem> query = this.em.createNamedQuery("event.by.calendar.icaluid", ContentItem.class); query.setParameter("calendar", calendar); query.setParameter("uid", uid); List<ContentItem> resultList = query.getResultList(); if (!resultList.isEmpty()) { return resultList.get(0); } return null; } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
public void removeUser(String username) { try { User user = findUserByUsername(username); // delete user if (user != null) { removeUser(user); } } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
public void removeUser(String username) { try { User user = findUserByUsername(username); // delete user if (user != null) { removeUser(user); } } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
@Override public Set<Item> findEvents(CollectionItem collection, Date rangeStart, Date rangeEnd, String timezoneId, boolean expandRecurringEvents) { // Create a NoteItemFilter that filters by parent NoteItemFilter itemFilter = new NoteItemFilter(); itemFilter.setParent(collection); // and EventStamp by timeRange EventStampFilter eventFilter = new EventStampFilter(); if (timezoneId != null) { TimeZone timeZone = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(timezoneId); eventFilter.setTimezone(timeZone); } eventFilter.setTimeRange(rangeStart, rangeEnd); eventFilter.setExpandRecurringEvents(expandRecurringEvents); itemFilter.getStampFilters().add(eventFilter); try { return itemFilterProcessor.processFilter(itemFilter); } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
@Override public Set<Item> findEvents(CollectionItem collection, Date rangeStart, Date rangeEnd, String timezoneId, boolean expandRecurringEvents) { // Create a NoteItemFilter that filters by parent NoteItemFilter itemFilter = new NoteItemFilter(); itemFilter.setParent(collection); // and EventStamp by timeRange EventStampFilter eventFilter = new EventStampFilter(); if (timezoneId != null) { TimeZone timeZone = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(timezoneId); eventFilter.setTimezone(timeZone); } eventFilter.setTimeRange(rangeStart, rangeEnd); eventFilter.setExpandRecurringEvents(expandRecurringEvents); itemFilter.getStampFilters().add(eventFilter); try { return itemFilterProcessor.processFilter(itemFilter); } catch (HibernateException e) { this.em.clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }