Modified: ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/Record.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/Record.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/Record.java (original) +++ ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/Record.java Wed Mar 24 09:23:07 2010 @@ -54,89 +54,89 @@ public class Record implements Serializa /** Creates new Record */ protected Record(ModelRecord modelRecord) { - if (modelRecord == null) - throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); - this.recordName = modelRecord.name; - this.modelRecord = modelRecord; - this.fields = new HashMap<String, Object>(); + if (modelRecord == null) + throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); + this.recordName = modelRecord.name; + this.modelRecord = modelRecord; + this.fields = new HashMap<String, Object>(); } /** Creates new Record from existing Map */ protected Record(ModelRecord modelRecord, Map<String, Object> fields) { - if (modelRecord == null) - throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); - this.recordName = modelRecord.name; - this.modelRecord = modelRecord; - this.fields = (fields == null ? new HashMap<String, Object>() : new HashMap<String, Object>(fields)); + if (modelRecord == null) + throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); + this.recordName = modelRecord.name; + this.modelRecord = modelRecord; + this.fields = (fields == null ? new HashMap<String, Object>() : new HashMap<String, Object>(fields)); } public String getRecordName() { - return recordName; + return recordName; } public ModelRecord getModelRecord() { - if (modelRecord == null) { - throw new IllegalStateException("[Record.getModelRecord] could not find modelRecord for recordName " + recordName); - } - return modelRecord; + if (modelRecord == null) { + throw new IllegalStateException("[Record.getModelRecord] could not find modelRecord for recordName " + recordName); + } + return modelRecord; } public Object get(String name) { - if (getModelRecord().getModelField(name) == null) { - throw new IllegalArgumentException("[Record.get] \"" + name + "\" is not a field of " + recordName); - // Debug.logWarning("[GenericRecord.get] \"" + name + "\" is not a field of " + recordName + ", but getting anyway...", module); - } - return fields.get(name); + if (getModelRecord().getModelField(name) == null) { + throw new IllegalArgumentException("[Record.get] \"" + name + "\" is not a field of " + recordName); + // Debug.logWarning("[GenericRecord.get] \"" + name + "\" is not a field of " + recordName + ", but getting anyway...", module); + } + return fields.get(name); } public String getString(String name) { - Object object = get(name); + Object object = get(name); - if (object == null) - return null; - if (object instanceof java.lang.String) - return (String) object; - else - return object.toString(); + if (object == null) + return null; + if (object instanceof java.lang.String) + return (String) object; + else + return object.toString(); } public String getStringAndEmpty(String name) { - Object object = get(name); + Object object = get(name); - if (object == null) - return ""; - if (object instanceof java.lang.String) - return (String) object; - else - return object.toString(); + if (object == null) + return ""; + if (object instanceof java.lang.String) + return (String) object; + else + return object.toString(); } public java.sql.Timestamp getTimestamp(String name) { - return (java.sql.Timestamp) get(name); + return (java.sql.Timestamp) get(name); } public java.sql.Time getTime(String name) { - return (java.sql.Time) get(name); + return (java.sql.Time) get(name); } public java.sql.Date getDate(String name) { - return (java.sql.Date) get(name); + return (java.sql.Date) get(name); } public Integer getInteger(String name) { - return (Integer) get(name); + return (Integer) get(name); } public Long getLong(String name) { - return (Long) get(name); + return (Long) get(name); } public Float getFloat(String name) { - return (Float) get(name); + return (Float) get(name); } public Double getDouble(String name) { - return (Double) get(name); + return (Double) get(name); } /** Sets the named field to the passed value, even if the value is null @@ -144,7 +144,7 @@ public class Record implements Serializa * @param value The value to set */ public void set(String name, Object value) { - set(name, value, true); + set(name, value, true); } /** Sets the named field to the passed value. If value is null, it is only @@ -154,25 +154,25 @@ public class Record implements Serializa * @param setIfNull Specifies whether or not to set the value if it is null */ public synchronized void set(String name, Object value, boolean setIfNull) { - if (getModelRecord().getModelField(name) == null) { - throw new IllegalArgumentException("[Record.set] \"" + name + "\" is not a field of " + recordName); - // Debug.logWarning("[GenericRecord.set] \"" + name + "\" is not a field of " + recordName + ", but setting anyway...", module); - } - if (value != null || setIfNull) { - if (value instanceof Boolean) { - value = ((Boolean) value).booleanValue() ? "Y" : "N"; - } - fields.put(name, value); + if (getModelRecord().getModelField(name) == null) { + throw new IllegalArgumentException("[Record.set] \"" + name + "\" is not a field of " + recordName); + // Debug.logWarning("[GenericRecord.set] \"" + name + "\" is not a field of " + recordName + ", but setting anyway...", module); + } + if (value != null || setIfNull) { + if (value instanceof Boolean) { + value = ((Boolean) value).booleanValue() ? "Y" : "N"; } + fields.put(name, value); + } } /** * little endian reader for 2 byte short. */ public final short readLEShort(byte[] byteArray) { - return (short)( - (byteArray[1]&0xff) << 8 | - (byteArray[0]&0xff)); + return (short)( + (byteArray[1]&0xff) << 8 | + (byteArray[0]&0xff)); } @@ -180,26 +180,26 @@ public class Record implements Serializa * little endian reader for 4 byte int. */ public final int readLEInt(byte []byteArray) { - return - (byteArray[3]) << 24 | - (byteArray[2]&0xff) << 16 | - (byteArray[1]&0xff) << 8 | - (byteArray[0]&0xff); + return + (byteArray[3]) << 24 | + (byteArray[2]&0xff) << 16 | + (byteArray[1]&0xff) << 8 | + (byteArray[0]&0xff); } /** - * little endian reader for 8 byte long. - */ + * little endian reader for 8 byte long. + */ public final long readLELong(byte []byteArray) { - return - (long)(byteArray[7]) << 56 | /* long cast needed or shift done modulo 32 */ - (long)(byteArray[6]&0xff) << 48 | - (long)(byteArray[5]&0xff) << 40 | - (long)(byteArray[4]&0xff) << 32 | - (long)(byteArray[3]&0xff) << 24 | - (long)(byteArray[2]&0xff) << 16 | - (long)(byteArray[1]&0xff) << 8 | - (long)(byteArray[0]&0xff); + return + (long)(byteArray[7]) << 56 | /* long cast needed or shift done modulo 32 */ + (long)(byteArray[6]&0xff) << 48 | + (long)(byteArray[5]&0xff) << 40 | + (long)(byteArray[4]&0xff) << 32 | + (long)(byteArray[3]&0xff) << 24 | + (long)(byteArray[2]&0xff) << 16 | + (long)(byteArray[1]&0xff) << 8 | + (long)(byteArray[0]&0xff); } /** Sets the named field to the passed value, converting the value from a String to the current type using <code>Type.valueOf()</code> @@ -207,272 +207,272 @@ public class Record implements Serializa * @param value The String value to convert and set */ public void setString(String name, String value) throws ParseException { - if (name == null || value == null || value.equals("")) - return; - ModelField field = getModelRecord().getModelField(name); - - if (field == null) - set(name, value); // this will get an error in the set() method... - - // if the string is all spaces ignore - boolean nonSpace = false; - - for (int i = 0; i < value.length(); i++) { - if (value.charAt(i) != ' ') { - nonSpace = true; - break; - } - } - if (!nonSpace) - return; - - // if (Debug.verboseOn()) Debug.logVerbose("Value: " + value, module); - - String fieldType = field.type; - - // first the custom types that need to be parsed - if (fieldType.equals("CustomTimestamp")) { - // this custom type will take a string a parse according to date formatting - // string then put the result in a java.sql.Timestamp - // a common timestamp format for flat files is with no separators: yyyyMMddHHmmss - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.util.Date tempDate = sdf.parse(value); - java.sql.Timestamp timestamp = new java.sql.Timestamp(tempDate.getTime()); - - set(name, timestamp); - } else if (fieldType.equals("CustomDate")) { - // a common date only format for flat files is with no separators: yyyyMMdd or MMddyyyy - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.util.Date tempDate = sdf.parse(value); - java.sql.Date date = new java.sql.Date(tempDate.getTime()); - - set(name, date); - } else if (fieldType.equals("CustomTime")) { - // a common time only format for flat files is with no separators: HHmmss - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.util.Date tempDate = sdf.parse(value); - java.sql.Time time = new java.sql.Time(tempDate.getTime()); - - set(name, time); - } else if (fieldType.equals("FixedPointDouble")) { - // this custom type will parse a fixed point number according to the number - // of decimal places in the formatting string then place it in a Double - NumberFormat nf = NumberFormat.getNumberInstance(); - Number tempNum = nf.parse(value); - double number = tempNum.doubleValue(); - double decimalPlaces = Double.parseDouble(field.format); - double divisor = Math.pow(10.0, decimalPlaces); - - number = number / divisor; - set(name, Double.valueOf(number)); - } // standard types - else if (fieldType.equals("java.lang.String") || fieldType.equals("String")) - if (field.format.equals("EncryptedString")) { - String hashType = LoginServices.getHashType(); - set(name, HashCrypt.getDigestHash(value, hashType)); - } else { - set(name, value); - } - else if (fieldType.equals("NullTerminatedString")) { - int terminate = value.indexOf(0x0); - set(name, terminate>0?value.substring(0,terminate):value); - } else if (fieldType.equals("java.sql.Timestamp") || fieldType.equals("Timestamp")) - set(name, java.sql.Timestamp.valueOf(value)); - else if (fieldType.equals("java.sql.Time") || fieldType.equals("Time")) - set(name, java.sql.Time.valueOf(value)); - else if (fieldType.equals("java.sql.Date") || fieldType.equals("Date")) - set(name, java.sql.Date.valueOf(value)); - else if (fieldType.equals("java.lang.Integer") || fieldType.equals("Integer")) - set(name, Integer.valueOf(value)); - else if (fieldType.equals("java.lang.Long") || fieldType.equals("Long")) - set(name, Long.valueOf(value)); - else if (fieldType.equals("java.lang.Float") || fieldType.equals("Float")) - set(name, Float.valueOf(value)); - else if (fieldType.equals("java.lang.Double") || fieldType.equals("Double")) - set(name, Double.valueOf(value)); - else if (fieldType.equals("LEShort")) - set(name, Short.valueOf(readLEShort(value.getBytes()))); - else if (fieldType.equals("LEInteger")) - set(name, Integer.valueOf(readLEInt(value.getBytes()))); - else if (fieldType.equals("LELong")) - set(name, Long.valueOf(readLELong(value.getBytes()))); - else { - throw new IllegalArgumentException("Field type " + fieldType + " not currently supported. Sorry."); - } + if (name == null || value == null || value.equals("")) + return; + ModelField field = getModelRecord().getModelField(name); + + if (field == null) + set(name, value); // this will get an error in the set() method... + + // if the string is all spaces ignore + boolean nonSpace = false; + + for (int i = 0; i < value.length(); i++) { + if (value.charAt(i) != ' ') { + nonSpace = true; + break; + } + } + if (!nonSpace) + return; + + // if (Debug.verboseOn()) Debug.logVerbose("Value: " + value, module); + + String fieldType = field.type; + + // first the custom types that need to be parsed + if (fieldType.equals("CustomTimestamp")) { + // this custom type will take a string a parse according to date formatting + // string then put the result in a java.sql.Timestamp + // a common timestamp format for flat files is with no separators: yyyyMMddHHmmss + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.util.Date tempDate = sdf.parse(value); + java.sql.Timestamp timestamp = new java.sql.Timestamp(tempDate.getTime()); + + set(name, timestamp); + } else if (fieldType.equals("CustomDate")) { + // a common date only format for flat files is with no separators: yyyyMMdd or MMddyyyy + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.util.Date tempDate = sdf.parse(value); + java.sql.Date date = new java.sql.Date(tempDate.getTime()); + + set(name, date); + } else if (fieldType.equals("CustomTime")) { + // a common time only format for flat files is with no separators: HHmmss + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.util.Date tempDate = sdf.parse(value); + java.sql.Time time = new java.sql.Time(tempDate.getTime()); + + set(name, time); + } else if (fieldType.equals("FixedPointDouble")) { + // this custom type will parse a fixed point number according to the number + // of decimal places in the formatting string then place it in a Double + NumberFormat nf = NumberFormat.getNumberInstance(); + Number tempNum = nf.parse(value); + double number = tempNum.doubleValue(); + double decimalPlaces = Double.parseDouble(field.format); + double divisor = Math.pow(10.0, decimalPlaces); + + number = number / divisor; + set(name, Double.valueOf(number)); + } // standard types + else if (fieldType.equals("java.lang.String") || fieldType.equals("String")) + if (field.format.equals("EncryptedString")) { + String hashType = LoginServices.getHashType(); + set(name, HashCrypt.getDigestHash(value, hashType)); + } else { + set(name, value); + } + else if (fieldType.equals("NullTerminatedString")) { + int terminate = value.indexOf(0x0); + set(name, terminate>0?value.substring(0,terminate):value); + } else if (fieldType.equals("java.sql.Timestamp") || fieldType.equals("Timestamp")) + set(name, java.sql.Timestamp.valueOf(value)); + else if (fieldType.equals("java.sql.Time") || fieldType.equals("Time")) + set(name, java.sql.Time.valueOf(value)); + else if (fieldType.equals("java.sql.Date") || fieldType.equals("Date")) + set(name, java.sql.Date.valueOf(value)); + else if (fieldType.equals("java.lang.Integer") || fieldType.equals("Integer")) + set(name, Integer.valueOf(value)); + else if (fieldType.equals("java.lang.Long") || fieldType.equals("Long")) + set(name, Long.valueOf(value)); + else if (fieldType.equals("java.lang.Float") || fieldType.equals("Float")) + set(name, Float.valueOf(value)); + else if (fieldType.equals("java.lang.Double") || fieldType.equals("Double")) + set(name, Double.valueOf(value)); + else if (fieldType.equals("LEShort")) + set(name, Short.valueOf(readLEShort(value.getBytes()))); + else if (fieldType.equals("LEInteger")) + set(name, Integer.valueOf(readLEInt(value.getBytes()))); + else if (fieldType.equals("LELong")) + set(name, Long.valueOf(readLELong(value.getBytes()))); + else { + throw new IllegalArgumentException("Field type " + fieldType + " not currently supported. Sorry."); + } } public String getFixedString(String name) { - if (name == null) - return null; - if (getModelRecord() == null) - throw new IllegalArgumentException("Could not find modelrecord for field named \"" + name + "\""); - ModelField field = getModelRecord().getModelField(name); - - if (field == null) - throw new IllegalArgumentException("Could not find model for field named \"" + name + "\""); - - Object value = get(name); - - if (value == null) { - return null; - } - - String fieldType = field.type; - String str = null; - - // first the custom types that need to be parsed - if (fieldType.equals("CustomTimestamp")) { - // a common timestamp format for flat files is with no separators: yyyyMMddHHmmss - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.sql.Timestamp timestamp = (java.sql.Timestamp) value; - - str = sdf.format(new Date(timestamp.getTime())); - } else if (fieldType.equals("CustomDate")) { - // a common date only format for flat files is with no separators: yyyyMMdd or MMddyyyy - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.sql.Date date = (java.sql.Date) value; - - str = sdf.format(new Date(date.getTime())); - } else if (fieldType.equals("CustomTime")) { - // a common time only format for flat files is with no separators: HHmmss - SimpleDateFormat sdf = new SimpleDateFormat(field.format); - java.sql.Time time = (java.sql.Time) value; - - str = sdf.format(new Date(time.getTime())); - } else if (fieldType.equals("FixedPointDouble")) { - // this custom type will parse a fixed point number according to the number - // of decimal places in the formatting string then place it in a Double - double decimalPlaces = Double.parseDouble(field.format); - double multiplier = Math.pow(10.0, decimalPlaces); - double dnum = multiplier * ((Double) value).doubleValue(); - long number = Math.round(dnum); - - str = padFrontZeros(Long.toString(number), field.length); - // if (Debug.infoOn()) Debug.logInfo("[Record.getFixedString] FixedPointDouble: multiplier=" + multiplier + ", value=" + value + ", dnum=" + dnum + ", number=" + number + ", str=" + str, module); - } // standard types - else if (fieldType.equals("java.lang.String") || fieldType.equals("String")) - str = value.toString(); - else if (fieldType.equals("java.sql.Timestamp") || fieldType.equals("Timestamp")) - str = value.toString(); - else if (fieldType.equals("java.sql.Time") || fieldType.equals("Time")) - str = value.toString(); - else if (fieldType.equals("java.sql.Date") || fieldType.equals("Date")) - str = value.toString(); - // for all numbers, pad front with zeros if field length is specified - else if (fieldType.equals("java.lang.Integer") || fieldType.equals("Integer")) - str = padFrontZeros(value.toString(), field.length); - else if (fieldType.equals("java.lang.Long") || fieldType.equals("Long")) - str = padFrontZeros(value.toString(), field.length); - else if (fieldType.equals("java.lang.Float") || fieldType.equals("Float")) - str = padFrontZeros(value.toString(), field.length); - else if (fieldType.equals("java.lang.Double") || fieldType.equals("Double")) - str = padFrontZeros(value.toString(), field.length); - else { - throw new IllegalArgumentException("Field type " + fieldType + " not currently supported. Sorry."); - } - - if (str != null && field.length > 0 && str.length() < field.length) { - // pad the end with spaces - StringBuilder strBuf = new StringBuilder(str); - - while (strBuf.length() < field.length) - strBuf.append(' '); - str = strBuf.toString(); - } - return str; + if (name == null) + return null; + if (getModelRecord() == null) + throw new IllegalArgumentException("Could not find modelrecord for field named \"" + name + "\""); + ModelField field = getModelRecord().getModelField(name); + + if (field == null) + throw new IllegalArgumentException("Could not find model for field named \"" + name + "\""); + + Object value = get(name); + + if (value == null) { + return null; + } + + String fieldType = field.type; + String str = null; + + // first the custom types that need to be parsed + if (fieldType.equals("CustomTimestamp")) { + // a common timestamp format for flat files is with no separators: yyyyMMddHHmmss + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.sql.Timestamp timestamp = (java.sql.Timestamp) value; + + str = sdf.format(new Date(timestamp.getTime())); + } else if (fieldType.equals("CustomDate")) { + // a common date only format for flat files is with no separators: yyyyMMdd or MMddyyyy + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.sql.Date date = (java.sql.Date) value; + + str = sdf.format(new Date(date.getTime())); + } else if (fieldType.equals("CustomTime")) { + // a common time only format for flat files is with no separators: HHmmss + SimpleDateFormat sdf = new SimpleDateFormat(field.format); + java.sql.Time time = (java.sql.Time) value; + + str = sdf.format(new Date(time.getTime())); + } else if (fieldType.equals("FixedPointDouble")) { + // this custom type will parse a fixed point number according to the number + // of decimal places in the formatting string then place it in a Double + double decimalPlaces = Double.parseDouble(field.format); + double multiplier = Math.pow(10.0, decimalPlaces); + double dnum = multiplier * ((Double) value).doubleValue(); + long number = Math.round(dnum); + + str = padFrontZeros(Long.toString(number), field.length); + // if (Debug.infoOn()) Debug.logInfo("[Record.getFixedString] FixedPointDouble: multiplier=" + multiplier + ", value=" + value + ", dnum=" + dnum + ", number=" + number + ", str=" + str, module); + } // standard types + else if (fieldType.equals("java.lang.String") || fieldType.equals("String")) + str = value.toString(); + else if (fieldType.equals("java.sql.Timestamp") || fieldType.equals("Timestamp")) + str = value.toString(); + else if (fieldType.equals("java.sql.Time") || fieldType.equals("Time")) + str = value.toString(); + else if (fieldType.equals("java.sql.Date") || fieldType.equals("Date")) + str = value.toString(); + // for all numbers, pad front with zeros if field length is specified + else if (fieldType.equals("java.lang.Integer") || fieldType.equals("Integer")) + str = padFrontZeros(value.toString(), field.length); + else if (fieldType.equals("java.lang.Long") || fieldType.equals("Long")) + str = padFrontZeros(value.toString(), field.length); + else if (fieldType.equals("java.lang.Float") || fieldType.equals("Float")) + str = padFrontZeros(value.toString(), field.length); + else if (fieldType.equals("java.lang.Double") || fieldType.equals("Double")) + str = padFrontZeros(value.toString(), field.length); + else { + throw new IllegalArgumentException("Field type " + fieldType + " not currently supported. Sorry."); + } + + if (str != null && field.length > 0 && str.length() < field.length) { + // pad the end with spaces + StringBuilder strBuf = new StringBuilder(str); + + while (strBuf.length() < field.length) + strBuf.append(' '); + str = strBuf.toString(); + } + return str; } public String writeLineString(ModelDataFile modelDataFile) throws DataFileException { - ModelRecord modelRecord = getModelRecord(); - boolean isFixedRecord = ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle); - boolean isFixedLength = ModelDataFile.SEP_FIXED_LENGTH.equals(modelDataFile.separatorStyle); - boolean isDelimited = ModelDataFile.SEP_DELIMITED.equals(modelDataFile.separatorStyle); + ModelRecord modelRecord = getModelRecord(); + boolean isFixedRecord = ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle); + boolean isFixedLength = ModelDataFile.SEP_FIXED_LENGTH.equals(modelDataFile.separatorStyle); + boolean isDelimited = ModelDataFile.SEP_DELIMITED.equals(modelDataFile.separatorStyle); - StringBuilder lineBuf = new StringBuilder(); + StringBuilder lineBuf = new StringBuilder(); - for (ModelField modelField: modelRecord.fields) { - String data = this.getFixedString(modelField.name); + for (ModelField modelField: modelRecord.fields) { + String data = this.getFixedString(modelField.name); - if (isDelimited && null != modelDataFile.textDelimiter) { - lineBuf.append(modelDataFile.textDelimiter); - } + if (isDelimited && null != modelDataFile.textDelimiter) { + lineBuf.append(modelDataFile.textDelimiter); + } - // if field is null (not set) then assume we want to pad the field - char PAD_CHAR = ' '; + // if field is null (not set) then assume we want to pad the field + char PAD_CHAR = ' '; - if (data == null) { - StringBuilder sb = new StringBuilder(""); + if (data == null) { + StringBuilder sb = new StringBuilder(""); - for (int i = 0; i < modelField.length; i++) - sb.append(PAD_CHAR); - data = sb.toString(); - } - - // Pad the record - if (isFixedRecord) { - while (modelField.position > lineBuf.length()) - lineBuf.append(" "); - } - // if (Debug.infoOn()) Debug.logInfo("Field: " + modelField.name + " Position: " + modelField.position + " BufLen: " + lineBuf.length(), module); + for (int i = 0; i < modelField.length; i++) + sb.append(PAD_CHAR); + data = sb.toString(); + } - // if (Debug.infoOn()) Debug.logInfo("Got data \"" + data + "\" for field " + modelField.name + " in record " + modelRecord.name, module); - if (modelField.length > 0 && data.length() != modelField.length) - throw new DataFileException("Got field length " + data.length() + " but expected field length is " + modelField.length + " for field \"" + - modelField.name + "\" of record \"" + modelRecord.name + "\" data is: \"" + data + "\""); - - lineBuf.append(data); - if (isDelimited) { - if (null != modelDataFile.textDelimiter) { - lineBuf.append(modelDataFile.textDelimiter); - } - lineBuf.append(modelDataFile.delimiter); - } + // Pad the record + if (isFixedRecord) { + while (modelField.position > lineBuf.length()) + lineBuf.append(" "); } + // if (Debug.infoOn()) Debug.logInfo("Field: " + modelField.name + " Position: " + modelField.position + " BufLen: " + lineBuf.length(), module); + + // if (Debug.infoOn()) Debug.logInfo("Got data \"" + data + "\" for field " + modelField.name + " in record " + modelRecord.name, module); + if (modelField.length > 0 && data.length() != modelField.length) + throw new DataFileException("Got field length " + data.length() + " but expected field length is " + modelField.length + " for field \"" + + modelField.name + "\" of record \"" + modelRecord.name + "\" data is: \"" + data + "\""); + lineBuf.append(data); if (isDelimited) { - // just remove the last delimiter to finish clean, otherwise shows as extra column - lineBuf.setLength(lineBuf.length() - 1); + if (null != modelDataFile.textDelimiter) { + lineBuf.append(modelDataFile.textDelimiter); } + lineBuf.append(modelDataFile.delimiter); + } + } + + if (isDelimited) { + // just remove the last delimiter to finish clean, otherwise shows as extra column + lineBuf.setLength(lineBuf.length() - 1); + } - if ((isFixedRecord || isFixedLength) && modelDataFile.recordLength > 0 && lineBuf.length() != modelDataFile.recordLength) - throw new DataFileException("Got record length " + lineBuf.length() + " but expected record length is " + modelDataFile.recordLength + - " for record \"" + modelRecord.name + "\" data line is: \"" + lineBuf + "\""); + if ((isFixedRecord || isFixedLength) && modelDataFile.recordLength > 0 && lineBuf.length() != modelDataFile.recordLength) + throw new DataFileException("Got record length " + lineBuf.length() + " but expected record length is " + modelDataFile.recordLength + + " for record \"" + modelRecord.name + "\" data line is: \"" + lineBuf + "\""); - // for convenience, insert the type-code in where it is looked for, if exists - if (modelRecord.tcPosition > 0 && modelRecord.typeCode.length() > 0) { - lineBuf.replace(modelRecord.tcPosition, modelRecord.tcPosition + modelRecord.tcLength, modelRecord.typeCode); - } + // for convenience, insert the type-code in where it is looked for, if exists + if (modelRecord.tcPosition > 0 && modelRecord.typeCode.length() > 0) { + lineBuf.replace(modelRecord.tcPosition, modelRecord.tcPosition + modelRecord.tcLength, modelRecord.typeCode); + } - if (isFixedLength || isDelimited) - lineBuf.append('\n'); + if (isFixedLength || isDelimited) + lineBuf.append('\n'); - return lineBuf.toString(); + return lineBuf.toString(); } String padFrontZeros(String str, int totalLength) { - if (totalLength > 0 && str.length() < totalLength) { - // pad the front with zeros - StringBuilder zeros = new StringBuilder(); - int numZeros = totalLength - str.length(); - - for (int i = 0; i < numZeros; i++) - zeros.append('0'); - zeros.append(str); - return zeros.toString(); - } else - return str; + if (totalLength > 0 && str.length() < totalLength) { + // pad the front with zeros + StringBuilder zeros = new StringBuilder(); + int numZeros = totalLength - str.length(); + + for (int i = 0; i < numZeros; i++) + zeros.append('0'); + zeros.append(str); + return zeros.toString(); + } else + return str; } public Record getParentRecord() { - return parentRecord; + return parentRecord; } public List<Record> getChildRecords() { - return childRecords; + return childRecords; } public void addChildRecord(Record record) { - childRecords.add(record); + childRecords.add(record); } /** Creates new Record @@ -481,9 +481,9 @@ public class Record implements Serializa * @return */ public static Record createRecord(ModelRecord modelRecord) throws DataFileException { - Record record = new Record(modelRecord); + Record record = new Record(modelRecord); - return record; + return record; } /** Creates new Record from existing fields Map @@ -493,9 +493,9 @@ public class Record implements Serializa * @return */ public static Record createRecord(ModelRecord modelRecord, Map<String, Object> fields) throws DataFileException { - Record record = new Record(modelRecord, fields); + Record record = new Record(modelRecord, fields); - return record; + return record; } /** @@ -506,30 +506,30 @@ public class Record implements Serializa * @return */ public static Record createRecord(String line, int lineNum, ModelRecord modelRecord) throws DataFileException { - Record record = new Record(modelRecord); + Record record = new Record(modelRecord); - for (ModelField modelField: modelRecord.fields) { - String strVal = null; + for (ModelField modelField: modelRecord.fields) { + String strVal = null; - try { - strVal = line.substring(modelField.position, modelField.position + modelField.length); - } catch (IndexOutOfBoundsException ioobe) { - throw new DataFileException("Field " + modelField.name + " from " + modelField.position + - " for " + modelField.length + " chars could not be read from a line (" + lineNum + ") with only " + - line.length() + " chars.", ioobe); - } - try { - record.setString(modelField.name, strVal); - } catch (java.text.ParseException e) { - throw new DataFileException("Could not parse field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + strVal + - " on line " + lineNum, e); - } catch (java.lang.NumberFormatException e) { - throw new DataFileException("Number not valid for field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + - strVal + " on line " + lineNum, e); - } + try { + strVal = line.substring(modelField.position, modelField.position + modelField.length); + } catch (IndexOutOfBoundsException ioobe) { + throw new DataFileException("Field " + modelField.name + " from " + modelField.position + + " for " + modelField.length + " chars could not be read from a line (" + lineNum + ") with only " + + line.length() + " chars.", ioobe); + } + try { + record.setString(modelField.name, strVal); + } catch (java.text.ParseException e) { + throw new DataFileException("Could not parse field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + strVal + + " on line " + lineNum, e); + } catch (java.lang.NumberFormatException e) { + throw new DataFileException("Number not valid for field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + + strVal + " on line " + lineNum, e); } - return record; + } + return record; } /** @@ -541,54 +541,58 @@ public class Record implements Serializa * @return */ public static Record createDelimitedRecord(String line, int lineNum, ModelRecord modelRecord, char delimiter, String textDelimiter) throws DataFileException { - Record record = new Record(modelRecord); + Record record = new Record(modelRecord); - StringTokenizer st = null; - if (line.endsWith(String.valueOf(delimiter))) { - st = new StringTokenizer(line + " ", "" + delimiter, true); - } - else { - st = new StringTokenizer(line, "" + delimiter, true); - } - for (ModelField modelField: modelRecord.fields) { - String strVal = null; - - if (modelField.expression) { - if (UtilValidate.isNotEmpty(modelField.refField)) { - strVal = record.getString(modelField.refField); - } - if (strVal == null) { - strVal = (String)modelField.defaultValue; - } - } else { - try { - strVal = st.nextToken(); - if (strVal.equals("" + delimiter)) { - strVal = null; - } else { - if (st.hasMoreTokens()) { - st.nextToken(); - } - } - } catch (NoSuchElementException nsee) { - throw new DataFileException("Field " + modelField.name + " could not be read from a line (" + lineNum + ") with only " + - line.length() + " chars.", nsee); - } - } + StringTokenizer st = null; + if (line.endsWith(String.valueOf(delimiter))) { + st = new StringTokenizer(line + " ", "" + delimiter, true); + } + else { + st = new StringTokenizer(line, "" + delimiter, true); + } + for (ModelField modelField: modelRecord.fields) { + String strVal = null; + + if (modelField.expression) { + if (UtilValidate.isNotEmpty(modelField.refField)) { + strVal = record.getString(modelField.refField); + } + if (strVal == null) { + strVal = (String)modelField.defaultValue; + } + } else { + //some input lines may be less than the header model. + if (st.hasMoreTokens()) { try { - if (textDelimiter != null && (strVal.startsWith(textDelimiter) && strVal.endsWith(textDelimiter))) { - strVal = strVal.substring(textDelimiter.length(), strVal.length() - textDelimiter.length()); - } - record.setString(modelField.name, strVal); - } catch (java.text.ParseException e) { - throw new DataFileException("Could not parse field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + strVal + - " on line " + lineNum, e); - } catch (java.lang.NumberFormatException e) { - throw new DataFileException("Number not valid for field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + - strVal + " on line " + lineNum, e); - } + strVal = st.nextToken(); + if (strVal.equals("" + delimiter)) { + strVal = null; + } else if (st.hasMoreTokens()) { + st.nextToken(); + } + } catch (NoSuchElementException nsee) { + throw new DataFileException("Field " + modelField.name + " could not be read from a line (" + lineNum + ") with only " + + line.length() + " chars.", nsee); + } + } + else { //if input line is less than the header model then pad with null + strVal = null; + } + } + try { + if (textDelimiter != null && (strVal.startsWith(textDelimiter) && strVal.endsWith(textDelimiter))) { + strVal = strVal.substring(textDelimiter.length(), strVal.length() - textDelimiter.length()); + } + record.setString(modelField.name, strVal); + } catch (java.text.ParseException e) { + throw new DataFileException("Could not parse field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + strVal + + " on line " + lineNum, e); + } catch (java.lang.NumberFormatException e) { + throw new DataFileException("Number not valid for field " + modelField.name + ", format string \"" + modelField.format + "\" with value " + + strVal + " on line " + lineNum, e); } - return record; + } + return record; } } Modified: ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java (original) +++ ofbiz/branches/multitenant20100310/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java Wed Mar 24 09:23:07 2010 @@ -26,9 +26,9 @@ import java.io.InputStreamReader; import java.net.URL; import java.util.Stack; - /** * Record Iterator for reading large files + * Note: this is a memory intensive and will not handle files that exceed memory. * */ @@ -74,7 +74,6 @@ public class RecordIterator { } catch (Exception e) { throw new DataFileException("UTF-8 is not supported"); } - // get the line seeded this.getNextLine(); } @@ -84,7 +83,6 @@ public class RecordIterator { this.nextRecord = null; boolean isFixedRecord = ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle); - boolean isFixedLength = ModelDataFile.SEP_FIXED_LENGTH.equals(modelDataFile.separatorStyle); boolean isDelimited = ModelDataFile.SEP_DELIMITED.equals(modelDataFile.separatorStyle); // if (Debug.infoOn()) Debug.logInfo("[DataFile.readDataFile] separatorStyle is " + modelDataFile.separatorStyle + ", isFixedRecord: " + isFixedRecord, module); @@ -92,7 +90,6 @@ public class RecordIterator { if (modelDataFile.recordLength <= 0) { throw new DataFileException("Cannot read a fixed record length file if no record length is specified"); } - try { char[] charData = new char[modelDataFile.recordLength + 1]; @@ -111,12 +108,14 @@ public class RecordIterator { } else { try { nextLine = br.readLine(); + //Debug.logInfo("br.readLine()=\"" + nextLine + "\"", module); } catch (IOException e) { throw new DataFileException("Error reading line #" + nextLineNum + " from location: " + locationInfo, e); } } - if (nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 == nextLine.length())) { + //if (nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 == nextLine.length())) { + if (nextLine != null && !((nextLine.contains(eof) ) )) { nextLineNum++; ModelRecord modelRecord = findModelForLine(nextLine, nextLineNum, modelDataFile); if (isDelimited) { @@ -136,8 +135,8 @@ public class RecordIterator { } public boolean hasNext() { - return nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 == nextLine.length()); - + //return nextLine != null && !(eof.equals(nextLine.substring(0,1)) && 1 == nextLine.length()); + return nextLine != null && !((nextLine.contains(eof) ) ); } public Record next() throws DataFileException { @@ -148,7 +147,6 @@ public class RecordIterator { if (ModelDataFile.SEP_DELIMITED.equals(modelDataFile.separatorStyle) || ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle) || ModelDataFile.SEP_FIXED_LENGTH.equals(modelDataFile.separatorStyle)) { boolean isFixedRecord = ModelDataFile.SEP_FIXED_RECORD.equals(modelDataFile.separatorStyle); // if (Debug.infoOn()) Debug.logInfo("[DataFile.readDataFile] separatorStyle is " + modelDataFile.separatorStyle + ", isFixedRecord: " + isFixedRecord, module); - // advance the line (we have already checked to make sure there is a next line this.curLine = this.nextLine; this.curRecord = this.nextRecord; @@ -179,18 +177,15 @@ public class RecordIterator { parentRecord = null; } } - if (parentRecord == null) { throw new DataFileException("Expected Parent Record not found for line " + this.getCurrentLineNumber() + "; record name of expected parent is " + this.nextRecord.getModelRecord().parentName); } - parentRecord.addChildRecord(this.nextRecord); // if the child record we just added is also a parent, push it onto the stack if (this.nextRecord.getModelRecord().childRecords.size() > 0) { parentStack.push(this.nextRecord); } - // if it can't find a next line it will nextRecord will be null and the loop will break out this.getNextLine(); } @@ -198,7 +193,6 @@ public class RecordIterator { } else { throw new DataFileException("Separator style " + modelDataFile.separatorStyle + " not recognized."); } - return curRecord; } @@ -227,12 +221,10 @@ public class RecordIterator { ModelRecord modelRecord = null; for (ModelRecord curModelRecord: modelDataFile.records) { - if (curModelRecord.tcPosition < 0) { modelRecord = curModelRecord; break; } - String typeCode = line.substring(curModelRecord.tcPosition, curModelRecord.tcPosition + curModelRecord.tcLength); // try to match with a single typecode @@ -247,7 +239,6 @@ public class RecordIterator { if (curModelRecord.tcIsNum) { // if (Debug.infoOn()) Debug.logInfo("[DataFile.findModelForLine] Doing ranged number typecode match - minNum=" + curModelRecord.tcMinNum + ", maxNum=" + curModelRecord.tcMaxNum + ", filelinecode=" + typeCode, module); long typeCodeNum = Long.parseLong(typeCode); - if ((curModelRecord.tcMinNum < 0 || typeCodeNum >= curModelRecord.tcMinNum) && (curModelRecord.tcMaxNum < 0 || typeCodeNum <= curModelRecord.tcMaxNum)) { modelRecord = curModelRecord; @@ -255,8 +246,7 @@ public class RecordIterator { } } else { // if (Debug.infoOn()) Debug.logInfo("[DataFile.findModelForLine] Doing ranged String typecode match - min=" + curModelRecord.tcMin + ", max=" + curModelRecord.tcMax + ", filelinecode=" + typeCode, module); - if ((typeCode.compareTo(curModelRecord.tcMin) >= 0) && - (typeCode.compareTo(curModelRecord.tcMax) <= 0)) { + if ((typeCode.compareTo(curModelRecord.tcMin) >= 0) && (typeCode.compareTo(curModelRecord.tcMax) <= 0)) { modelRecord = curModelRecord; break; } @@ -272,4 +262,3 @@ public class RecordIterator { return modelRecord; } } - Modified: ofbiz/branches/multitenant20100310/framework/documents/Framework.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/documents/Framework.xml?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/documents/Framework.xml (original) +++ ofbiz/branches/multitenant20100310/framework/documents/Framework.xml Wed Mar 24 09:23:07 2010 @@ -18,11 +18,11 @@ under the License. --> <chapter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - version="5.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" - xsi:schemaLocation="http://docbook.org/ns/docbook ../../applications/content/dtd/docbook.xsd" - xmlns="http://docbook.org/ns/docbook"> - <title>The OFBiz Framework Introduction.</title> + version="5.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" + xsi:schemaLocation="http://docbook.org/ns/docbook ../../applications/content/dtd/docbook.xsd" + xmlns="http://docbook.org/ns/docbook"> + <title>The OFBiz Framework Introduction.</title> <para> - For a core configuration guide check <link xl:href="http://ofbiz.apache.org/docs/coreconfig.html">the OFBiz website.</link> + For a core configuration guide check <link xl:href="http://ofbiz.apache.org/docs/coreconfig.html">the OFBiz website.</link> </para> </chapter> Modified: ofbiz/branches/multitenant20100310/framework/entity/documents/EntityEngine.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/documents/EntityEngine.xml?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/documents/EntityEngine.xml (original) +++ ofbiz/branches/multitenant20100310/framework/entity/documents/EntityEngine.xml Wed Mar 24 09:23:07 2010 @@ -18,10 +18,10 @@ under the License. --> <section xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - version="5.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" - xsi:schemaLocation="http://docbook.org/ns/docbook ../../../applications/content/dtd/docbook.xsd" - xmlns="http://docbook.org/ns/docbook"> - <title>The Entity Engine.</title> + version="5.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude" + xsi:schemaLocation="http://docbook.org/ns/docbook ../../../applications/content/dtd/docbook.xsd" + xmlns="http://docbook.org/ns/docbook"> + <title>The Entity Engine.</title> <section> <title>Entity Engine guide.</title> @@ -44,5 +44,5 @@ </para> </section> - + </section> Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactory.java Wed Mar 24 09:23:07 2010 @@ -18,20 +18,38 @@ */ package org.ofbiz.entity; +import java.util.concurrent.ConcurrentHashMap; + +import org.ofbiz.base.lang.Factory; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.Factory; import org.ofbiz.base.util.UtilObject; /** <code>Delegator</code> factory abstract class. */ public abstract class DelegatorFactory implements Factory<Delegator, String> { public static final String module = DelegatorFactoryImpl.class.getName(); + private static final ConcurrentHashMap<String, Delegator> delegatorCache = new ConcurrentHashMap<String, Delegator>(); public static Delegator getDelegator(String delegatorName) { - try { - return UtilObject.getObjectFromFactory(DelegatorFactory.class, delegatorName); - } catch (ClassNotFoundException e) { - Debug.logError(e, module); + if (delegatorName == null) { + delegatorName = "default"; + //Debug.logWarning(new Exception("Location where getting delegator with null name"), "Got a getGenericDelegator call with a null delegatorName, assuming default for the name.", module); } - return null; + do { + Delegator delegator = delegatorCache.get(delegatorName); + + if (delegator != null) { + // setup the Entity ECA Handler + delegator.initEntityEcaHandler(); + //Debug.logInfo("got delegator(" + delegatorName + ") from cache", module); + return delegator; + } + try { + delegator = UtilObject.getObjectFromFactory(DelegatorFactory.class, delegatorName); + } catch (ClassNotFoundException e) { + Debug.logError(e, module); + } + //Debug.logInfo("putting delegator(" + delegatorName + ") into cache", module); + delegatorCache.putIfAbsent(delegatorName, delegator); + } while (true); } } Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactoryImpl.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactoryImpl.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactoryImpl.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/DelegatorFactoryImpl.java Wed Mar 24 09:23:07 2010 @@ -27,32 +27,13 @@ public class DelegatorFactoryImpl extend public static final String module = DelegatorFactoryImpl.class.getName(); public Delegator getInstance(String delegatorName) { - if (delegatorName == null) { - delegatorName = "default"; - Debug.logWarning(new Exception("Location where getting delegator with null name"), "Got a getGenericDelegator call with a null delegatorName, assuming default for the name.", module); + if (Debug.infoOn()) Debug.logInfo("Creating new delegator [" + delegatorName + "] (" + Thread.currentThread().getName() + ")", module); + //Debug.logInfo(new Exception(), "Showing stack where new delegator is being created...", module); + try { + return new GenericDelegator(delegatorName); + } catch (GenericEntityException e) { + Debug.logError(e, "Error creating delegator", module); + return null; } - GenericDelegator delegator = GenericDelegator.delegatorCache.get(delegatorName); - if (delegator == null) { - synchronized (GenericDelegator.delegatorCache) { - // must check if null again as one of the blocked threads can still enter - delegator = GenericDelegator.delegatorCache.get(delegatorName); - if (delegator == null) { - if (Debug.infoOn()) Debug.logInfo("Creating new delegator [" + delegatorName + "] (" + Thread.currentThread().getName() + ")", module); - //Debug.logInfo(new Exception(), "Showing stack where new delegator is being created...", module); - try { - delegator = new GenericDelegator(delegatorName); - } catch (GenericEntityException e) { - Debug.logError(e, "Error creating delegator", module); - } - if (delegator != null) { - GenericDelegator.delegatorCache.put(delegatorName, delegator); - } else { - Debug.logError("Could not create delegator with name " + delegatorName + ", constructor failed (got null value).", module); - } - } - } - } - return delegator; } - } Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Wed Mar 24 09:23:07 2010 @@ -95,9 +95,6 @@ public class GenericDelegator implements /** This flag is only here for lower level technical testing, it shouldn't be user configurable (or at least I don't think so yet); when true all operations without a transaction will be wrapped in one; seems to be necessary for some (all?) XA aware connection pools, and should improve overall stability and consistency */ public static final boolean alwaysUseTransaction = true; - /** the delegatorCache will now be a HashMap, allowing reload of definitions, - * but the delegator will always be the same object for the given name */ - public static Map<String, GenericDelegator> delegatorCache = FastMap.newInstance(); protected String delegatorBaseName = null; protected String delegatorFullName = null; protected String delegatorTenantId = null; @@ -286,9 +283,6 @@ public class GenericDelegator implements } // 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 - // TODO: we should find a better way to do this since putting the delegator in the cache before it is completely setup may cause errors with multiple threads - GenericDelegator.delegatorCache.put(delegatorFullName, this); // setup the crypto class; this also after the delegator is in the cache otherwise we get infinite recursion this.crypto = new EntityCrypto(this); @@ -319,9 +313,6 @@ public class GenericDelegator implements } else { Debug.logInfo("Distributed Cache Clear System disabled for delegator [" + delegatorFullName + "]", module); } - - // setup the Entity ECA Handler - initEntityEcaHandler(); } protected void setDelegatorNames(String delegatorFullName) { @@ -339,7 +330,10 @@ public class GenericDelegator implements /* (non-Javadoc) * @see org.ofbiz.entity.Delegator#initEntityEcaHandler() */ - public void initEntityEcaHandler() { + public synchronized void initEntityEcaHandler() { + if (!getDelegatorInfo().useEntityEca || this.entityEcaHandler != null) { + return; + } if (getDelegatorInfo().useEntityEca) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); // initialize the entity eca handler @@ -619,9 +613,7 @@ public class GenericDelegator implements if (entity == null) { throw new IllegalArgumentException("[GenericDelegator.makeValue] could not find entity for entityName: " + entityName); } - GenericValue value = GenericValue.create(entity, fields); - value.setDelegator(this); - return value; + return GenericValue.create(this, entity, fields); } /* (non-Javadoc) @@ -632,9 +624,7 @@ public class GenericDelegator implements if (entity == null) { throw new IllegalArgumentException("[GenericDelegator.makeValue] could not find entity for entityName: " + entityName); } - GenericValue value = GenericValue.create(entity, singlePkValue); - value.setDelegator(this); - return value; + return GenericValue.create(this, entity, singlePkValue); } /* (non-Javadoc) @@ -653,9 +643,9 @@ public class GenericDelegator implements throw new IllegalArgumentException("[GenericDelegator.makeValidValue] could not find entity for entityName: " + entityName); } GenericValue value = GenericValue.create(entity); + value.setDelegator(this); value.setPKFields(fields, true); value.setNonPKFields(fields, true); - value.setDelegator(this); return value; } @@ -681,10 +671,7 @@ public class GenericDelegator implements if (entity == null) { throw new IllegalArgumentException("[GenericDelegator.makePK] could not find entity for entityName: " + entityName); } - GenericPK pk = GenericPK.create(entity, fields); - - pk.setDelegator(this); - return pk; + return GenericPK.create(this, entity, fields); } /* (non-Javadoc) @@ -695,10 +682,7 @@ public class GenericDelegator implements if (entity == null) { throw new IllegalArgumentException("[GenericDelegator.makePKSingle] could not find entity for entityName: " + entityName); } - GenericPK pk = GenericPK.create(entity, singlePkValue); - - pk.setDelegator(this); - return pk; + return GenericPK.create(this, entity, singlePkValue); } /* (non-Javadoc) @@ -734,7 +718,7 @@ public class GenericDelegator implements return null; } ModelEntity entity = this.getModelReader().getModelEntity(entityName); - GenericValue genericValue = GenericValue.create(entity, fields); + GenericValue genericValue = GenericValue.create(this, entity, fields); return this.create(genericValue, true); } @@ -747,7 +731,7 @@ public class GenericDelegator implements return null; } ModelEntity entity = this.getModelReader().getModelEntity(entityName); - GenericValue genericValue = GenericValue.create(entity, singlePkValue); + GenericValue genericValue = GenericValue.create(this, entity, singlePkValue); return this.create(genericValue, true); } @@ -1456,8 +1440,7 @@ public class GenericDelegator implements } else { // don't send fields that are the same, and if no fields have changed, update nothing ModelEntity modelEntity = value.getModelEntity(); - GenericValue toStore = GenericValue.create(modelEntity, (Map<String, ? extends Object>) value.getPrimaryKey()); - toStore.setDelegator(this); + GenericValue toStore = GenericValue.create(this, modelEntity, (Map<String, ? extends Object>) value.getPrimaryKey()); boolean atLeastOneField = false; Iterator<ModelField> nonPksIter = modelEntity.getNopksIterator(); while (nonPksIter.hasNext()) { @@ -2479,9 +2462,7 @@ public class GenericDelegator implements fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName())); } - GenericPK dummyPK = GenericPK.create(relatedEntity, fields); - dummyPK.setDelegator(this); - return dummyPK; + return GenericPK.create(this, relatedEntity, fields); } /* (non-Javadoc) @@ -2603,8 +2584,7 @@ public class GenericDelegator implements //if never cached, then don't bother clearing if (entity.getNeverCache()) return; - GenericValue dummyValue = GenericValue.create(entity, fields); - dummyValue.setDelegator(this); + GenericValue dummyValue = GenericValue.create(this, entity, fields); this.clearCacheLineFlexible(dummyValue); } Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericEntity.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericEntity.java Wed Mar 24 09:23:07 2010 @@ -121,13 +121,13 @@ public class GenericEntity extends Obser } /** Creates new GenericEntity from existing Map */ - public static GenericEntity createGenericEntity(ModelEntity modelEntity, Map<String, ? extends Object> fields) { + public static GenericEntity createGenericEntity(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fields) { if (modelEntity == null) { throw new IllegalArgumentException("Cannot create a GenericEntity with a null modelEntity parameter"); } GenericEntity newEntity = new GenericEntity(); - newEntity.init(modelEntity, fields); + newEntity.init(delegator, modelEntity, fields); return newEntity; } @@ -157,12 +157,14 @@ public class GenericEntity extends Obser } /** Creates new GenericEntity from existing Map */ - protected void init(ModelEntity modelEntity, Map<String, ? extends Object> fields) { + protected void init(Delegator delegator, 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(); + this.delegatorName = delegator.getDelegatorName(); + this.internalDelegator = delegator; setFields(fields); // check some things @@ -172,7 +174,7 @@ public class GenericEntity extends Obser } /** Creates new GenericEntity from existing Map */ - protected void init(ModelEntity modelEntity, Object singlePkValue) { + protected void init(Delegator delegator, ModelEntity modelEntity, Object singlePkValue) { if (modelEntity == null) { throw new IllegalArgumentException("Cannot create a GenericEntity with a null modelEntity parameter"); } @@ -181,6 +183,8 @@ public class GenericEntity extends Obser } this.modelEntity = modelEntity; this.entityName = modelEntity.getEntityName(); + this.delegatorName = delegator.getDelegatorName(); + this.internalDelegator = delegator; set(modelEntity.getOnlyPk().getName(), singlePkValue); // check some things @@ -816,9 +820,7 @@ public class GenericEntity extends Obser ModelField curField = iter.next(); pkNames.add(curField.getName()); } - GenericPK newPK = GenericPK.create(getModelEntity(), this.getFields(pkNames)); - newPK.setDelegator(this.getDelegator()); - return newPK; + return GenericPK.create(this.getDelegator(), getModelEntity(), this.getFields(pkNames)); } /** go through the pks and for each one see if there is an entry in fields to set */ Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericPK.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericPK.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericPK.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericPK.java Wed Mar 24 09:23:07 2010 @@ -47,16 +47,16 @@ public class GenericPK extends GenericEn } /** Creates new GenericPK from existing Map */ - public static GenericPK create(ModelEntity modelEntity, Map<String, ? extends Object> fields) { + public static GenericPK create(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fields) { GenericPK newPK = genericPKFactory.object(); - newPK.init(modelEntity, fields); + newPK.init(delegator, modelEntity, fields); return newPK; } /** Creates new GenericPK from existing Map */ - public static GenericPK create(ModelEntity modelEntity, Object singlePkValue) { + public static GenericPK create(Delegator delegator, ModelEntity modelEntity, Object singlePkValue) { GenericPK newPK = genericPKFactory.object(); - newPK.init(modelEntity, singlePkValue); + newPK.init(delegator, modelEntity, singlePkValue); return newPK; } @@ -72,8 +72,6 @@ public class GenericPK extends GenericEn */ @Override public Object clone() { - GenericPK newEntity = GenericPK.create(this); - newEntity.setDelegator(internalDelegator); - return newEntity; + return GenericPK.create(this); } } Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericValue.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericValue.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/GenericValue.java Wed Mar 24 09:23:07 2010 @@ -77,16 +77,16 @@ public class GenericValue extends Generi } /** Creates new GenericValue from existing Map */ - public static GenericValue create(ModelEntity modelEntity, Map<String, ? extends Object> fields) { + public static GenericValue create(Delegator delegator, ModelEntity modelEntity, Map<String, ? extends Object> fields) { GenericValue newValue = genericValueFactory.object(); - newValue.init(modelEntity, fields); + newValue.init(delegator, modelEntity, fields); return newValue; } /** Creates new GenericValue from existing Map */ - public static GenericValue create(ModelEntity modelEntity, Object singlePkValue) { + public static GenericValue create(Delegator delegator, ModelEntity modelEntity, Object singlePkValue) { GenericValue newValue = genericValueFactory.object(); - newValue.init(modelEntity, singlePkValue); + newValue.init(delegator, modelEntity, singlePkValue); return newValue; } @@ -495,9 +495,7 @@ public class GenericValue extends Generi */ @Override public Object clone() { - GenericValue newEntity = GenericValue.create(this); - newEntity.setDelegator(internalDelegator); - return newEntity; + return GenericValue.create(this); } protected static class NullGenericValue extends GenericValue implements NULL { Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/finder/PrimaryKeyFinder.java Wed Mar 24 09:23:07 2010 @@ -41,6 +41,7 @@ import org.w3c.dom.Element; * Uses the delegator to find entity values by a condition * */ +@SuppressWarnings("serial") public class PrimaryKeyFinder extends Finder { public static final String module = PrimaryKeyFinder.class.getName(); @@ -99,9 +100,9 @@ public class PrimaryKeyFinder extends Fi if (autoFieldMap) { GenericValue tempVal = delegator.makeValue(modelEntity.getEntityName()); - // try a map called "parameters", try it first so values from here are overriden by values in the main context + // try a map called "parameters", try it first so values from here are overridden by values in the main context Object parametersObj = context.get("parameters"); - if (parametersObj != null && parametersObj instanceof Map) { + if (parametersObj != null && parametersObj instanceof Map<?, ?>) { tempVal.setAllFields(UtilGenerics.checkMap(parametersObj), true, null, Boolean.TRUE); } Modified: ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java?rev=926987&r1=926986&r2=926987&view=diff ============================================================================== --- ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java (original) +++ ofbiz/branches/multitenant20100310/framework/entity/src/org/ofbiz/entity/model/ModelEntityChecker.java Wed Mar 24 09:23:07 2010 @@ -194,7 +194,8 @@ public class ModelEntityChecker { // make sure all FK names are <= 18 characters if (relation.getFkName().length() > 18) { - warningList.add("[RelFKNameGT18] The foregn key name (length:" + relation.getFkName().length() + warningList.add("[RelFKNameGT18] The foreign key named " + relation.getFkName() + + " (length:" + relation.getFkName().length() + ") was greater than 18 characters in length for relation " + relation.getTitle() + relation.getRelEntityName() + " of entity " + entity.getEntityName() + "."); } |
Free forum by Nabble | Edit this page |