/** * {@inheritDoc} */ public void performPendingOperations() { clearPendingOperations(); }
/** * {@inheritDoc} */ public IEntity cloneInUnitOfWork(IEntity entity) { return cloneInUnitOfWork(Collections.singletonList(entity)).get(0); }
/** * {@inheritDoc} * * @return the username */ @Override public String getUsername() { if (getPrincipal() != null) { return getPrincipal().getName(); } return SecurityHelper.ANONYMOUS_USER_NAME; }
try { dirtRecorder.setEnabled(false); IEntity registeredEntity = getRegisteredEntity(entity.getContract(), entity.getId()); boolean newlyRegistered = false; if (mergeMode == MergeMode.MERGE_CLEAN_EAGER || mergeMode == MergeMode.MERGE_CLEAN_LAZY) { cleanDirtyProperties(registeredEntity); if (property.getValue() instanceof IEntity) { if (mergeMode != MergeMode.MERGE_CLEAN_EAGER && !isInitialized(property.getValue())) { if (registeredEntityProperties.get(property.getKey()) == null) { mergedProperties.put(property.getKey(), property.getValue()); Object registeredProperty = registeredEntityProperties .get(property.getKey()); if (isInitialized(registeredProperty)) { mergedProperties.put(property.getKey(), merge( (IEntity) property.getValue(), mergeMode, alreadyMerged)); && !isInitialized(property.getValue())) { if (registeredEntityProperties.get(property.getKey()) == null) { mergedProperties.put(property.getKey(), property.getValue()); Collection<IEntity> registeredCollection = (Collection<IEntity>) registeredEntityProperties .get(property.getKey()); if (isInitialized(registeredCollection)) {
for (Map.Entry<String, Object> property : entityProperties.entrySet()) { if (property.getValue() instanceof IEntity) { if (isInitialized(property.getValue())) { uowEntity.straightSetProperty(property.getKey(), cloneInUnitOfWork( (IEntity) property.getValue(), alreadyCloned)); } else { if (isInitialized(property.getValue())) { Collection<IEntity> uowEntityCollection = createTransientEntityCollection((Collection) property .getValue()); for (IEntity entityCollectionElement : (Collection<IEntity>) property .getValue()) { uowEntityCollection.add(cloneInUnitOfWork(entityCollectionElement, alreadyCloned)); .get(property.getKey()); if (snapshotCollection != null) { Collection clonedSnapshotCollection = createTransientEntityCollection(snapshotCollection); for (Object snapshotCollectionElement : snapshotCollection) { clonedSnapshotCollection.add(cloneInUnitOfWork( (IEntity) snapshotCollectionElement, alreadyCloned)); uowEntityCollection = wrapDetachedEntityCollection(entity, uowEntityCollection, snapshotCollection, property.getKey()); uowEntity.straightSetProperty(property.getKey(), uowEntityCollection); cloneComponentInUnitOfWork((IComponent) property.getValue(), alreadyCloned));
private IComponent cloneComponentInUnitOfWork(IComponent component, Map<Class<?>, Map<Serializable, IEntity>> alreadyCloned) { IComponent uowComponent = carbonEntityCloneFactory.cloneComponent( component, entityFactory); Map<String, Object> componentProperties = component.straightGetProperties(); for (Map.Entry<String, Object> property : componentProperties.entrySet()) { if (property.getValue() instanceof IEntity) { if (isInitialized(property.getValue())) { uowComponent.straightSetProperty(property.getKey(), cloneInUnitOfWork((IEntity) property.getValue(), alreadyCloned)); } else { uowComponent.straightSetProperty(property.getKey(), property .getValue()); } } else if (property.getValue() instanceof IComponent) { uowComponent.straightSetProperty(property.getKey(), cloneComponentInUnitOfWork((IComponent) property.getValue(), alreadyCloned)); } } return uowComponent; }
if (property.getValue() instanceof IEntity) { if (mergeMode != MergeMode.MERGE_CLEAN_EAGER && !isInitialized(property.getValue())) { if (registeredComponentProperties.get(property.getKey()) == null) { mergedProperties.put(property.getKey(), property.getValue()); Object registeredProperty = registeredComponentProperties .get(property.getKey()); if (isInitialized(registeredProperty)) { mergedProperties.put(property.getKey(), merge((IEntity) property .getValue(), mergeMode, alreadyMerged)); IComponent registeredSubComponent = (IComponent) registeredComponentProperties .get(property.getKey()); mergedProperties.put(property.getKey(), mergeComponent( (IComponent) property.getValue(), registeredSubComponent, mergeMode, alreadyMerged));
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public void initializePropertyIfNeeded(IComponent componentOrEntity, IPropertyDescriptor propertyDescriptor) { if (propertyDescriptor instanceof ICollectionPropertyDescriptor) { String propertyName = propertyDescriptor.getName(); Object propertyValue = componentOrEntity .straightGetProperty(propertyName); sortCollectionProperty(componentOrEntity, propertyName); for (Iterator<IEntity> ite = ((Collection<IEntity>) propertyValue) .iterator(); ite.hasNext();) { IEntity collectionElement = ite.next(); if (isEntityRegisteredForDeletion(collectionElement)) { ite.remove(); } } } }
/** * {@inheritDoc} */ public void commitUnitOfWork() { if (!unitOfWork.isActive()) { throw new ApplicationSessionException( "Cannot commit a unit of work that has not begun."); } try { Map<IEntity, IEntity> alreadyMerged = new HashMap<IEntity, IEntity>(); for (IEntity entityToMergeBack : entitiesToMergeBack) { merge(entityToMergeBack, MergeMode.MERGE_CLEAN_LAZY, alreadyMerged); } } finally { unitOfWork.commit(); entitiesToMergeBack = null; clearPendingOperations(); } }
/** * {@inheritDoc} */ public boolean isDirty(IEntity entity) { if (unitOfWork.isActive()) { return unitOfWork.isDirty(entity); } Map<String, Object> entityDirtyProperties = getDirtyProperties(entity); return (entityDirtyProperties != null && entityDirtyProperties.size() > 0); }
/** * {@inheritDoc} */ public boolean isDirty(IEntity entity, String propertyName) { if (unitOfWork.isActive()) { return unitOfWork.isDirty(entity, propertyName); } Map<String, Object> entityDirtyProperties = getDirtyProperties(entity); return (entityDirtyProperties != null && entityDirtyProperties .containsKey(propertyName)); }
/** * {@inheritDoc} */ public List<IEntity> cloneInUnitOfWork(List<IEntity> entities) { List<IEntity> uowEntities = new ArrayList<IEntity>(); Map<Class<?>, Map<Serializable, IEntity>> alreadyCloned = new HashMap<Class<?>, Map<Serializable, IEntity>>(); for (IEntity entity : entities) { uowEntities.add(cloneInUnitOfWork(entity, alreadyCloned)); } return uowEntities; }