/** * Determines whether the instance is <em>Detached</em>, i.e. stored in database but not attached to a persistence * context at the moment. * * @param entity entity instance * @return - true if the instance is detached,<br> * - false if it is New or Managed, or if it is not a persistent entity * @throws IllegalArgumentException if entity instance is null */ public boolean isDetached(Object entity) { checkNotNullArgument(entity, "entity is null"); if (entity instanceof BaseGenericIdEntity && BaseEntityInternalAccess.isDetached((BaseGenericIdEntity) entity)) { return true; } else { if (log.isTraceEnabled()) { log.trace("EntityStates.isDetached is called for unsupported type '{}'. Stacktrace:\n{}", entity.getClass().getSimpleName(), StackTrace.asString()); } } return false; }
@Override public String toString() { String state = ""; if (isNew(this)) state += "new,"; if (isManaged(this)) state += "managed,"; if (isDetached(this)) state += "detached,"; if (isRemoved(this)) state += "removed,"; if (state.length() > 0) state = state.substring(0, state.length() - 1); return getClass().getName() + "-" + getId() + " [" + state + "]"; } }
protected void fireBeforeDetachEntityListener(BaseGenericIdEntity entity, String storeName) { if (!BaseEntityInternalAccess.isDetached(entity)) { CubaEntityFetchGroup.setAccessLocalUnfetched(false); try { entityListenerManager.fireListener(entity, EntityListenerType.BEFORE_DETACH, storeName); } finally { CubaEntityFetchGroup.setAccessLocalUnfetched(true); } } }
BaseGenericIdEntity<?> sourceGenericEntity = (BaseGenericIdEntity<?>) source; BaseEntityInternalAccess.setDetached(destGenericEntity, BaseEntityInternalAccess.isDetached(sourceGenericEntity)); BaseEntityInternalAccess.setNew(destGenericEntity, BaseEntityInternalAccess.isNew(sourceGenericEntity)); destGenericEntity.setDynamicAttributes(sourceGenericEntity.getDynamicAttributes());