Author: mbrohl
Date: Fri Dec 8 21:13:26 2017 New Revision: 1817570 URL: http://svn.apache.org/viewvc?rev=1817570&view=rev Log: Improved: Fixing defects reported by FindBugs, package org.apache.ofbiz.entity.datasource. (OFBIZ-9723) Did some additional cleanup by removing commented out code. Thanks Julian Leichert for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java?rev=1817570&r1=1817569&r2=1817570&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericDAO.java Fri Dec 8 21:13:26 2017 @@ -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<ModelField> partialFields = new LinkedList<ModelField>(); Collection<String> 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<String> 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<ModelField> partialFields = new LinkedList<ModelField>(); @@ -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<String> collist = new LinkedList<String>(); List<String> fldlist = new LinkedList<String>(); for (Iterator<ModelField> 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; Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java?rev=1817570&r1=1817569&r2=1817570&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/datasource/GenericHelperFactory.java Fri Dec 8 21:13:26 2017 @@ -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<String, GenericHelper> helperCache = new HashMap<String, GenericHelper>(); + protected static final Map<String, GenericHelper> helperCache = new HashMap<String, GenericHelper>(); 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()); } |
Free forum by Nabble | Edit this page |