diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java index 01f57eb7c0..f8c9ef8466 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java @@ -105,11 +105,6 @@ public class GenericDAO { public int insert(GenericEntity entity) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } - - try (SQLProcessor sqlP = new SQLProcessor(entity.getDelegator(), helperInfo)) { try { return singleInsert(entity, modelEntity, modelEntity.getFieldsUnmodifiable(), sqlP); @@ -181,20 +176,12 @@ public class GenericDAO { public int updateAll(GenericEntity entity) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } - return customUpdate(entity, modelEntity, modelEntity.getNopksCopy()); } public int update(GenericEntity entity) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } - // we don't want to update ALL fields, just the nonpk fields that are in the passed GenericEntity List partialFields = new LinkedList(); Collection keys = entity.getAllKeys(); @@ -483,10 +470,6 @@ public class GenericDAO { public void select(GenericEntity entity, SQLProcessor sqlP) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } - if (modelEntity.getPksSize() <= 0) { throw new GenericEntityException("Entity has no primary keys, cannot select by primary key"); } @@ -525,20 +508,10 @@ public class GenericDAO { public void partialSelect(GenericEntity entity, Set keys) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } - if (modelEntity instanceof ModelViewEntity) { throw new org.apache.ofbiz.entity.GenericNotImplementedException("Operation partialSelect not supported yet for view entities"); } - /* - if (entity == null || entity.<%=modelEntity.pkNameString(" == null || entity."," == null")%>) { - Debug.logWarning("[GenericDAO.select]: Cannot select GenericEntity: required primary key field(s) missing.", module); - return false; - } - */ // we don't want to select ALL fields, just the nonpk fields that are in the passed GenericEntity List partialFields = new LinkedList(); @@ -580,7 +553,6 @@ public class GenericDAO { entity.synchronizedWithDatasource(); } else { - // Debug.logWarning("[GenericDAO.select]: select failed, result set was empty.", module); throw new GenericEntityNotFoundException("Result set was empty for entity: " + entity.toString()); } } @@ -828,9 +800,8 @@ public class GenericDAO { String viewEntityCondHavingString = null; if (modelViewEntity != null) { EntityCondition viewHavingEntityCondition = EntityCondition.makeCondition(viewHavingConditions); - if (viewHavingEntityCondition != null) { - viewEntityCondHavingString = viewHavingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasource); - } + viewEntityCondHavingString = viewHavingEntityCondition.makeWhereString(modelEntity, + havingEntityConditionParams, this.datasource); } if (UtilValidate.isNotEmpty(entityCondHavingString) || UtilValidate.isNotEmpty(viewEntityCondHavingString)) { @@ -886,13 +857,11 @@ public class GenericDAO { // get the column name string to select StringBuilder selsb = new StringBuilder(); - List collist = new LinkedList(); List fldlist = new LinkedList(); for (Iterator iterator = modelEntityTwo.getFieldsIterator(); iterator.hasNext();) { ModelField mf = iterator.next(); - collist.add(mf.getColName()); fldlist.add(mf.getName()); selsb.append(ttable).append(".").append(mf.getColName()); if (iterator.hasNext()) { @@ -1130,14 +1099,13 @@ public class GenericDAO { public int delete(GenericEntity entity, SQLProcessor sqlP) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); - if (modelEntity == null) { - throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); - } + if (modelEntity instanceof ModelViewEntity) { throw new org.apache.ofbiz.entity.GenericNotImplementedException("Operation delete not supported yet for view entities"); } - StringBuilder sql = new StringBuilder().append("DELETE FROM ").append(modelEntity.getTableName(datasource)).append(" WHERE "); + StringBuilder sql = new StringBuilder().append("DELETE FROM ").append(modelEntity.getTableName(datasource)) + .append(" WHERE "); SqlJdbcUtil.makeWhereStringFromFields(sql, modelEntity.getPkFieldsUnmodifiable(), entity, "AND"); int retVal; diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java index 16c7187088..d555960e16 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java @@ -18,6 +18,7 @@ *******************************************************************************/ package org.apache.ofbiz.entity.datasource; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -35,7 +36,7 @@ public class GenericHelperFactory { public static final String module = GenericHelperFactory.class.getName(); // protected static UtilCache helperCache = new UtilCache("entity.GenericHelpers", 0, 0); - protected static Map helperCache = new HashMap(); + protected static final Map helperCache = new HashMap(); public static GenericHelper getHelper(GenericHelperInfo helperInfo) { GenericHelper helper = helperCache.get(helperInfo.getHelperFullName()); @@ -79,13 +80,8 @@ public class GenericHelperFactory { } try { helper = (GenericHelper) helperConstructor.newInstance(params); - } catch (IllegalAccessException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading GenericHelper class \"" + helperClassName + "\": " + e.getMessage()); - } catch (InstantiationException e) { - Debug.logWarning(e, module); - throw new IllegalStateException("Error loading GenericHelper class \"" + helperClassName + "\": " + e.getMessage()); - } catch (java.lang.reflect.InvocationTargetException e) { + } catch (IllegalAccessException | InstantiationException | InvocationTargetException + | ExceptionInInitializerError | IllegalArgumentException | NullPointerException e) { Debug.logWarning(e, module); throw new IllegalStateException("Error loading GenericHelper class \"" + helperClassName + "\": " + e.getMessage()); }