diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java
index 9ed7aed8e8..58f1dc25df 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/Delegator.java
@@ -246,7 +246,7 @@ public interface Delegator {
EntityListIterator find(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Set fieldsToSelect, List 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 {
*
Remove the Entities from the List from the persistent store.
*
The List contains GenericEntity objects, can be either GenericPK or
* GenericValue.
- *
If a certain entity contains a complete primary key, the entity in
- * the datasource corresponding to that primary key will be removed, this
+ *
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.
- *
On the other hand, if a certain entity is an incomplete or non
+ *
On the other hand, if a certain entity is an incomplete or non
* primary key, if will behave like the removeByAnd method.
*
These updates all happen in one transaction, so they will either
* all succeed or all fail, if the data source supports transactions.
@@ -875,7 +875,7 @@ public interface Delegator {
/**
*
Store the Entities from the List GenericValue instances to the persistent
- * store.
+ * store.
*
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();
}
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java
index 84058c2a74..5756e9666d 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java
@@ -49,7 +49,7 @@ public class DelegatorContainer implements Container {
if (UtilValidate.isEmpty(preloadedDelegatorNames)) {
return true;
}
- List> futures = new ArrayList>();
+ List> futures = new ArrayList<>();
for (String preloadedDelegatorName: preloadedDelegatorNames) {
futures.add(DelegatorFactory.getDelegatorFuture(preloadedDelegatorName));
}
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java
index 6f3b6b00f8..d806e389ce 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactory.java
@@ -33,7 +33,7 @@ import org.apache.ofbiz.base.util.UtilObject;
/** Delegator factory abstract class. */
public abstract class DelegatorFactory implements Factory {
public static final String module = DelegatorFactory.class.getName();
- private static final ConcurrentHashMap> delegators = new ConcurrentHashMap>();
+ private static final ConcurrentHashMap> 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 implements Factory {
Future 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 implements Factory {
public static Future 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 future = delegators.get(delegatorName);
if (future != null) {
- //Debug.logInfo("got delegator(future(" + delegatorName + ")) from cache", module);
return future;
}
- FutureTask futureTask = new FutureTask(new DelegatorConfigurable(delegatorName));
- //Debug.logInfo("putting delegator(future(" + delegatorName + ")) into cache", module);
+ FutureTask futureTask = new FutureTask<>(new DelegatorConfigurable(delegatorName));
if (delegators.putIfAbsent(delegatorName, futureTask) != null) {
continue;
}
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java
index e7102c8afa..a8f79597e7 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorFactoryImpl.java
@@ -28,8 +28,9 @@ public class DelegatorFactoryImpl extends DelegatorFactory {
// 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) {
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
index 574d7de891..d950824f42 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
@@ -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 Delegator {
protected Cache cache = null;
- protected final AtomicReference> distributedCacheClear = new AtomicReference>();
+ protected final AtomicReference> distributedCacheClear = new AtomicReference<>();
protected boolean warnNoEcaHandler = false;
- protected final AtomicReference>> entityEcaHandler = new AtomicReference>>();
- protected final AtomicReference AtomicRefSequencer = new AtomicReference(null);
+ protected final AtomicReference>> entityEcaHandler = new AtomicReference<>();
+ protected final AtomicReference 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> userIdentifierStack = new ThreadLocal>();
+ private static final ThreadLocal> 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> sessionIdentifierStack = new ThreadLocal>();
+ private static final ThreadLocal> sessionIdentifierStack = new ThreadLocal<>();
private boolean testMode = false;
private boolean testRollbackInProgress = false;
@@ -126,7 +125,7 @@ public class GenericDelegator implements Delegator {
protected static List getUserIdentifierStack() {
List curValList = userIdentifierStack.get();
if (curValList == null) {
- curValList = new LinkedList();
+ curValList = new LinkedList<>();
userIdentifierStack.set(curValList);
}
return curValList;
@@ -144,9 +143,8 @@ public class GenericDelegator implements Delegator {
List 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 Delegator {
protected static List getSessionIdentifierStack() {
List curValList = sessionIdentifierStack.get();
if (curValList == null) {
- curValList = new LinkedList();
+ curValList = new LinkedList<>();
sessionIdentifierStack.set(curValList);
}
return curValList;
@@ -175,9 +173,8 @@ public class GenericDelegator implements Delegator {
List 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 Delegator {
/** 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 Delegator {
cache = new Cache(delegatorFullName);
// do the entity model check
- List warningList = new LinkedList();
+ List 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 Delegator {
// initialize helpers by group
Set groupNames = getModelGroupReader().getGroupNames(delegatorBaseName);
- List> futures = new LinkedList>();
+ List> futures = new LinkedList<>();
for (String groupName: groupNames) {
futures.add(ExecutionPool.GLOBAL_BATCH.submit(createHelperCallable(groupName)));
}
@@ -318,7 +314,7 @@ public class GenericDelegator implements Delegator {
return createEntityEcaHandler();
}
};
- FutureTask> futureTask = new FutureTask>(creator);
+ FutureTask> 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 Delegator {
}
}
- Map entities = new HashMap();
+ Map entities = new HashMap<>();
if (UtilValidate.isEmpty(entityNameSet)) {
return entities;
}
@@ -545,9 +541,8 @@ public class GenericDelegator implements Delegator {
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 Delegator {
}
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 Delegator {
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 Delegator {
throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
}
- Map fields = new HashMap();
+ Map fields = new HashMap<>();
for (ModelKeyMap keyMap : relation.getKeyMaps()) {
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
@@ -1285,7 +1275,9 @@ public class GenericDelegator implements Delegator {
}
// 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 Delegator {
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 Delegator {
}
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 Delegator {
// 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 fields = new HashMap();
+ Map fields = new HashMap<>();
if (byAndFields != null) {
fields.putAll(byAndFields);
}
@@ -1739,7 +1737,7 @@ public class GenericDelegator implements Delegator {
// 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 fields = new HashMap();
+ Map fields = new HashMap<>();
if (byAndFields != null) {
fields.putAll(byAndFields);
}
@@ -1764,7 +1762,7 @@ public class GenericDelegator implements Delegator {
throw new GenericModelException("Relation is not a 'one' or a 'one-nofk' relation: " + relationName + " of entity " + value.getEntityName());
}
- Map fields = new HashMap();
+ Map fields = new HashMap<>();
for (ModelKeyMap keyMap : relation.getKeyMaps()) {
fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
}
@@ -1859,7 +1857,9 @@ public class GenericDelegator implements Delegator {
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 Delegator {
*/
@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 Delegator {
*/
@Override
public void setDistributedCacheClear(DistributedCacheClear distributedCacheClear) {
- this.distributedCacheClear.set(new ConstantFuture(distributedCacheClear));
+ this.distributedCacheClear.set(new ConstantFuture<>(distributedCacheClear));
}
// ======= XML Related Methods ========
@@ -2078,7 +2077,7 @@ public class GenericDelegator implements Delegator {
if (document == null) {
return null;
}
- List values = new LinkedList();
+ List values = new LinkedList<>();
Element docElement = document.getDocumentElement();
@@ -2184,9 +2183,6 @@ public class GenericDelegator implements Delegator {
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 Delegator {
}
protected static EntityEcaRuleRunner createEntityEcaRuleRunner(EntityEcaHandler entityEcaHandler, String entityName) {
- return new EntityEcaRuleRunner(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 Delegator {
Future> 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 Delegator {
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 Delegator {
// get values in whatever order, we will go through all of them to find the highest value
List 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 Delegator {
return createDistributedCacheClear();
}
};
- FutureTask futureTask = new FutureTask(creator);
+ FutureTask futureTask = new FutureTask<>(creator);
if (distributedCacheClear.compareAndSet(null, futureTask)) {
ExecutionPool.GLOBAL_BATCH.submit(futureTask);
}
@@ -2663,9 +2655,7 @@ public class GenericDelegator implements Delegator {
Future 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;
diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
index eb91eb0fc9..77084743f3 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
@@ -100,7 +100,7 @@ public class GenericEntity implements Map, LocalizedMap