diff --git a/base/src/org/adempiere/util/ModelClassGenerator.java b/base/src/org/adempiere/util/ModelClassGenerator.java index 120495afa1..31f2dfc730 100644 --- a/base/src/org/adempiere/util/ModelClassGenerator.java +++ b/base/src/org/adempiere/util/ModelClassGenerator.java @@ -566,13 +566,14 @@ public class ModelClassGenerator // String length check if (clazz.equals(String.class) && fieldLength > 0) { + sb.append( "\t\tint fieldLength = p_info.getFieldLength( COLUMNNAME_").append( columnName ).append( " );" ).append(NL); sb.append ("\n\t\tif ("); if (!isMandatory) sb.append(columnName).append(" != null && "); - sb.append(columnName).append(".length() > ").append(fieldLength).append(")").append(NL) + sb.append(columnName).append(".length() > fieldLength ").append(")").append(NL) .append("\t\t{").append(NL) - .append("\t\t\tlog.warning(\"Length > ").append(fieldLength).append(" - truncated\");").append(NL) - .append("\t\t\t").append(columnName).append(" = ").append(columnName).append(".substring(0, ").append(fieldLength).append(");").append(NL) + .append("\t\t\tlog.warning(\"Length > \" + fieldLength + \" - truncated\");").append(NL) + .append("\t\t\t").append(columnName).append(" = ").append( columnName ).append(".substring(0, fieldLength ").append(");").append(NL) .append("\t\t}").append(NL) ; } @@ -599,7 +600,7 @@ public class ModelClassGenerator else if (clazz.equals(BigDecimal.class)) mandatory.append("Env.ZERO"); else if (clazz.equals(Timestamp.class)) - mandatory.append("new Timestamp(System.currentTimeMillis())"); + mandatory.append("new Timestamp( System.currentTimeMillis() )"); else mandatory.append("null"); mandatory.append(");").append(NL); diff --git a/base/src/org/compiere/model/POInfo.java b/base/src/org/compiere/model/POInfo.java index f1185d9a2c..5a2d953b1b 100644 --- a/base/src/org/compiere/model/POInfo.java +++ b/base/src/org/compiere/model/POInfo.java @@ -605,6 +605,20 @@ public class POInfo implements Serializable return m_columns[index].FieldLength; } // getFieldLength + /** + * Get Column FieldLength + * @param columnName Column Name + * @return field length or 0 + */ + public int getFieldLength (String columnName) + { + int index = getColumnIndex( columnName ); + if (index >= 0) { + return getFieldLength( index ); + } + return 0; + } + /** * Validate Content * @param index index