Author: adrianc Date: Sat Mar 21 10:47:49 2015 New Revision: 1668232 URL: http://svn.apache.org/r1668232 Log: Some small optimizations in the entity engine - don't repeatedly build things that don't change over time.
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=1668232&r1=1668231&r2=1668232&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Sat Mar 21 10:47:49 2015 @@ -905,13 +905,7 @@ public class GenericEntity implements Ma } public GenericPK getPrimaryKey() { - Collection<String> pkNames = new LinkedList<String>(); - Iterator<ModelField> iter = this.getModelEntity().getPksIterator(); - while (iter != null && iter.hasNext()) { - ModelField curField = iter.next(); - pkNames.add(curField.getName()); - } - return GenericPK.create(this.getDelegator(), getModelEntity(), this.getFields(pkNames)); + return GenericPK.create(this.getDelegator(), getModelEntity(), getFields(getModelEntity().getPkFieldNames())); } /** go through the pks and for each one see if there is an entry in fields to set */ Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java?rev=1668232&r1=1668231&r2=1668232&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/cache/AbstractCache.java Sat Mar 21 10:47:49 2015 @@ -24,11 +24,12 @@ import org.ofbiz.entity.DelegatorFactory public abstract class AbstractCache<K, V> { - protected String delegatorName, id; + protected final String delegatorName, id, cacheNamePrefix; protected AbstractCache(String delegatorName, String id) { this.delegatorName = delegatorName; this.id = id; + this.cacheNamePrefix = "entitycache.".concat(id).concat(".").concat(delegatorName).concat("."); } public Delegator getDelegator() { @@ -44,13 +45,13 @@ public abstract class AbstractCache<K, V } public String getCacheNamePrefix() { - return "entitycache." + id + "." + delegatorName + "."; + return cacheNamePrefix; } public String[] getCacheNamePrefixes() { return new String[] { "entitycache." + id + ".${delegator-name}.", - "entitycache." + id + "." + delegatorName + "." + cacheNamePrefix }; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=1668232&r1=1668231&r2=1668232&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Sat Mar 21 10:47:49 2015 @@ -98,6 +98,8 @@ public class ModelEntity implements Comp private final Map<String, ModelField> fieldsMap = new HashMap<String, ModelField>(); + private final ArrayList<String> pkFieldNames = new ArrayList<String>(); + /** A List of the Field objects for the Entity, one for each Primary Key */ private final ArrayList<ModelField> pks = new ArrayList<ModelField>(); @@ -168,7 +170,6 @@ public class ModelEntity implements Comp if (utilTimer != null) utilTimer.timerString(" createModelEntity: before general/basic info"); this.populateBasicInfo(entityElement); if (utilTimer != null) utilTimer.timerString(" createModelEntity: before prim-keys"); - List<String> pkFieldNames = new ArrayList<String>(); for (Element pkElement: UtilXml.childElementList(entityElement, "prim-key")) { pkFieldNames.add(pkElement.getAttribute("field").intern()); } @@ -216,6 +217,7 @@ public class ModelEntity implements Comp pks.add(pkField); } } + pkFieldNames.trimToSize(); pks.trimToSize(); nopks.trimToSize(); reader.incrementFieldCount(fieldsMap.size()); @@ -375,6 +377,9 @@ public class ModelEntity implements Comp this.pks.remove(existingField); } this.pks.add(newField); + if (!this.pkFieldNames.contains(newField.getName())) { + this.pkFieldNames.add(newField.getName()); + } } } } @@ -627,6 +632,9 @@ public class ModelEntity implements Comp fieldsMap.put(field.getName(), field); if (field.getIsPk()) { pks.add(field); + if (!pkFieldNames.contains(field.getName())) { + pkFieldNames.add(field.getName()); + } } else { nopks.add(field); } @@ -642,6 +650,7 @@ public class ModelEntity implements Comp this.fieldsList.remove(field); if (field.getIsPk()) { pks.remove(field); + pkFieldNames.remove(field.getName()); } else { nopks.remove(field); } @@ -652,14 +661,14 @@ public class ModelEntity implements Comp public List<String> getAllFieldNames() { synchronized (fieldsLock) { - List<String> newList = new ArrayList<String>(fieldsMap.size()); - newList.addAll(this.fieldsMap.keySet()); - return newList; + return new ArrayList<String>(this.fieldsMap.keySet()); } } public List<String> getPkFieldNames() { - return getFieldNamesFromFieldVector(getPkFields()); + synchronized (fieldsLock) { + return new ArrayList<String>(pkFieldNames); + } } public List<String> getNoPkFieldNames() {