Author: mbrohl
Date: Sun Dec 17 09:56:54 2017 New Revision: 1818468 URL: http://svn.apache.org/viewvc?rev=1818468&view=rev Log: Improved: General refactoring and code improvements, package org.apache.ofbiz.entity. (OFBIZ-9957) Thanks Dennis Balkir for reporting and providing the patches. Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java Sun Dec 17 09:56:54 2017 @@ -246,7 +246,7 @@ public interface Delegator { EntityListIterator find(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; /** - * Finds all Generic entities + * Finds all Generic entities * * @param entityName * The Name of the Entity as defined in the entity XML file @@ -291,7 +291,7 @@ public interface Delegator { /** * Gets the hit count of GenericValues for the given EntityCondition objects. - * + * * @param entityName * @param whereEntityCondition * @param havingEntityCondition @@ -738,10 +738,10 @@ public interface Delegator { * <p>Remove the Entities from the List from the persistent store.</p> * <p>The List contains GenericEntity objects, can be either GenericPK or * GenericValue. </p> - * <p>If a certain entity contains a complete primary key, the entity in - * the datasource corresponding to that primary key will be removed, this + * <p>If a certain entity contains a complete primary key, the entity in + * the datasource corresponding to that primary key will be removed, this * is like a removeByPrimary Key.</p> - * <p>On the other hand, if a certain entity is an incomplete or non + * <p>On the other hand, if a certain entity is an incomplete or non * primary key, if will behave like the removeByAnd method. </p> * <p>These updates all happen in one transaction, so they will either * all succeed or all fail, if the data source supports transactions.</p> @@ -875,7 +875,7 @@ public interface Delegator { /** * <p>Store the Entities from the List GenericValue instances to the persistent - * store.</p> + * store.</p> * <p>This is different than the normal store method in that the * store method only does an update, while the storeAll method checks to see * if each entity exists, then either does an insert or an update as @@ -912,7 +912,7 @@ public interface Delegator { /** * Get use of Distributed Cache Clear mechanism status - * @return boolean true if this delegator uses a Distributed Cache Clear mechanism + * @return boolean true if this delegator uses a Distributed Cache Clear mechanism */ boolean useDistributedCacheClear(); } Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java Sun Dec 17 09:56:54 2017 @@ -49,7 +49,7 @@ public class DelegatorContainer implemen if (UtilValidate.isEmpty(preloadedDelegatorNames)) { return true; } - List<Future<Delegator>> futures = new ArrayList<Future<Delegator>>(); + List<Future<Delegator>> futures = new ArrayList<>(); for (String preloadedDelegatorName: preloadedDelegatorNames) { futures.add(DelegatorFactory.getDelegatorFuture(preloadedDelegatorName)); } Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java Sun Dec 17 09:56:54 2017 @@ -33,7 +33,7 @@ import org.apache.ofbiz.base.util.UtilOb /** <code>Delegator</code> factory abstract class. */ public abstract class DelegatorFactory implements Factory<Delegator, String> { public static final String module = DelegatorFactory.class.getName(); - private static final ConcurrentHashMap<String, Future<Delegator>> delegators = new ConcurrentHashMap<String, Future<Delegator>>(); + private static final ConcurrentHashMap<String, Future<Delegator>> delegators = new ConcurrentHashMap<>(); private static final ThreadGroup DELEGATOR_THREAD_GROUP = new ThreadGroup("DelegatorFactory"); private static final ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(DELEGATOR_THREAD_GROUP, "delegator-startup", Runtime.getRuntime().availableProcessors(), 10, true); @@ -41,10 +41,7 @@ public abstract class DelegatorFactory i Future<Delegator> future = getDelegatorFuture(delegatorName); try { return future.get(); - } catch (ExecutionException e) { - Debug.logError(e, module); - return null; - } catch (InterruptedException e) { + } catch (ExecutionException | InterruptedException e) { Debug.logError(e, module); return null; } @@ -53,16 +50,13 @@ public abstract class DelegatorFactory i public static Future<Delegator> getDelegatorFuture(String delegatorName) { if (delegatorName == null) { delegatorName = "default"; - //Debug.logWarning(new Exception("Location where getting delegator with null name"), "Got a getGenericDelegator call with a null delegatorName, assuming default for the name.", module); } do { Future<Delegator> future = delegators.get(delegatorName); if (future != null) { - //Debug.logInfo("got delegator(future(" + delegatorName + ")) from cache", module); return future; } - FutureTask<Delegator> futureTask = new FutureTask<Delegator>(new DelegatorConfigurable(delegatorName)); - //Debug.logInfo("putting delegator(future(" + delegatorName + ")) into cache", module); + FutureTask<Delegator> futureTask = new FutureTask<>(new DelegatorConfigurable(delegatorName)); if (delegators.putIfAbsent(delegatorName, futureTask) != null) { continue; } Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java Sun Dec 17 09:56:54 2017 @@ -28,8 +28,9 @@ public class DelegatorFactoryImpl extend // TODO: this method should propagate the GenericEntityException public Delegator getInstance(String delegatorName) { - if (Debug.infoOn()) Debug.logInfo("Creating new delegator [" + delegatorName + "] (" + Thread.currentThread().getName() + ")", module); - //Debug.logInfo(new Exception(), "Showing stack where new delegator is being created...", module); + if (Debug.infoOn()) { + Debug.logInfo("Creating new delegator [" + delegatorName + "] (" + Thread.currentThread().getName() + ")", module); + } try { return new GenericDelegator(delegatorName); } catch (GenericEntityException e) { Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java Sun Dec 17 09:56:54 2017 @@ -18,7 +18,6 @@ */ package org.apache.ofbiz.entity; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.sql.Timestamp; @@ -107,16 +106,16 @@ public class GenericDelegator implements protected Cache cache = null; - protected final AtomicReference<Future<DistributedCacheClear>> distributedCacheClear = new AtomicReference<Future<DistributedCacheClear>>(); + protected final AtomicReference<Future<DistributedCacheClear>> distributedCacheClear = new AtomicReference<>(); protected boolean warnNoEcaHandler = false; - protected final AtomicReference<Future<EntityEcaHandler<?>>> entityEcaHandler = new AtomicReference<Future<EntityEcaHandler<?>>>(); - protected final AtomicReference<SequenceUtil> AtomicRefSequencer = new AtomicReference<SequenceUtil>(null); + protected final AtomicReference<Future<EntityEcaHandler<?>>> entityEcaHandler = new AtomicReference<>(); + protected final AtomicReference<SequenceUtil> AtomicRefSequencer = new AtomicReference<>(null); protected EntityCrypto crypto = null; /** A ThreadLocal variable to allow other methods to specify a user identifier (usually the userLoginId, though technically the Entity Engine doesn't know anything about the UserLogin entity) */ - private static final ThreadLocal<List<String>> userIdentifierStack = new ThreadLocal<List<String>>(); + private static final ThreadLocal<List<String>> userIdentifierStack = new ThreadLocal<>(); /** A ThreadLocal variable to allow other methods to specify a session identifier (usually the visitId, though technically the Entity Engine doesn't know anything about the Visit entity) */ - private static final ThreadLocal<List<String>> sessionIdentifierStack = new ThreadLocal<List<String>>(); + private static final ThreadLocal<List<String>> sessionIdentifierStack = new ThreadLocal<>(); private boolean testMode = false; private boolean testRollbackInProgress = false; @@ -126,7 +125,7 @@ public class GenericDelegator implements protected static List<String> getUserIdentifierStack() { List<String> curValList = userIdentifierStack.get(); if (curValList == null) { - curValList = new LinkedList<String>(); + curValList = new LinkedList<>(); userIdentifierStack.set(curValList); } return curValList; @@ -144,9 +143,8 @@ public class GenericDelegator implements List<String> curValList = getUserIdentifierStack(); if (curValList.size() == 0) { return null; - } else { - return curValList.remove(0); } + return curValList.remove(0); } public static void clearUserIdentifierStack() { @@ -157,7 +155,7 @@ public class GenericDelegator implements protected static List<String> getSessionIdentifierStack() { List<String> curValList = sessionIdentifierStack.get(); if (curValList == null) { - curValList = new LinkedList<String>(); + curValList = new LinkedList<>(); sessionIdentifierStack.set(curValList); } return curValList; @@ -175,9 +173,8 @@ public class GenericDelegator implements List<String> curValList = getSessionIdentifierStack(); if (curValList.size() == 0) { return null; - } else { - return curValList.remove(0); } + return curValList.remove(0); } public static void clearSessionIdentifierStack() { @@ -190,7 +187,6 @@ public class GenericDelegator implements /** Only allow creation through the factory method */ protected GenericDelegator(String delegatorFullName) throws GenericEntityException { - //if (Debug.infoOn()) Debug.logInfo("Creating new Delegator with name \"" + delegatorFullName + "\".", module); this.setDelegatorNames(delegatorFullName); this.delegatorInfo = EntityConfig.getInstance().getDelegator(delegatorBaseName); @@ -224,7 +220,7 @@ public class GenericDelegator implements cache = new Cache(delegatorFullName); // do the entity model check - List<String> warningList = new LinkedList<String>(); + List<String> warningList = new LinkedList<>(); Debug.logInfo("Doing entity definition check...", module); ModelEntityChecker.checkEntities(this, warningList); if (warningList.size() > 0) { @@ -236,7 +232,7 @@ public class GenericDelegator implements // initialize helpers by group Set<String> groupNames = getModelGroupReader().getGroupNames(delegatorBaseName); - List<Future<Void>> futures = new LinkedList<Future<Void>>(); + List<Future<Void>> futures = new LinkedList<>(); for (String groupName: groupNames) { futures.add(ExecutionPool.GLOBAL_BATCH.submit(createHelperCallable(groupName))); } @@ -318,7 +314,7 @@ public class GenericDelegator implements return createEntityEcaHandler(); } }; - FutureTask<EntityEcaHandler<?>> futureTask = new FutureTask<EntityEcaHandler<?>>(creator); + FutureTask<EntityEcaHandler<?>> futureTask = new FutureTask<>(creator); if (this.entityEcaHandler.compareAndSet(null, futureTask)) { // This needs to use BATCH, as the service engine might add it's own items into a thread pool. ExecutionPool.GLOBAL_BATCH.submit(futureTask); @@ -440,7 +436,7 @@ public class GenericDelegator implements } } - Map<String, ModelEntity> entities = new HashMap<String, ModelEntity>(); + Map<String, ModelEntity> entities = new HashMap<>(); if (UtilValidate.isEmpty(entityNameSet)) { return entities; } @@ -545,9 +541,8 @@ public class GenericDelegator implements if (helperInfo != null) { return GenericHelperFactory.getHelper(helperInfo); - } else { - throw new GenericEntityException("There is no datasource (Helper) configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; was trying to find datasource (helper) for entity [" + entityName + "]"); } + throw new GenericEntityException("There is no datasource (Helper) configured for the entity-group [" + this.getEntityGroupName(entityName) + "]; was trying to find datasource (helper) for entity [" + entityName + "]"); } /* (non-Javadoc) @@ -809,23 +804,22 @@ public class GenericDelegator implements } if (existingValue == null) { throw e; - } else { - if (Debug.infoOn()) { - Debug.logInfo("Error creating entity record with a sequenced value [" + value.getPrimaryKey() + "], trying again about to refresh bank for entity [" + value.getEntityName() + "]", module); - } + } + if (Debug.infoOn()) { + Debug.logInfo("Error creating entity record with a sequenced value [" + value.getPrimaryKey() + "], trying again about to refresh bank for entity [" + value.getEntityName() + "]", module); + } - // found an existing value... was probably a duplicate key, so clean things up and try again - this.AtomicRefSequencer.get().forceBankRefresh(value.getEntityName(), 1); + // found an existing value... was probably a duplicate key, so clean things up and try again + this.AtomicRefSequencer.get().forceBankRefresh(value.getEntityName(), 1); - value.setNextSeqId(); - value = helper.create(value); - if (Debug.infoOn()) { - Debug.logInfo("Successfully created new entity record on retry with a sequenced value [" + value.getPrimaryKey() + "], after getting refreshed bank for entity [" + value.getEntityName() + "]", module); - } + value.setNextSeqId(); + value = helper.create(value); + if (Debug.infoOn()) { + Debug.logInfo("Successfully created new entity record on retry with a sequenced value [" + value.getPrimaryKey() + "], after getting refreshed bank for entity [" + value.getEntityName() + "]", module); + } - if (testMode) { - storeForTestRollback(new TestOperation(OperationType.INSERT, value)); - } + if (testMode) { + storeForTestRollback(new TestOperation(OperationType.INSERT, value)); } } @@ -952,11 +946,7 @@ public class GenericDelegator implements String serializedPK = null; try { serializedPK = XmlSerializer.serialize(dummyPK); - } catch (SerializeException e) { - Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module); - } catch (FileNotFoundException e) { - Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module); - } catch (IOException e) { + } catch (SerializeException | IOException e) { Debug.logError(e, "Could not serialize primary key to save EntitySyncRemove", module); } @@ -1144,7 +1134,7 @@ public class GenericDelegator implements throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value); } - Map<String, Object> fields = new HashMap<String, Object>(); + Map<String, Object> fields = new HashMap<>(); for (ModelKeyMap keyMap : relation.getKeyMaps()) { fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } @@ -1285,7 +1275,9 @@ public class GenericDelegator implements } // if no store options passed, use default - if (storeOptions == null) storeOptions = new EntityStoreOptions(); + if (storeOptions == null) { + storeOptions = new EntityStoreOptions(); + } int numberChanged = 0; @@ -1490,7 +1482,9 @@ public class GenericDelegator implements value = helper.findByPrimaryKeyPartial(primaryKey, keys); } catch (GenericEntityNotFoundException e) { } - if (value != null) value.setDelegator(this); + if (value != null) { + value.setDelegator(this); + } ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, primaryKey, false); TransactionUtil.commit(beganTransaction); @@ -1617,8 +1611,12 @@ public class GenericDelegator implements } ModelViewEntity modelViewEntity = dynamicViewEntity.makeModelViewEntity(this); - if (whereEntityCondition != null) whereEntityCondition.checkCondition(modelViewEntity); - if (havingEntityCondition != null) havingEntityCondition.checkCondition(modelViewEntity); + if (whereEntityCondition != null) { + whereEntityCondition.checkCondition(modelViewEntity); + } + if (havingEntityCondition != null) { + havingEntityCondition.checkCondition(modelViewEntity); + } GenericHelper helper = getEntityHelper(dynamicViewEntity.getOneRealEntityName()); EntityListIterator eli = helper.findListIteratorByCondition(this, modelViewEntity, whereEntityCondition, @@ -1713,7 +1711,7 @@ public class GenericDelegator implements // put the byAndFields (if not null) into the hash map first, // they will be overridden by value's fields if over-specified this is important for security and cleanliness - Map<String, Object> fields = new HashMap<String, Object>(); + Map<String, Object> fields = new HashMap<>(); if (byAndFields != null) { fields.putAll(byAndFields); } @@ -1739,7 +1737,7 @@ public class GenericDelegator implements // put the byAndFields (if not null) into the hash map first, // they will be overridden by value's fields if over-specified this is important for security and cleanliness - Map<String, Object> fields = new HashMap<String, Object>(); + Map<String, Object> fields = new HashMap<>(); if (byAndFields != null) { fields.putAll(byAndFields); } @@ -1764,7 +1762,7 @@ public class GenericDelegator implements throw new GenericModelException("Relation is not a 'one' or a 'one-nofk' relation: " + relationName + " of entity " + value.getEntityName()); } - Map<String, Object> fields = new HashMap<String, Object>(); + Map<String, Object> fields = new HashMap<>(); for (ModelKeyMap keyMap : relation.getKeyMaps()) { fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } @@ -1859,7 +1857,9 @@ public class GenericDelegator implements public void clearCacheLineFlexible(GenericEntity dummyPK, boolean distribute) { if (dummyPK != null) { //if never cached, then don't bother clearing - if (dummyPK.getModelEntity().getNeverCache()) return; + if (dummyPK.getModelEntity().getNeverCache()) { + return; + } cache.remove(dummyPK); @@ -1953,7 +1953,6 @@ public class GenericDelegator implements */ @Override public void clearCacheLine(GenericValue value, boolean distribute) { - // Debug.logInfo("running clearCacheLine for value: " + value + ", distribute: " + distribute, module); if (value == null) { return; } @@ -2055,7 +2054,7 @@ public class GenericDelegator implements */ @Override public void setDistributedCacheClear(DistributedCacheClear distributedCacheClear) { - this.distributedCacheClear.set(new ConstantFuture<DistributedCacheClear>(distributedCacheClear)); + this.distributedCacheClear.set(new ConstantFuture<>(distributedCacheClear)); } // ======= XML Related Methods ======== @@ -2078,7 +2077,7 @@ public class GenericDelegator implements if (document == null) { return null; } - List<GenericValue> values = new LinkedList<GenericValue>(); + List<GenericValue> values = new LinkedList<>(); Element docElement = document.getDocumentElement(); @@ -2184,9 +2183,6 @@ public class GenericDelegator implements if (entityEcaHandler == null) { return; } - //if (!"find".equals(currentOperation)) { - // Debug.logWarning("evalRules for entity " + value.getEntityName() + ", currentOperation " + currentOperation + ", event " + event, module); - //} entityEcaHandler.evalRules(currentOperation, eventMap, event, value, isError); } } @@ -2199,7 +2195,7 @@ public class GenericDelegator implements } protected static <T> EntityEcaRuleRunner<T> createEntityEcaRuleRunner(EntityEcaHandler<T> entityEcaHandler, String entityName) { - return new EntityEcaRuleRunner<T>(entityEcaHandler, entityEcaHandler != null ? entityEcaHandler.getEntityEventMap(entityName) : null); + return new EntityEcaRuleRunner<>(entityEcaHandler, entityEcaHandler != null ? entityEcaHandler.getEntityEventMap(entityName) : null); } /* (non-Javadoc) @@ -2219,9 +2215,7 @@ public class GenericDelegator implements Future<EntityEcaHandler<?>> future = this.entityEcaHandler.get(); try { return UtilGenerics.cast(future != null ? future.get() : null); - } catch (ExecutionException e) { - Debug.logError(e, "Could not fetch EntityEcaHandler from the asynchronous instantiation", module); - } catch (InterruptedException e) { + } catch (ExecutionException | InterruptedException e) { Debug.logError(e, "Could not fetch EntityEcaHandler from the asynchronous instantiation", module); } return null; @@ -2249,9 +2243,8 @@ public class GenericDelegator implements if (UtilValidate.isNotEmpty(this.delegatorInfo.getSequencedIdPrefix())) { return this.delegatorInfo.getSequencedIdPrefix() + nextSeqLong.toString(); - } else { - return nextSeqLong.toString(); } + return nextSeqLong.toString(); } /* (non-Javadoc) @@ -2327,7 +2320,6 @@ public class GenericDelegator implements // get values in whatever order, we will go through all of them to find the highest value List<GenericValue> allValues = this.findByAnd(value.getEntityName(), lookupValue, null, false); - //Debug.logInfo("Get existing values from entity " + value.getEntityName() + " with lookupValue: " + lookupValue + ", and the seqFieldName: " + seqFieldName + ", and the results are: " + allValues, module); Integer highestSeqVal = null; for (GenericValue curValue: allValues) { String currentSeqId = curValue.getString(seqFieldName); @@ -2625,7 +2617,7 @@ public class GenericDelegator implements return createDistributedCacheClear(); } }; - FutureTask<DistributedCacheClear> futureTask = new FutureTask<DistributedCacheClear>(creator); + FutureTask<DistributedCacheClear> futureTask = new FutureTask<>(creator); if (distributedCacheClear.compareAndSet(null, futureTask)) { ExecutionPool.GLOBAL_BATCH.submit(futureTask); } @@ -2663,9 +2655,7 @@ public class GenericDelegator implements Future<DistributedCacheClear> future = this.distributedCacheClear.get(); try { return future != null ? future.get() : null; - } catch (ExecutionException e) { - Debug.logError(e, "Could not fetch DistributedCacheClear from the asynchronous instantiation", module); - } catch (InterruptedException e) { + } catch (ExecutionException | InterruptedException e) { Debug.logError(e, "Could not fetch DistributedCacheClear from the asynchronous instantiation", module); } return null; Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java?rev=1818468&r1=1818467&r2=1818468&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java Sun Dec 17 09:56:54 2017 @@ -100,7 +100,7 @@ public class GenericEntity implements Ma * between desiring to set a value to null and desiring to not modify the * current value on an update. */ - private Map<String, Object> fields = new HashMap<String, Object>(); + private Map<String, Object> fields = new HashMap<>(); /** Contains the entityName of this entity, necessary for efficiency when creating EJBs */ private String entityName = null; @@ -236,7 +236,9 @@ public class GenericEntity implements Ma this.entityName = value.getEntityName(); // NOTE: could call getModelEntity to insure we have a value, just in case the value passed in has been serialized, but might as well leave it null to keep the object light if it isn't there this.modelEntity = value.modelEntity; - if (value.fields != null) this.fields.putAll(value.fields); + if (value.fields != null) { + this.fields.putAll(value.fields); + } this.delegatorName = value.delegatorName; this.internalDelegator = value.internalDelegator; this.observable = new Observable(value.observable); @@ -248,7 +250,7 @@ public class GenericEntity implements Ma this.delegatorName = null; this.internalDelegator = null; this.originalDbValues = null; - this.fields = new HashMap<String, Object>(); + this.fields = new HashMap<>(); this.entityName = null; this.modelEntity = null; this.generateHashCode = true; @@ -268,7 +270,7 @@ public class GenericEntity implements Ma if (!thisPK.equals(newPK)) { throw new GenericEntityException("Could not refresh value, new value did not have the same primary key; this PK=" + thisPK + ", new value PK=" + newPK); } - this.fields = new HashMap<String, Object>(newValue.fields); + this.fields = new HashMap<>(newValue.fields); this.setDelegator(newValue.getDelegator()); this.generateHashCode = newValue.generateHashCode; this.cachedHashCode = newValue.cachedHashCode; @@ -276,7 +278,7 @@ public class GenericEntity implements Ma } /** - * + * * @deprecated Use hasChanged() */ public boolean isModified() { @@ -338,7 +340,9 @@ public class GenericEntity implements Ma public ModelEntity getModelEntity() { if (modelEntity == null) { - if (entityName != null) modelEntity = this.getDelegator().getModelEntity(entityName); + if (entityName != null) { + modelEntity = this.getDelegator().getModelEntity(entityName); + } if (modelEntity == null) { throw new IllegalStateException("[GenericEntity.getModelEntity] could not find modelEntity for entityName " + entityName); } @@ -351,7 +355,9 @@ public class GenericEntity implements Ma */ public Delegator getDelegator() { if (internalDelegator == null) { - if (delegatorName == null) delegatorName = "default"; + if (delegatorName == null) { + delegatorName = "default"; + } internalDelegator = DelegatorFactory.getDelegator(delegatorName); if (internalDelegator == null) { throw new IllegalStateException("[GenericEntity.getDelegator] could not find delegator with name " + delegatorName); @@ -363,7 +369,9 @@ public class GenericEntity implements Ma /** Set the GenericDelegator instance that created this value object and that is responsible for it. */ public void setDelegator(Delegator internalDelegator) { assertIsMutable(); - if (internalDelegator == null) return; + if (internalDelegator == null) { + return; + } this.delegatorName = internalDelegator.getDelegatorName(); this.internalDelegator = internalDelegator; } @@ -380,17 +388,23 @@ public class GenericEntity implements Ma return isPrimaryKey(false); } public boolean isPrimaryKey(boolean requireValue) { - TreeSet<String> fieldKeys = new TreeSet<String>(this.fields.keySet()); + TreeSet<String> fieldKeys = new TreeSet<>(this.fields.keySet()); for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) { String fieldName = curPk.getName(); if (requireValue) { - if (this.fields.get(fieldName) == null) return false; + if (this.fields.get(fieldName) == null) { + return false; + } } else { - if (!this.fields.containsKey(fieldName)) return false; + if (!this.fields.containsKey(fieldName)) { + return false; + } } fieldKeys.remove(fieldName); } - if (!fieldKeys.isEmpty()) return false; + if (!fieldKeys.isEmpty()) { + return false; + } return true; } @@ -399,13 +413,16 @@ public class GenericEntity implements Ma return containsPrimaryKey(false); } public boolean containsPrimaryKey(boolean requireValue) { - //TreeSet fieldKeys = new TreeSet(fields.keySet()); for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) { String fieldName = curPk.getName(); if (requireValue) { - if (this.fields.get(fieldName) == null) return false; + if (this.fields.get(fieldName) == null) { + return false; + } } else { - if (!this.fields.containsKey(fieldName)) return false; + if (!this.fields.containsKey(fieldName)) { + return false; + } } } return true; @@ -491,14 +508,15 @@ public class GenericEntity implements Ma this.setChanged(); this.notifyObservers(name); return old; - } else { - return fields.get(name); } + return fields.get(name); } public void dangerousSetNoCheckButFast(ModelField modelField, Object value) { assertIsMutable(); - if (modelField == null) throw new IllegalArgumentException("Cannot set field with a null modelField"); + if (modelField == null) { + throw new IllegalArgumentException("Cannot set field with a null modelField"); + } generateHashCode = true; this.fields.put(modelField.getName(), value); this.setChanged(); @@ -506,7 +524,9 @@ public class GenericEntity implements Ma } public Object dangerousGetNoCheckButFast(ModelField modelField) { - if (modelField == null) throw new IllegalArgumentException("Cannot get field with a null modelField"); + if (modelField == null) { + throw new IllegalArgumentException("Cannot get field with a null modelField"); + } return this.fields.get(modelField.getName()); } @@ -527,7 +547,10 @@ public class GenericEntity implements Ma } ModelField field = getModelEntity().getField(name); - if (field == null) set(name, value); // this will get an error in the set() method... + if (field == null) + { + set(name, value); // this will get an error in the set() method... + } ModelFieldType type = null; try { @@ -537,7 +560,9 @@ public class GenericEntity implements Ma } catch (IllegalStateException | GenericEntityException e) { Debug.logWarning(e, module); } - if (type == null) throw new IllegalArgumentException("Type " + field.getType() + " not found"); + if (type == null) { + throw new IllegalArgumentException("Type " + field.getType() + " not found"); + } String fieldType = type.getJavaType(); try { @@ -809,15 +834,12 @@ public class GenericEntity implements Ma resourceValue = get(this.getModelEntity(), modelEntityToUse, name, resource, locale); if (resourceValue == null) { return fieldValue; - } else { - return resourceValue; } - } else { - return fieldValue; - } - } else { return resourceValue; + } + return fieldValue; } + return resourceValue; } /** @@ -831,7 +853,6 @@ public class GenericEntity implements Ma resource = modelEntityToUse.getDefaultResourceName(); // still empty? return null if (UtilValidate.isEmpty(resource)) { - //Debug.logWarning("Tried to getResource value for field named " + name + " but no resource name was passed to the method or specified in the default-resource-name attribute of the entity definition", module); return null; } } @@ -846,7 +867,6 @@ public class GenericEntity implements Ma bundle = null; } if (bundle == null) { - //Debug.logWarning("Tried to getResource value for field named " + name + " but no resource was found with the name " + resource + " in the locale " + locale, module); return null; } @@ -860,7 +880,7 @@ public class GenericEntity implements Ma if (modelEntity instanceof ModelViewEntity){ // retrieve pkNames of realEntity ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity; - List<String> pkNamesToUse = new LinkedList<String>(); + List<String> pkNamesToUse = new LinkedList<>(); // iterate on realEntity for pkField Iterator<ModelField> iter = modelEntityToUse.getPksIterator(); while (iter != null && iter.hasNext()) { @@ -878,7 +898,9 @@ public class GenericEntity implements Ma } } } - if (pkName == null) pkName = curField.getName(); + if (pkName == null) { + pkName = curField.getName(); + } pkNamesToUse.add(pkName); } // read value with modelEntity name of pkNames @@ -967,7 +989,6 @@ public class GenericEntity implements Ma if (fields.containsKey(sourceFieldName)) { Object field = fields.get(sourceFieldName); - // if (Debug.verboseOn()) Debug.logVerbose("Setting field " + curField.getName() + ": " + field + ", setIfEmpty = " + setIfEmpty, module); if (setIfEmpty) { // if empty string, set to null if (field != null && field instanceof String && ((String) field).length() == 0) { @@ -1005,7 +1026,7 @@ public class GenericEntity implements Ma * @return java.util.Map */ public Map<String, Object> getAllFields() { - return new HashMap<String, Object>(this.fields); + return new HashMap<>(this.fields); } /** Used by clients to specify exactly the fields they are interested in @@ -1013,8 +1034,10 @@ public class GenericEntity implements Ma * @return java.util.Map */ public Map<String, Object> getFields(Collection<String> keysofFields) { - if (keysofFields == null) return null; - Map<String, Object> aMap = new HashMap<String, Object>(); + if (keysofFields == null) { + return null; + } + Map<String, Object> aMap = new HashMap<>(); for (String aKey: keysofFields) { aMap.put(aKey, this.fields.get(aKey)); @@ -1026,7 +1049,9 @@ public class GenericEntity implements Ma * @param keyValuePairs java.util.Map */ public void setFields(Map<? extends String, ? extends Object> keyValuePairs) { - if (keyValuePairs == null) return; + if (keyValuePairs == null) { + return; + } // this could be implement with Map.putAll, but we'll leave it like this for the extra features it has for (Map.Entry<? extends String, ? extends Object> anEntry: keyValuePairs.entrySet()) { this.set(anEntry.getKey(), anEntry.getValue(), true); @@ -1034,8 +1059,12 @@ public class GenericEntity implements Ma } public boolean matchesFields(Map<String, ? extends Object> keyValuePairs) { - if (fields == null) return true; - if (UtilValidate.isEmpty(keyValuePairs)) return true; + if (fields == null) { + return true; + } + if (UtilValidate.isEmpty(keyValuePairs)) { + return true; + } for (Map.Entry<String, ? extends Object> anEntry: keyValuePairs.entrySet()) { if (!UtilValidate.areEqual(anEntry.getValue(), this.fields.get(anEntry.getKey()))) { return false; @@ -1055,7 +1084,9 @@ public class GenericEntity implements Ma public static Document makeXmlDocument(Collection<GenericValue> values) { Document document = UtilXml.makeEmptyXmlDocument("entity-engine-xml"); - if (document == null) return null; + if (document == null) { + return null; + } addToXmlDocument(values, document); return document; @@ -1066,8 +1097,12 @@ public class GenericEntity implements Ma } public static int addToXmlElement(Collection<GenericValue> values, Document document, Element element) { - if (values == null) return 0; - if (document == null) return 0; + if (values == null) { + return 0; + } + if (document == null) { + return 0; + } int numberAdded = 0; @@ -1096,10 +1131,15 @@ public class GenericEntity implements Ma public Element makeXmlElement(Document document, String prefix) { Element element = null; - if (prefix == null) prefix = ""; - if (document != null) element = document.createElement(prefix + this.getEntityName()); - // else element = new ElementImpl(null, this.getEntityName()); - if (element == null) return null; + if (prefix == null) { + prefix = ""; + } + if (document != null) { + element = document.createElement(prefix + this.getEntityName()); + } + if (element == null) { + return null; + } Iterator<ModelField> modelFields = this.getModelEntity().getFieldsIterator(); while (modelFields.hasNext()) { @@ -1113,8 +1153,6 @@ public class GenericEntity implements Ma } else { element.setAttribute(name, value); } - // } else { - // element.setAttribute(name, GenericEntity.NULL_FIELD.toString()); } } @@ -1128,10 +1166,14 @@ public class GenericEntity implements Ma public void writeXmlText(PrintWriter writer, String prefix) { int indent = 4; StringBuilder indentStrBuf = new StringBuilder(); - for (int i = 0; i < indent; i++) indentStrBuf.append(' '); + for (int i = 0; i < indent; i++) { + indentStrBuf.append(' '); + } String indentString = indentStrBuf.toString(); - if (prefix == null) prefix = ""; + if (prefix == null) { + prefix = ""; + } writer.print(indentString); writer.print('<'); @@ -1139,7 +1181,7 @@ public class GenericEntity implements Ma writer.print(this.getEntityName()); // write attributes immediately and if a CDATA element is needed, put those in a Map for now - Map<String, String> cdataMap = new HashMap<String, String>(); + Map<String, String> cdataMap = new HashMap<>(); Iterator<ModelField> modelFields = this.getModelEntity().getFieldsIterator(); while (modelFields.hasNext()) { @@ -1320,7 +1362,7 @@ public class GenericEntity implements Ma theString.append(getEntityName()); theString.append(']'); - for (String curKey: new TreeSet<String>(fields.keySet())) { + for (String curKey: new TreeSet<>(fields.keySet())) { Object curValue = fields.get(curKey); ModelField field = this.getModelEntity().getField(curKey); if (field.getEncryptMethod().isEncrypted() && curValue instanceof String) { @@ -1355,7 +1397,7 @@ public class GenericEntity implements Ma theString.append(getEntityName()); theString.append(']'); - for (String curKey: new TreeSet<String>(fields.keySet())) { + for (String curKey: new TreeSet<>(fields.keySet())) { Object curValue = fields.get(curKey); theString.append('['); theString.append(curKey); @@ -1374,18 +1416,17 @@ public class GenericEntity implements Ma Object thatVal = that.fields.get(name); if (thisVal == null) { - if (thatVal == null) + if (thatVal == null) { return 0; // if thisVal is null, but thatVal is not, return 1 to put this earlier in the list - else - return 1; - } else { - // if thatVal is null, put the other earlier in the list - if (thatVal == null) - return -1; - else - return thisVal.compareTo(thatVal); + } + return 1; } + // if thatVal is null, put the other earlier in the list + if (thatVal == null) { + return -1; + } + return thisVal.compareTo(thatVal); } /** Compares this GenericEntity to the passed object @@ -1394,19 +1435,25 @@ public class GenericEntity implements Ma */ public int compareTo(GenericEntity that) { // if null, it will push to the beginning - if (that == null) return -1; + if (that == null) { + return -1; + } int tempResult = this.entityName.compareTo(that.entityName); // if they did not match, we know the order, otherwise compare the primary keys - if (tempResult != 0) return tempResult; + if (tempResult != 0) { + return tempResult; + } // both have same entityName, should be the same so let's compare PKs Iterator<ModelField> pkIter = getModelEntity().getPksIterator(); while (pkIter.hasNext()) { ModelField curField = pkIter.next(); tempResult = compareToFields(that, curField.getName()); - if (tempResult != 0) return tempResult; + if (tempResult != 0) { + return tempResult; + } } // okay, if we got here it means the primaryKeys are exactly the SAME, so compare the rest of the fields @@ -1415,7 +1462,9 @@ public class GenericEntity implements Ma ModelField curField = nopkIter.next(); if (!curField.getIsAutoCreatedInternal()) { tempResult = compareToFields(that, curField.getName()); - if (tempResult != 0) return tempResult; + if (tempResult != 0) { + return tempResult; + } } } @@ -1529,7 +1578,9 @@ public class GenericEntity implements Ma if (getModelEntity().getField(name) == null) { throw new IllegalArgumentException("[GenericEntity.get] \"" + name + "\" is not a field of " + getEntityName()); } - if (originalDbValues == null) return null; + if (originalDbValues == null) { + return null; + } return originalDbValues.get(name); } @@ -1548,7 +1599,7 @@ public class GenericEntity implements Ma ModelRelation relation = relItr.next(); if ("one".equalsIgnoreCase(relation.getType())) { // see if the related value exists - Map<String, Object> fields = new HashMap<String, Object>(); + Map<String, Object> fields = new HashMap<>(); for (ModelKeyMap keyMap : relation.getKeyMaps()) { fields.put(keyMap.getRelFieldName(), this.get(keyMap.getFieldName())); } @@ -1562,13 +1613,17 @@ public class GenericEntity implements Ma for (ModelKeyMap mkm : relation.getKeyMaps()) { if (this.get(mkm.getFieldName()) != null) { newValue.set(mkm.getRelFieldName(), this.get(mkm.getFieldName())); - if (Debug.infoOn()) Debug.logInfo("Set [" + mkm.getRelFieldName() + "] to - " + this.get(mkm.getFieldName()), module); + if (Debug.infoOn()) { + Debug.logInfo("Set [" + mkm.getRelFieldName() + "] to - " + this.get(mkm.getFieldName()), module); + } } else { allFieldsSet = false; } } if (allFieldsSet) { - if (Debug.infoOn()) Debug.logInfo("Creating place holder value : " + newValue, module); + if (Debug.infoOn()) { + Debug.logInfo("Creating place holder value : " + newValue, module); + } // inherit create and update times from this value in order to make this not seem like new/fresh data newValue.put(ModelEntity.CREATE_STAMP_FIELD, this.get(ModelEntity.CREATE_STAMP_FIELD)); |
Free forum by Nabble | Edit this page |