Integrate Trifon's change from trunk revision 5799

Feature: [ 2028151 ] Dynamic column lenght validation
http://sourceforge.net/tracker/index.php?func=detail&aid=2028151&group_id=176962&atid=883808
This commit is contained in:
Carlos Ruiz 2008-07-29 07:04:21 +00:00
parent 185a04088c
commit 5c4d6def6f
2 changed files with 19 additions and 4 deletions

View File

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

View File

@ -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