/** * {@inheritDoc} */ @Override public final <E extends IEntity> E cloneInUnitOfWork(E entity) { return cloneInUnitOfWork(Collections.singletonList(entity)).get(0); }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { IEntity entityClone = cloneInUnitOfWork(entity); resetTransientEntity(entityClone); merge(entityClone, EMergeMode.MERGE_EAGER); } });
/** * {@inheritDoc} */ @Override public void performPendingOperations() { Collection<IEntity> entitiesToUpdate = sessionUnitOfWork.getEntitiesRegisteredForUpdate(); Collection<IEntity> entitiesToDelete = sessionUnitOfWork.getEntitiesRegisteredForDeletion(); if (entitiesToUpdate != null) { List<IEntity> uowEntitiesToUpdate = cloneInUnitOfWork(new ArrayList<>(entitiesToUpdate)); for (IEntity uowEntity : uowEntitiesToUpdate) { // Must force insertion registerForUpdate(uowEntity); } } if (entitiesToDelete != null) { List<IEntity> uowEntitiesToDelete = cloneInUnitOfWork(new ArrayList<>(entitiesToDelete)); for (IEntity uowEntity : uowEntitiesToDelete) { // Must force deletion registerForDeletion(uowEntity); } } clearPendingOperations(); }
/** * {@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; }
if (isInitialized(propertyValue)) { uowComponent.straightSetProperty(propertyName, cloneInUnitOfWork((IEntity) propertyValue, alreadyCloned, eventsToRelease)); } else { uowComponent.straightSetProperty(propertyName, cloneUninitializedProperty(uowComponent, propertyValue)); IComponent uowOwningComponent; if (owningComponent instanceof IEntity) { uowOwningComponent = cloneInUnitOfWork((IEntity) owningComponent, alreadyCloned, eventsToRelease); } else { uowOwningComponent = cloneComponentInUnitOfWork(owningComponent, alreadyCloned, eventsToRelease);
if (isInitialized(propertyValue)) { uowEntity.straightSetProperty(propertyName, cloneInUnitOfWork((IEntity) propertyValue, alreadyCloned, eventsToRelease)); } else { uowEntity.straightSetProperty(propertyName, cloneUninitializedProperty(uowEntity, propertyValue)); if (collectionElement != null) { if (collectionElement instanceof IEntity) { uowCollection.add(cloneInUnitOfWork((IEntity) collectionElement, alreadyCloned, eventsToRelease)); } else if (collectionElement instanceof IComponent) { uowCollection.add( if (snapshotCollectionElement instanceof IEntity) { clonedSnapshotCollection.add( cloneInUnitOfWork((IEntity) snapshotCollectionElement, alreadyCloned, eventsToRelease)); } else if (snapshotCollectionElement instanceof IComponent) { clonedSnapshotCollection.add( IEntity[] uowArray = new IEntity[((IEntity[]) propertyValue).length]; for (int i = 0; i < uowArray.length; i++) { uowArray[i] = cloneInUnitOfWork(((IEntity[]) propertyValue)[i], alreadyCloned, eventsToRelease);
/** * {@inheritDoc} */ @Override public <E extends IEntity> List<E> cloneInUnitOfWork(List<E> entities) { IEntityRegistry uowEntityRegistry = getUowEntityRegistry(); final List<E> uowEntities = super.cloneInUnitOfWork(entities); IEntityRegistry alreadyDetached = createEntityRegistry("detachFromHibernateInDepth"); IEntityRegistry alreadyLocked = createEntityRegistry("lockInHibernateInDepth"); for (IEntity uowEntity : uowEntities) { // prevent detach/attach entities that were previously in the UOW for performance reasons. // see bug jspresso-ce-#103 if (uowEntity != null && uowEntityRegistry.get(getComponentContract(uowEntity), uowEntity.getId()) == null) { detachFromHibernate(uowEntity, getHibernateSession(), alreadyDetached); lockInHibernateInDepth(uowEntity, getHibernateSession(), alreadyLocked); } } return uowEntities; }