/** * {@inheritDoc} */ @Override public boolean isUpdated(IEntity entity) { if (!isActive()) { throw new BackendException("Cannot access unit of work."); } if (nestedUnitOfWork != null) { return nestedUnitOfWork.isUpdated(entity); } return updatedEntities != null && updatedEntities.contains(entity); }
/** * {@inheritDoc} */ @Override public Map<Class<? extends IEntity>, Map<Serializable, IEntity>> getUnitOfWorkEntities() { if (!isUnitOfWorkActive()) { throw new BackendException("Cannot query a unit of work that has not begun."); } return unitOfWork.getRegisteredEntities(); }
/** * {@inheritDoc} */ @Override public boolean isUpdatedInUnitOfWork(IEntity entity) { if (!isUnitOfWorkActive()) { throw new BackendException("Cannot access unit of work."); } return unitOfWork.isUpdated(entity); }
/** * {@inheritDoc} */ @Override public IEntity getUnitOfWorkEntity(Class<? extends IEntity> entityContract, Serializable entityId) { if (!isUnitOfWorkActive()) { throw new BackendException("Cannot query a unit of work that has not begun."); } return unitOfWork.getRegisteredEntity(entityContract, entityId); }
/** * {@inheritDoc} */ @Override public final void beginUnitOfWork() { if (isUnitOfWorkSuspended()) { return; } if (isUnitOfWorkActive()) { throw new BackendException("Cannot begin a new unit of work. Another one is already active."); } doBeginUnitOfWork(); }
private <E extends IEntity> void checkBadMergeUsage(E entity) { if (isUnitOfWorkActive()) { if (isInitialized(entity) && entity.isPersistent() && isDirty(entity)) { String message = MessageFormatter.arrayFormat( "*BAD MERGE USAGE* An attempt is made to merge a UOW dirty entity ({})[{}] to the application session.\n" + "This will break transaction isolation since, if the transaction is rolled back," + " the UOW dirty state will be kept.\n" + "Dirty UOW entities will be automatically merged whenever the transaction is committed.", new Object[]{entity, getComponentContract(entity).getSimpleName()}).getMessage(); LOG.error(message); if (isThrowExceptionOnBadUsage()) { throw new BackendException("A bad usage has been detected on the backend controller." + "This is certainly an application coding problem:\n" + message); } } } }
private Session getNoTxSession() { if (noTxSession == null) { if (noTxDataSource != null) { try { noTxSession = getHibernateSessionFactory().withOptions().connection(noTxDataSource.getConnection()) .openSession(); } catch (SQLException ex) { LOG.error("Couldn't get connection from non transactional data source {}", noTxDataSource); throw new BackendException(ex, "Couldn't get connection from non transactional data source"); } } else { noTxSession = getHibernateSessionFactory().openSession(); } noTxSession.setFlushMode(FlushMode.MANUAL); } return noTxSession; }
if (isEntityRegisteredForDeletion(uowEntity)) { if (readOnly) { throw new BackendException("The transaction is read-only but would lead to a flush in the database."); } else if (isDirtyInDepth(uowEntity)) { if (readOnly) { throw new BackendException("The transaction is read-only but would lead to a flush in the database.");
new Object[]{flushedEntity, flushedEntity.getComponentContract().getSimpleName()}).getMessage(); LOG.error(message); throw new BackendException( "An entity has been flushed to the persistent store without being first registered" + " in the UOW :\n" + message);
/** * {@inheritDoc} */ @Override public <E extends IEntity> List<E> cloneInUnitOfWork(List<E> entities) { if (!isUnitOfWorkActive()) { throw new BackendException("Cannot use a unit of work that has not begun."); } List<E> uowEntities = new ArrayList<>(); IEntityRegistry alreadyCloned = getUowEntityRegistry(); Set<IEntity> eventsToRelease = new LinkedHashSet<>(); boolean wasDirtyTrackingEnabled = isDirtyTrackingEnabled(); try { setDirtyTrackingEnabled(false); for (E entity : entities) { uowEntities.add(cloneInUnitOfWork(entity, alreadyCloned, eventsToRelease)); } } finally { for (IEntity entity : eventsToRelease) { try { entity.releaseEvents(); } catch (Throwable t) { LOG.error("An unexpected exception occurred when releasing events after a merge", t); } } setDirtyTrackingEnabled(wasDirtyTrackingEnabled); } return uowEntities; }
/** * {@inheritDoc} */ @Override public final void commitUnitOfWork() { if (isUnitOfWorkSuspended()) { return; } if (!isUnitOfWorkActive()) { throw new BackendException("Cannot commit a unit of work that has not begun."); } if (unitOfWork.hasNested()) { unitOfWork.commit(); } else { doCommitUnitOfWork(); } }
/** * {@inheritDoc} */ @Override public final void rollbackUnitOfWork() { if (isUnitOfWorkSuspended()) { return; } if (!isUnitOfWorkActive()) { throw new BackendException("Cannot rollback a unit of work that has not begun."); } if (unitOfWork.hasNested()) { unitOfWork.rollback(); } else { doRollbackUnitOfWork(); } }
LOG.error(message); if (isThrowExceptionOnBadUsage()) { throw new BackendException( "An invalid modification on a session entity has been detected while having an active Unit of Work:\n" + message); LOG.error(message); if (isThrowExceptionOnBadUsage()) { throw new BackendException( "An invalid usage of a session entity has been detected while having an active Unit of Work:\n" + message); LOG.error(message); if (isThrowExceptionOnBadUsage()) { throw new BackendException( "An invalid modification of an entity that was not previously registered in the session has been " + "detected:\n" + message); LOG.error(message); if (isThrowExceptionOnBadUsage()) { throw new BackendException( "An invalid usage of an entity that was not previously registered in the session has been detected:\n" + message);
Workspace parentWorkspace = getParentWorkspace(context); String parentWorkspaceName = parentWorkspace!=null ? parentWorkspace.getName() : "null"; throw new BackendException("Destination module not found for workpace '" + parentWorkspaceName + "' and module '" + getParentModuleName(context) + "'");