@Override public void delete(final PersistentObject entity) throws SPersistenceException { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); try { if (session.contains(entity)) { session.delete(entity); } else { // Deletion must be performed on the session entity and not on a potential transitional entity. final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), 0)); session.delete(pe); } } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void delete(final PersistentObject entity) throws SPersistenceException { if (logger.isLoggable(getClass(), TechnicalLogSeverity.DEBUG)) { logger.log(this.getClass(), TechnicalLogSeverity.DEBUG, "Deleting instance of class " + entity.getClass().getSimpleName() + " with id=" + entity.getId()); } final Class<? extends PersistentObject> mappedClass = getMappedClass(entity.getClass()); final Session session = getSession(true); try { if (session.contains(entity)) { session.delete(entity); } else { // Deletion must be performed on the session entity and not on a potential transitional entity. final Object pe = session.get(mappedClass, new PersistentObjectId(entity.getId(), 0)); session.delete(pe); } } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void deleteAll(final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("deleteAll" + mappedClass.getSimpleName()); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void deleteAll(final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("deleteAll" + mappedClass.getSimpleName()); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void delete(final List<Long> ids, final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("deleteByIds" + mappedClass.getSimpleName()); query.setParameterList("ids", ids); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException sse) { throw new SPersistenceException(sse); } }
@Override public void delete(final long id, final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("delete" + mappedClass.getSimpleName()); query.setLong("id", id); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void delete(final long id, final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("delete" + mappedClass.getSimpleName()); query.setLong("id", id); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@SuppressWarnings("unchecked") <T extends PersistentObject> T selectById(final Session session, final SelectByIdDescriptor<T> selectDescriptor) throws SBonitaReadException { Class<? extends PersistentObject> mappedClass; try { mappedClass = getMappedClass(selectDescriptor.getEntityType()); } catch (final SPersistenceException e) { throw new SBonitaReadException(e); } try { return (T) session.get(mappedClass, selectDescriptor.getId()); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SBonitaReadException(he); } }
@SuppressWarnings("unchecked") <T extends PersistentObject> T selectById(final Session session, final SelectByIdDescriptor<T> selectDescriptor) throws SBonitaReadException { Class<? extends PersistentObject> mappedClass; try { mappedClass = getMappedClass(selectDescriptor.getEntityType()); } catch (final SPersistenceException e) { throw new SBonitaReadException(e); } try { return (T) session.get(mappedClass, selectDescriptor.getId()); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SBonitaReadException(he); } }
@Override public void delete(final List<Long> ids, final Class<? extends PersistentObject> entityClass) throws SPersistenceException { final Class<? extends PersistentObject> mappedClass = getMappedClass(entityClass); final Query query = getSession(true).getNamedQuery("deleteByIds" + mappedClass.getSimpleName()); query.setParameterList("ids", ids); try { query.executeUpdate(); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException sse) { throw new SPersistenceException(sse); } }