Feature Request [ 1772015 ] Generate java Interface and implementation instead of X_ classes

https://sourceforge.net/tracker/?func=detail&atid=879335&aid=1772015&group_id=176962
This commit is contained in:
trifonnt 2007-08-20 09:13:23 +00:00
parent 8b086bcb05
commit bc451d1044
3 changed files with 167 additions and 9 deletions

View File

@ -0,0 +1,157 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
* Contributor(s): Carlos Ruiz - globalqss *
* Teo Sarca *
* Trifon Trifonov *
*****************************************************************************/
package org.adempiere.util;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
/**
* Generate Model Classes extending PO.
* Base class for CMP interface - will be extended to create byte code directly
*
* @author Jorg Janke
* @version $Id: GenerateModel.java,v 1.42 2005/05/08 15:16:56 jjanke Exp $
*/
public class GenerateModel
{
/** Logger */
private static CLogger log = CLogger.getCLogger (GenerateModel.class);
/**
* String representation
* @return string representation
*/
public String toString()
{
StringBuffer sb = new StringBuffer ("GenerateModel[").append("]");
return sb.toString();
}
/**************************************************************************
* Generate PO Model Class.
* <pre>
* Example: java GenerateModel.class mydirectory myPackage 'U','A'
* would generate entity type User and Application classes into mydirectory.
* Without parameters, the default is used:
* C:\Compiere\compiere-all\extend\src\compiere\model\ compiere.model 'U','A'
* </pre>
* @param args directory package entityType
* - directory where to save the generated file
* - package of the classes to be generated
* - entityType to be generated
*/
public static void main (String[] args)
{
Adempiere.startupEnvironment(true);
CLogMgt.setLevel(Level.FINE);
log.info("Generate Model $Revision: 1.42 $");
log.info("----------------------------------");
// first parameter
String directory = "C:\\Compiere\\compiere-all\\extend\\src\\compiere\\model\\";
if (args.length > 0)
directory = args[0];
if (directory == null || directory.length() == 0)
{
System.err.println("No Directory");
System.exit(1);
}
log.info("Directory: " + directory);
// second parameter
String packageName = "compiere.model";
if (args.length > 1)
packageName = args[1];
if (packageName == null || packageName.length() == 0)
{
System.err.println("No package");
System.exit(1);
}
log.info("Package: " + packageName);
// third parameter
String entityType = "'U','A'"; // User, Application
if (args.length > 2)
entityType = args[2];
if (entityType == null || entityType.length() == 0)
{
System.err.println("No EntityType");
System.exit(1);
}
StringBuffer sql = new StringBuffer("EntityType IN (")
.append(entityType).append(")");
log.info(sql.toString());
log.info("----------------------------------");
String tableLike = "'%'"; // All tables
if (args.length > 3)
tableLike = args[3];
log.info("Table Like: " + tableLike);
// complete sql
sql.insert(0, "SELECT AD_Table_ID "
+ "FROM AD_Table "
+ "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" // special views
+ " OR IsView='N')"
+ " AND TableName NOT LIKE '%_Trl' AND ");
sql.append(" AND TableName LIKE ").append(tableLike);
sql.append(" ORDER BY TableName");
//
int count = 0;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), null);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
new ModelClassGenerator(rs.getInt(1), directory, packageName);
count++;
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.severe("main - " + e);
}
finally
{
try {
if (pstmt != null)
pstmt.close ();
} catch (Exception e) { /* ignored */ }
pstmt = null;
}
log.info("Generated = " + count);
}
}

View File

@ -41,7 +41,7 @@ import org.compiere.util.Env;
* @author Jorg Janke
* @version $Id: GenerateModel.java,v 1.42 2005/05/08 15:16:56 jjanke Exp $
*/
public class GenerateModelTrifon
public class ModelClassGenerator
{
/**
* Generate PO Class
@ -49,7 +49,7 @@ public class GenerateModelTrifon
* @param directory directory with \ or / at the end.
* @param packageName package name
*/
public GenerateModelTrifon (int AD_Table_ID, String directory, String packageName)
public ModelClassGenerator (int AD_Table_ID, String directory, String packageName)
{
// create column access methods
StringBuffer mandatory = new StringBuffer();
@ -82,10 +82,10 @@ public class GenerateModelTrifon
+" *****************************************************************************/\n";
/** Generated on */
private Timestamp s_run = new Timestamp(System.currentTimeMillis());
// private Timestamp s_run = new Timestamp(System.currentTimeMillis());
/** Logger */
private static CLogger log = CLogger.getCLogger (GenerateModelTrifon.class);
private static CLogger log = CLogger.getCLogger (ModelClassGenerator.class);
/**
* Add Header info to buffer
@ -922,7 +922,8 @@ public class GenerateModelTrifon
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
new GenerateModelTrifon(rs.getInt(1), directory, packageName);
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
new ModelClassGenerator(rs.getInt(1), directory, packageName);
count++;
}
rs.close();

View File

@ -47,7 +47,7 @@ import org.compiere.util.Env;
* @author Trifon Trifonov
* @version $Id$
*/
public class GenerateInterfaceTrifon {
public class ModelInterfaceGenerator {
private String packageName = "";
@ -86,10 +86,10 @@ public class GenerateInterfaceTrifon {
private Timestamp s_run = new Timestamp(System.currentTimeMillis());
/** Logger */
private static CLogger log = CLogger.getCLogger(GenerateInterfaceTrifon.class);
private static CLogger log = CLogger.getCLogger(ModelInterfaceGenerator.class);
public GenerateInterfaceTrifon(int AD_Table_ID, String directory, String packageName) {
public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) {
this.packageName = packageName;
// create column access methods
StringBuffer mandatory = new StringBuffer();
@ -514,7 +514,7 @@ public class GenerateInterfaceTrifon {
pstmt = DB.prepareStatement(sql.toString(), null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
new GenerateInterfaceTrifon(rs.getInt(1), directory, packageName);
new ModelInterfaceGenerator(rs.getInt(1), directory, packageName);
count++;
}
rs.close();