Failure to generate getI* shouldn't be fatal. Also, the current algorithm use to discover the reference tablename is by no mean fool proof.

This commit is contained in:
Heng Sin Low 2008-12-03 09:51:08 +00:00
parent 6b33b0ab59
commit 4022504df5
2 changed files with 60 additions and 57 deletions

View File

@ -397,8 +397,8 @@ public class ModelClassGenerator
String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3); String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3);
MTable table = MTable.get(Env.getCtx(), tableName); MTable table = MTable.get(Env.getCtx(), tableName);
if (table == null) if (table != null)
throw new RuntimeException("No table found for "+tableName); {
String entityType = table.getEntityType(); String entityType = table.getEntityType();
if (!"D".equals(entityType)) if (!"D".equals(entityType))
{ {
@ -424,11 +424,11 @@ public class ModelClassGenerator
.append(" ").append(referenceClassName).append(" result = null;").append(NL) .append(" ").append(referenceClassName).append(" result = null;").append(NL)
.append(" try {").append(NL) .append(" try {").append(NL)
.append(" Constructor<?> constructor = null;").append(NL) .append(" Constructor<?> constructor = null;").append(NL)
// .append(" try {").append(NL) // .append(" try {").append(NL)
.append(" constructor = clazz.getDeclaredConstructor(new Class[]{Properties.class, int.class, String.class});").append(NL) .append(" constructor = clazz.getDeclaredConstructor(new Class[]{Properties.class, int.class, String.class});").append(NL)
// .append(" } catch (NoSuchMethodException e) {").append(NL) // .append(" } catch (NoSuchMethodException e) {").append(NL)
// .append(" log.warning(\"No transaction Constructor for \" + clazz + \" Exception[\" + e.toString() + \"]\");").append(NL) // .append(" log.warning(\"No transaction Constructor for \" + clazz + \" Exception[\" + e.toString() + \"]\");").append(NL)
// .append(" }").append(NL) // .append(" }").append(NL)
// TODO - here we can implement Lazy loading or Cache of record. Like in Hibernate, objects can be loaded on demand or when master object is loaded. // TODO - here we can implement Lazy loading or Cache of record. Like in Hibernate, objects can be loaded on demand or when master object is loaded.
.append(" result = ("+referenceClassName+")constructor.newInstance(new Object[] {getCtx(), new Integer(get"+columnName+"()), get_TrxName()});").append(NL) .append(" result = ("+referenceClassName+")constructor.newInstance(new Object[] {getCtx(), new Integer(get"+columnName+"()), get_TrxName()});").append(NL)
.append(" } catch (Exception e) {").append(NL) .append(" } catch (Exception e) {").append(NL)
@ -439,6 +439,7 @@ public class ModelClassGenerator
.append(" return result;").append(NL) .append(" return result;").append(NL)
.append(" }").append(NL) .append(" }").append(NL)
; ;
}
// Add imports: // Add imports:
addImportClass(java.lang.reflect.Constructor.class); addImportClass(java.lang.reflect.Constructor.class);
addImportClass(java.util.logging.Level.class); addImportClass(java.util.logging.Level.class);

View File

@ -360,6 +360,7 @@ public class ModelInterfaceGenerator
String tableName = columnName.substring(0, columnName.length()-3); String tableName = columnName.substring(0, columnName.length()-3);
MTable table = MTable.get(Env.getCtx(), tableName); MTable table = MTable.get(Env.getCtx(), tableName);
if (table != null) {
String entityType = table.getEntityType(); String entityType = table.getEntityType();
if (!"D".equals(entityType)) if (!"D".equals(entityType))
{ {
@ -381,6 +382,7 @@ public class ModelInterfaceGenerator
sb.append("\n") sb.append("\n")
.append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws RuntimeException;") .append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws RuntimeException;")
; ;
}
} else { } else {
// TODO - Handle other types // TODO - Handle other types
//sb.append("\tpublic I_"+columnName+" getI_").append(columnName).append("(){return null; };"); //sb.append("\tpublic I_"+columnName+" getI_").append(columnName).append("(){return null; };");