Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/Delegator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/Delegator.java?rev=1621696&r1=1621695&r2=1621696&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/Delegator.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/Delegator.java Mon Sep 1 07:29:23 2014 @@ -51,17 +51,17 @@ public interface Delegator { enum OperationType {INSERT, UPDATE, DELETE} - public void clearAllCacheLinesByDummyPK(Collection<GenericPK> dummyPKs); + void clearAllCacheLinesByDummyPK(Collection<GenericPK> dummyPKs); - public void clearAllCacheLinesByValue(Collection<GenericValue> values); + void clearAllCacheLinesByValue(Collection<GenericValue> values); /** * This method is a shortcut to completely clear all entity engine caches. * For performance reasons this should not be called very often. */ - public void clearAllCaches(); + void clearAllCaches(); - public void clearAllCaches(boolean distribute); + void clearAllCaches(boolean distribute); /** * Remove a CACHED Generic Entity from the cache by its primary key, does @@ -71,9 +71,9 @@ public interface Delegator { * @param primaryKey * The primary key to clear by. */ - public void clearCacheLine(GenericPK primaryKey); + void clearCacheLine(GenericPK primaryKey); - public void clearCacheLine(GenericPK primaryKey, boolean distribute); + void clearCacheLine(GenericPK primaryKey, boolean distribute); /** * Remove a CACHED GenericValue from as many caches as it can. Automatically @@ -84,9 +84,9 @@ public interface Delegator { * @param value * The GenericValue to clear by. */ - public void clearCacheLine(GenericValue value); + void clearCacheLine(GenericValue value); - public void clearCacheLine(GenericValue value, boolean distribute); + void clearCacheLine(GenericValue value, boolean distribute); /** * Remove all CACHED Generic Entity (List) from the cache @@ -94,7 +94,7 @@ public interface Delegator { * @param entityName * The Name of the Entity as defined in the entity XML file */ - public void clearCacheLine(String entityName); + void clearCacheLine(String entityName); /** * Remove a CACHED Generic Entity (List) from the cache, either a PK, ByAnd, @@ -106,7 +106,7 @@ public interface Delegator { * The fields of the named entity to query by with their * corresponding values */ - public void clearCacheLine(String entityName, Map<String, ? extends Object> fields); + void clearCacheLine(String entityName, Map<String, ? extends Object> fields); /** * Remove a CACHED Generic Entity (List) from the cache, either a PK, ByAnd, @@ -118,11 +118,11 @@ public interface Delegator { * The fields of the named entity to query by with their * corresponding values */ - public void clearCacheLine(String entityName, Object... fields); + void clearCacheLine(String entityName, Object... fields); - public void clearCacheLineByCondition(String entityName, EntityCondition condition); + void clearCacheLineByCondition(String entityName, EntityCondition condition); - public void clearCacheLineByCondition(String entityName, EntityCondition condition, boolean distribute); + void clearCacheLineByCondition(String entityName, EntityCondition condition, boolean distribute); /** * Remove a CACHED Generic Entity from the cache by its primary key. Checks @@ -135,13 +135,13 @@ public interface Delegator { * @param dummyPK * The dummy primary key to clear by. */ - public void clearCacheLineFlexible(GenericEntity dummyPK); + void clearCacheLineFlexible(GenericEntity dummyPK); - public void clearCacheLineFlexible(GenericEntity dummyPK, boolean distribute); + void clearCacheLineFlexible(GenericEntity dummyPK, boolean distribute); - public GenericDelegator cloneDelegator(); + Delegator cloneDelegator(); - public GenericDelegator cloneDelegator(String delegatorName); + Delegator cloneDelegator(String delegatorName); /** * Creates a Entity in the form of a GenericValue and write it to the @@ -151,7 +151,7 @@ public interface Delegator { * The GenericPK to create a value in the datasource from * @return GenericValue instance containing the new instance */ - public GenericValue create(GenericPK primaryKey) throws GenericEntityException; + GenericValue create(GenericPK primaryKey) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -167,7 +167,7 @@ public interface Delegator { * @deprecated use {@link #create(GenericPK primaryKey)} */ @Deprecated - public GenericValue create(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; + GenericValue create(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -177,7 +177,7 @@ public interface Delegator { * The GenericValue to create a value in the datasource from * @return GenericValue instance containing the new instance */ - public GenericValue create(GenericValue value) throws GenericEntityException; + GenericValue create(GenericValue value) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -193,7 +193,7 @@ public interface Delegator { * @deprecated use {@link #create(GenericValue value)} */ @Deprecated - public GenericValue create(GenericValue value, boolean doCacheClear) throws GenericEntityException; + GenericValue create(GenericValue value, boolean doCacheClear) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -201,7 +201,7 @@ public interface Delegator { * * @return GenericValue instance containing the new instance */ - public GenericValue create(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + GenericValue create(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -209,7 +209,7 @@ public interface Delegator { * * @return GenericValue instance containing the new instance */ - public GenericValue create(String entityName, Object... fields) throws GenericEntityException; + GenericValue create(String entityName, Object... fields) throws GenericEntityException; /** * Creates or stores an Entity @@ -219,7 +219,7 @@ public interface Delegator { * instance * @return GenericValue instance containing the new or updated instance */ - public GenericValue createOrStore(GenericValue value) throws GenericEntityException; + GenericValue createOrStore(GenericValue value) throws GenericEntityException; /** * Creates or stores an Entity @@ -235,7 +235,7 @@ public interface Delegator { * @deprecated use {@link #createOrStore(GenericValue value)} */ @Deprecated - public GenericValue createOrStore(GenericValue value, boolean doCacheClear) throws GenericEntityException; + GenericValue createOrStore(GenericValue value, boolean doCacheClear) throws GenericEntityException; /** * Sets the sequenced ID (for entity with one primary key field ONLY), and @@ -247,7 +247,7 @@ public interface Delegator { * The GenericValue to create a value in the datasource from * @return GenericValue instance containing the new instance */ - public GenericValue createSetNextSeqId(GenericValue value) throws GenericEntityException; + GenericValue createSetNextSeqId(GenericValue value) throws GenericEntityException; /** * Creates a Entity in the form of a GenericValue and write it to the @@ -255,26 +255,26 @@ public interface Delegator { * * @return GenericValue instance containing the new instance */ - public GenericValue createSingle(String entityName, Object singlePkValue) throws GenericEntityException; + GenericValue createSingle(String entityName, Object singlePkValue) throws GenericEntityException; @Deprecated - public void decryptFields(GenericEntity entity) throws GenericEntityException; + void decryptFields(GenericEntity entity) throws GenericEntityException; @Deprecated - public void decryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + void decryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; @Deprecated - public void encryptFields(GenericEntity entity) throws GenericEntityException; + void encryptFields(GenericEntity entity) throws GenericEntityException; @Deprecated - public void encryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + void encryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; - public Object decryptFieldValue(String entityName, String encValue) throws EntityCryptoException; + Object decryptFieldValue(String entityName, String encValue) throws EntityCryptoException; @Deprecated - public Object encryptFieldValue(String entityName, Object fieldValue) throws EntityCryptoException; + Object encryptFieldValue(String entityName, Object fieldValue) throws EntityCryptoException; - public Object encryptFieldValue(String entityName, ModelField.EncryptMethod encryptMethod, Object fieldValue) throws EntityCryptoException; + Object encryptFieldValue(String entityName, ModelField.EncryptMethod encryptMethod, Object fieldValue) throws EntityCryptoException; /** * Finds GenericValues by the conditions specified in the EntityCondition @@ -306,7 +306,7 @@ public interface Delegator { * ARE DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT * WILL MAINTAIN A DATABASE CONNECTION. */ - public EntityListIterator find(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; + EntityListIterator find(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; /** * Finds all Generic entities @@ -317,7 +317,7 @@ public interface Delegator { * Whether to cache the results * @return List containing all Generic entities */ - public List<GenericValue> findAll(String entityName, boolean useCache) throws GenericEntityException; + List<GenericValue> findAll(String entityName, boolean useCache) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -332,7 +332,7 @@ public interface Delegator { * @deprecated use {@link #findByAnd(String, Map, List, boolean)} */ @Deprecated - public List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -351,7 +351,7 @@ public interface Delegator { * @deprecated use {@link #findByAnd(String, Map, List, boolean)} */ @Deprecated - public List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; + List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -366,7 +366,7 @@ public interface Delegator { * @deprecated use {@link #findByAnd(String, Map, List, boolean)} */ @Deprecated - public List<GenericValue> findByAnd(String entityName, Object... fields) throws GenericEntityException; + List<GenericValue> findByAnd(String entityName, Object... fields) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -382,7 +382,7 @@ public interface Delegator { * @deprecated use {@link #findByAnd(String, Map, List, boolean)} */ @Deprecated - public List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -402,7 +402,7 @@ public interface Delegator { * @deprecated use {@link #findByAnd(String, Map, List, boolean)} */ @Deprecated - public List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; + List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; /** * Finds Generic Entity records by all of the specified fields (ie: combined @@ -422,7 +422,7 @@ public interface Delegator { * Whether to cache the results * @return List of GenericValue instances that match the query */ - public List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy, boolean useCache) throws GenericEntityException; + List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy, boolean useCache) throws GenericEntityException; /** * Find a Generic Entity by its Primary Key NOTE 20080502: 550 references @@ -438,7 +438,7 @@ public interface Delegator { * @deprecated use {@link #findOne(String, Map, boolean)} */ @Deprecated - public GenericValue findByPrimaryKey(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + GenericValue findByPrimaryKey(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Find a CACHED Generic Entity by its Primary Key NOTE 20080502: 218 @@ -453,7 +453,7 @@ public interface Delegator { * @deprecated use {@link #findOne(String, Map, boolean)} */ @Deprecated - public GenericValue findByPrimaryKeyCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + GenericValue findByPrimaryKeyCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Find a CACHED Generic Entity by its Primary Key NOTE 20080502: 2 @@ -468,7 +468,7 @@ public interface Delegator { * @deprecated use {@link #findOne(String, boolean, Object...)} */ @Deprecated - public GenericValue findByPrimaryKeyCache(String entityName, Object... fields) throws GenericEntityException; + GenericValue findByPrimaryKeyCache(String entityName, Object... fields) throws GenericEntityException; /** * Find a Generic Entity by its Primary Key and only returns the values @@ -481,12 +481,12 @@ public interface Delegator { * values will be retrieved * @return The GenericValue corresponding to the primaryKey */ - public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException; + GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException; /** * NOTE 20080502: 2 references */ - public long findCountByCondition(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; + long findCountByCondition(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; /** * Finds GenericValues by the conditions specified in the EntityCondition @@ -511,7 +511,7 @@ public interface Delegator { * options. See the EntityFindOptions JavaDoc for more details. * @return List of GenericValue objects representing the result */ - public List<GenericValue> findList(String entityName, EntityCondition entityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions, boolean useCache) throws GenericEntityException; + List<GenericValue> findList(String entityName, EntityCondition entityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions, boolean useCache) throws GenericEntityException; /** * Finds GenericValues by the conditions specified in the EntityCondition @@ -544,7 +544,7 @@ public interface Delegator { * LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE * CONNECTION. */ - public EntityListIterator findListIteratorByCondition(DynamicViewEntity dynamicViewEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; + EntityListIterator findListIteratorByCondition(DynamicViewEntity dynamicViewEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; /** * Find a Generic Entity by its primary key. @@ -555,7 +555,7 @@ public interface Delegator { * @return The Generic Entity corresponding to the primary key * @throws GenericEntityException */ - public GenericValue findOne(String entityName, boolean useCache, Object... fields) throws GenericEntityException; + GenericValue findOne(String entityName, boolean useCache, Object... fields) throws GenericEntityException; /** * Find a Generic Entity by its Primary Key NOTE 20080502: 6 references @@ -567,15 +567,21 @@ public interface Delegator { * corresponding values * @return The GenericValue corresponding to the primaryKey */ - public GenericValue findOne(String entityName, Map<String, ? extends Object> fields, boolean useCache) throws GenericEntityException; + GenericValue findOne(String entityName, Map<String, ? extends Object> fields, boolean useCache) throws GenericEntityException; - public Cache getCache(); + Cache getCache(); - public String getDelegatorName(); - public String getDelegatorBaseName(); - public String getDelegatorTenantId(); + String getCurrentSessionIdentifier(); - public <T> EntityEcaHandler<T> getEntityEcaHandler(); + String getCurrentUserIdentifier(); + + String getDelegatorName(); + + String getDelegatorBaseName(); + + String getDelegatorTenantId(); + + <T> EntityEcaHandler<T> getEntityEcaHandler(); /** * Gets a field type instance by name from the helper that corresponds to @@ -588,7 +594,7 @@ public interface Delegator { * @return ModelFieldType instance for the named type from the helper that * corresponds to the specified entity */ - public ModelFieldType getEntityFieldType(ModelEntity entity, String type) throws GenericEntityException; + ModelFieldType getEntityFieldType(ModelEntity entity, String type) throws GenericEntityException; /** * Gets field type names from the helper that corresponds to the specified @@ -599,7 +605,7 @@ public interface Delegator { * @return Collection of field type names from the helper that corresponds * to the specified entity */ - public Collection<String> getEntityFieldTypeNames(ModelEntity entity) throws GenericEntityException; + Collection<String> getEntityFieldTypeNames(ModelEntity entity) throws GenericEntityException; /** * Gets the helper name that corresponds to this delegator and the specified @@ -610,7 +616,7 @@ public interface Delegator { * @return String with the helper name that corresponds to this delegator * and the specified entityName */ - public String getEntityGroupName(String entityName); + String getEntityGroupName(String entityName); /** * Gets the an instance of helper that corresponds to this delegator and the @@ -621,7 +627,7 @@ public interface Delegator { * @return GenericHelper that corresponds to this delegator and the * specified entity */ - public GenericHelper getEntityHelper(ModelEntity entity) throws GenericEntityException; + GenericHelper getEntityHelper(ModelEntity entity) throws GenericEntityException; /** * Gets the an instance of helper that corresponds to this delegator and the @@ -632,7 +638,7 @@ public interface Delegator { * @return GenericHelper that corresponds to this delegator and the * specified entityName */ - public GenericHelper getEntityHelper(String entityName) throws GenericEntityException; + GenericHelper getEntityHelper(String entityName) throws GenericEntityException; /** * Gets the helper name that corresponds to this delegator and the specified @@ -643,7 +649,7 @@ public interface Delegator { * @return String with the helper name that corresponds to this delegator * and the specified entity */ - public String getEntityHelperName(ModelEntity entity); + String getEntityHelperName(ModelEntity entity); /** * Gets the helper name that corresponds to this delegator and the specified @@ -654,9 +660,9 @@ public interface Delegator { * @return String with the helper name that corresponds to this delegator * and the specified entityName */ - public String getEntityHelperName(String entityName); + String getEntityHelperName(String entityName); - public GenericValue getFromPrimaryKeyCache(GenericPK primaryKey); + GenericValue getFromPrimaryKeyCache(GenericPK primaryKey); /** * Gets the helper name that corresponds to this delegator and the specified @@ -667,9 +673,9 @@ public interface Delegator { * @return String with the helper name that corresponds to this delegator * and the specified entityName */ - public String getGroupHelperName(String groupName); + String getGroupHelperName(String groupName); - public GenericHelperInfo getGroupHelperInfo(String entityGroupName); + GenericHelperInfo getGroupHelperInfo(String entityGroupName); /** * Gets the instance of ModelEntity that corresponds to this delegator and @@ -680,7 +686,7 @@ public interface Delegator { * @return ModelEntity that corresponds to this delegator and the specified * entityName */ - public ModelEntity getModelEntity(String entityName); + ModelEntity getModelEntity(String entityName); /** * Gets a Map of entity name & entity model pairs that are in the named @@ -690,23 +696,23 @@ public interface Delegator { * The name of the group * @return Map of entityName String keys and ModelEntity instance values */ - public Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) throws GenericEntityException; + Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) throws GenericEntityException; - public ModelFieldTypeReader getModelFieldTypeReader(ModelEntity entity); + ModelFieldTypeReader getModelFieldTypeReader(ModelEntity entity); /** * Gets the instance of ModelGroupReader that corresponds to this delegator * * @return ModelGroupReader that corresponds to this delegator */ - public ModelGroupReader getModelGroupReader(); + ModelGroupReader getModelGroupReader(); /** * Gets the instance of ModelReader that corresponds to this delegator * * @return ModelReader that corresponds to this delegator */ - public ModelReader getModelReader(); + ModelReader getModelReader(); /** * Get the named Related Entity for the GenericValue from the persistent @@ -728,7 +734,7 @@ public interface Delegator { * @return List of GenericValue instances as specified in the relation * definition */ - public List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException; + List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException; /** * Get the next guaranteed unique seq id from the sequence with the given @@ -738,7 +744,7 @@ public interface Delegator { * The name of the sequence to get the next seq id from * @return String with the next sequenced id for the given sequence name */ - public String getNextSeqId(String seqName); + String getNextSeqId(String seqName); /** * Get the next guaranteed unique seq id from the sequence with the given @@ -753,7 +759,7 @@ public interface Delegator { * staggerMax * @return Long with the next seq id for the given sequence name */ - public String getNextSeqId(String seqName, long staggerMax); + String getNextSeqId(String seqName, long staggerMax); /** * Get the next guaranteed unique seq id from the sequence with the given @@ -763,7 +769,7 @@ public interface Delegator { * The name of the sequence to get the next seq id from * @return Long with the next sequenced id for the given sequence name */ - public Long getNextSeqIdLong(String seqName); + Long getNextSeqIdLong(String seqName); /** * Get the next guaranteed unique seq id from the sequence with the given @@ -778,7 +784,7 @@ public interface Delegator { * staggerMax * @return Long with the next seq id for the given sequence name */ - public Long getNextSeqIdLong(String seqName, long staggerMax); + Long getNextSeqIdLong(String seqName, long staggerMax); /** * Gets the name of the server configuration that corresponds to this @@ -786,7 +792,7 @@ public interface Delegator { * * @return server configuration name */ - public String getOriginalDelegatorName(); + String getOriginalDelegatorName(); /** * Get the named Related Entity for the GenericValue from the persistent @@ -809,7 +815,7 @@ public interface Delegator { * @deprecated use {@link #getRelated(String, Map, List, GenericValue, boolean)} */ @Deprecated - public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value) throws GenericEntityException; + List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value) throws GenericEntityException; /** * Get the named Related Entity for the GenericValue from the persistent @@ -827,7 +833,7 @@ public interface Delegator { * @deprecated use {@link #getRelated(String, Map, List, GenericValue, boolean)} */ @Deprecated - public List<GenericValue> getRelatedCache(String relationName, GenericValue value) throws GenericEntityException; + List<GenericValue> getRelatedCache(String relationName, GenericValue value) throws GenericEntityException; /** * Get the named Related Entity for the GenericValue from the persistent @@ -850,7 +856,7 @@ public interface Delegator { * @return List of GenericValue instances as specified in the relation * definition */ - public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value, boolean useCache) throws GenericEntityException; + List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value, boolean useCache) throws GenericEntityException; /** * Get a dummy primary key for the named Related Entity for the GenericValue @@ -867,7 +873,7 @@ public interface Delegator { * @return GenericPK containing a possibly incomplete PrimaryKey object * representing the related entity or entities */ - public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException; + GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException; /** * Get related entity where relation is of type one, uses findOne @@ -878,7 +884,7 @@ public interface Delegator { * @deprecated use {@link #getRelatedOne(String, GenericValue, boolean)} */ @Deprecated - public GenericValue getRelatedOne(String relationName, GenericValue value) throws GenericEntityException; + GenericValue getRelatedOne(String relationName, GenericValue value) throws GenericEntityException; /** * Get related entity where relation is of type one, uses findOne @@ -890,7 +896,7 @@ public interface Delegator { * @deprecated use {@link #getRelatedOne(String, GenericValue, boolean)} */ @Deprecated - public GenericValue getRelatedOneCache(String relationName, GenericValue value) throws GenericEntityException; + GenericValue getRelatedOneCache(String relationName, GenericValue value) throws GenericEntityException; /** * Get related entity where relation is of type one, uses findByPrimaryKey @@ -907,62 +913,62 @@ public interface Delegator { * @throws IllegalArgumentException * if the list found has more than one item */ - public GenericValue getRelatedOne(String relationName, GenericValue value, boolean useCache) throws GenericEntityException; + GenericValue getRelatedOne(String relationName, GenericValue value, boolean useCache) throws GenericEntityException; - public void initEntityEcaHandler(); + void initEntityEcaHandler(); - public void initDistributedCacheClear(); + void initDistributedCacheClear(); - public GenericPK makePK(Element element); + GenericPK makePK(Element element); /** Creates a Primary Key in the form of a GenericPK without persisting it */ - public GenericPK makePK(String entityName); + GenericPK makePK(String entityName); /** Creates a Primary Key in the form of a GenericPK without persisting it */ - public GenericPK makePK(String entityName, Map<String, ? extends Object> fields); + GenericPK makePK(String entityName, Map<String, ? extends Object> fields); /** Creates a Primary Key in the form of a GenericPK without persisting it */ - public GenericPK makePK(String entityName, Object... fields); + GenericPK makePK(String entityName, Object... fields); /** Creates a Primary Key in the form of a GenericPK without persisting it */ - public GenericPK makePKSingle(String entityName, Object singlePkValue); + GenericPK makePKSingle(String entityName, Object singlePkValue); - public GenericDelegator makeTestDelegator(String delegatorName); + Delegator makeTestDelegator(String delegatorName); /** * Creates a Entity in the form of a GenericValue without persisting it; * only valid fields will be pulled from the fields Map */ - public GenericValue makeValidValue(String entityName, Map<String, ? extends Object> fields); + GenericValue makeValidValue(String entityName, Map<String, ? extends Object> fields); /** * Creates a Entity in the form of a GenericValue without persisting it; * only valid fields will be pulled from the fields Map */ - public GenericValue makeValidValue(String entityName, Object... fields); + GenericValue makeValidValue(String entityName, Object... fields); - public GenericValue makeValue(Element element); + GenericValue makeValue(Element element); /** Creates a Entity in the form of a GenericValue without persisting it */ - public GenericValue makeValue(String entityName); + GenericValue makeValue(String entityName); /** Creates a Entity in the form of a GenericValue without persisting it */ - public GenericValue makeValue(String entityName, Map<String, ? extends Object> fields); + GenericValue makeValue(String entityName, Map<String, ? extends Object> fields); /** Creates a Entity in the form of a GenericValue without persisting it */ - public GenericValue makeValue(String entityName, Object... fields); + GenericValue makeValue(String entityName, Object... fields); - public List<GenericValue> makeValues(Document document); + List<GenericValue> makeValues(Document document); /** Creates a Entity in the form of a GenericValue without persisting it */ - public GenericValue makeValueSingle(String entityName, Object singlePkValue); + GenericValue makeValueSingle(String entityName, Object singlePkValue); - public void putAllInPrimaryKeyCache(List<GenericValue> values); + void putAllInPrimaryKeyCache(List<GenericValue> values); - public void putInPrimaryKeyCache(GenericPK primaryKey, GenericValue value); + void putInPrimaryKeyCache(GenericPK primaryKey, GenericValue value); // ======= XML Related Methods ======== - public List<GenericValue> readXmlDocument(URL url) throws SAXException, ParserConfigurationException, java.io.IOException; + List<GenericValue> readXmlDocument(URL url) throws SAXException, ParserConfigurationException, java.io.IOException; /** * Refresh the Entity for the GenericValue from the persistent store @@ -970,7 +976,7 @@ public interface Delegator { * @param value * GenericValue instance containing the entity to refresh */ - public void refresh(GenericValue value) throws GenericEntityException; + void refresh(GenericValue value) throws GenericEntityException; /** * Refresh the Entity for the GenericValue from the persistent store @@ -984,7 +990,7 @@ public interface Delegator { * @deprecated use {@link #refresh(GenericValue value)} */ @Deprecated - public void refresh(GenericValue value, boolean doCacheClear) throws GenericEntityException; + void refresh(GenericValue value, boolean doCacheClear) throws GenericEntityException; /** * Refresh the Entity for the GenericValue from the cache @@ -992,10 +998,10 @@ public interface Delegator { * @param value * GenericValue instance containing the entity to refresh */ - public void refreshFromCache(GenericValue value) throws GenericEntityException; + void refreshFromCache(GenericValue value) throws GenericEntityException; /** Refreshes the ID sequencer clearing all cached bank values. */ - public void refreshSequencer(); + void refreshSequencer(); /** * Remove the Entities from the List from the persistent store. <br/>The @@ -1013,7 +1019,7 @@ public interface Delegator { * or by and fields to remove * @return int representing number of rows effected by this operation */ - public int removeAll(List<? extends GenericEntity> dummyPKs) throws GenericEntityException; + int removeAll(List<? extends GenericEntity> dummyPKs) throws GenericEntityException; /** * Remove the Entities from the List from the persistent store. <br/>The @@ -1037,9 +1043,9 @@ public interface Delegator { * @deprecated use {@link #removeAll(List<? extends GenericEntity> dummyPKs)} */ @Deprecated - public int removeAll(List<? extends GenericEntity> dummyPKs, boolean doCacheClear) throws GenericEntityException; + int removeAll(List<? extends GenericEntity> dummyPKs, boolean doCacheClear) throws GenericEntityException; - public int removeAll(String entityName) throws GenericEntityException; + int removeAll(String entityName) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by all of the specified @@ -1056,7 +1062,7 @@ public interface Delegator { * corresponding values * @return int representing number of rows effected by this operation */ - public int removeByAnd(String entityName, boolean doCacheClear, Object... fields) throws GenericEntityException; + int removeByAnd(String entityName, boolean doCacheClear, Object... fields) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by all of the specified @@ -1069,7 +1075,7 @@ public interface Delegator { * corresponding values * @return int representing number of rows effected by this operation */ - public int removeByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + int removeByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by all of the specified @@ -1088,7 +1094,7 @@ public interface Delegator { * @deprecated use {@link #removeByAnd(String entityName, Map<String, ? extends Object> fields)} */ @Deprecated - public int removeByAnd(String entityName, Map<String, ? extends Object> fields, boolean doCacheClear) throws GenericEntityException; + int removeByAnd(String entityName, Map<String, ? extends Object> fields, boolean doCacheClear) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by all of the specified @@ -1101,7 +1107,7 @@ public interface Delegator { * corresponding values * @return int representing number of rows effected by this operation */ - public int removeByAnd(String entityName, Object... fields) throws GenericEntityException; + int removeByAnd(String entityName, Object... fields) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by the condition @@ -1112,7 +1118,7 @@ public interface Delegator { * The condition used to restrict the removing * @return int representing number of rows effected by this operation */ - public int removeByCondition(String entityName, EntityCondition condition) throws GenericEntityException; + int removeByCondition(String entityName, EntityCondition condition) throws GenericEntityException; /** * Removes/deletes Generic Entity records found by the condition @@ -1129,7 +1135,7 @@ public interface Delegator { * @deprecated use {@link #removeByCondition(String entityName, EntityCondition condition)} */ @Deprecated - public int removeByCondition(String entityName, EntityCondition condition, boolean doCacheClear) throws GenericEntityException; + int removeByCondition(String entityName, EntityCondition condition, boolean doCacheClear) throws GenericEntityException; /** * Remove a Generic Entity corresponding to the primaryKey @@ -1138,7 +1144,7 @@ public interface Delegator { * The primary key of the entity to remove. * @return int representing number of rows effected by this operation */ - public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; + int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; /** * Remove a Generic Entity corresponding to the primaryKey @@ -1153,7 +1159,7 @@ public interface Delegator { * @deprecated use {@link #removeByPrimaryKey(GenericPK primaryKey)} */ @Deprecated - public int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; + int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; /** * Remove the named Related Entity for the GenericValue from the persistent @@ -1167,7 +1173,7 @@ public interface Delegator { * GenericValue instance containing the entity * @return int representing number of rows effected by this operation */ - public int removeRelated(String relationName, GenericValue value) throws GenericEntityException; + int removeRelated(String relationName, GenericValue value) throws GenericEntityException; /** * Remove the named Related Entity for the GenericValue from the persistent @@ -1187,7 +1193,7 @@ public interface Delegator { * @deprecated use {@link #removeRelated(String relationName, GenericValue value)} */ @Deprecated - public int removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException; + int removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException; /** * Remove a Generic Value from the database @@ -1196,7 +1202,7 @@ public interface Delegator { * The GenericValue object of the entity to remove. * @return int representing number of rows effected by this operation */ - public int removeValue(GenericValue value) throws GenericEntityException; + int removeValue(GenericValue value) throws GenericEntityException; /** * Remove a Generic Value from the database @@ -1211,28 +1217,28 @@ public interface Delegator { * @deprecated use {@link #removeValue(GenericValue value)} */ @Deprecated - public int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException; + int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException; - public void rollback(); + void rollback(); - public void setDistributedCacheClear(DistributedCacheClear distributedCacheClear); + void setDistributedCacheClear(DistributedCacheClear distributedCacheClear); - public void setEntityCrypto(EntityCrypto crypto); + void setEntityCrypto(EntityCrypto crypto); - public <T> void setEntityEcaHandler(EntityEcaHandler<T> entityEcaHandler); + <T> void setEntityEcaHandler(EntityEcaHandler<T> entityEcaHandler); /** * Look at existing values for a sub-entity with a sequenced secondary ID, * and get the highest plus 1 */ - public void setNextSubSeqId(GenericValue value, String seqFieldName, int numericPadding, int incrementBy); + void setNextSubSeqId(GenericValue value, String seqFieldName, int numericPadding, int incrementBy); /** * Allows you to pass a SequenceUtil class (possibly one that overrides the * getNextSeqId method); if null is passed will effectively refresh the * sequencer. */ - public void setSequencer(SequenceUtil sequencer); + void setSequencer(SequenceUtil sequencer); /** * Store the Entity from the GenericValue to the persistent store @@ -1241,7 +1247,7 @@ public interface Delegator { * GenericValue instance containing the entity * @return int representing number of rows effected by this operation */ - public int store(GenericValue value) throws GenericEntityException; + int store(GenericValue value) throws GenericEntityException; /** * Store the Entity from the GenericValue to the persistent store @@ -1256,7 +1262,7 @@ public interface Delegator { * @deprecated use {@link #store(GenericValue value)} */ @Deprecated - public int store(GenericValue value, boolean doCacheClear) throws GenericEntityException; + int store(GenericValue value, boolean doCacheClear) throws GenericEntityException; /** * Store the Entities from the List GenericValue instances to the persistent @@ -1273,7 +1279,7 @@ public interface Delegator { * store * @return int representing number of rows effected by this operation */ - public int storeAll(List<GenericValue> values) throws GenericEntityException; + int storeAll(List<GenericValue> values) throws GenericEntityException; /** * Store the Entities from the List GenericValue instances to the persistent @@ -1296,7 +1302,7 @@ public interface Delegator { * @deprecated use {@link #storeAll(List<GenericValue> values)} */ @Deprecated - public int storeAll(List<GenericValue> values, boolean doCacheClear) throws GenericEntityException; + int storeAll(List<GenericValue> values, boolean doCacheClear) throws GenericEntityException; /** * Store the Entities from the List GenericValue instances to the persistent @@ -1321,7 +1327,7 @@ public interface Delegator { * @return int representing number of rows effected by this operation * @deprecated use {@link #storeAll(GenericValue value, boolean createDummyFks)} */ - public int storeAll(List<GenericValue> values, boolean doCacheClear, boolean createDummyFks) throws GenericEntityException; + int storeAll(List<GenericValue> values, boolean doCacheClear, boolean createDummyFks) throws GenericEntityException; /** * Store a group of values @@ -1335,7 +1341,7 @@ public interface Delegator { * @return int representing number of rows effected by this operation * @throws GenericEntityException */ - public int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException; + int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException; /** * Store a group of values @@ -1355,12 +1361,12 @@ public interface Delegator { * @deprecated use {@link #storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition)} */ @Deprecated - public int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition, boolean doCacheClear) throws GenericEntityException; + int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityCondition condition, boolean doCacheClear) throws GenericEntityException; /** * Get use of Distributed Cache Clear mechanism status * @return boolean true if this delegator uses a Distributed Cache Clear mechanism */ - public boolean useDistributedCacheClear(); + boolean useDistributedCacheClear(); } Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1621696&r1=1621695&r2=1621696&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Mon Sep 1 07:29:23 2014 @@ -72,7 +72,6 @@ import org.ofbiz.entity.model.ModelRelat import org.ofbiz.entity.model.ModelViewEntity; import org.ofbiz.entity.serialize.SerializeException; import org.ofbiz.entity.serialize.XmlSerializer; -import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.entity.util.DistributedCacheClear; import org.ofbiz.entity.util.EntityCrypto; @@ -85,7 +84,7 @@ import org.w3c.dom.Node; import org.xml.sax.SAXException; /** - * Generic Data Source Delegator Class + * The default implementation of the <code>Delegator</code> interface. * */ public class GenericDelegator implements Delegator { @@ -122,15 +121,6 @@ public class GenericDelegator implements private static final AtomicReferenceFieldUpdater<GenericDelegator, LinkedBlockingDeque<?>> testOperationsUpdater = UtilGenerics.cast(AtomicReferenceFieldUpdater.newUpdater(GenericDelegator.class, LinkedBlockingDeque.class, "testOperations")); private volatile LinkedBlockingDeque<TestOperation> testOperations = null; - /** @deprecated Use Delegator delegator = DelegatorFactory.getDelegator(delegatorName); - * @param delegatorName - * @return the configured delegator - */ - @Deprecated - public static GenericDelegator getGenericDelegator(String delegatorName) { - return (GenericDelegator) DelegatorFactory.getDelegator(delegatorName); - } - protected static List<String> getUserIdentifierStack() { List<String> curValList = userIdentifierStack.get(); if (curValList == null) { @@ -140,11 +130,6 @@ public class GenericDelegator implements return curValList; } - public static String getCurrentUserIdentifier() { - List<String> curValList = getUserIdentifierStack(); - return curValList.size() > 0 ? curValList.get(0) : null; - } - public static void pushUserIdentifier(String userIdentifier) { if (userIdentifier == null) { return; @@ -176,11 +161,6 @@ public class GenericDelegator implements return curValList; } - public static String getCurrentSessionIdentifier() { - List<String> curValList = getSessionIdentifierStack(); - return curValList.size() > 0 ? curValList.get(0) : null; - } - public static void pushSessionIdentifier(String sessionIdentifier) { if (sessionIdentifier == null) { return; @@ -1201,10 +1181,6 @@ public class GenericDelegator implements beganTransaction = TransactionUtil.begin(); } - if (doCacheClear) { - // always clear cache before the operation - this.clearCacheLineByCondition(entityName, condition); - } ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); @@ -1214,6 +1190,9 @@ public class GenericDelegator implements } int rowsAffected = helper.removeByCondition(this, modelEntity, condition); + if (rowsAffected > 0 && doCacheClear) { + this.clearCacheLine(entityName); + } if (testMode) { for (GenericValue entity : removedEntities) { @@ -1315,10 +1294,6 @@ public class GenericDelegator implements beganTransaction = TransactionUtil.begin(); } - if (doCacheClear) { - // always clear cache before the operation - this.clearCacheLineByCondition(entityName, condition); - } ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); @@ -1328,6 +1303,9 @@ public class GenericDelegator implements } int rowsAffected = helper.storeByCondition(this, modelEntity, fieldsToSet, condition); + if (rowsAffected > 0 && doCacheClear) { + this.clearCacheLine(entityName); + } if (testMode) { for (GenericValue entity : updatedEntities) { @@ -2544,24 +2522,14 @@ public class GenericDelegator implements /* (non-Javadoc) * @see org.ofbiz.entity.Delegator#getNextSeqIdLong(java.lang.String, long) */ - @Override public Long getNextSeqIdLong(String seqName, long staggerMax) { - boolean beganTransaction = false; try { - if (alwaysUseTransaction) { - beganTransaction = TransactionUtil.begin(); - } - SequenceUtil sequencer = this.AtomicRefSequencer.get(); if (sequencer == null) { ModelEntity seqEntity = this.getModelEntity("SequenceValueItem"); - sequencer = new SequenceUtil(this, this.getEntityHelperInfo("SequenceValueItem"), seqEntity, "seqName", "seqId"); - try { - if (!AtomicRefSequencer.compareAndSet(null, sequencer)) { - sequencer = this.AtomicRefSequencer.get(); - } - } catch (Exception e) { - throw new IllegalStateException("Error thrown while creating AtomicReference<SequenceUtil> in getNextSeqIdLong()" + e); + sequencer = new SequenceUtil(this.getEntityHelperInfo("SequenceValueItem"), seqEntity, "seqName", "seqId"); + if (!AtomicRefSequencer.compareAndSet(null, sequencer)) { + sequencer = this.AtomicRefSequencer.get(); } } @@ -2569,16 +2537,10 @@ public class GenericDelegator implements ModelEntity seqModelEntity = this.getModelEntity(seqName); Long newSeqId = sequencer == null ? null : sequencer.getNextSeqId(seqName, staggerMax, seqModelEntity); - TransactionUtil.commit(beganTransaction); return newSeqId; } catch (Exception e) { String errMsg = "Failure in getNextSeqIdLong operation for seqName [" + seqName + "]: " + e.toString() + ". Rolling back transaction."; Debug.logError(e, errMsg, module); - try { - TransactionUtil.rollback(beganTransaction, errMsg, e); - } catch (GenericTransactionException e1) { - Debug.logError(e1, "Exception thrown while rolling back transaction: ", module); - } throw new GeneralRuntimeException(errMsg, e); } } @@ -2829,7 +2791,7 @@ public class GenericDelegator implements * @see org.ofbiz.entity.Delegator#cloneDelegator(java.lang.String) */ @Override - public GenericDelegator cloneDelegator(String delegatorFullName) { + public Delegator cloneDelegator(String delegatorFullName) { // creates an exact clone of the delegator; except for the sequencer // note that this will not be cached and should be used only when // needed to change something for single instance (use). @@ -2859,7 +2821,7 @@ public class GenericDelegator implements * @see org.ofbiz.entity.Delegator#cloneDelegator() */ @Override - public GenericDelegator cloneDelegator() { + public Delegator cloneDelegator() { return this.cloneDelegator(this.delegatorFullName); } @@ -2867,8 +2829,8 @@ public class GenericDelegator implements * @see org.ofbiz.entity.Delegator#makeTestDelegator(java.lang.String) */ @Override - public GenericDelegator makeTestDelegator(String delegatorName) { - GenericDelegator testDelegator = this.cloneDelegator(delegatorName); + public Delegator makeTestDelegator(String delegatorName) { + GenericDelegator testDelegator = (GenericDelegator) this.cloneDelegator(delegatorName); testDelegator.entityEcaHandler.set(null); testDelegator.initEntityEcaHandler(); testDelegator.setTestMode(true); @@ -3009,4 +2971,16 @@ public class GenericDelegator implements public boolean useDistributedCacheClear() { return this.delegatorInfo.getDistributedCacheClearEnabled(); } + + @Override + public String getCurrentSessionIdentifier() { + List<String> curValList = getSessionIdentifierStack(); + return curValList.size() > 0 ? curValList.get(0) : null; + } + + @Override + public String getCurrentUserIdentifier() { + List<String> curValList = getUserIdentifierStack(); + return curValList.size() > 0 ? curValList.get(0) : null; + } } Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=1621696&r1=1621695&r2=1621696&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Mon Sep 1 07:29:23 2014 @@ -27,9 +27,16 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicBoolean; import javax.sql.rowset.serial.SerialBlob; +import org.ofbiz.base.concurrent.ExecutionPool; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.Observable; import org.ofbiz.base.util.Observer; @@ -38,6 +45,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilXml; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; +import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericPK; @@ -56,6 +64,8 @@ import org.ofbiz.entity.transaction.Tran import org.ofbiz.entity.util.EntityFindOptions; import org.ofbiz.entity.util.EntityListIterator; import org.ofbiz.entity.util.EntitySaxReader; +import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.entity.util.SequenceUtil; public class EntityTestSuite extends EntityTestCase { @@ -198,8 +208,21 @@ public class EntityTestSuite extends Ent testValue.store(); testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-1", testValue.getString("description")); + // Test storeByCondition updates the cache + testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + EntityCondition storeByCondition = EntityCondition.makeCondition(UtilMisc.toMap("testingTypeId", "TEST-CACHE-1", + "lastUpdatedStamp", testValue.get("lastUpdatedStamp"))); + int qtyChanged = delegator.storeByCondition("TestingType", UtilMisc.toMap("description", "New Testing Type #Cache-0"), storeByCondition); + assertEquals("Delegator.storeByCondition updated one value", 1, qtyChanged); + testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + assertEquals("Retrieved from cache value has the correct description", "New Testing Type #Cache-0", testValue.getString("description")); + // Test removeByCondition updates the cache + qtyChanged = delegator.removeByCondition("TestingType", storeByCondition); + assertEquals("Delegator.removeByCondition removed one value", 1, qtyChanged); + testValue = EntityUtil.getFirst(delegator.findByAnd("TestingType", UtilMisc.toMap("testingTypeId", "TEST-CACHE-1"), null, true)); + assertEquals("Retrieved from cache value is null", null, testValue); // Test entity value remove operation updates the cache - testValue = (GenericValue) testValue.clone(); + testValue = delegator.create("TestingType", "testingTypeId", "TEST-CACHE-1", "description", "Testing Type #Cache-1"); testValue.remove(); testValue = delegator.findOne("TestingType", true, "testingTypeId", "TEST-CACHE-1"); assertEquals("Retrieved from cache value is null", null, testValue); @@ -1069,6 +1092,66 @@ public class EntityTestSuite extends Ent assertNull("Delete TestingType 2", testType); } + public void testSequenceValueItem() { + SequenceUtil sequencer = new SequenceUtil(delegator.getGroupHelperInfo(delegator.getEntityGroupName("SequenceValueItem")), + delegator.getModelEntity("SequenceValueItem"), + "seqName", "seqId"); + UUID id = UUID.randomUUID(); + String sequenceName = "BogusSequence" + id.toString(); + for (int i = 10000; i <= 10015; i++) { + Long seqId = sequencer.getNextSeqId(sequenceName, 1, null); + assertEquals(i, seqId.longValue()); + } + sequencer.forceBankRefresh(sequenceName, 1); + Long seqId = sequencer.getNextSeqId(sequenceName, 1, null); + assertEquals(10020, seqId.longValue()); + } + + public void testSequenceValueItemWithConcurrentThreads() { + final SequenceUtil sequencer = new SequenceUtil(delegator.getGroupHelperInfo(delegator.getEntityGroupName("SequenceValueItem")), + delegator.getModelEntity("SequenceValueItem"), + "seqName", "seqId"); + UUID id = UUID.randomUUID(); + final String sequenceName = "BogusSequence" + id.toString(); + final ConcurrentMap<Long, Long> seqIds = new ConcurrentHashMap<Long, Long>(); + final AtomicBoolean duplicateFound = new AtomicBoolean(false); + final AtomicBoolean nullSeqIdReturned = new AtomicBoolean(false); + + List<Future<Void>> futures = new ArrayList<Future<Void>>(); + Callable getSeqIdTask = new Callable() { + public Callable<Void> call() throws Exception { + Long seqId = sequencer.getNextSeqId(sequenceName, 1, null); + if (seqId == null) { + nullSeqIdReturned.set(true); + return null; + } + Long existingValue = seqIds.putIfAbsent(seqId, seqId); + if (existingValue != null) { + duplicateFound.set(true); + } + return null; + } + }; + Callable refreshTask = new Callable() { + public Callable<Void> call() throws Exception { + sequencer.forceBankRefresh(sequenceName, 1); + return null; + } + }; + double probabilityOfRefresh = 0.1; + for (int i = 1; i <= 1000; i++) { + Callable randomTask = Math.random() < probabilityOfRefresh ? refreshTask : getSeqIdTask; + futures.add(ExecutionPool.GLOBAL_FORK_JOIN.submit(randomTask)); + } + long startTime = System.currentTimeMillis(); + ExecutionPool.getAllFutures(futures); + long endTime = System.currentTimeMillis(); + long totalTime = endTime - startTime; + Debug.logInfo("testSequenceValueItemWithConcurrentThreads total time (ms): " + totalTime, module); + assertFalse("Null sequence id returned", nullSeqIdReturned.get()); + assertFalse("Duplicate sequence id returned", duplicateFound.get()); + } + private final class TestObserver implements Observer { private Observable observable; private Object arg; |
Free forum by Nabble | Edit this page |