[ 1785001 ] Using ModelPackage of EntityType to Generate Model Class
http://sourceforge.net/tracker/index.php?func=detail&aid=1785001&group_id=176962&atid=879335
This commit is contained in:
parent
0c3cbc3162
commit
b348312efd
|
@ -32,10 +32,14 @@ import java.util.TreeSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.Adempiere;
|
import org.compiere.Adempiere;
|
||||||
|
import org.compiere.model.MEntityType;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate Model Classes extending PO.
|
* Generate Model Classes extending PO.
|
||||||
|
@ -48,7 +52,9 @@ import org.compiere.util.DisplayType;
|
||||||
* <li>BF [ 1781629 ] Don't use Env.NL in model class/interface generators
|
* <li>BF [ 1781629 ] Don't use Env.NL in model class/interface generators
|
||||||
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
|
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
|
||||||
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
|
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
|
||||||
* <li>better formating of generated source
|
* <li>better formating of generated source
|
||||||
|
* @author Victor Perez, e-Evolution
|
||||||
|
* <li>FR [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class
|
||||||
*/
|
*/
|
||||||
public class ModelClassGenerator
|
public class ModelClassGenerator
|
||||||
{
|
{
|
||||||
|
@ -103,6 +109,10 @@ public class ModelClassGenerator
|
||||||
/** Package Name */
|
/** Package Name */
|
||||||
private String packageName = "";
|
private String packageName = "";
|
||||||
|
|
||||||
|
/** EntityType */
|
||||||
|
private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Header info to buffer
|
* Add Header info to buffer
|
||||||
* @param AD_Table_ID table
|
* @param AD_Table_ID table
|
||||||
|
@ -431,10 +441,31 @@ public class ModelClassGenerator
|
||||||
// 1) Must understand which class to reference
|
// 1) Must understand which class to reference
|
||||||
if (DisplayType.isID(displayType) && !IsKey) {
|
if (DisplayType.isID(displayType) && !IsKey) {
|
||||||
if (displayType == DisplayType.TableDir) {
|
if (displayType == DisplayType.TableDir) {
|
||||||
|
|
||||||
|
//begin [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class - vpj-cd
|
||||||
|
String tableName = columnName.substring(0, columnName.length()-3);
|
||||||
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);
|
||||||
|
String entityType = table.getEntityType();
|
||||||
|
if (!"D".equals(entityType))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < entityTypes.length; i++)
|
||||||
|
{
|
||||||
|
if (entityTypes[i].getEntityType().equals(entityType))
|
||||||
|
{
|
||||||
|
String modelpackage = entityTypes[i].getModelPackage();
|
||||||
|
if (modelpackage != null)
|
||||||
|
{
|
||||||
|
referenceClassName = modelpackage+".I_"+columnName.substring(0, columnName.length()-3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//end [ 1785001 ]
|
||||||
sb.append(NL)
|
sb.append(NL)
|
||||||
.append("\tpublic "+referenceClassName+" get").append(referenceClassName).append("() throws Exception ").append(NL)
|
.append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws Exception ").append(NL)
|
||||||
.append(" {").append(NL)
|
.append(" {").append(NL)
|
||||||
// TODO - here we can implement Lazy loading or Cache of class
|
// TODO - here we can implement Lazy loading or Cache of class
|
||||||
.append(" Class<?> clazz = MTable.getClass("+referenceClassName+".Table_Name);").append(NL)
|
.append(" Class<?> clazz = MTable.getClass("+referenceClassName+".Table_Name);").append(NL)
|
||||||
|
@ -934,7 +965,8 @@ public class ModelClassGenerator
|
||||||
log.info("Generate Model $Revision: 1.42 $");
|
log.info("Generate Model $Revision: 1.42 $");
|
||||||
log.info("----------------------------------");
|
log.info("----------------------------------");
|
||||||
// first parameter
|
// first parameter
|
||||||
String directory = "C:\\Compiere\\compiere-all\\extend\\src\\compiere\\model\\";
|
//String directory = "/Users/Horus/Documents/adempiere/clientes/adempiere_trunk/base/src/org/compiere/model/";
|
||||||
|
String directory = "/Users/Horus/Documents/adempiere/clientes/libero/src/org/eevolution/model/";
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
directory = args[0];
|
directory = args[0];
|
||||||
if (directory == null || directory.length() == 0)
|
if (directory == null || directory.length() == 0)
|
||||||
|
@ -945,7 +977,7 @@ public class ModelClassGenerator
|
||||||
log.info("Directory: " + directory);
|
log.info("Directory: " + directory);
|
||||||
|
|
||||||
// second parameter
|
// second parameter
|
||||||
String packageName = "compiere.model";
|
String packageName = "org.eevolution.model";
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
packageName = args[1];
|
packageName = args[1];
|
||||||
if (packageName == null || packageName.length() == 0)
|
if (packageName == null || packageName.length() == 0)
|
||||||
|
@ -956,7 +988,8 @@ public class ModelClassGenerator
|
||||||
log.info("Package: " + packageName);
|
log.info("Package: " + packageName);
|
||||||
|
|
||||||
// third parameter
|
// third parameter
|
||||||
String entityType = "'U','A'"; // User, Application
|
//String entityType = "'U','A','D','EE01'"; // User, Application
|
||||||
|
String entityType = "'EE01'"; // User, Application
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
entityType = args[2];
|
entityType = args[2];
|
||||||
if (entityType == null || entityType.length() == 0)
|
if (entityType == null || entityType.length() == 0)
|
||||||
|
|
|
@ -41,10 +41,13 @@ import java.util.TreeSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.Adempiere;
|
import org.compiere.Adempiere;
|
||||||
|
import org.compiere.model.MEntityType;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Trifon Trifonov
|
* @author Trifon Trifonov
|
||||||
|
@ -55,6 +58,8 @@ import org.compiere.util.DisplayType;
|
||||||
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
|
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
|
||||||
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
|
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
|
||||||
* <li>better formating of generated source
|
* <li>better formating of generated source
|
||||||
|
* @author Victor Perez, e-Evolution
|
||||||
|
* <li>FR [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class
|
||||||
*/
|
*/
|
||||||
public class ModelInterfaceGenerator {
|
public class ModelInterfaceGenerator {
|
||||||
|
|
||||||
|
@ -98,6 +103,10 @@ public class ModelInterfaceGenerator {
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(ModelInterfaceGenerator.class);
|
private static CLogger log = CLogger.getCLogger(ModelInterfaceGenerator.class);
|
||||||
|
|
||||||
|
/** EntityType */
|
||||||
|
private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) {
|
public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) {
|
||||||
|
@ -377,9 +386,30 @@ public class ModelInterfaceGenerator {
|
||||||
if (DisplayType.isID(displayType) && !IsKey) {
|
if (DisplayType.isID(displayType) && !IsKey) {
|
||||||
if (displayType == DisplayType.TableDir) {
|
if (displayType == DisplayType.TableDir) {
|
||||||
String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3);
|
String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3);
|
||||||
|
//begin [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class - vpj-cd
|
||||||
|
String tableName = columnName.substring(0, columnName.length()-3);
|
||||||
|
|
||||||
|
MTable table = MTable.get(Env.getCtx(), tableName);
|
||||||
|
String entityType = table.getEntityType();
|
||||||
|
if (!"D".equals(entityType))
|
||||||
|
{
|
||||||
|
for (int i = 0; i < entityTypes.length; i++)
|
||||||
|
{
|
||||||
|
if (entityTypes[i].getEntityType().equals(entityType))
|
||||||
|
{
|
||||||
|
String modelpackage = entityTypes[i].getModelPackage();
|
||||||
|
if (modelpackage != null)
|
||||||
|
{
|
||||||
|
referenceClassName = modelpackage+".I_"+columnName.substring(0, columnName.length()-3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//end [ 1785001 ]
|
||||||
|
|
||||||
sb.append("\n")
|
sb.append("\n")
|
||||||
.append("\tpublic "+referenceClassName+" get").append(referenceClassName).append("() throws Exception;")
|
.append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws Exception;")
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
// TODO - Handle other types
|
// TODO - Handle other types
|
||||||
|
@ -515,7 +545,8 @@ public class ModelInterfaceGenerator {
|
||||||
log.info("Generate Interface $Revision: 1.0 $");
|
log.info("Generate Interface $Revision: 1.0 $");
|
||||||
log.info("----------------------------------");
|
log.info("----------------------------------");
|
||||||
// first parameter
|
// first parameter
|
||||||
String directory = "C:\\extend\\src\\compiere\\model\\";
|
//String directory = "/Users/Horus/Documents/adempiere/clientes/adempiere_trunk/base/src/org/compiere/model/";
|
||||||
|
String directory = "/Users/Horus/Documents/adempiere/clientes/libero/src/org/eevolution/model/";
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
directory = args[0];
|
directory = args[0];
|
||||||
if (directory == null || directory.length() == 0) {
|
if (directory == null || directory.length() == 0) {
|
||||||
|
@ -525,7 +556,8 @@ public class ModelInterfaceGenerator {
|
||||||
log.info("Directory: " + directory);
|
log.info("Directory: " + directory);
|
||||||
|
|
||||||
// second parameter
|
// second parameter
|
||||||
String packageName = "compiere.model";
|
//String packageName = "org.compiere.model";
|
||||||
|
String packageName = "org.eevolution.model";
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
packageName = args[1];
|
packageName = args[1];
|
||||||
if (packageName == null || packageName.length() == 0) {
|
if (packageName == null || packageName.length() == 0) {
|
||||||
|
@ -535,7 +567,8 @@ public class ModelInterfaceGenerator {
|
||||||
log.info("Package: " + packageName);
|
log.info("Package: " + packageName);
|
||||||
|
|
||||||
// third parameter
|
// third parameter
|
||||||
String entityType = "'U','A'"; // User, Application
|
//String entityType = "'U','A','EE01','D'"; // User, Application
|
||||||
|
String entityType = "'EE01'"; // User, Application
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
entityType = args[2];
|
entityType = args[2];
|
||||||
if (entityType == null || entityType.length() == 0) {
|
if (entityType == null || entityType.length() == 0) {
|
||||||
|
|
Loading…
Reference in New Issue