/** * INTERNAL: * Return FetchGroup held by the object. */ public FetchGroup getObjectFetchGroup(Object domainObject) { if (domainObject != null) { return ((FetchGroupTracker)domainObject)._persistence_getFetchGroup(); } return null; }
/** * Set this EntityFetchGroup on an entity implementing * {@link FetchGroupTracker}. */ public void setOnEntity(Object entity, AbstractSession session) { ((FetchGroupTracker)entity)._persistence_setFetchGroup(this); ((FetchGroupTracker)entity)._persistence_setSession(session); }
/** * INTERNAL: * Reset object attributes to the default values. */ public void reset(Object source) { ((FetchGroupTracker)source)._persistence_resetFetchGroup(); }
/** * INTERNAL: * Return true if the cached object data should be written in clone. * It is used in Fetch Group case when filling in the clone from the cached object. */ public boolean shouldWriteInto(Object cachedObject, Object clone) { FetchGroup fetchGroupInTarg = ((FetchGroupTracker)clone)._persistence_getFetchGroup(); if (fetchGroupInTarg != null) { FetchGroup fetchGroupInSrc = ((FetchGroupTracker)cachedObject)._persistence_getFetchGroup(); //should write if target's fetch group is not a superset of that of the source, //or if refresh is required, should always write (either refresh or revert) data from the cache to the clones. return !fetchGroupInTarg.isSupersetOf(fetchGroupInSrc) || ((FetchGroupTracker) cachedObject)._persistence_shouldRefreshFetchGroup(); } return false; }
/** * Called on attempt to assign value to an attribute that hasn't been fetched yet. * Returns an error message in case exception should be thrown by the calling method, * null otherwise. */ @Override public String onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName) { if (entity._persistence_getSession() != null) { return super.onUnfetchedAttributeForSet(entity, attributeName); } else { entity._persistence_setFetchGroup(new EntityFetchGroup(this, attributeName)); return null; } }
protected void mergeSystemState(Entity srcEntity, Entity dstEntity) { if (dstEntity instanceof BaseGenericIdEntity) { BaseEntityInternalAccess.copySystemState((BaseGenericIdEntity) srcEntity, (BaseGenericIdEntity) dstEntity); if (srcEntity instanceof FetchGroupTracker && dstEntity instanceof FetchGroupTracker) { FetchGroup srcFetchGroup = ((FetchGroupTracker) srcEntity)._persistence_getFetchGroup(); FetchGroup dstFetchGroup = ((FetchGroupTracker) dstEntity)._persistence_getFetchGroup(); if (srcFetchGroup == null || dstFetchGroup == null) { ((FetchGroupTracker) dstEntity)._persistence_setFetchGroup(null); } else { ((FetchGroupTracker) dstEntity)._persistence_setFetchGroup(FetchGroupUtils.mergeFetchGroups(srcFetchGroup, dstFetchGroup)); } } } else if (dstEntity instanceof AbstractNotPersistentEntity) { BaseEntityInternalAccess.setNew((AbstractNotPersistentEntity) dstEntity, BaseEntityInternalAccess.isNew((AbstractNotPersistentEntity) srcEntity)); } }
return rootEntity._persistence_getFetchGroup().onUnfetchedAttribute(rootEntity, attributeName); Session session = entity._persistence_getSession(); boolean shouldLoadResultIntoSelectionObject = false; if (session.isUnitOfWork()) { query.setShouldMaintainCache(false); entity._persistence_setFetchGroup(null); entity._persistence_setSession(null); entity._persistence_setFetchGroup(this); entity._persistence_setSession(session);
protected void makeDetached(Object instance) { if (instance instanceof BaseGenericIdEntity) { BaseEntityInternalAccess.setNew((BaseGenericIdEntity) instance, false); BaseEntityInternalAccess.setManaged((BaseGenericIdEntity) instance, false); BaseEntityInternalAccess.setDetached((BaseGenericIdEntity) instance, true); } if (instance instanceof FetchGroupTracker) { ((FetchGroupTracker) instance)._persistence_setSession(null); } if (instance instanceof ChangeTracker) { ((ChangeTracker) instance)._persistence_setPropertyChangeListener(null); } }
/** * INTERNAL: * Set if the tracked object is fetched from executing a query with or without refresh. */ public void setRefreshOnFetchGroupToObject(Object source, boolean shouldRefreshOnFetchgroup) { ((FetchGroupTracker)source)._persistence_setShouldRefreshFetchGroup(shouldRefreshOnFetchgroup); }
/** * Called on attempt to get value of an attribute that hasn't been fetched yet. * Returns an error message in case exception should be thrown by the calling method, * null otherwise. */ @Override public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName) { if (entity._persistence_getSession() != null) { return super.onUnfetchedAttribute(entity, attributeName); } throw new IllegalStateException(ExceptionLocalization.buildMessage("cannot_get_unfetched_attribute", new Object[]{entity, attributeName})); }
@Override public void postRefresh(DescriptorEvent event) { if (event.getObject() instanceof FetchGroupTracker) { FetchGroupTracker entity = (FetchGroupTracker) event.getObject(); FetchGroup fetchGroup = entity._persistence_getFetchGroup(); if (fetchGroup != null && !(fetchGroup instanceof CubaEntityFetchGroup)) entity._persistence_setFetchGroup(new CubaEntityFetchGroup(fetchGroup)); } }
public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName, FetchGroup newFetchGroup) { if (rootEntity != null){ return rootEntity._persistence_getFetchGroup().onUnfetchedAttribute(rootEntity, attributeName); Session session = entity._persistence_getSession(); if (session instanceof UnitOfWorkImpl) { if (((UnitOfWorkImpl) session).getLifecycle() >= UnitOfWorkImpl.Death) { query.setShouldMaintainCache(false); entity._persistence_setFetchGroup(null); entity._persistence_setSession(null); } else if (newFetchGroup != null) { query.setFetchGroup(newFetchGroup); entity._persistence_setFetchGroup(this); entity._persistence_setSession(session);
/** * INTERNAL: * Return true if the cached object data should be written in clone. * It is used in Fetch Group case when filling in the clone from the cached object. */ public boolean shouldWriteInto(Object cachedObject, Object clone) { FetchGroup fetchGroupInTarg = ((FetchGroupTracker)clone)._persistence_getFetchGroup(); if (fetchGroupInTarg != null) { FetchGroup fetchGroupInSrc = ((FetchGroupTracker)cachedObject)._persistence_getFetchGroup(); //should write if target's fetch group is not a superset of that of the source, //or if refresh is required, should always write (either refresh or revert) data from the cache to the clones. return !fetchGroupInTarg.isSupersetOf(fetchGroupInSrc) || ((FetchGroupTracker) cachedObject)._persistence_shouldRefreshFetchGroup(); } return false; }
((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(context.getEmf()));
/** * Called on attempt to assign value to an attribute that hasn't been fetched yet. * Returns an error message in case exception should be thrown by the calling method, * null otherwise. */ @Override public String onUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName) { if (entity._persistence_getSession() != null) { return super.onUnfetchedAttributeForSet(entity, attributeName); } else { entity._persistence_setFetchGroup(new EntityFetchGroup(this, attributeName)); return null; } }
/** * INTERNAL: * Set if the tracked object is fetched from executing a query with or without refresh. */ public void setRefreshOnFetchGroupToObject(Object source, boolean shouldRefreshOnFetchgroup) { ((FetchGroupTracker)source)._persistence_setShouldRefreshFetchGroup(shouldRefreshOnFetchgroup); }
/** * Called on attempt to get value of an attribute that hasn't been fetched yet. * Returns an error message in case exception should be thrown by the calling method, * null otherwise. */ @Override public String onUnfetchedAttribute(FetchGroupTracker entity, String attributeName) { if (entity._persistence_getSession() != null) { return super.onUnfetchedAttribute(entity, attributeName); } throw new IllegalStateException(ExceptionLocalization.buildMessage("cannot_get_unfetched_attribute", new Object[]{entity, attributeName})); }
/** * INTERNAL: * Return true if the object is partially fetched and cached. * It applies to the query with fetch group. */ public boolean isPartialObject(Object domainObject) { if (domainObject != null) { FetchGroup fetchGroupInCache = ((FetchGroupTracker)domainObject)._persistence_getFetchGroup(); //if the fetch group reference is not null, it means the object is partial. return (fetchGroupInCache != null); } return false; }
@Override public void postBuild(DescriptorEvent event) { if (event.getObject() instanceof BaseGenericIdEntity) { BaseEntityInternalAccess.setNew((BaseGenericIdEntity) event.getObject(), false); } if (event.getObject() instanceof FetchGroupTracker) { FetchGroupTracker entity = (FetchGroupTracker) event.getObject(); FetchGroup fetchGroup = entity._persistence_getFetchGroup(); if (fetchGroup != null && !(fetchGroup instanceof CubaEntityFetchGroup)) entity._persistence_setFetchGroup(new CubaEntityFetchGroup(fetchGroup)); } }
/** * INTERNAL: * Reset object attributes to the default their values. */ public void setObjectFetchGroup(Object source, FetchGroup fetchGroup, AbstractSession session) { FetchGroupTracker tracker = (FetchGroupTracker)source; tracker._persistence_setFetchGroup(fetchGroup); tracker._persistence_setSession(session); }