Author: doogie
Date: Wed Oct 17 20:52:08 2007 New Revision: 585841 URL: http://svn.apache.org/viewvc?rev=585841&view=rev Log: Java 1.5 markup for entity datasource. Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=585841&r1=585840&r2=585841&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Wed Oct 17 20:52:08 2007 @@ -62,7 +62,7 @@ public static final String module = GenericDAO.class.getName(); - protected static Map genericDAOs = FastMap.newInstance(); + protected static Map<String, GenericDAO> genericDAOs = FastMap.newInstance(); protected String helperName; protected ModelFieldTypeReader modelFieldTypeReader = null; protected DatasourceInfo datasourceInfo; @@ -88,10 +88,8 @@ this.datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); } - private void addFieldIfMissing(List fieldsToSave, String fieldName, ModelEntity modelEntity) { - Iterator fieldsToSaveIter = fieldsToSave.iterator(); - while (fieldsToSaveIter.hasNext()) { - ModelField fieldToSave = (ModelField) fieldsToSaveIter.next(); + private void addFieldIfMissing(List<ModelField> fieldsToSave, String fieldName, ModelEntity modelEntity) { + for (ModelField fieldToSave: fieldsToSave) { if (fieldName.equals(fieldToSave.getName())) { return; } @@ -120,7 +118,7 @@ } } - private int singleInsert(GenericEntity entity, ModelEntity modelEntity, List fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { + private int singleInsert(GenericEntity entity, ModelEntity modelEntity, List<ModelField> fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { if (modelEntity instanceof ModelViewEntity) { return singleUpdateView(entity, (ModelViewEntity) modelEntity, fieldsToSave, sqlP); } @@ -193,12 +191,12 @@ } // we don't want to update ALL fields, just the nonpk fields that are in the passed GenericEntity - List partialFields = FastList.newInstance(); - Collection keys = entity.getAllKeys(); + List<ModelField> partialFields = FastList.newInstance(); + Collection<String> keys = entity.getAllKeys(); - Iterator nopkIter = modelEntity.getNopksIterator(); + Iterator<ModelField> nopkIter = modelEntity.getNopksIterator(); while (nopkIter.hasNext()) { - ModelField curField = (ModelField) nopkIter.next(); + ModelField curField = nopkIter.next(); if (keys.contains(curField.getName())) { partialFields.add(curField); } @@ -207,7 +205,7 @@ return customUpdate(entity, modelEntity, partialFields); } - private int customUpdate(GenericEntity entity, ModelEntity modelEntity, List fieldsToSave) throws GenericEntityException { + private int customUpdate(GenericEntity entity, ModelEntity modelEntity, List<ModelField> fieldsToSave) throws GenericEntityException { SQLProcessor sqlP = new SQLProcessor(helperName); try { return singleUpdate(entity, modelEntity, fieldsToSave, sqlP); @@ -220,7 +218,7 @@ } } - private int singleUpdate(GenericEntity entity, ModelEntity modelEntity, List fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { + private int singleUpdate(GenericEntity entity, ModelEntity modelEntity, List<ModelField> fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { if (modelEntity instanceof ModelViewEntity) { return singleUpdateView(entity, (ModelViewEntity) modelEntity, fieldsToSave, sqlP); } @@ -283,7 +281,7 @@ return retVal; } - public int updateByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException { + public int updateByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { SQLProcessor sqlP = new SQLProcessor(helperName); try { @@ -296,7 +294,7 @@ } } - public int updateByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition, SQLProcessor sqlP) throws GenericEntityException { + public int updateByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition, SQLProcessor sqlP) throws GenericEntityException { if (modelEntity == null || fieldsToSet == null || condition == null) return 0; if (modelEntity instanceof ModelViewEntity) { @@ -305,11 +303,9 @@ String sql = "UPDATE " + modelEntity.getTableName(datasourceInfo); sql += " SET "; - Iterator i = fieldsToSet.keySet().iterator(); - List fieldList = new LinkedList(); + List<ModelField> fieldList = new LinkedList<ModelField>(); boolean firstField = true; - while (i.hasNext()) { - String name = (String) i.next(); + for (String name: fieldsToSet.keySet()) { ModelField field = modelEntity.getField(name); if (field != null) { if (!firstField) { @@ -325,9 +321,7 @@ try { sqlP.prepareStatement(sql); - Iterator fi = fieldList.iterator(); - while (fi.hasNext()) { - ModelField field = (ModelField) fi.next(); + for (ModelField field: fieldList) { Object value = fieldsToSet.get(field.getName()); SqlJdbcUtil.setValue(sqlP, field, modelEntity.getEntityName(), value, modelFieldTypeReader); } @@ -355,17 +349,14 @@ * <li>A new exception, e.g. GenericViewNotUpdatable, should be defined and thrown if the update fails</li> * */ - private int singleUpdateView(GenericEntity entity, ModelViewEntity modelViewEntity, List fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { + private int singleUpdateView(GenericEntity entity, ModelViewEntity modelViewEntity, List<ModelField> fieldsToSave, SQLProcessor sqlP) throws GenericEntityException { GenericDelegator delegator = entity.getDelegator(); int retVal = 0; ModelEntity memberModelEntity = null; // Construct insert/update for each model entity - Iterator meIter = modelViewEntity.getMemberModelMemberEntities().entrySet().iterator(); - while (meIter != null && meIter.hasNext()) { - Map.Entry meMapEntry = (Map.Entry) meIter.next(); - ModelViewEntity.ModelMemberEntity modelMemberEntity = (ModelViewEntity.ModelMemberEntity) meMapEntry.getValue(); + for (ModelViewEntity.ModelMemberEntity modelMemberEntity: modelViewEntity.getMemberModelMemberEntities().values()) { String meName = modelMemberEntity.getEntityName(); String meAlias = modelMemberEntity.getEntityAlias(); @@ -376,20 +367,20 @@ throw new GenericEntityException("Failed to get model entity for " + meName, e); } - Map findByMap = FastMap.newInstance(); + Map<String, Object> findByMap = FastMap.newInstance(); // Now iterate the ModelViewLinks to construct the "WHERE" part for update/insert - Iterator linkIter = modelViewEntity.getViewLinksIterator(); + Iterator<ModelViewEntity.ModelViewLink> linkIter = modelViewEntity.getViewLinksIterator(); while (linkIter != null && linkIter.hasNext()) { - ModelViewEntity.ModelViewLink modelViewLink = (ModelViewEntity.ModelViewLink) linkIter.next(); + ModelViewEntity.ModelViewLink modelViewLink = linkIter.next(); if (modelViewLink.getEntityAlias().equals(meAlias) || modelViewLink.getRelEntityAlias().equals(meAlias)) { - Iterator kmIter = modelViewLink.getKeyMapsIterator(); + Iterator<ModelKeyMap> kmIter = modelViewLink.getKeyMapsIterator(); while (kmIter != null && kmIter.hasNext()) { - ModelKeyMap keyMap = (ModelKeyMap) kmIter.next(); + ModelKeyMap keyMap = kmIter.next(); String fieldName = ""; @@ -418,7 +409,7 @@ } // Look what there already is in the database - List meResult = null; + List<GenericValue> meResult = null; try { meResult = delegator.findByAnd(meName, findByMap); @@ -446,12 +437,8 @@ } // Construct fieldsToSave list for this member entity - List meFieldsToSave = FastList.newInstance(); - Iterator fieldIter = fieldsToSave.iterator(); - - while (fieldIter != null && fieldIter.hasNext()) { - ModelField modelField = (ModelField) fieldIter.next(); - + List<ModelField> meFieldsToSave = FastList.newInstance(); + for (ModelField modelField: fieldsToSave) { if (memberModelEntity.isField(modelField.getName())) { ModelField meModelField = memberModelEntity.getField(modelField.getName()); @@ -530,9 +517,9 @@ if (sqlP.next()) { int idx = 1; - Iterator nopkIter = modelEntity.getNopksIterator(); + Iterator<ModelField> nopkIter = modelEntity.getNopksIterator(); while (nopkIter.hasNext()) { - ModelField curField = (ModelField) nopkIter.next(); + ModelField curField = nopkIter.next(); SqlJdbcUtil.getValue(sqlP.getResultSet(), idx, curField, entity, modelFieldTypeReader); idx++; } @@ -547,7 +534,7 @@ } } - public void partialSelect(GenericEntity entity, Set keys) throws GenericEntityException { + public void partialSelect(GenericEntity entity, Set<String> keys) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); if (modelEntity == null) { @@ -565,13 +552,13 @@ } */ // we don't want to select ALL fields, just the nonpk fields that are in the passed GenericEntity - List partialFields = FastList.newInstance(); + List<ModelField> partialFields = FastList.newInstance(); - Set tempKeys = new TreeSet(keys); + Set<String> tempKeys = new TreeSet<String>(keys); - Iterator nopkIter = modelEntity.getNopksIterator(); + Iterator<ModelField> nopkIter = modelEntity.getNopksIterator(); while (nopkIter.hasNext()) { - ModelField curField = (ModelField) nopkIter.next(); + ModelField curField = nopkIter.next(); if (tempKeys.contains(curField.getName())) { partialFields.add(curField); tempKeys.remove(curField.getName()); @@ -601,7 +588,7 @@ if (sqlP.next()) { for (int j = 0; j < partialFields.size(); j++) { - ModelField curField = (ModelField) partialFields.get(j); + ModelField curField = partialFields.get(j); SqlJdbcUtil.getValue(sqlP.getResultSet(), j + 1, curField, entity, modelFieldTypeReader); } @@ -629,7 +616,7 @@ * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ public EntityListIterator selectListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, - EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) + EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { if (modelEntity == null) { return null; @@ -646,13 +633,13 @@ } // make two ArrayLists of fields, one for fields to select and the other for where clause fields (to find by) - List selectFields = FastList.newInstance(); + List<ModelField> selectFields = FastList.newInstance(); if (fieldsToSelect != null && fieldsToSelect.size() > 0) { - Set tempKeys = FastSet.newInstance(); + Set<String> tempKeys = FastSet.newInstance(); tempKeys.addAll(fieldsToSelect); - Iterator fieldIter = modelEntity.getFieldsIterator(); + Iterator<ModelField> fieldIter = modelEntity.getFieldsIterator(); while (fieldIter.hasNext()) { - ModelField curField = (ModelField) fieldIter.next(); + ModelField curField = fieldIter.next(); if (tempKeys.contains(curField.getName())) { selectFields.add(curField); tempKeys.remove(curField.getName()); @@ -684,7 +671,7 @@ // WHERE clause StringBuilder whereString = new StringBuilder(); String entityCondWhereString = ""; - List whereEntityConditionParams = FastList.newInstance(); + List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance(); if (whereEntityCondition != null) { entityCondWhereString = whereEntityCondition.makeWhereString(modelEntity, whereEntityConditionParams, this.datasourceInfo); } @@ -721,7 +708,7 @@ // HAVING clause String entityCondHavingString = ""; - List havingEntityConditionParams = FastList.newInstance(); + List<EntityConditionParam> havingEntityConditionParams = FastList.newInstance(); if (havingEntityCondition != null) { entityCondHavingString = havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo); @@ -744,10 +731,7 @@ Debug.logVerbose("Setting the whereEntityConditionParams: " + whereEntityConditionParams, module); } // set all of the values from the Where EntityCondition - Iterator whereEntityConditionParamsIter = whereEntityConditionParams.iterator(); - while (whereEntityConditionParamsIter.hasNext()) { - EntityConditionParam whereEntityConditionParam = (EntityConditionParam) whereEntityConditionParamsIter.next(); - + for (EntityConditionParam whereEntityConditionParam: whereEntityConditionParams) { SqlJdbcUtil.setValue(sqlP, whereEntityConditionParam.getModelField(), modelEntity.getEntityName(), whereEntityConditionParam.getFieldValue(), modelFieldTypeReader); } if (verboseOn) { @@ -755,10 +739,7 @@ Debug.logVerbose("Setting the havingEntityConditionParams: " + havingEntityConditionParams, module); } // set all of the values from the Having EntityCondition - Iterator havingEntityConditionParamsIter = havingEntityConditionParams.iterator(); - while (havingEntityConditionParamsIter.hasNext()) { - EntityConditionParam havingEntityConditionParam = (EntityConditionParam) havingEntityConditionParamsIter.next(); - + for (EntityConditionParam havingEntityConditionParam: havingEntityConditionParams) { SqlJdbcUtil.setValue(sqlP, havingEntityConditionParam.getModelField(), modelEntity.getEntityName(), havingEntityConditionParam.getFieldValue(), modelFieldTypeReader); } @@ -777,8 +758,8 @@ return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader); } - public List selectByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, - ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException { + public List<GenericValue> selectByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, + ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException { SQLProcessor sqlP = new SQLProcessor(helperName); // get the tables names @@ -787,11 +768,11 @@ // get the column name string to select StringBuilder selsb = new StringBuilder(); - List collist = FastList.newInstance(); - List fldlist = FastList.newInstance(); + List<String> collist = FastList.newInstance(); + List<String> fldlist = FastList.newInstance(); - for (Iterator iterator = modelEntityTwo.getFieldsIterator(); iterator.hasNext();) { - ModelField mf = (ModelField) iterator.next(); + for (Iterator<ModelField> iterator = modelEntityTwo.getFieldsIterator(); iterator.hasNext();) { + ModelField mf = iterator.next(); collist.add(mf.getColName()); fldlist.add(mf.getName()); @@ -821,7 +802,7 @@ // construct the source entity qualifier // get the fields from relation description kmsize = modelRelationOne.getKeyMapsSize(); - Map bindMap = FastMap.newInstance(); + Map<ModelField, Object> bindMap = FastMap.newInstance(); for (int i = 0; i < kmsize; i++) { // get the equivalent column names in the relation @@ -852,16 +833,13 @@ sqlsb.append(SqlJdbcUtil.makeOrderByClause(modelEntityTwo, orderBy, true, datasourceInfo)); // now execute the query - List retlist = FastList.newInstance(); + List<GenericValue> retlist = FastList.newInstance(); GenericDelegator gd = value.getDelegator(); try { sqlP.prepareStatement(sqlsb.toString()); - Set entrySet = bindMap.entrySet(); - - for (Iterator iterator = entrySet.iterator(); iterator.hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); - ModelField mf = (ModelField) entry.getKey(); + for (Map.Entry<ModelField, Object> entry: bindMap.entrySet()) { + ModelField mf = entry.getKey(); Object curvalue = entry.getValue(); SqlJdbcUtil.setValue(sqlP, mf, modelEntityOne.getEntityName(), curvalue, modelFieldTypeReader); @@ -870,13 +848,12 @@ //int collsize = collist.size(); while (sqlP.next()) { - GenericValue gv = gd.makeValue(modelEntityTwo.getEntityName(), Collections.EMPTY_MAP); + Map<String, Object> emptyMap = Collections.emptyMap(); + GenericValue gv = gd.makeValue(modelEntityTwo.getEntityName(), emptyMap); // loop thru all columns for in one row int idx = 1; - Iterator fldIter = fldlist.iterator(); - while (fldIter.hasNext()) { - String fldname = (String) fldIter.next(); + for (String fldname: fldlist) { ModelField mf = modelEntityTwo.getField(fldname); SqlJdbcUtil.getValue(sqlP.getResultSet(), idx, mf, gv, modelFieldTypeReader); idx++; @@ -920,7 +897,7 @@ // WHERE clause StringBuilder whereString = new StringBuilder(); String entityCondWhereString = ""; - List whereEntityConditionParams = FastList.newInstance(); + List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance(); if (whereEntityCondition != null) { entityCondWhereString = whereEntityCondition.makeWhereString(modelEntity, whereEntityConditionParams, this.datasourceInfo); } @@ -957,7 +934,7 @@ // HAVING clause String entityCondHavingString = ""; - List havingEntityConditionParams = FastList.newInstance(); + List<EntityConditionParam> havingEntityConditionParams = FastList.newInstance(); if (havingEntityCondition != null) { entityCondHavingString = havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo); } @@ -976,9 +953,7 @@ Debug.logVerbose("Setting the whereEntityConditionParams: " + whereEntityConditionParams, module); } // set all of the values from the Where EntityCondition - Iterator whereEntityConditionParamsIter = whereEntityConditionParams.iterator(); - while (whereEntityConditionParamsIter.hasNext()) { - EntityConditionParam whereEntityConditionParam = (EntityConditionParam) whereEntityConditionParamsIter.next(); + for (EntityConditionParam whereEntityConditionParam: whereEntityConditionParams) { SqlJdbcUtil.setValue(sqlP, whereEntityConditionParam.getModelField(), modelEntity.getEntityName(), whereEntityConditionParam.getFieldValue(), modelFieldTypeReader); } if (verboseOn) { @@ -986,9 +961,7 @@ Debug.logVerbose("Setting the havingEntityConditionParams: " + havingEntityConditionParams, module); } // set all of the values from the Having EntityCondition - Iterator havingEntityConditionParamsIter = havingEntityConditionParams.iterator(); - while (havingEntityConditionParamsIter.hasNext()) { - EntityConditionParam havingEntityConditionParam = (EntityConditionParam) havingEntityConditionParamsIter.next(); + for (EntityConditionParam havingEntityConditionParam: havingEntityConditionParams) { SqlJdbcUtil.setValue(sqlP, havingEntityConditionParam.getModelField(), modelEntity.getEntityName(), havingEntityConditionParam.getFieldValue(), modelFieldTypeReader); } @@ -1084,13 +1057,13 @@ /* ====================================================================== */ - public void checkDb(Map modelEntities, List messages, boolean addMissing) { + public void checkDb(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) { DatabaseUtil dbUtil = new DatabaseUtil(this.helperName); dbUtil.checkDb(modelEntities, messages, addMissing); } /** Creates a list of ModelEntity objects based on meta data from the database */ - public List induceModelFromDb(Collection messages) { + public List<ModelEntity> induceModelFromDb(Collection<String> messages) { DatabaseUtil dbUtil = new DatabaseUtil(this.helperName); return dbUtil.induceModelFromDb(messages); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java?rev=585841&r1=585840&r2=585841&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelper.java Wed Oct 17 20:52:08 2007 @@ -62,13 +62,13 @@ *@param keys The keys, or names, of the values to retrieve; only these values will be retrieved *@return The GenericValue corresponding to the primaryKey */ - public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set keys) throws GenericEntityException; + public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException; /** Find a number of Generic Value objects by their Primary Keys, all at once *@param primaryKeys A List of primary keys to find by. *@return List of GenericValue objects corresponding to the passed primaryKey objects */ - public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException; + public List<GenericValue> findAllByPrimaryKeys(List<GenericPK> primaryKeys) throws GenericEntityException; /** Remove a Generic Entity corresponding to the primaryKey *@param primaryKey The primary key of the entity to remove. @@ -76,8 +76,8 @@ */ public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; - public List findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, - ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException; + public List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, + ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException; /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file @@ -90,7 +90,7 @@ * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, - EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) + EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException; public long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, @@ -110,7 +110,7 @@ *@return int representing number of rows effected by this operation *@throws GenericEntityException */ - public int storeByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException; + public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException; /** Store the Entity from the GenericValue to the persistent store *@param value GenericValue instance containing the entity @@ -123,5 +123,5 @@ *@param messages List to put any result messages in *@param addMissing Flag indicating whether or not to add missing entities and fields on the server */ - public void checkDataSource(Map modelEntities, List messages, boolean addMissing) throws GenericEntityException; + public void checkDataSource(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) throws GenericEntityException; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java?rev=585841&r1=585840&r2=585841&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperDAO.java Wed Oct 17 20:52:08 2007 @@ -86,7 +86,7 @@ *@param keys The keys, or names, of the values to retrieve; only these values will be retrieved *@return The GenericValue corresponding to the primaryKey */ - public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set keys) throws GenericEntityException { + public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException { if (primaryKey == null) { return null; } @@ -102,14 +102,11 @@ *@param primaryKeys A List of primary keys to find by. *@return List of GenericValue objects corresponding to the passed primaryKey objects */ - public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException { + public List<GenericValue> findAllByPrimaryKeys(List<GenericPK> primaryKeys) throws GenericEntityException { if (primaryKeys == null) return null; - List results = new LinkedList(); + List<GenericValue> results = new LinkedList<GenericValue>(); - Iterator pkiter = primaryKeys.iterator(); - - while (pkiter.hasNext()) { - GenericPK primaryKey = (GenericPK) pkiter.next(); + for (GenericPK primaryKey: primaryKeys) { GenericValue result = this.findByPrimaryKey(primaryKey); if (result != null) results.add(result); @@ -138,13 +135,13 @@ * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. */ public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, - EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) + EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { return genericDAO.selectListIteratorByCondition(modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); } - public List findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, - ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException { + public List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, + ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException { return genericDAO.selectByMultiRelation(value, modelRelationOne, modelEntityOne, modelRelationTwo, modelEntityTwo, orderBy); } @@ -182,7 +179,7 @@ *@return int representing number of rows effected by this operation *@throws GenericEntityException */ - public int storeByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException { + public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { if (modelEntity == null || condition == null) { return 0; } @@ -194,7 +191,7 @@ *@param messages List to put any result messages in *@param addMissing Flag indicating whether or not to add missing entities and fields on the server */ - public void checkDataSource(Map modelEntities, List messages, boolean addMissing) throws GenericEntityException { + public void checkDataSource(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) throws GenericEntityException { genericDAO.checkDb(modelEntities, messages, addMissing); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java?rev=585841&r1=585840&r2=585841&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericHelperFactory.java Wed Oct 17 20:52:08 2007 @@ -34,16 +34,16 @@ 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 Map<String, GenericHelper> helperCache = new HashMap<String, GenericHelper>(); public static GenericHelper getHelper(String helperName) { - GenericHelper helper = (GenericHelper) helperCache.get(helperName); + GenericHelper helper = helperCache.get(helperName); if (helper == null) // don't want to block here { synchronized (GenericHelperFactory.class) { // must check if null again as one of the blocked threads can still enter - helper = (GenericHelper) helperCache.get(helperName); + helper = helperCache.get(helperName); if (helper == null) { try { DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName); @@ -52,7 +52,7 @@ throw new IllegalStateException("Could not find datasource definition with name " + helperName); } String helperClassName = datasourceInfo.helperClass; - Class helperClass = null; + Class<?> helperClass = null; if (helperClassName != null && helperClassName.length() > 0) { try { @@ -64,7 +64,7 @@ } } - Class[] paramTypes = new Class[] {String.class}; + Class<?>[] paramTypes = new Class<?>[] {String.class}; Object[] params = new Object[] {helperName}; java.lang.reflect.Constructor helperConstructor = null; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java?rev=585841&r1=585840&r2=585841&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/MemoryHelper.java Wed Oct 17 20:52:08 2007 @@ -51,10 +51,10 @@ public class MemoryHelper implements GenericHelper { public static final String module = MemoryHelper.class.getName(); - private static Map cache = new HashMap(); + private static Map<String, HashMap<GenericPK, GenericValue>> cache = new HashMap<String, HashMap<GenericPK, GenericValue>>(); public static void clearCache() { - cache = new HashMap(); + cache = new HashMap<String, HashMap<GenericPK, GenericValue>>(); } private String helperName; @@ -69,9 +69,9 @@ } value = (GenericValue) value.clone(); - HashMap entityCache = (HashMap) cache.get(value.getEntityName()); + HashMap<GenericPK, GenericValue> entityCache = cache.get(value.getEntityName()); if (entityCache == null) { - entityCache = new HashMap(); + entityCache = new HashMap<GenericPK, GenericValue>(); cache.put(value.getEntityName(), entityCache); } @@ -84,12 +84,12 @@ return null; } - HashMap entityCache = (HashMap) cache.get(pk.getEntityName()); + HashMap<GenericPK, GenericValue> entityCache = cache.get(pk.getEntityName()); if (entityCache == null) { return null; } - GenericValue value = (GenericValue) entityCache.get(pk); + GenericValue value = entityCache.get(pk); if (value == null) { return null; } else { @@ -102,7 +102,7 @@ return 0; } - HashMap entityCache = (HashMap) cache.get(pk.getEntityName()); + HashMap<GenericPK, GenericValue> entityCache = cache.get(pk.getEntityName()); if (entityCache == null) { return 0; } @@ -120,7 +120,7 @@ return 0; } - HashMap entityCache = (HashMap) cache.get(entityName); + HashMap<GenericPK, GenericValue> entityCache = cache.get(entityName); if (entityCache == null) { return 0; } @@ -137,9 +137,8 @@ return count; } - private boolean isAndMatch(Map values, Map fields) { - for (Iterator iterator = fields.entrySet().iterator(); iterator.hasNext();) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); + private boolean isAndMatch(Map<String, Object> values, Map<String, Object> fields) { + for (Map.Entry<String, Object> mapEntry: fields.entrySet()) { if (mapEntry.getValue() == null) { if (values.get(mapEntry.getKey()) != null) { return false; @@ -158,9 +157,8 @@ return true; } - private boolean isOrMatch(Map values, Map fields) { - for (Iterator iterator = fields.entrySet().iterator(); iterator.hasNext();) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); + private boolean isOrMatch(Map<String, Object> values, Map<String, Object> fields) { + for (Map.Entry<String, Object> mapEntry: fields.entrySet()) { if (mapEntry.getValue() == null) { if (values.get(mapEntry.getKey()) == null) { return true; @@ -183,24 +181,23 @@ ModelEntity me = value.getModelEntity(); // make sure the PKs exist - for (Iterator iterator = me.getPksIterator(); iterator.hasNext();) { - ModelField field = (ModelField) iterator.next(); + for (Iterator<ModelField> iterator = me.getPksIterator(); iterator.hasNext();) { + ModelField field = iterator.next(); if (!value.containsKey(field.getName())) { return false; } } // make sure the value doesn't have any extra (unknown) fields - for (Iterator iterator = value.entrySet().iterator(); iterator.hasNext();) { - Map.Entry entry = (Map.Entry) iterator.next(); - if (me.getField((String) entry.getKey()) == null) { + for (Map.Entry<String, Object> entry: value.entrySet()) { + if (me.getField(entry.getKey()) == null) { return false; } } // make sure all fields that are in the value are of the right type - for (Iterator iterator = me.getFieldsIterator(); iterator.hasNext();) { - ModelField field = (ModelField) iterator.next(); + for (Iterator<ModelField> iterator = me.getFieldsIterator(); iterator.hasNext();) { + ModelField field = iterator.next(); Object o = value.get(field.getName()); int typeValue = 0; try { @@ -297,16 +294,15 @@ return findFromCache(primaryKey); } - public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set keys) throws GenericEntityException { + public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException { GenericValue value = findFromCache(primaryKey); value.setFields(value.getFields(keys)); return value; } - public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException { - ArrayList result = new ArrayList(primaryKeys.size()); - for (Iterator iterator = primaryKeys.iterator(); iterator.hasNext();) { - GenericPK pk = (GenericPK) iterator.next(); + public List<GenericValue> findAllByPrimaryKeys(List<GenericPK> primaryKeys) throws GenericEntityException { + ArrayList<GenericValue> result = new ArrayList<GenericValue>(primaryKeys.size()); + for (GenericPK pk: primaryKeys) { result.add(this.findByPrimaryKey(pk)); } @@ -317,17 +313,14 @@ return removeFromCache(primaryKey); } - public List findByAnd(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException { - HashMap entityCache = (HashMap) cache.get(modelEntity.getEntityName()); + public List<GenericValue> findByAnd(ModelEntity modelEntity, Map<String, Object> fields, List<String> orderBy) throws GenericEntityException { + HashMap<GenericPK, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } - ArrayList result = new ArrayList(); - for (Iterator iterator = entityCache.entrySet().iterator(); iterator.hasNext();) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); - GenericValue value = (GenericValue) mapEntry.getValue(); - + ArrayList<GenericValue> result = new ArrayList<GenericValue>(); + for (GenericValue value: entityCache.values()) { if (isAndMatch(value.getAllFields(), fields)) { result.add(value); } @@ -336,25 +329,22 @@ return result; } - public List findByAnd(ModelEntity modelEntity, List expressions, List orderBy) throws GenericEntityException { + public List<GenericValue> findByAnd(ModelEntity modelEntity, List<EntityCondition> expressions, List<String> orderBy) throws GenericEntityException { return null; } - public List findByLike(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException { + public List<GenericValue> findByLike(ModelEntity modelEntity, Map<String, Object> fields, List<String> orderBy) throws GenericEntityException { return null; } - public List findByOr(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException { - HashMap entityCache = (HashMap) cache.get(modelEntity.getEntityName()); + public List<GenericValue> findByOr(ModelEntity modelEntity, Map<String, Object> fields, List<String> orderBy) throws GenericEntityException { + HashMap<GenericPK, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } - ArrayList result = new ArrayList(); - for (Iterator iterator = entityCache.entrySet().iterator(); iterator.hasNext();) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); - GenericValue value = (GenericValue) mapEntry.getValue(); - + ArrayList<GenericValue> result = new ArrayList<GenericValue>(); + for (GenericValue value: entityCache.values()) { if (isOrMatch(value.getAllFields(), fields)) { result.add(value); } @@ -364,22 +354,22 @@ } - public List findByOr(ModelEntity modelEntity, List expressions, List orderBy) throws GenericEntityException { + public List<GenericValue> findByOr(ModelEntity modelEntity, List<EntityCondition> expressions, List<String> orderBy) throws GenericEntityException { return null; } - public List findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, - Collection fieldsToSelect, List orderBy) throws GenericEntityException { + public List<GenericValue> findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, + Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException { return null; } - public List findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, - ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException { + public List<GenericValue> findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, + ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException { return null; } public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, - EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) + EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { return null; } @@ -388,16 +378,15 @@ return 0; } - public int removeByAnd(ModelEntity modelEntity, Map fields) throws GenericEntityException { - HashMap entityCache = (HashMap) cache.get(modelEntity.getEntityName()); + public int removeByAnd(ModelEntity modelEntity, Map<String, Object> fields) throws GenericEntityException { + HashMap<GenericPK, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { return 0; } - ArrayList removeList = new ArrayList(); - for (Iterator iterator = entityCache.entrySet().iterator(); iterator.hasNext();) { - Map.Entry mapEntry = (Map.Entry) iterator.next(); - GenericValue value = (GenericValue) mapEntry.getValue(); + ArrayList<GenericPK> removeList = new ArrayList<GenericPK>(); + for (Map.Entry<GenericPK, GenericValue> mapEntry: entityCache.entrySet()) { + GenericValue value = mapEntry.getValue(); if (isAndMatch(value.getAllFields(), fields)) { removeList.add(mapEntry.getKey()); } @@ -410,7 +399,7 @@ return removeFromCache(modelEntity.getEntityName(), condition); } - public int storeByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException { + public int storeByCondition(ModelEntity modelEntity, Map<String, ? extends Object> fieldsToSet, EntityCondition condition) throws GenericEntityException { return 0; } @@ -422,10 +411,9 @@ } } - public int storeAll(List values) throws GenericEntityException { + public int storeAll(List<GenericValue> values) throws GenericEntityException { int count = 0; - for (Iterator iterator = values.iterator(); iterator.hasNext();) { - GenericValue gv = (GenericValue) iterator.next(); + for (GenericValue gv: values) { if (addToCache(gv)) { count++; } @@ -434,17 +422,16 @@ return count; } - public int removeAll(List dummyPKs) throws GenericEntityException { + public int removeAll(List<GenericPK> dummyPKs) throws GenericEntityException { int count = 0; - for (Iterator iterator = dummyPKs.iterator(); iterator.hasNext();) { - GenericPK pk = (GenericPK) iterator.next(); + for (GenericPK pk: dummyPKs) { count = count + removeFromCache(pk); } return count; } - public void checkDataSource(Map modelEntities, List messages, boolean addMissing) throws GenericEntityException { + public void checkDataSource(Map<String, ModelEntity> modelEntities, List<String> messages, boolean addMissing) throws GenericEntityException { messages.add("checkDataSource not implemented for MemoryHelper"); } } |
Free forum by Nabble | Edit this page |