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
This commit is contained in:
Carlos Ruiz 2010-05-04 16:40:18 +00:00
parent 04210dc6aa
commit c8b861968c
1 changed files with 39 additions and 44 deletions

View File

@ -174,11 +174,8 @@ public class MTable extends X_AD_Table
// AD_Attribute_Value, AD_TreeNode // 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 * @param tableName table name
* @return class or null * @return class or null
*/ */
@ -188,21 +185,6 @@ public class MTable extends X_AD_Table
if (tableName == null || tableName.endsWith("_Trl")) if (tableName == null || tableName.endsWith("_Trl"))
return null; 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 //check cache
Class<?> cache = s_classCache.get(tableName); Class<?> cache = s_classCache.get(tableName);
if (cache != null) if (cache != null)
@ -214,6 +196,27 @@ public class MTable extends X_AD_Table
return cache; 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 // Special Naming
for (int i = 0; i < s_special.length; i++) 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)) if (!MEntityType.ENTITYTYPE_Dictionary.equals(entityType))
{ {
for (int i = 0; i < entityTypes.length; i++) MEntityType et = MEntityType.get(Env.getCtx(), entityType);
{ String etmodelpackage = et.getModelPackage();
if (entityTypes[i].getEntityType().equals(entityType)) if (etmodelpackage != null)
{ {
String modelpackage = entityTypes[i].getModelPackage(); Class<?> clazz = null;
if (modelpackage != null) clazz = getPOclass(etmodelpackage + ".M" + Util.replace(tableName, "_", ""));
{ if (clazz != null) {
Class<?> clazz = null; s_classCache.put(tableName, clazz);
if (! tableName.startsWith("I_")) return clazz;
{
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);
}
} }
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 ] //end [ 1784588 ]