From c8b861968c26d6ba3356cd205a41ce20ff48e7ff Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 4 May 2010 16:40:18 +0000 Subject: [PATCH] Refactored [2949927] - The current Persistence Engine Allow not get I_Table - peer reviewed and tested with dictionary tables, libero tables and the new libero import table Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2949927 --- base/src/org/compiere/model/MTable.java | 83 ++++++++++++------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/base/src/org/compiere/model/MTable.java b/base/src/org/compiere/model/MTable.java index be30492266..9ed057e9e3 100644 --- a/base/src/org/compiere/model/MTable.java +++ b/base/src/org/compiere/model/MTable.java @@ -174,11 +174,8 @@ public class MTable extends X_AD_Table // AD_Attribute_Value, AD_TreeNode }; - /** EntityType */ - private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx()); - /** - * Get Persistency Class for Table + * Get Persistence Class for Table * @param tableName table name * @return class or null */ @@ -188,21 +185,6 @@ public class MTable extends X_AD_Table if (tableName == null || tableName.endsWith("_Trl")) return null; - MTable table = MTable.get(Env.getCtx(), tableName); - String entityType = table.getEntityType(); - - // Import Tables (Name conflict) - if (tableName.startsWith("I_") && MEntityType.ENTITYTYPE_Dictionary.equals(entityType)) - { - Class clazz = getPOclass("org.compiere.model.X_" + tableName); - if (clazz != null) - return clazz; - s_log.warning("No class for table: " + tableName); - return null; - } - - - //check cache Class cache = s_classCache.get(tableName); if (cache != null) @@ -214,6 +196,27 @@ public class MTable extends X_AD_Table return cache; } + MTable table = MTable.get(Env.getCtx(), tableName); + String entityType = table.getEntityType(); + + // Import Tables (Name conflict) + // Import Tables doesn't manage model M classes, just X_ + if (tableName.startsWith("I_")) + { + MEntityType et = MEntityType.get(Env.getCtx(), entityType); + String etmodelpackage = et.getModelPackage(); + if (etmodelpackage == null || MEntityType.ENTITYTYPE_Dictionary.equals(entityType)) + etmodelpackage = "org.compiere.model"; // fallback for dictionary or empty model package on entity type + Class clazz = getPOclass(etmodelpackage + ".X_" + tableName); + if (clazz != null) + { + s_classCache.put(tableName, clazz); + return clazz; + } + s_log.warning("No class for table: " + tableName); + return null; + } + // Special Naming for (int i = 0; i < s_special.length; i++) { @@ -229,33 +232,25 @@ public class MTable extends X_AD_Table } } - //begin [ 1784588 ] Use ModelPackage of EntityType to Find Model Class - vpj-cd + //begin [ 1784588 ] Use ModelPackage of EntityType to Find Model Class - vpj-cd if (!MEntityType.ENTITYTYPE_Dictionary.equals(entityType)) - { - for (int i = 0; i < entityTypes.length; i++) - { - if (entityTypes[i].getEntityType().equals(entityType)) - { - String modelpackage = entityTypes[i].getModelPackage(); - if (modelpackage != null) - { - Class clazz = null; - if (! tableName.startsWith("I_")) - { - clazz = getPOclass(entityTypes[i].getModelPackage() + ".M" + Util.replace(tableName, "_", "")); - if (clazz != null) { - s_classCache.put(tableName, clazz); - return clazz; - } - } - clazz = getPOclass(entityTypes[i].getModelPackage() + ".X_" + tableName); - if (clazz != null) { - s_classCache.put(tableName, clazz); - return clazz; - } - s_log.warning("No class for table with it entity: " + tableName); - } + { + MEntityType et = MEntityType.get(Env.getCtx(), entityType); + String etmodelpackage = et.getModelPackage(); + if (etmodelpackage != null) + { + Class clazz = null; + clazz = getPOclass(etmodelpackage + ".M" + Util.replace(tableName, "_", "")); + if (clazz != null) { + s_classCache.put(tableName, clazz); + return clazz; } + clazz = getPOclass(etmodelpackage + ".X_" + tableName); + if (clazz != null) { + s_classCache.put(tableName, clazz); + return clazz; + } + s_log.warning("No class for table with it entity: " + tableName); } } //end [ 1784588 ]