You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2009/08/14 01:33:40 UTC

svn commit: r804060 [3/7] - in /ofbiz/branches/executioncontext20090812: applications/accounting/src/org/ofbiz/accounting/payment/ applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ applications/order/src/org/ofbiz/order/finaccount/ app...

Added: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java?rev=804060&view=auto
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java (added)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java Thu Aug 13 23:33:38 2009
@@ -0,0 +1,1446 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity;
+
+import java.io.PrintWriter;
+import java.math.BigDecimal;
+import java.sql.Blob;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Observable;
+import java.util.ResourceBundle;
+import java.util.TreeSet;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.ofbiz.base.crypto.HashCrypt;
+import org.ofbiz.base.util.Base64;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.jdbc.SqlJdbcUtil;
+import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelField;
+import org.ofbiz.entity.model.ModelFieldType;
+import org.ofbiz.entity.model.ModelViewEntity;
+import org.ofbiz.entity.model.ModelViewEntity.ModelAlias;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+/**
+ * Generic Entity Value Object - Handles persistence for any defined entity.
+ * <p>Note that this class extends <code>Observable</code> to achieve change notification for
+ * <code>Observer</code>s. Whenever a field changes the name of the field will be passed to
+ * the <code>notifyObservers()</code> method, and through that to the <code>update()</code> method of each
+ * <code>Observer</code>.
+ *
+ */
+@SuppressWarnings({ "unchecked", "serial" })
+public class GenericEntityImpl extends Observable implements GenericEntity {
+
+    public static final String module = GenericEntityImpl.class.getName();
+
+    /** Name of the GenericDelegator, used to re-get the GenericDelegator when deserialized */
+    protected String delegatorName = null;
+
+    /** Reference to an instance of GenericDelegator used to do some basic operations on this entity value. If null various methods in this class will fail. This is automatically set by the GenericDelegator for all GenericValue objects instantiated through it. You may set this manually for objects you instantiate manually, but it is optional. */
+    protected transient GenericDelegator internalDelegator = null;
+
+    /** Contains the fields for this entity. Note that this should always be a
+     *  HashMap to allow for two things: non-synchronized reads (synchronized
+     *  writes are done through synchronized setters) and being able to store
+     *  null values. Null values are important because with them we can distinguish
+     *  between desiring to set a value to null and desiring to not modify the
+     *  current value on an update.
+     */
+    protected Map<String, Object> fields = FastMap.newInstance();
+
+    /** Contains the entityName of this entity, necessary for efficiency when creating EJBs */
+    protected String entityName = null;
+
+    /** Contains the ModelEntity instance that represents the definition of this entity, not to be serialized */
+    protected transient ModelEntity modelEntity = null;
+
+    /** Denotes whether or not this entity has been modified, or is known to be out of sync with the persistent record */
+    protected boolean modified = false;
+    protected boolean generateHashCode = true;
+    protected int cachedHashCode = 0;
+
+    /** Used to specify whether or not this representation of the entity can be changed; generally cleared when this object comes from a cache */
+    protected boolean mutable = true;
+
+    /** This is an internal field used to specify that a value has come from a sync process and that the auto-stamps should not be over-written */
+    protected boolean isFromEntitySync = false;
+
+    /** Creates new GenericEntity - Should never be used, prefer the other options. */
+    protected GenericEntityImpl() { }
+
+    /** Creates new GenericEntity */
+    protected void init(ModelEntity modelEntity) {
+        if (modelEntity == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null modelEntity parameter");
+        }
+        this.modelEntity = modelEntity;
+        this.entityName = modelEntity.getEntityName();
+
+        // check some things
+        if (this.entityName == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null entityName in the modelEntity parameter");
+        }
+    }
+
+    /** Creates new GenericEntity from existing Map */
+    protected void init(ModelEntity modelEntity, Map<String, ? extends Object> fields) {
+        if (modelEntity == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null modelEntity parameter");
+        }
+        this.modelEntity = modelEntity;
+        this.entityName = modelEntity.getEntityName();
+        setFields(fields);
+
+        // check some things
+        if (this.entityName == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null entityName in the modelEntity parameter");
+        }
+    }
+
+    /** Creates new GenericEntity from existing Map */
+    protected void init(ModelEntity modelEntity, Object singlePkValue) {
+        if (modelEntity == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null modelEntity parameter");
+        }
+        if (modelEntity.getPksSize() != 1) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with more than one primary key field");
+        }
+        this.modelEntity = modelEntity;
+        this.entityName = modelEntity.getEntityName();
+        set(modelEntity.getOnlyPk().getName(), singlePkValue);
+
+        // check some things
+        if (this.entityName == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null entityName in the modelEntity parameter");
+        }
+    }
+
+    /** Copy Constructor: Creates new GenericEntity from existing GenericEntity */
+    protected void init(GenericEntity value) {
+        // check some things
+        if (value.getEntityName() == null) {
+            throw new IllegalArgumentException("Cannot create a GenericEntity with a null entityName in the modelEntity parameter");
+        }
+        this.entityName = value.getEntityName();
+        // NOTE: could call getModelEntity to insure we have a value, just in case the value passed in has been serialized, but might as well leave it null to keep the object light if it isn't there
+        this.modelEntity = value.getModelEntity();
+        if (value.getAllFields() != null) this.fields.putAll(value.getAllFields());
+        this.delegatorName = value.getDelegator().getDelegatorName();
+        this.internalDelegator = value.getDelegator();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#reset()
+	 */
+    public void reset() {
+        // from GenericEntity
+        this.delegatorName = null;
+        this.internalDelegator = null;
+        this.fields = FastMap.newInstance();
+        this.entityName = null;
+        this.modelEntity = null;
+        this.modified = false;
+        this.generateHashCode = true;
+        this.cachedHashCode = 0;
+        this.mutable = true;
+        this.isFromEntitySync = false;
+    }
+
+    public void refreshFromValue(GenericEntity newValue) throws GenericEntityException {
+        if (newValue == null) {
+            throw new GenericEntityException("Could not refresh value, new value not found for: " + this);
+        }
+        GenericPK thisPK = this.getPrimaryKey();
+        GenericPK newPK = newValue.getPrimaryKey();
+        if (!thisPK.equals(newPK)) {
+            throw new GenericEntityException("Could not refresh value, new value did not have the same primary key; this PK=" + thisPK + ", new value PK=" + newPK);
+        }
+        GenericEntityImpl that = (GenericEntityImpl) newValue;
+        this.fields = that.fields;
+        this.setDelegator(that.getDelegator());
+        this.generateHashCode = that.generateHashCode;
+        this.cachedHashCode = that.cachedHashCode;
+        this.modified = false;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#isModified()
+	 */
+    public boolean isModified() {
+        return this.modified;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#synchronizedWithDatasource()
+	 */
+    public void synchronizedWithDatasource() {
+        this.modified = false;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#removedFromDatasource()
+	 */
+    public void removedFromDatasource() {
+        // seems kind of minimal, but should do for now...
+        this.modified = true;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#isMutable()
+	 */
+    public boolean isMutable() {
+        return this.mutable;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setImmutable()
+	 */
+    public void setImmutable() {
+        this.mutable = false;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getIsFromEntitySync()
+	 */
+    public boolean getIsFromEntitySync() {
+        return this.isFromEntitySync;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setIsFromEntitySync(boolean)
+	 */
+    public void setIsFromEntitySync(boolean isFromEntitySync) {
+        this.isFromEntitySync = isFromEntitySync;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getEntityName()
+	 */
+    public String getEntityName() {
+        return entityName;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getModelEntity()
+	 */
+    public ModelEntity getModelEntity() {
+        if (modelEntity == null) {
+            if (entityName != null) modelEntity = this.getDelegator().getModelEntity(entityName);
+            if (modelEntity == null) {
+                throw new IllegalStateException("[EntityFactory.getModelEntity] could not find modelEntity for entityName " + entityName);
+            }
+        }
+        return modelEntity;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getDelegator()
+	 */
+    public GenericDelegator getDelegator() {
+        if (internalDelegator == null) {
+            if (delegatorName == null) delegatorName = "default";
+            if (delegatorName != null) internalDelegator = DelegatorFactory.getGenericDelegator(delegatorName);
+            if (internalDelegator == null) {
+                throw new IllegalStateException("[EntityFactory.getDelegator] could not find delegator with name " + delegatorName);
+            }
+        }
+        return internalDelegator;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setDelegator(org.ofbiz.entity.GenericDelegator)
+	 */
+    public void setDelegator(GenericDelegator internalDelegator) {
+        if (internalDelegator == null) return;
+        this.delegatorName = internalDelegator.getDelegatorName();
+        this.internalDelegator = internalDelegator;
+    }
+
+    protected Object getFieldValue(String name) {
+        if (getModelEntity().getField(name) == null) {
+            throw new IllegalArgumentException("[EntityFactory.get] \"" + name + "\" is not a field of " + entityName);
+        }
+        return fields.get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#isPrimaryKey()
+	 */
+    public boolean isPrimaryKey() {
+        return isPrimaryKey(false);
+    }
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#isPrimaryKey(boolean)
+	 */
+    public boolean isPrimaryKey(boolean requireValue) {
+        TreeSet<String> fieldKeys = new TreeSet<String>(this.fields.keySet());
+        for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) {
+            String fieldName = curPk.getName();
+            if (requireValue) {
+                if (this.fields.get(fieldName) == null) return false;
+            } else {
+                if (!this.fields.containsKey(fieldName)) return false;
+            }
+            fieldKeys.remove(fieldName);
+        }
+        if (!fieldKeys.isEmpty()) return false;
+        return true;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#containsPrimaryKey()
+	 */
+    public boolean containsPrimaryKey() {
+        return containsPrimaryKey(false);
+    }
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#containsPrimaryKey(boolean)
+	 */
+    public boolean containsPrimaryKey(boolean requireValue) {
+        //TreeSet fieldKeys = new TreeSet(fields.keySet());
+        for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) {
+            String fieldName = curPk.getName();
+            if (requireValue) {
+                if (this.fields.get(fieldName) == null) return false;
+            } else {
+                if (!this.fields.containsKey(fieldName)) return false;
+            }
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getPkShortValueString()
+	 */
+    public String getPkShortValueString() {
+        StringBuilder sb = new StringBuilder();
+        for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) {
+            if (sb.length() > 0) {
+                sb.append("::");
+            }
+            sb.append(this.get(curPk.getName()));
+        }
+        return sb.toString();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#set(java.lang.String, java.lang.Object)
+	 */
+    public void set(String name, Object value) {
+        set(name, value, true);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#set(java.lang.String, java.lang.Object, boolean)
+	 */
+    public synchronized Object set(String name, Object value, boolean setIfNull) {
+        if (!this.mutable) {
+            // comment this out to disable the mutable check
+            throw new IllegalStateException("This object has been flagged as immutable (unchangeable), probably because it came from an Entity Engine cache. Cannot set a value in an immutable entity object.");
+        }
+
+        ModelField modelField = getModelEntity().getField(name);
+        if (modelField == null) {
+            throw new IllegalArgumentException("[EntityFactory.set] \"" + name + "\" is not a field of " + entityName + ", must be one of: " + getModelEntity().fieldNameString());
+        }
+        if (value != null || setIfNull) {
+            ModelFieldType type = null;
+            try {
+                type = getDelegator().getEntityFieldType(getModelEntity(), modelField.getType());
+            } catch (GenericEntityException e) {
+                Debug.logWarning(e, module);
+            }
+            if (type == null) {
+                throw new IllegalArgumentException("Type " + modelField.getType() + " not found for entity [" + this.getEntityName() + "]; probably because there is no datasource (helper) setup for the entity group that this entity is in: [" + this.getDelegator().getEntityGroupName(this.getEntityName()) + "]");
+            }
+
+            if (value instanceof Boolean) {
+                // if this is a Boolean check to see if we should convert from an indicator or just leave as is
+                try {
+                    int fieldType = SqlJdbcUtil.getType(type.getJavaType());
+                    if (fieldType != 10) {
+                        value = ((Boolean) value).booleanValue() ? "Y" : "N";
+                    }
+                } catch (GenericNotImplementedException e) {
+                    throw new IllegalArgumentException(e.getMessage());
+                }
+            } else if (value != null && !(value instanceof EntityFactory.NULL)) {
+                // make sure the type matches the field Java type
+                if (!ObjectType.instanceOf(value, type.getJavaType())) {
+                    String errMsg = "In entity field [" + this.getEntityName() + "." + name + "] set the value passed in [" + value.getClass().getName() + "] is not compatible with the Java type of the field [" + type.getJavaType() + "]";
+                    // eventually we should do this, but for now we'll do a "soft" failure: throw new IllegalArgumentException(errMsg);
+                    Debug.logWarning(new Exception("Location of database type warning"), "=-=-=-=-=-=-=-=-= Database type warning EntityFactory.set =-=-=-=-=-=-=-=-= " + errMsg, module);
+                }
+            }
+            Object old = fields.put(name, value);
+
+            generateHashCode = true;
+            modified = true;
+            this.setChanged();
+            this.notifyObservers(name);
+            return old;
+        } else {
+            return fields.get(name);
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#dangerousSetNoCheckButFast(org.ofbiz.entity.model.ModelField, java.lang.Object)
+	 */
+    public void dangerousSetNoCheckButFast(ModelField modelField, Object value) {
+        if (modelField == null) throw new IllegalArgumentException("Cannot set field with a null modelField");
+        generateHashCode = true;
+        this.fields.put(modelField.getName(), value);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#dangerousGetNoCheckButFast(org.ofbiz.entity.model.ModelField)
+	 */
+    public Object dangerousGetNoCheckButFast(ModelField modelField) {
+        if (modelField == null) throw new IllegalArgumentException("Cannot get field with a null modelField");
+        return this.fields.get(modelField.getName());
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setString(java.lang.String, java.lang.String)
+	 */
+    public void setString(String name, String value) {
+        if (value == null) {
+            set(name, null);
+            return;
+        }
+
+        boolean isNullString = false;
+        if ("null".equals(value)) {
+            // count this as a null too, but only for numbers and stuff, not for Strings
+            isNullString = true;
+        }
+
+        ModelField field = getModelEntity().getField(name);
+        if (field == null) set(name, value); // this will get an error in the set() method...
+
+        ModelFieldType type = null;
+        try {
+            type = getDelegator().getEntityFieldType(getModelEntity(), field.getType());
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e, module);
+        }
+        if (type == null) throw new IllegalArgumentException("Type " + field.getType() + " not found");
+        String fieldType = type.getJavaType();
+
+        try {
+            switch (SqlJdbcUtil.getType(fieldType)) {
+            case 1:
+                set(name, value);
+                break;
+
+            case 2:
+                set(name, isNullString ? null : java.sql.Timestamp.valueOf(value));
+                break;
+
+            case 3:
+                set(name, isNullString ? null : java.sql.Time.valueOf(value));
+                break;
+
+            case 4:
+                set(name, isNullString ? null : java.sql.Date.valueOf(value));
+                break;
+
+            case 5:
+                set(name, isNullString ? null : Integer.valueOf(value));
+                break;
+
+            case 6:
+                set(name, isNullString ? null : Long.valueOf(value));
+                break;
+
+            case 7:
+                set(name, isNullString ? null : Float.valueOf(value));
+                break;
+
+            case 8:
+                set(name, isNullString ? null : Double.valueOf(value));
+                break;
+
+            case 9: // BigDecimal
+                set(name, isNullString ? null : new BigDecimal(value));
+                break;
+
+            case 10:
+                set(name, isNullString ? null : Boolean.valueOf(value));
+                break;
+
+            case 11: // Object
+                set(name, value);
+                break;
+
+            case 12: // java.sql.Blob
+                // TODO: any better way to handle Blob from String?
+                set(name, value);
+                break;
+
+            case 13: // java.sql.Clob
+                // TODO: any better way to handle Clob from String?
+                set(name, value);
+                break;
+
+            case 14: // java.util.Date
+                set(name, UtilDateTime.toDate(value));
+                break;
+
+            case 15: // java.util.Collection
+                // TODO: how to convert from String to Collection? ie what should the default behavior be?
+                set(name, value);
+                break;
+            }
+        } catch (GenericNotImplementedException ex) {
+            throw new IllegalArgumentException(ex.getMessage());
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setBytes(java.lang.String, byte[])
+	 */
+    public void setBytes(String name, byte[] bytes) {
+        this.set(name, bytes);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setNextSeqId()
+	 */
+    public void setNextSeqId() {
+        List<String> pkFieldNameList = this.modelEntity.getPkFieldNames();
+        if (pkFieldNameList.size() != 1) {
+            throw new IllegalArgumentException("Cannot setNextSeqId for entity [" + this.getEntityName() + "] that does not have a single primary key field, instead has [" + pkFieldNameList.size() + "]");
+        }
+
+        String pkFieldName = pkFieldNameList.get(0);
+        if (this.get(pkFieldName) != null) {
+            // don't throw exception, too much of a pain and usually intended: throw new IllegalArgumentException("Cannot setNextSeqId, pk field [" + pkFieldName + "] of entity [" + this.getEntityName() + "] already has a value [" + this.get(pkFieldName) + "]");
+        }
+
+        String sequencedValue = this.getDelegator().getNextSeqId(this.getEntityName());
+        this.set(pkFieldName, sequencedValue);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getBoolean(java.lang.String)
+	 */
+    public Boolean getBoolean(String name) {
+        Object obj = get(name);
+
+        if (obj == null) {
+            return null;
+        }
+        if (obj instanceof Boolean) {
+            return (Boolean) obj;
+        } else if (obj instanceof String) {
+            String value = (String) obj;
+
+            if ("Y".equalsIgnoreCase(value) || "T".equalsIgnoreCase(value)) {
+                return Boolean.TRUE;
+            } else if ("N".equalsIgnoreCase(value) || "F".equalsIgnoreCase(value)) {
+                return Boolean.FALSE;
+            } else {
+                throw new IllegalArgumentException("getBoolean could not map the String '" + value + "' to Boolean type");
+            }
+        } else {
+            throw new IllegalArgumentException("getBoolean could not map the object '" + obj.toString() + "' to Boolean type, unknown object type: " + obj.getClass().getName());
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getString(java.lang.String)
+	 */
+    public String getString(String name) {
+        // might be nice to add some ClassCastException handling... and auto conversion? hmmm...
+        Object object = get(name);
+        if (object == null) return null;
+        if (object instanceof java.lang.String) {
+            return (String) object;
+        } else {
+            return object.toString();
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getTimestamp(java.lang.String)
+	 */
+    public java.sql.Timestamp getTimestamp(String name) {
+        return (java.sql.Timestamp) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getTime(java.lang.String)
+	 */
+    public java.sql.Time getTime(String name) {
+        return (java.sql.Time) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getDate(java.lang.String)
+	 */
+    public java.sql.Date getDate(String name) {
+        return (java.sql.Date) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getInteger(java.lang.String)
+	 */
+    public Integer getInteger(String name) {
+        return (Integer) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getLong(java.lang.String)
+	 */
+    public Long getLong(String name) {
+        return (Long) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getFloat(java.lang.String)
+	 */
+    public Float getFloat(String name) {
+        return (Float) get(name);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getDouble(java.lang.String)
+	 */
+    public Double getDouble(String name) {
+        // this "hack" is needed for now until the Double/BigDecimal issues are all resolved
+        Object value = get(name);
+        if (value instanceof BigDecimal) {
+            return Double.valueOf(((BigDecimal) value).doubleValue());
+        } else {
+            return (Double) value;
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getBigDecimal(java.lang.String)
+	 */
+    public BigDecimal getBigDecimal(String name) {
+        // this "hack" is needed for now until the Double/BigDecimal issues are all resolved
+        // NOTE: for things to generally work properly BigDecimal should really be used as the java-type in the field type def XML files
+        Object value = get(name);
+        if (value instanceof Double) {
+            return BigDecimal.valueOf(((Double) value).doubleValue());
+        } else {
+            return (BigDecimal) value;
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getBytes(java.lang.String)
+	 */
+    @SuppressWarnings("deprecation")
+    public byte[] getBytes(String name) {
+        Object value = get(name);
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof Blob) {
+            try {
+                Blob valueBlob = (Blob) value;
+                return valueBlob.getBytes(1, (int) valueBlob.length());
+            } catch (SQLException e) {
+                String errMsg = "Error getting byte[] from Blob: " + e.toString();
+                Debug.logError(e, errMsg, module);
+                return null;
+            }
+        }
+        if (value instanceof byte[]) {
+            return (byte[]) value;
+        }
+        if (value instanceof org.ofbiz.entity.util.ByteWrapper) {
+            // NOTE DEJ20071022: the use of ByteWrapper is not recommended and is deprecated, only old data should be stored that way
+            Debug.logWarning("Found a ByteWrapper object in the database for field [" + this.getEntityName() + "." + name + "]; converting to byte[] and returning, but note that you need to update your database to unwrap these objects for future compatibility", module);
+            org.ofbiz.entity.util.ByteWrapper wrapper = (org.ofbiz.entity.util.ByteWrapper) value;
+            return wrapper.getBytes();
+        }
+        // uh-oh, this shouldn't happen...
+        throw new IllegalArgumentException("In call to getBytes the value is not a supported type, should be byte[] or ByteWrapper, is: " + value.getClass().getName());
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#get(java.lang.String, java.util.Locale)
+	 */
+    public Object get(String name, Locale locale) {
+        return get(name, null, locale);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#get(java.lang.String, java.lang.String, java.util.Locale)
+	 */
+    public Object get(String name, String resource, Locale locale) {
+        Object fieldValue = null;
+        try {
+            fieldValue = getFieldValue(name);
+        } catch (IllegalArgumentException e) {
+            if (Debug.verboseOn()) {
+                Debug.logVerbose(e, "The field name (or key) [" + name + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
+            } else {
+                Debug.logWarning("The field name (or key) [" + name + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
+            }
+            fieldValue = null;
+        }
+
+        // In case of view entity try to retrieve the field heading from the real entity linked to the view
+        ModelEntity modelEntityToUse = this.getModelEntity();
+        if (modelEntityToUse instanceof ModelViewEntity) {
+            ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntityToUse;
+            Iterator<ModelAlias> it = modelViewEntity.getAliasesIterator();
+            while (it.hasNext()) {
+                ModelAlias modelAlias = it.next();
+                if (modelAlias.getName().equalsIgnoreCase(name)) {
+                    modelEntityToUse = modelViewEntity.getMemberModelEntity(modelAlias.getEntityAlias());
+                    name = modelAlias.getField();
+                    break;
+                }
+            }
+        }
+        if (UtilValidate.isEmpty(resource)) {
+            resource = modelEntityToUse.getDefaultResourceName();
+            // still empty? return the fieldValue
+            if (UtilValidate.isEmpty(resource)) {
+                //Debug.logWarning("Tried to getResource value for field named " + name + " but no resource name was passed to the method or specified in the default-resource-name attribute of the entity definition", module);
+                return fieldValue;
+            }
+        }
+        if (UtilProperties.isPropertiesResourceNotFound(resource, locale, false)) {
+            // Properties do not exist for this resource+locale combination
+            return fieldValue;
+        }
+        ResourceBundle bundle = null;
+        try {
+            bundle = UtilProperties.getResourceBundle(resource, locale);
+        } catch (IllegalArgumentException e) {
+            bundle = null;
+        }
+        if (bundle == null) {
+            //Debug.logWarning("Tried to getResource value for field named " + name + " but no resource was found with the name " + resource + " in the locale " + locale, module);
+            return fieldValue;
+        }
+
+        StringBuilder keyBuffer = new StringBuilder();
+        // start with the Entity Name
+        keyBuffer.append(modelEntityToUse.getEntityName());
+        // next add the Field Name
+        keyBuffer.append('.');
+        keyBuffer.append(name);
+        // finish off by adding the values of all PK fields
+        Iterator<ModelField> iter = modelEntityToUse.getPksIterator();
+        while (iter != null && iter.hasNext()) {
+            ModelField curField = iter.next();
+            keyBuffer.append('.');
+            keyBuffer.append(this.getFieldValue(curField.getName()));
+        }
+
+        String bundleKey = keyBuffer.toString();
+
+        Object resourceValue = null;
+        try {
+            resourceValue = bundle.getObject(bundleKey);
+        } catch (MissingResourceException e) {
+            return fieldValue;
+        }
+        if (resourceValue == null) {
+            return fieldValue;
+        } else {
+            return resourceValue;
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getPrimaryKey()
+	 */
+    public GenericPK getPrimaryKey() {
+        Collection<String> pkNames = FastList.newInstance();
+        Iterator<ModelField> iter = this.getModelEntity().getPksIterator();
+        while (iter != null && iter.hasNext()) {
+            ModelField curField = iter.next();
+            pkNames.add(curField.getName());
+        }
+        GenericPK newPK = EntityFactory.createGenericPK(getModelEntity(), this.getFields(pkNames));
+        newPK.setDelegator(this.getDelegator());
+        return newPK;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setPKFields(java.util.Map)
+	 */
+    public void setPKFields(Map<? extends Object, ? extends Object> fields) {
+        setAllFields(fields, true, null, Boolean.TRUE);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setPKFields(java.util.Map, boolean)
+	 */
+    public void setPKFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty) {
+        setAllFields(fields, setIfEmpty, null, Boolean.TRUE);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setNonPKFields(java.util.Map)
+	 */
+    public void setNonPKFields(Map<? extends Object, ? extends Object> fields) {
+        setAllFields(fields, true, null, Boolean.FALSE);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setNonPKFields(java.util.Map, boolean)
+	 */
+    public void setNonPKFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty) {
+        setAllFields(fields, setIfEmpty, null, Boolean.FALSE);
+    }
+
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setAllFields(java.util.Map, boolean, java.lang.String, java.lang.Boolean)
+	 */
+    public void setAllFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty, String namePrefix, Boolean pks) {
+        if (fields == null) {
+            return;
+        }
+        Iterator<ModelField> iter = null;
+        if (pks != null) {
+            if (pks.booleanValue()) {
+                iter = this.getModelEntity().getPksIterator();
+            } else {
+                iter = this.getModelEntity().getNopksIterator();
+            }
+        } else {
+            iter = this.getModelEntity().getFieldsIterator();
+        }
+
+        while (iter != null && iter.hasNext()) {
+            ModelField curField = iter.next();
+            String fieldName = curField.getName();
+            String sourceFieldName = null;
+            if (UtilValidate.isNotEmpty(namePrefix)) {
+                sourceFieldName = namePrefix + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
+            } else {
+                sourceFieldName = curField.getName();
+            }
+
+            if (fields.containsKey(sourceFieldName)) {
+                Object field = fields.get(sourceFieldName);
+
+                // if (Debug.verboseOn()) Debug.logVerbose("Setting field " + curField.getName() + ": " + field + ", setIfEmpty = " + setIfEmpty, module);
+                if (setIfEmpty) {
+                    // if empty string, set to null
+                    if (field != null && field instanceof String && ((String) field).length() == 0) {
+                        this.set(curField.getName(), null);
+                    } else {
+                        this.set(curField.getName(), field);
+                    }
+                } else {
+                    // okay, only set if not empty...
+                    if (field != null) {
+                        // if it's a String then we need to check length, otherwise set it because it's not null
+                        if (field instanceof String) {
+                            String fieldStr = (String) field;
+
+                            if (fieldStr.length() > 0) {
+                                this.set(curField.getName(), fieldStr);
+                            }
+                        } else {
+                            this.set(curField.getName(), field);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getAllKeys()
+	 */
+    public Collection<String> getAllKeys() {
+        return fields.keySet();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getAllFields()
+	 */
+    public Map<String, Object> getAllFields() {
+        Map<String, Object> newMap = FastMap.newInstance();
+        newMap.putAll(this.fields);
+        return newMap;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getFields(java.util.Collection)
+	 */
+    public Map<String, Object> getFields(Collection<String> keysofFields) {
+        if (keysofFields == null) return null;
+        Map<String, Object> aMap = FastMap.newInstance();
+
+        for (String aKey: keysofFields) {
+            aMap.put(aKey, this.fields.get(aKey));
+        }
+        return aMap;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#setFields(java.util.Map)
+	 */
+    public void setFields(Map<? extends String, ? extends Object> keyValuePairs) {
+        if (keyValuePairs == null) return;
+        // this could be implement with Map.putAll, but we'll leave it like this for the extra features it has
+        for (Map.Entry<? extends String, ? extends Object> anEntry: keyValuePairs.entrySet()) {
+            this.set(anEntry.getKey(), anEntry.getValue(), true);
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#matchesFields(java.util.Map)
+	 */
+    public boolean matchesFields(Map<String, ? extends Object> keyValuePairs) {
+        if (fields == null) return true;
+        if (keyValuePairs == null || keyValuePairs.size() == 0) return true;
+        for (Map.Entry<String, ? extends Object> anEntry: keyValuePairs.entrySet()) {
+            if (!UtilValidate.areEqual(anEntry.getValue(), this.fields.get(anEntry.getKey()))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#lockEnabled()
+	 */
+    public boolean lockEnabled() {
+        return getModelEntity().lock();
+    }
+
+    // ======= XML Related Methods ========
+    public static Document makeXmlDocument(Collection<GenericValue> values) {
+        Document document = UtilXml.makeEmptyXmlDocument("entity-engine-xml");
+
+        if (document == null) return null;
+
+        addToXmlDocument(values, document);
+        return document;
+    }
+
+    public static int addToXmlDocument(Collection<GenericValue> values, Document document) {
+        return addToXmlElement(values, document, document.getDocumentElement());
+    }
+
+    public static int addToXmlElement(Collection<GenericValue> values, Document document, Element element) {
+        if (values == null) return 0;
+        if (document == null) return 0;
+
+        int numberAdded = 0;
+
+        for (GenericValue value: values) {
+            Element valueElement = value.makeXmlElement(document);
+
+            element.appendChild(valueElement);
+            numberAdded++;
+        }
+        return numberAdded;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#makeXmlElement(org.w3c.dom.Document)
+	 */
+    public Element makeXmlElement(Document document) {
+        return makeXmlElement(document, null);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#makeXmlElement(org.w3c.dom.Document, java.lang.String)
+	 */
+    public Element makeXmlElement(Document document, String prefix) {
+        Element element = null;
+
+        if (prefix == null) prefix = "";
+        if (document != null) element = document.createElement(prefix + this.getEntityName());
+        // else element = new ElementImpl(null, this.getEntityName());
+        if (element == null) return null;
+
+        Iterator modelFields = this.getModelEntity().getFieldsIterator();
+        while (modelFields.hasNext()) {
+            ModelField modelField = (ModelField) modelFields.next();
+            String name = modelField.getName();
+            String value = this.getString(name);
+
+            if (value != null) {
+                if (value.indexOf('\n') >= 0 || value.indexOf('\r') >= 0) {
+                    UtilXml.addChildElementCDATAValue(element, name, value, document);
+                } else {
+                    element.setAttribute(name, value);
+                }
+            }
+        }
+
+        return element;
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#writeXmlText(java.io.PrintWriter, java.lang.String)
+	 */
+    public void writeXmlText(PrintWriter writer, String prefix) {
+        int indent = 4;
+        StringBuilder indentStrBuf = new StringBuilder();
+        for (int i = 0; i < indent; i++) indentStrBuf.append(' ');
+        String indentString = indentStrBuf.toString();
+
+        if (prefix == null) prefix = "";
+
+        writer.print(indentString);
+        writer.print('<');
+        writer.print(prefix);
+        writer.print(this.getEntityName());
+
+        // write attributes immediately and if a CDATA element is needed, put those in a Map for now
+        Map<String, String> cdataMap = FastMap.newInstance();
+
+        Iterator<ModelField> modelFields = this.getModelEntity().getFieldsIterator();
+        while (modelFields.hasNext()) {
+            ModelField modelField = modelFields.next();
+            String name = modelField.getName();
+
+            String type = modelField.getType();
+            if (type != null && type.equals("blob")) {
+                Object obj = get(name);
+                boolean b1 = obj instanceof byte [];
+                if (b1) {
+                    byte [] binData = (byte [])obj;
+                    String strData = new String(Base64.base64Encode(binData));
+                    cdataMap.put(name, strData);
+                } else {
+                    Debug.logWarning("Field:" + name + " is not of type 'byte[]'. obj: " + obj, module);
+                }
+            } else {
+                String valueStr = this.getString(name);
+
+                if (valueStr != null) {
+                    StringBuilder value = new StringBuilder(valueStr);
+                    boolean needsCdata = false;
+
+                    // check each character, if line-feed or carriage-return is found set needsCdata to true; also look for invalid characters
+                    for (int i = 0; i < value.length(); i++) {
+                        char curChar = value.charAt(i);
+                        /* Some common character for these invalid values, have seen these are mostly from MS Word, but may be part of some standard:
+                         5 = ...
+                         18 = apostrophe
+                         19 = left quotation mark
+                         20 = right quotation mark
+                         22 = –
+                         23 = -
+                         25 = tm
+                         *
+                         */
+
+                        switch (curChar) {
+                        case '\'':
+                            value.replace(i, i+1, "&apos;");
+                            break;
+                        case '"':
+                            value.replace(i, i+1, "&quot;");
+                            break;
+                        case '&':
+                            value.replace(i, i+1, "&amp;");
+                            break;
+                        case '<':
+                            value.replace(i, i+1, "&lt;");
+                            break;
+                        case '>':
+                            value.replace(i, i+1, "&gt;");
+                            break;
+                        case 0xA: // newline, \n
+                            needsCdata = true;
+                            break;
+                        case 0xD: // carriage return, \r
+                            needsCdata = true;
+                            break;
+                        case 0x9: // tab
+                            // do nothing, just catch here so it doesn't get into the default
+                            break;
+                        case 0x5: // elipses (...)
+                            value.replace(i, i+1, "...");
+                            break;
+                        case 0x12: // apostrophe
+                            value.replace(i, i+1, "&apos;");
+                            break;
+                        case 0x13: // left quote
+                            value.replace(i, i+1, "&quot;");
+                            break;
+                        case 0x14: // right quote
+                            value.replace(i, i+1, "&quot;");
+                            break;
+                        case 0x16: // big(?) dash -
+                            value.replace(i, i+1, "-");
+                            break;
+                        case 0x17: // dash -
+                            value.replace(i, i+1, "-");
+                            break;
+                        case 0x19: // tm
+                            value.replace(i, i+1, "tm");
+                            break;
+                        default:
+                            if (curChar < 0x20) {
+                                // if it is less that 0x20 at this point it is invalid because the only valid values < 0x20 are 0x9, 0xA, 0xD as caught above
+                                Debug.logInfo("Removing invalid character [" + curChar + "] numeric value [" + (int) curChar + "] for field " + name + " of entity with PK: " + this.getPrimaryKey().toString(), module);
+                                value.deleteCharAt(i);
+                            } else if (curChar > 0x7F) {
+                                // Replace each char which is out of the ASCII range with a XML entity
+                                String replacement = "&#" + (int) curChar + ";";
+                                if (Debug.verboseOn()) {
+                                    Debug.logVerbose("Entity: " + this.getEntityName() + ", PK: " + this.getPrimaryKey().toString() + " -> char [" + curChar + "] replaced with [" + replacement + "]", module);
+                                }
+                                value.replace(i, i+1, replacement);
+                            }
+                        }
+                    }
+
+                    if (needsCdata) {
+                        // use valueStr instead of the escaped value, not needed or wanted in a CDATA block
+                        cdataMap.put(name, valueStr);
+                    } else {
+                        writer.print(' ');
+                        writer.print(name);
+                        writer.print("=\"");
+                        // encode the value...
+                        writer.print(value.toString());
+                        writer.print("\"");
+                    }
+                }
+            }
+        }
+
+        if (cdataMap.size() == 0) {
+            writer.println("/>");
+        } else {
+            writer.println('>');
+
+            for (Map.Entry<String, String> entry: cdataMap.entrySet()) {
+                writer.print(indentString);
+                writer.print(indentString);
+                writer.print('<');
+                writer.print(entry.getKey());
+                writer.print("><![CDATA[");
+                writer.print(entry.getValue());
+                writer.print("]]></");
+                writer.print(entry.getKey());
+                writer.println('>');
+            }
+
+            // don't forget to close the entity.
+            writer.print(indentString);
+            writer.print("</");
+            writer.print(this.getEntityName());
+            writer.println(">");
+        }
+    }
+
+    /** Determines the equality of two GenericEntity objects, overrides the default equals
+     *@param  obj  The object (GenericEntity) to compare this two
+     *@return      boolean stating if the two objects are equal
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof GenericEntity)) return false;
+
+        // from here, use the compareTo method since it is more efficient:
+        try {
+            return this.compareTo((GenericEntity) obj) == 0;
+        } catch (ClassCastException e) {
+            return false;
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#hashCode()
+	 */
+    @Override
+    public int hashCode() {
+        // divide both by two (shift to right one bit) to maintain scale and add together
+        if (generateHashCode) {
+            cachedHashCode = 0;
+            if (getEntityName() != null) {
+                cachedHashCode += getEntityName().hashCode() >> 1;
+            }
+            cachedHashCode += fields.hashCode() >> 1;
+            generateHashCode = false;
+        }
+        return cachedHashCode;
+    }
+
+    /**
+     * Creates a String for the entity, overrides the default toString
+     * This method is secure, it will not display encrypted fields
+     *
+     *@return String corresponding to this entity
+     */
+    @Override
+    public String toString() {
+        StringBuilder theString = new StringBuilder();
+        theString.append("[GenericEntity:");
+        theString.append(getEntityName());
+        theString.append(']');
+
+        for (String curKey: new TreeSet<String>(fields.keySet())) {
+            Object curValue = fields.get(curKey);
+            ModelField field = this.getModelEntity().getField(curKey);
+            if (field.getEncrypt()) {
+                String encryptField = (String) curValue;
+                curValue = HashCrypt.getDigestHash(encryptField);
+            }
+            theString.append('[');
+            theString.append(curKey);
+            theString.append(',');
+            theString.append(curValue);
+            theString.append('(');
+            theString.append(curValue != null ? curValue.getClass().getName() : "");
+            theString.append(')');
+            theString.append(']');
+        }
+        return theString.toString();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#toStringInsecure()
+	 */
+    public String toStringInsecure() {
+        StringBuilder theString = new StringBuilder();
+        theString.append("[GenericEntity:");
+        theString.append(getEntityName());
+        theString.append(']');
+
+        for (String curKey: new TreeSet<String>(fields.keySet())) {
+            Object curValue = fields.get(curKey);
+            theString.append('[');
+            theString.append(curKey);
+            theString.append(',');
+            theString.append(curValue);
+            theString.append('(');
+            theString.append(curValue != null ? curValue.getClass().getName() : "");
+            theString.append(')');
+            theString.append(']');
+        }
+        return theString.toString();
+    }
+
+    protected int compareToFields(GenericEntity that, String name) {
+        Comparable<Object> thisVal = UtilGenerics.cast(this.fields.get(name));
+        Object thatVal = that.getAllFields().get(name);
+
+        if (thisVal == null) {
+            if (thatVal == null)
+                return 0;
+            // if thisVal is null, but thatVal is not, return 1 to put this earlier in the list
+            else
+                return 1;
+        } else {
+            // if thatVal is null, put the other earlier in the list
+            if (thatVal == null)
+                return  -1;
+            else
+                return thisVal.compareTo(thatVal);
+        }
+    }
+
+    /** Compares this GenericEntity to the passed object
+     *@param that Object to compare this to
+     *@return int representing the result of the comparison (-1,0, or 1)
+     */
+    public int compareTo(GenericEntity that) {
+        // if null, it will push to the beginning
+        if (that == null) return -1;
+
+        int tempResult = this.entityName.compareTo(that.getEntityName());
+
+        // if they did not match, we know the order, otherwise compare the primary keys
+        if (tempResult != 0) return tempResult;
+
+        // both have same entityName, should be the same so let's compare PKs
+        Iterator<ModelField> pkIter = getModelEntity().getPksIterator();
+        while (pkIter.hasNext()) {
+            ModelField curField = pkIter.next();
+            tempResult = compareToFields(that, curField.getName());
+            if (tempResult != 0) return tempResult;
+        }
+
+        // okay, if we got here it means the primaryKeys are exactly the SAME, so compare the rest of the fields
+        Iterator<ModelField> nopkIter = getModelEntity().getNopksIterator();
+        while (nopkIter.hasNext()) {
+            ModelField curField = nopkIter.next();
+            if (!curField.getIsAutoCreatedInternal()) {
+                tempResult = compareToFields(that, curField.getName());
+                if (tempResult != 0) return tempResult;
+            }
+        }
+
+        // if we got here it means the two are exactly the same, so return tempResult, which should be 0
+        return tempResult;
+    }
+
+    /** Clones this GenericEntity, this is a shallow clone & uses the default shallow HashMap clone
+     *@return Object that is a clone of this GenericEntity
+     */
+    @Override
+    public Object clone() {
+        GenericEntityImpl newEntity = new GenericEntityImpl();
+        newEntity.init(this);
+
+        newEntity.setDelegator(internalDelegator);
+        return newEntity;
+    }
+
+    // ---- Methods added to implement the Map interface: ----
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#remove(java.lang.Object)
+	 */
+    public Object remove(Object key) {
+        return this.fields.remove(key);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#containsKey(java.lang.Object)
+	 */
+    public boolean containsKey(Object key) {
+        return this.fields.containsKey(key);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#entrySet()
+	 */
+    public java.util.Set<Map.Entry<String, Object>> entrySet() {
+        return Collections.unmodifiableMap(this.fields).entrySet();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#put(java.lang.String, java.lang.Object)
+	 */
+    public Object put(String key, Object value) {
+        return this.set(key, value, true);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#putAll(java.util.Map)
+	 */
+    public void putAll(java.util.Map<? extends String, ? extends Object> map) {
+        this.setFields(map);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#clear()
+	 */
+    public void clear() {
+        this.fields.clear();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#get(java.lang.Object)
+	 */
+    public Object get(Object key) {
+        try {
+            return this.get((String)key, this.getDelegator().getLocale());
+        } catch (IllegalArgumentException e) {
+            if (Debug.verboseOn()) {
+                Debug.logVerbose(e, "The field name (or key) [" + key + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
+            } else {
+                Debug.logWarning("The field name (or key) [" + key + "] is not valid for entity [" + this.getEntityName() + "], printing IllegalArgumentException instead of throwing it because Map interface specification does not allow throwing that exception.", module);
+            }
+            return null;
+        }
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#keySet()
+	 */
+    public java.util.Set<String> keySet() {
+        return Collections.unmodifiableSet(this.fields.keySet());
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#isEmpty()
+	 */
+    public boolean isEmpty() {
+        return this.fields.isEmpty();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#values()
+	 */
+    public java.util.Collection<Object> values() {
+        return Collections.unmodifiableMap(this.fields).values();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#containsValue(java.lang.Object)
+	 */
+    public boolean containsValue(Object value) {
+        return this.fields.containsValue(value);
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#size()
+	 */
+    public int size() {
+        return this.fields.size();
+    }
+
+    /* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#matches(org.ofbiz.entity.condition.EntityCondition)
+	 */
+    public boolean matches(EntityCondition condition) {
+        return condition.entityMatches(this);
+    }
+
+	/* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getLocation()
+	 */
+	public String getLocation() {
+		return this.modelEntity.getLocation();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.ofbiz.entity.GenericEntity#getName()
+	 */
+	public String getName() {
+		return this.entityName;
+	}
+
+}

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericEntityImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPK.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPK.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPK.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPK.java Thu Aug 13 23:33:38 2009
@@ -1,79 +1,5 @@
-/*******************************************************************************
- * 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
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *******************************************************************************/
 package org.ofbiz.entity;
 
-import java.util.Map;
+public interface GenericPK extends GenericEntity {
 
-import javolution.context.ObjectFactory;
-
-import org.ofbiz.entity.model.ModelEntity;
-
-/**
- * Generic Entity Primary Key Object
- *
- */
-public class GenericPK extends GenericEntity {
-
-    protected static final ObjectFactory<GenericPK> genericPKFactory = new ObjectFactory<GenericPK>() {
-        @Override
-        protected GenericPK create() {
-            return new GenericPK();
-        }
-    };
-
-    protected GenericPK() { }
-
-    /** Creates new GenericPK */
-    public static GenericPK create(ModelEntity modelEntity) {
-        GenericPK newPK = genericPKFactory.object();
-        newPK.init(modelEntity);
-        return newPK;
-    }
-
-    /** Creates new GenericPK from existing Map */
-    public static GenericPK create(ModelEntity modelEntity, Map<String, ? extends Object> fields) {
-        GenericPK newPK = genericPKFactory.object();
-        newPK.init(modelEntity, fields);
-        return newPK;
-    }
-
-    /** Creates new GenericPK from existing Map */
-    public static GenericPK create(ModelEntity modelEntity, Object singlePkValue) {
-        GenericPK newPK = genericPKFactory.object();
-        newPK.init(modelEntity, singlePkValue);
-        return newPK;
-    }
-
-    /** Creates new GenericPK from existing GenericPK */
-    public static GenericPK create(GenericPK value) {
-        GenericPK newPK = genericPKFactory.object();
-        newPK.init(value);
-        return newPK;
-    }
-
-    /** Clones this GenericPK, this is a shallow clone & uses the default shallow HashMap clone
-     *@return Object that is a clone of this GenericPK
-     */
-    @Override
-    public Object clone() {
-        GenericPK newEntity = GenericPK.create(this);
-        newEntity.setDelegator(internalDelegator);
-        return newEntity;
-    }
-}
+}
\ No newline at end of file

Added: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java?rev=804060&view=auto
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java (added)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java Thu Aug 13 23:33:38 2009
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.entity;
+
+import javolution.context.ObjectFactory;
+
+/**
+ * Generic Entity Primary Key Object
+ *
+ */
+@SuppressWarnings("serial")
+public class GenericPKImpl extends GenericEntityImpl implements GenericPK {
+
+    protected static final ObjectFactory<GenericPK> genericPKFactory = new ObjectFactory<GenericPK>() {
+        @Override
+        protected GenericPK create() {
+            return new GenericPKImpl();
+        }
+    };
+
+    protected GenericPKImpl() { }
+
+    /** Clones this GenericPK, this is a shallow clone & uses the default shallow HashMap clone
+     *@return Object that is a clone of this GenericPK
+     */
+    @Override
+    public Object clone() {
+        GenericPK newEntity = EntityFactory.createGenericPK(this);
+        newEntity.setDelegator(internalDelegator);
+        return newEntity;
+    }
+}

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericPKImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericValue.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericValue.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericValue.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/GenericValue.java Thu Aug 13 23:33:38 2009
@@ -44,7 +44,7 @@
  *
  */
 @SuppressWarnings("serial")
-public class GenericValue extends GenericEntity implements Reusable {
+public class GenericValue extends GenericEntityImpl implements Reusable {
 
     public static final GenericValue NULL_VALUE = new NullGenericValue();
 
@@ -147,7 +147,7 @@
 
     public Object getOriginalDbValue(String name) {
         if (getModelEntity().getField(name) == null) {
-            throw new IllegalArgumentException("[GenericEntity.get] \"" + name + "\" is not a field of " + entityName);
+            throw new IllegalArgumentException("[EntityFactory.get] \"" + name + "\" is not a field of " + entityName);
         }
         if (originalDbValues == null) return null;
         return originalDbValues.get(name);
@@ -500,7 +500,7 @@
         return newEntity;
     }
 
-    protected static class NullGenericValue extends GenericValue implements NULL {
+    protected static class NullGenericValue extends GenericValue implements EntityFactory.NULL {
         @Override
         public String getEntityName() {
             return "[null-entity-value]";

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/cache/AbstractEntityConditionCache.java Thu Aug 13 23:33:38 2009
@@ -27,6 +27,7 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.cache.UtilCache;
+import org.ofbiz.entity.EntityFactory;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericPK;
 import org.ofbiz.entity.GenericValue;
@@ -110,7 +111,7 @@
     }
 
     protected static final boolean isNull(Map value) {
-        return value == null || value == GenericEntity.NULL_ENTITY || value == GenericValue.NULL_VALUE;
+        return value == null || value == EntityFactory.NULL_ENTITY || value == GenericValue.NULL_VALUE;
     }
 
     protected ModelEntity getModelCheckValid(GenericEntity oldEntity, GenericEntity newEntity) {

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Thu Aug 13 23:33:38 2009
@@ -27,9 +27,9 @@
 import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.EntityCryptoException;
+import org.ofbiz.entity.EntityFactory;
 import org.ofbiz.entity.DelegatorFactory;
 import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericModelException;
 import org.ofbiz.entity.config.DatasourceInfo;
@@ -89,7 +89,7 @@
             throw new IllegalArgumentException("The operator argument cannot be null");
         }
 
-        if (rhs == null || rhs == GenericEntity.NULL_FIELD) {
+        if (rhs == null || rhs == EntityFactory.NULL_FIELD) {
             if (!EntityOperator.NOT_EQUAL.equals(operator) && !EntityOperator.EQUALS.equals(operator)) {
                 throw new IllegalArgumentException("Operator must be EQUALS or NOT_EQUAL when right/rhs argument is NULL ");
             }
@@ -235,7 +235,7 @@
     }
 
     public void checkRhsType(ModelEntity modelEntity, GenericDelegator delegator) {
-        if (this.rhs == null || this.rhs == GenericEntity.NULL_FIELD || modelEntity == null) return;
+        if (this.rhs == null || this.rhs == EntityFactory.NULL_FIELD || modelEntity == null) return;
 
         Object value = this.rhs;
         if (this.rhs instanceof EntityFunction) {

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Thu Aug 13 23:33:38 2009
@@ -29,8 +29,8 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.EntityFactory;
 import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericModelException;
 import org.ofbiz.entity.config.DatasourceInfo;
 import org.ofbiz.entity.model.ModelEntity;
@@ -184,7 +184,7 @@
         if (map == null) {
             return null;
         }
-        if (map instanceof GenericEntity.NULL) {
+        if (map instanceof EntityFactory.NULL) {
             return null;
         } else {
             return map.get(fieldName);

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java Thu Aug 13 23:33:38 2009
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.ofbiz.entity.EntityFactory;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericModelException;
@@ -82,7 +83,7 @@
         public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); }
         @Override
         protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) {
-            if (rhs == null || rhs == GenericEntity.NULL_FIELD) {
+            if (rhs == null || rhs == EntityFactory.NULL_FIELD) {
                 //Debug.logInfo("makeRHSWhereString: field IS NULL: " + field.getName(), module);
                 sb.append(" IS NULL");
             } else {
@@ -97,7 +98,7 @@
         public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); }
         @Override
         protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) {
-            if (rhs == null || rhs == GenericEntity.NULL_FIELD) {
+            if (rhs == null || rhs == EntityFactory.NULL_FIELD) {
                 sb.append(" IS NOT NULL");
             } else {
                 super.makeRHSWhereString(entity, entityConditionParams, sb, field, rhs, datasourceInfo);

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Thu Aug 13 23:33:38 2009
@@ -231,7 +231,7 @@
         }
 
         if (modelEntity.lock()) {
-            GenericEntity entityCopy = GenericEntity.createGenericEntity(entity);
+            GenericEntity entityCopy = EntityFactory.createGenericEntity(entity);
 
             select(entityCopy, sqlP);
             Object stampField = entity.get(ModelEntity.STAMP_FIELD);

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/DatabaseUtil.java Thu Aug 13 23:33:38 2009
@@ -46,6 +46,7 @@
 import org.ofbiz.entity.config.DatasourceInfo;
 import org.ofbiz.entity.config.EntityConfigUtil;
 import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelEntityImpl;
 import org.ofbiz.entity.model.ModelField;
 import org.ofbiz.entity.model.ModelFieldType;
 import org.ofbiz.entity.model.ModelFieldTypeReader;
@@ -698,7 +699,7 @@
         // iterate over the table names is alphabetical order
         for (String tableName: new TreeSet<String>(colInfo.keySet())) {
             Map<String, ColumnCheckInfo> colMap = colInfo.get(tableName);
-            ModelEntity newEntity = new ModelEntity(tableName, colMap, modelFieldTypeReader, isCaseSensitive);
+            ModelEntity newEntity = new ModelEntityImpl(tableName, colMap, modelFieldTypeReader, isCaseSensitive);
             newEntList.add(newEntity);
         }
 
@@ -747,7 +748,7 @@
         // iterate over the table names is alphabetical order
         for (String tableName: new TreeSet<String>(colInfo.keySet())) {
             Map<String, ColumnCheckInfo> colMap = colInfo.get(tableName);
-            ModelEntity newEntity = new ModelEntity(tableName, colMap, modelFieldTypeReader, isCaseSensitive);
+            ModelEntity newEntity = new ModelEntityImpl(tableName, colMap, modelFieldTypeReader, isCaseSensitive);
             root.appendChild(newEntity.toXmlElement(document, "org.ofbiz.ext." + packageName));
         }
 

Modified: ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=804060&r1=804059&r2=804060&view=diff
==============================================================================
--- ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original)
+++ ofbiz/branches/executioncontext20090812/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Thu Aug 13 23:33:38 2009
@@ -46,6 +46,7 @@
 import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.EntityFactory;
 import org.ofbiz.entity.GenericDataSourceException;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericEntityException;
@@ -256,7 +257,7 @@
             }
 
             Object fieldValue = fields.get(name);
-            if (fieldValue != null && fieldValue != GenericEntity.NULL_FIELD) {
+            if (fieldValue != null && fieldValue != EntityFactory.NULL_FIELD) {
                 returnString.append('=');
                 addValue(returnString, modelField, fieldValue, entityConditionParams);
             } else {
@@ -719,8 +720,8 @@
                     entityName + "." + modelField.getName() + ".");
         }
 
-        // if the value is the GenericEntity.NullField, treat as null
-        if (fieldValue == GenericEntity.NULL_FIELD) {
+        // if the value is the EntityFactory.NullField, treat as null
+        if (fieldValue == EntityFactory.NULL_FIELD) {
             fieldValue = null;
         }