Author: jonesde
Date: Mon Jun 30 10:04:43 2008 New Revision: 672821 URL: http://svn.apache.org/viewvc?rev=672821&view=rev Log: Changed to support a default-group-name per delegator, so that they don't have to specified for each entity; also some cleanups of the DelegatorInterface to remove deprecated stuff and add some new things, I still don't think that needs to exist but oh well Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java ofbiz/trunk/framework/entity/dtd/entity-config.xsd ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorInterface.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DelegatorInfo.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilJavaParse.java Mon Jun 30 10:04:43 2008 @@ -158,7 +158,6 @@ static { entityMethodNames.add("getModelEntity"); entityMethodNames.add("getEntityGroupName"); - entityMethodNames.add("getModelEntitiesByGroup"); entityMethodNames.add("getModelEntityMapByGroup"); entityMethodNames.add("getGroupHelperName"); entityMethodNames.add("getEntityHelperName"); Modified: ofbiz/trunk/framework/entity/dtd/entity-config.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entity-config.xsd?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/dtd/entity-config.xsd (original) +++ ofbiz/trunk/framework/entity/dtd/entity-config.xsd Mon Jun 30 10:04:43 2008 @@ -117,6 +117,7 @@ <xs:attribute type="xs:string" name="distributed-cache-clear-class-name" default="org.ofbiz.entityext.cache.EntityCacheServices"/> <xs:attribute type="xs:string" name="distributed-cache-clear-user-login-id" default="system"/> <xs:attribute type="xs:string" name="sequenced-id-prefix"/> + <xs:attribute type="xs:string" name="default-group-name" default="org.ofbiz"/> </xs:attributeGroup> <xs:element name="group-map"> <xs:complexType> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorInterface.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorInterface.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorInterface.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/DelegatorInterface.java Mon Jun 30 10:04:43 2008 @@ -49,9 +49,7 @@ String getEntityGroupName(String entityName); - List<ModelEntity> getModelEntitiesByGroup(String groupName); - - Map<String, ModelEntity> getModelEntityMapByGroup(String groupName); + Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) throws GenericEntityException; String getGroupHelperName(String groupName); @@ -105,30 +103,16 @@ GenericValue createOrStore(GenericValue value) throws GenericEntityException; - GenericValue findByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; - - GenericValue findByPrimaryKeyCache(GenericPK primaryKey) throws GenericEntityException; - - GenericValue findByPrimaryKey(String entityName, Object... fields) throws GenericEntityException; + GenericValue findOne(String entityName, Map<String, ? extends Object> fields, boolean useCache) throws GenericEntityException; GenericValue findByPrimaryKey(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; - GenericValue findByPrimaryKeySingle(String entityName, Object singlePkValue) throws GenericEntityException; - GenericValue findByPrimaryKeyCache(String entityName, Object... fields) throws GenericEntityException; GenericValue findByPrimaryKeyCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; - GenericValue findByPrimaryKeyCacheSingle(String entityName, Object singlePkValue) throws GenericEntityException; - - GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, String... keys) throws GenericEntityException; - GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException; - List<GenericValue> findAllByPrimaryKeys(Collection<GenericPK> primaryKeys) throws GenericEntityException; - - List<GenericValue> findAllByPrimaryKeysCache(Collection<GenericPK> primaryKeys) throws GenericEntityException; - int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; @@ -137,65 +121,28 @@ int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException; - List<GenericValue> findAll(String entityName) throws GenericEntityException; - - List<GenericValue> findAll(String entityName, String... orderBy) throws GenericEntityException; - - List<GenericValue> findAll(String entityName, List<String> orderBy) throws GenericEntityException; - - List<GenericValue> findAllCache(String entityName) throws GenericEntityException; - - List<GenericValue> findAllCache(String entityName, String... orderBy) throws GenericEntityException; - - List<GenericValue> findAllCache(String entityName, List<String> orderBy) throws GenericEntityException; - List<GenericValue> findByAnd(String entityName, Object... fields) throws GenericEntityException; List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; - List<GenericValue> findByOr(String entityName, Object... fields) throws GenericEntityException; - - List<GenericValue> findByOr(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; - List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; //List<GenericValue> findByAnd(ModelEntity modelEntity, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; List<GenericValue> findByOr(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; - List<GenericValue> findByAndCache(String entityName, Object... fields) throws GenericEntityException; - List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; - <T extends EntityCondition> List<GenericValue> findByAnd(String entityName, T... expressions) throws GenericEntityException; - - <T extends EntityCondition> List<GenericValue> findByAnd(String entityName, List<T> expressions) throws GenericEntityException; - - <T extends EntityCondition> List<GenericValue> findByOr(String entityName, T... expressions) throws GenericEntityException; - - <T extends EntityCondition> List<GenericValue> findByOr(String entityName, List<T> expressions) throws GenericEntityException; - - <T extends EntityCondition> List<GenericValue> findByAnd(String entityName, List<T> expressions, List<String> orderBy) throws GenericEntityException; - - <T extends EntityCondition> List<GenericValue> findByOr(String entityName, List<T> expressions, List<String> orderBy) throws GenericEntityException; - - List<GenericValue> findByLike(String entityName, Object... fields) throws GenericEntityException; - - List<GenericValue> findByLike(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; - - List<GenericValue> findByLike(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; - - List<GenericValue> findByCondition(String entityName, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException; - - EntityListIterator findListIteratorByCondition(String entityName, EntityCondition entityCondition, - Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException; - - EntityListIterator findListIteratorByCondition(String entityName, EntityCondition whereEntityCondition, - EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) - throws GenericEntityException; - + EntityListIterator find(String entityName, EntityCondition whereEntityCondition, + EntityCondition havingEntityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) + throws GenericEntityException; + + List<GenericValue> findList(String entityName, EntityCondition entityCondition, + Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions, boolean useCache) + throws GenericEntityException; + int removeByAnd(String entityName, Object... fields) throws GenericEntityException; int removeByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; @@ -210,14 +157,6 @@ List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException; - List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo) throws GenericEntityException; - - List<GenericValue> getRelated(String relationName, GenericValue value) throws GenericEntityException; - - List<GenericValue> getRelatedByAnd(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException; - - List<GenericValue> getRelatedOrderBy(String relationName, List<String> orderBy, GenericValue value) throws GenericEntityException; - List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value) throws GenericEntityException; GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Mon Jun 30 10:04:43 2008 @@ -191,8 +191,8 @@ //if (Debug.infoOn()) Debug.logInfo("Creating new Delegator with name \"" + delegatorName + "\".", module); this.delegatorName = delegatorName; - modelReader = ModelReader.getModelReader(delegatorName); - modelGroupReader = ModelGroupReader.getModelGroupReader(delegatorName); + this.modelReader = ModelReader.getModelReader(delegatorName); + this.modelGroupReader = ModelGroupReader.getModelGroupReader(delegatorName); cache = new Cache(delegatorName); @@ -242,7 +242,7 @@ // NOTE: doing some things before the ECAs and such to make sure it is in place just in case it is used in a service engine startup thing or something // put the delegator in the master Map by its name - delegatorCache.put(delegatorName, this); + this.delegatorCache.put(delegatorName, this); // setup the crypto class this.crypto = new EntityCrypto(this); @@ -305,10 +305,10 @@ } protected DelegatorInfo getDelegatorInfo() { - if (delegatorInfo == null) { - delegatorInfo = EntityConfigUtil.getDelegatorInfo(this.delegatorName); + if (this.delegatorInfo == null) { + this.delegatorInfo = EntityConfigUtil.getDelegatorInfo(this.delegatorName); } - return delegatorInfo; + return this.delegatorInfo; } /** Gets the instance of ModelReader that corresponds to this delegator @@ -344,55 +344,47 @@ */ public String getEntityGroupName(String entityName) { String groupName = getModelGroupReader().getEntityGroupName(entityName); + if (UtilValidate.isEmpty(groupName)) { + groupName = this.getDelegatorInfo().defaultGroupName; + } return groupName; } - /** Gets a list of entity models that are in a group corresponding to the specified group name - *@param groupName The name of the group - *@return List of ModelEntity instances - */ - public List<ModelEntity> getModelEntitiesByGroup(String groupName) { - Iterator<String> enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); - List<ModelEntity> entities = FastList.newInstance(); - - if (enames == null || !enames.hasNext()) - return entities; - while (enames.hasNext()) { - String ename = enames.next(); - ModelEntity entity = this.getModelEntity(ename); - - if (entity != null) - entities.add(entity); - } - return entities; - } - /** Gets a Map of entity name & entity model pairs that are in the named group *@param groupName The name of the group *@return Map of entityName String keys and ModelEntity instance values */ - public Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) { - Iterator<String> enames = UtilMisc.toIterator(getModelGroupReader().getEntityNamesByGroup(groupName)); + public Map<String, ModelEntity> getModelEntityMapByGroup(String groupName) throws GenericEntityException { + Set<String> entityNameSet = getModelGroupReader().getEntityNamesByGroup(groupName); + + if (this.getDelegatorInfo().defaultGroupName.equals(groupName)) { + // add all entities with no group name to the Set + Set<String> allEntityNames = this.getModelReader().getEntityNames(); + for (String entityName: allEntityNames) { + if (UtilValidate.isEmpty(getModelGroupReader().getEntityGroupName(entityName))) { + entityNameSet.add(entityName); + } + } + } + Map<String, ModelEntity> entities = FastMap.newInstance(); - - if (enames == null || !enames.hasNext()) { + if (entityNameSet == null || entityNameSet.size() == 0) { return entities; } int errorCount = 0; - while (enames.hasNext()) { - String ename = enames.next(); + for (String entityName: entityNameSet) { try { - ModelEntity entity = getModelReader().getModelEntity(ename); + ModelEntity entity = getModelReader().getModelEntity(entityName); if (entity != null) { entities.put(entity.getEntityName(), entity); } else { - throw new IllegalStateException("Could not find entity with name " + ename); + throw new IllegalStateException("Could not find entity with name " + entityName); } } catch (GenericEntityException ex) { errorCount++; - Debug.logError("Entity " + ename + " named in Entity Group with name " + groupName + " are not defined in any Entity Definition file", module); + Debug.logError("Entity [" + entityName + "] named in Entity Group with name " + groupName + " are not defined in any Entity Definition file", module); } } @@ -416,9 +408,7 @@ *@return String with the helper name that corresponds to this delegator and the specified entityName */ public String getEntityHelperName(String entityName) { - String groupName = getModelGroupReader().getEntityGroupName(entityName); - - return this.getGroupHelperName(groupName); + return this.getGroupHelperName(this.getEntityGroupName(entityName)); } /** Gets the helper name that corresponds to this delegator and the specified entity @@ -438,10 +428,11 @@ public GenericHelper getEntityHelper(String entityName) throws GenericEntityException { String helperName = getEntityHelperName(entityName); - if (helperName != null && helperName.length() > 0) + if (helperName != null && helperName.length() > 0) { return GenericHelperFactory.getHelper(helperName); - else + } else { throw new GenericEntityException("Helper name not found for entity " + entityName); + } } /** Gets the an instance of helper that corresponds to this delegator and the specified entity Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DelegatorInfo.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DelegatorInfo.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DelegatorInfo.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/config/DelegatorInfo.java Mon Jun 30 10:04:43 2008 @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -15,12 +15,10 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - *******************************************************************************/ + */ package org.ofbiz.entity.config; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; import org.ofbiz.base.util.UtilValidate; @@ -42,6 +40,7 @@ public String distributedCacheClearClassName; public String distributedCacheClearUserLoginId; public String sequencedIdPrefix; + public String defaultGroupName; public Map<String, String> groupMap = new HashMap<String, String>(); public DelegatorInfo(Element element) { @@ -60,10 +59,13 @@ if (UtilValidate.isEmpty(this.distributedCacheClearClassName)) this.distributedCacheClearClassName = "org.ofbiz.entityext.cache.EntityCacheServices"; this.distributedCacheClearUserLoginId = element.getAttribute("distributed-cache-clear-user-login-id"); - if (UtilValidate.isEmpty(this.distributedCacheClearUserLoginId)) this.distributedCacheClearUserLoginId= "admin"; + if (UtilValidate.isEmpty(this.distributedCacheClearUserLoginId)) this.distributedCacheClearUserLoginId = "admin"; this.sequencedIdPrefix = element.getAttribute("sequenced-id-prefix"); + this.defaultGroupName = element.getAttribute("default-group-name"); + if (UtilValidate.isEmpty(this.defaultGroupName)) this.defaultGroupName = "org.ofbiz"; + for (Element groupMapElement: UtilXml.childElementList(element, "group-map")) { groupMap.put(groupMapElement.getAttribute("group-name"), groupMapElement.getAttribute("datasource-name")); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelGroupReader.java Mon Jun 30 10:04:43 2008 @@ -22,25 +22,26 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import javolution.util.FastSet; + import org.ofbiz.base.component.ComponentConfig; import org.ofbiz.base.config.GenericConfigException; import org.ofbiz.base.config.MainResourceHandler; import org.ofbiz.base.config.ResourceHandler; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilTimer; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityConfException; import org.ofbiz.entity.config.DelegatorInfo; import org.ofbiz.entity.config.EntityConfigUtil; import org.ofbiz.entity.config.EntityGroupReaderInfo; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.cache.UtilCache; -import org.ofbiz.base.util.UtilTimer; -import org.ofbiz.base.util.UtilXml; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -173,28 +174,31 @@ public String getEntityGroupName(String entityName) { Map<String, String> gc = getGroupCache(); - if (gc != null) + if (gc != null) { return gc.get(entityName); - else + } else { return null; + } } - /** Creates a Collection with all of the groupNames defined in the specified XML Entity Group Descriptor file. - * @return A Collection of groupNames Strings + /** Creates a Set with all of the groupNames defined in the specified XML Entity Group Descriptor file. + * @return A Set of groupNames Strings */ - public Collection<String> getGroupNames() { + public Set<String> getGroupNames() { getGroupCache(); if (this.groupNames == null) return null; - return new ArrayList<String>(this.groupNames); + Set<String> newSet = FastSet.newInstance(); + newSet.addAll(this.groupNames); + return newSet; } - /** Creates a Collection with names of all of the entities for a given group + /** Creates a Set with names of all of the entities for a given group * @param groupName - * @return A Collection of entityName Strings + * @return A Set of entityName Strings */ - public Collection<String> getEntityNamesByGroup(String groupName) { + public Set<String> getEntityNamesByGroup(String groupName) { Map<String, String> gc = getGroupCache(); - Collection<String> enames = new LinkedList<String>(); + Set<String> enames = FastSet.newInstance(); if (groupName == null || groupName.length() <= 0) return enames; if (gc == null || gc.size() == 0) return enames; Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java?rev=672821&r1=672820&r2=672821&view=diff ============================================================================== --- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java (original) +++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/data/EntityDataServices.java Mon Jun 30 10:04:43 2008 @@ -41,6 +41,8 @@ import java.net.URL; import java.net.URISyntaxException; +import javolution.util.FastList; + /** * Entity Data Import/Export Services * @@ -336,14 +338,21 @@ String groupName = (String) context.get("groupName"); Boolean fixSizes = (Boolean) context.get("fixColSizes"); if (fixSizes == null) fixSizes = Boolean.FALSE; - List messages = new ArrayList(); + List<String> messages = FastList.newInstance(); String helperName = delegator.getGroupHelperName(groupName); DatabaseUtil dbUtil = new DatabaseUtil(helperName); - Map modelEntities = delegator.getModelEntityMapByGroup(groupName); - Set modelEntityNames = new TreeSet(modelEntities.keySet()); + Map<String, ModelEntity> modelEntities; + try { + modelEntities = delegator.getModelEntityMapByGroup(groupName); + } catch (GenericEntityException e) { + String errorMessage = "Error getting list of entities in group: " + e.toString(); + Debug.logError(e, errorMessage, module); + return ServiceUtil.returnError(errorMessage); + } + Set<String> modelEntityNames = new TreeSet(modelEntities.keySet()); - Iterator modelEntityNameIter = null; + Iterator<String> modelEntityNameIter = null; // step 1 - remove FK indices Debug.logImportant("Removing all foreign key indices", module); @@ -388,7 +397,7 @@ // step 5 - repair field sizes if (fixSizes.booleanValue()) { Debug.logImportant("Updating column field size changes", module); - List fieldsWrongSize = new LinkedList(); + List fieldsWrongSize = FastList.newInstance(); dbUtil.checkDb(modelEntities, fieldsWrongSize, messages, true, true, true, true); if (fieldsWrongSize.size() > 0) { dbUtil.repairColumnSizeChanges(modelEntities, fieldsWrongSize, messages); |
Free forum by Nabble | Edit this page |