void flushStatements(final boolean useTenant) throws SPersistenceException { final Session session = getSession(useTenant); session.flush(); }
void flushStatements(final boolean useTenant) throws SPersistenceException { final Session session = getSession(useTenant); session.flush(); }
@Override protected Session getSession(final boolean useTenant) throws SPersistenceException { final Session session = super.getSession(useTenant); updateTenantFilter(session, useTenant); return session; }
@Override protected Session getSession(final boolean useTenant) throws SPersistenceException { final Session session = super.getSession(useTenant); updateTenantFilter(session, useTenant); return session; }
@Override public void insertInBatch(final List<? extends PersistentObject> entities) throws SPersistenceException { if (!entities.isEmpty()) { final Session session = getSession(true); for (final PersistentObject entity : entities) { final Class<? extends PersistentObject> entityClass = entity.getClass(); checkClassMapping(entityClass); setId(entity); session.save(entity); } } }
@Override public void insertInBatch(final List<? extends PersistentObject> entities) throws SPersistenceException { if (!entities.isEmpty()) { final Session session = getSession(true); for (final PersistentObject entity : entities) { final Class<? extends PersistentObject> entityClass = entity.getClass(); checkClassMapping(entityClass); setId(entity); session.save(entity); } } }
@Override public <T> T selectOne(final SelectOneDescriptor<T> selectDescriptor) throws SBonitaReadException { try { return selectOne(getSession(true), selectDescriptor); } catch (final SPersistenceException e) { throw new SBonitaReadException(e, selectDescriptor); } }
@Override public <T> T selectOne(final SelectOneDescriptor<T> selectDescriptor) throws SBonitaReadException { try { return selectOne(getSession(true), selectDescriptor); } catch (final SPersistenceException e) { throw new SBonitaReadException(e, selectDescriptor); } }
@Override public void insert(final PersistentObject entity) throws SPersistenceException { final Class<? extends PersistentObject> entityClass = entity.getClass(); checkClassMapping(entityClass); final Session session = getSession(true); setId(entity); try { session.save(entity); } catch (final AssertionFailure | LockAcquisitionException | StaleStateException e) { throw new SRetryableException(e); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public void update(final UpdateDescriptor updateDescriptor) throws SPersistenceException { // FIXME: deal with disconnected objects: final Class<? extends PersistentObject> entityClass = updateDescriptor.getEntity().getClass(); checkClassMapping(entityClass); final PersistentObject entity = updateDescriptor.getEntity(); final Session session = getSession(false); if (!session.contains(entity)) { throw new SPersistenceException("The object cannot be updated because it's disconnected " + entity); } for (final Map.Entry<String, Object> field : updateDescriptor.getFields().entrySet()) { setField(entity, field.getKey(), field.getValue()); } }
@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 int update(final String updateQueryName, final Map<String, Object> inputParameters) throws SPersistenceException { final Query query = getSession(true).getNamedQuery(updateQueryName); try { if (inputParameters != null) { setParameters(query, inputParameters); } return query.executeUpdate(); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public int update(final String updateQueryName, final Map<String, Object> inputParameters) throws SPersistenceException { final Query query = getSession(true).getNamedQuery(updateQueryName); try { if (inputParameters != null) { setParameters(query, inputParameters); } return query.executeUpdate(); } catch (final HibernateException he) { throw new SPersistenceException(he); } }
@Override public <T extends PersistentObject> T selectById(final SelectByIdDescriptor<T> selectDescriptor) throws SBonitaReadException { try { final Session session = getSession(true); final T object = this.selectById(session, selectDescriptor); if (selectDescriptor.isReadOnly()) { disconnectEntityFromSession(session, object); } return object; } catch (final SPersistenceException e) { throw new SBonitaReadException(e, selectDescriptor); } }
@Override public <T extends PersistentObject> T selectById(final SelectByIdDescriptor<T> selectDescriptor) throws SBonitaReadException { try { final Session session = getSession(true); final T object = this.selectById(session, selectDescriptor); if (selectDescriptor.isReadOnly()) { disconnectEntityFromSession(session, object); } return object; } catch (final SPersistenceException e) { throw new SBonitaReadException(e, selectDescriptor); } }
@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); } }
@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); } }