Skip to content

Commit

Permalink
Some small optimizations in the entity engine - don't repeatedly buil…
Browse files Browse the repository at this point in the history
…d things that don't change over time.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1668232 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
adrian-crum committed Mar 21, 2015
1 parent 269e982 commit a6d4783
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
8 changes: 1 addition & 7 deletions framework/entity/src/org/ofbiz/entity/GenericEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,7 @@ private Object get(ModelEntity modelEntity, ModelEntity modelEntityToUse, String
}

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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

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() {
Expand All @@ -44,13 +45,13 @@ public void clear() {
}

public String getCacheNamePrefix() {
return "entitycache." + id + "." + delegatorName + ".";
return cacheNamePrefix;
}

public String[] getCacheNamePrefixes() {
return new String[] {
"entitycache." + id + ".${delegator-name}.",
"entitycache." + id + "." + delegatorName + "."
cacheNamePrefix
};
}

Expand Down
19 changes: 14 additions & 5 deletions framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class ModelEntity implements Comparable<ModelEntity>, Serializable {

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>();

Expand Down Expand Up @@ -168,7 +170,6 @@ public ModelEntity(ModelReader reader, Element entityElement, UtilTimer utilTime
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());
}
Expand Down Expand Up @@ -216,6 +217,7 @@ public ModelEntity(ModelReader reader, Element entityElement, UtilTimer utilTime
pks.add(pkField);
}
}
pkFieldNames.trimToSize();
pks.trimToSize();
nopks.trimToSize();
reader.incrementFieldCount(fieldsMap.size());
Expand Down Expand Up @@ -375,6 +377,9 @@ public void addExtendEntity(ModelReader reader, Element extendEntityElement) {
this.pks.remove(existingField);
}
this.pks.add(newField);
if (!this.pkFieldNames.contains(newField.getName())) {
this.pkFieldNames.add(newField.getName());
}
}
}
}
Expand Down Expand Up @@ -627,6 +632,9 @@ public void addField(ModelField field) {
fieldsMap.put(field.getName(), field);
if (field.getIsPk()) {
pks.add(field);
if (!pkFieldNames.contains(field.getName())) {
pkFieldNames.add(field.getName());
}
} else {
nopks.add(field);
}
Expand All @@ -642,6 +650,7 @@ public ModelField removeField(String fieldName) {
this.fieldsList.remove(field);
if (field.getIsPk()) {
pks.remove(field);
pkFieldNames.remove(field.getName());
} else {
nopks.remove(field);
}
Expand All @@ -652,14 +661,14 @@ public ModelField removeField(String fieldName) {

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() {
Expand Down

0 comments on commit a6d4783

Please sign in to comment.