parameterize, indentation, imports
This commit is contained in:
parent
36d10d08fb
commit
9c1c4ea524
|
@ -18,14 +18,22 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.eevolution.tools;
|
package org.eevolution.tools;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.math.*;
|
import java.io.FileOutputStream;
|
||||||
import java.sql.*;
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.logging.*;
|
import java.io.Writer;
|
||||||
import org.compiere.*;
|
import java.math.BigDecimal;
|
||||||
import org.compiere.dbPort.*;
|
import java.sql.PreparedStatement;
|
||||||
import org.compiere.db.*;
|
import java.sql.ResultSet;
|
||||||
import org.compiere.util.*;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.Adempiere;
|
||||||
|
import org.compiere.util.CLogMgt;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
/**
|
/**
|
||||||
* Generate Model Classes extending PO.
|
* Generate Model Classes extending PO.
|
||||||
* Base class for CMP interface - will be extended to create byte code directly
|
* Base class for CMP interface - will be extended to create byte code directly
|
||||||
|
@ -61,7 +69,7 @@ public class GenerateModel
|
||||||
|
|
||||||
/** File Header */
|
/** File Header */
|
||||||
public static final String COPY =
|
public static final String COPY =
|
||||||
"/******************************************************************************\n"
|
"/******************************************************************************\n"
|
||||||
+" * Product: Adempiere ERP & CRM Smart Business Solution *\n"
|
+" * Product: Adempiere ERP & CRM Smart Business Solution *\n"
|
||||||
+" * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *\n"
|
+" * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved. *\n"
|
||||||
+" * This program is free software; you can redistribute it and/or modify it *\n"
|
+" * This program is free software; you can redistribute it and/or modify it *\n"
|
||||||
|
@ -78,9 +86,6 @@ public class GenerateModel
|
||||||
+" * or via info@compiere.org or http://www.compiere.org/license.html *\n"
|
+" * or via info@compiere.org or http://www.compiere.org/license.html *\n"
|
||||||
+" *****************************************************************************/\n";
|
+" *****************************************************************************/\n";
|
||||||
|
|
||||||
/** Generated on */
|
|
||||||
private Timestamp s_run = new Timestamp(System.currentTimeMillis());
|
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger (GenerateModel.class);
|
private static CLogger log = CLogger.getCLogger (GenerateModel.class);
|
||||||
|
|
||||||
|
@ -142,79 +147,79 @@ public class GenerateModel
|
||||||
String className = "X_" + tableName;
|
String className = "X_" + tableName;
|
||||||
//
|
//
|
||||||
StringBuffer start = new StringBuffer ()
|
StringBuffer start = new StringBuffer ()
|
||||||
.append (COPY)
|
.append (COPY)
|
||||||
.append ("package " + packageName + ";\n"
|
.append ("package " + packageName + ";\n"
|
||||||
+ "/** Generated Model - DO NOT CHANGE */\n");
|
+ "/** Generated Model - DO NOT CHANGE */\n");
|
||||||
if (!packageName.equals("org.compiere.model"))
|
if (!packageName.equals("org.compiere.model"))
|
||||||
start.append("import org.compiere.model.*;");
|
start.append("import org.compiere.model.*;");
|
||||||
start.append("import java.util.*;"
|
start.append("import java.util.*;"
|
||||||
+ "import java.sql.*;"
|
+ "import java.sql.*;"
|
||||||
+ "import java.math.*;"
|
+ "import java.math.*;"
|
||||||
+ "import org.compiere.util.*;"
|
+ "import org.compiere.util.*;"
|
||||||
// Class
|
// Class
|
||||||
+ "/** Generated Model for ").append(tableName).append("\n"
|
+ "/** Generated Model for ").append(tableName).append("\n"
|
||||||
+ " * @author Adempiere (generated) \n"
|
+ " * @author Adempiere (generated) \n"
|
||||||
+ " * @version ").append(Adempiere.MAIN_VERSION).append(" - $Id$")
|
+ " * @version ").append(Adempiere.MAIN_VERSION).append(" - $Id$")
|
||||||
// .append(s_run) // Timestamp
|
// .append(s_run) // Timestamp
|
||||||
.append(" */\n"
|
.append(" */\n"
|
||||||
+ "public class ").append(className).append(" extends PO"
|
+ "public class ").append(className).append(" extends PO"
|
||||||
+ "{"
|
+ "{"
|
||||||
// Standard Constructor
|
// Standard Constructor
|
||||||
+ "/** Standard Constructor\n@param ctx context\n@param "
|
+ "/** Standard Constructor\n@param ctx context\n@param "
|
||||||
+ keyColumn + " id\n@param trxName transaction\n*/\n"
|
+ keyColumn + " id\n@param trxName transaction\n*/\n"
|
||||||
+ "public ").append(className).append(" (Properties ctx, int ").append(keyColumn)
|
+ "public ").append(className).append(" (Properties ctx, int ").append(keyColumn)
|
||||||
.append(", String trxName)"
|
.append(", String trxName)"
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "super (ctx, ").append(keyColumn).append(", trxName);"
|
+ "super (ctx, ").append(keyColumn).append(", trxName);"
|
||||||
+ "/** if (").append(keyColumn).append(" == 0)"
|
+ "/** if (").append(keyColumn).append(" == 0)"
|
||||||
+ "{").append(mandatory).append("} */\n"
|
+ "{").append(mandatory).append("} */\n"
|
||||||
+ "}" // Constructor End
|
+ "}" // Constructor End
|
||||||
// Short Constructor
|
// Short Constructor
|
||||||
// + "/** Short Constructor */\n"
|
// + "/** Short Constructor */\n"
|
||||||
// + "public ").append(className).append(" (Properties ctx, int ").append(keyColumn).append(")"
|
// + "public ").append(className).append(" (Properties ctx, int ").append(keyColumn).append(")"
|
||||||
// + "{"
|
// + "{"
|
||||||
// + "this (ctx, ").append(keyColumn).append(", null);"
|
// + "this (ctx, ").append(keyColumn).append(", null);"
|
||||||
// + "}" // Constructor End
|
// + "}" // Constructor End
|
||||||
|
|
||||||
// Load Constructor
|
// Load Constructor
|
||||||
+ "/** Load Constructor \n@param ctx context\n@param rs result set \n@param trxName transaction\n*/\n"
|
+ "/** Load Constructor \n@param ctx context\n@param rs result set \n@param trxName transaction\n*/\n"
|
||||||
+ "public ").append(className).append(" (Properties ctx, ResultSet rs, String trxName)"
|
+ "public ").append(className).append(" (Properties ctx, ResultSet rs, String trxName)"
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "super (ctx, rs, trxName);"
|
+ "super (ctx, rs, trxName);"
|
||||||
+ "}" // Load Constructor End
|
+ "}" // Load Constructor End
|
||||||
//
|
//
|
||||||
// globalqss - Grant independence to GenerateModel from AD_Table_ID
|
// globalqss - Grant independence to GenerateModel from AD_Table_ID
|
||||||
+ "/** TableName=").append(tableName).append(" */\n"
|
+ "/** TableName=").append(tableName).append(" */\n"
|
||||||
+ "public static final String Table_Name=\"").append(tableName).append("\";\n"
|
+ "public static final String Table_Name=\"").append(tableName).append("\";\n"
|
||||||
// + "public static final int Table_ID=").append(AD_Table_ID).append(";\n"
|
// + "public static final int Table_ID=").append(AD_Table_ID).append(";\n"
|
||||||
+ "/** AD_Table_ID=").append(AD_Table_ID).append(" */\n"
|
+ "/** AD_Table_ID=").append(AD_Table_ID).append(" */\n"
|
||||||
+ "public static final int Table_ID=MTable.getTable_ID(Table_Name);\n"
|
+ "public static final int Table_ID=MTable.getTable_ID(Table_Name);\n"
|
||||||
//
|
//
|
||||||
// globalqss
|
// globalqss
|
||||||
// + "protected static KeyNamePair Model = new KeyNamePair(").append(AD_Table_ID).append(",\"").append(tableName).append("\");\n"
|
// + "protected static KeyNamePair Model = new KeyNamePair(").append(AD_Table_ID).append(",\"").append(tableName).append("\");\n"
|
||||||
+ "protected static KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);\n"
|
+ "protected static KeyNamePair Model = new KeyNamePair(Table_ID, Table_Name);\n"
|
||||||
//
|
//
|
||||||
+ "protected BigDecimal accessLevel = BigDecimal.valueOf(").append(accessLevel).append(");"
|
+ "protected BigDecimal accessLevel = BigDecimal.valueOf(").append(accessLevel).append(");"
|
||||||
+ "/** AccessLevel\n@return ").append(accessLevelInfo).append("\n*/\n"
|
+ "/** AccessLevel\n@return ").append(accessLevelInfo).append("\n*/\n"
|
||||||
+ "protected int get_AccessLevel()"
|
+ "protected int get_AccessLevel()"
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "return accessLevel.intValue();"
|
+ "return accessLevel.intValue();"
|
||||||
+ "}"
|
+ "}"
|
||||||
//
|
//
|
||||||
+ "/** Load Meta Data\n@param ctx context\n@return PO Info\n*/\n"
|
+ "/** Load Meta Data\n@param ctx context\n@return PO Info\n*/\n"
|
||||||
+ "protected POInfo initPO (Properties ctx)"
|
+ "protected POInfo initPO (Properties ctx)"
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "POInfo poi = POInfo.getPOInfo (ctx, Table_ID);"
|
+ "POInfo poi = POInfo.getPOInfo (ctx, Table_ID);"
|
||||||
+ "return poi;"
|
+ "return poi;"
|
||||||
+ "}" // initPO
|
+ "}" // initPO
|
||||||
//
|
//
|
||||||
+ "/** Info\n@return info\n*/\n"
|
+ "/** Info\n@return info\n*/\n"
|
||||||
+ "public String toString()"
|
+ "public String toString()"
|
||||||
+ "{"
|
+ "{"
|
||||||
+ "StringBuffer sb = new StringBuffer (\"").append(className).append("[\")"
|
+ "StringBuffer sb = new StringBuffer (\"").append(className).append("[\")"
|
||||||
+ ".append(get_ID()).append(\"]\");"
|
+ ".append(get_ID()).append(\"]\");"
|
||||||
+ "return sb.toString();"
|
+ "return sb.toString();"
|
||||||
+ "}");
|
+ "}");
|
||||||
|
|
||||||
StringBuffer end = new StringBuffer ("}");
|
StringBuffer end = new StringBuffer ("}");
|
||||||
//
|
//
|
||||||
|
@ -276,10 +281,10 @@ public class GenerateModel
|
||||||
boolean IsEncrypted = "Y".equals(rs.getString(16));
|
boolean IsEncrypted = "Y".equals(rs.getString(16));
|
||||||
//
|
//
|
||||||
sb.append(createColumnMethods (mandatory,
|
sb.append(createColumnMethods (mandatory,
|
||||||
columnName, isUpdateable, isMandatory,
|
columnName, isUpdateable, isMandatory,
|
||||||
displayType, AD_Reference_Value_ID, fieldLength,
|
displayType, AD_Reference_Value_ID, fieldLength,
|
||||||
defaultValue, ValueMin, ValueMax, VFormat,
|
defaultValue, ValueMin, ValueMax, VFormat,
|
||||||
Callout, Name, Description, virtualColumn, IsEncrypted));
|
Callout, Name, Description, virtualColumn, IsEncrypted));
|
||||||
//
|
//
|
||||||
if (seqNo == 1 && "Y".equals(rs.getString("IsIdentifier"))) {
|
if (seqNo == 1 && "Y".equals(rs.getString("IsIdentifier"))) {
|
||||||
if (!isKeyNamePairCreated) {
|
if (!isKeyNamePairCreated) {
|
||||||
|
@ -293,8 +298,8 @@ public class GenerateModel
|
||||||
}
|
}
|
||||||
// Create COLUMNNAME_ property (teo_sarca, [ 1662447 ])
|
// Create COLUMNNAME_ property (teo_sarca, [ 1662447 ])
|
||||||
sb.append("/** Column name ").append(columnName).append(" */\n")
|
sb.append("/** Column name ").append(columnName).append(" */\n")
|
||||||
.append("public static final String COLUMNNAME_").append(columnName)
|
.append("public static final String COLUMNNAME_").append(columnName)
|
||||||
.append(" = \"").append(columnName).append("\";");
|
.append(" = \"").append(columnName).append("\";");
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
|
@ -339,14 +344,14 @@ public class GenerateModel
|
||||||
@return set/get method
|
@return set/get method
|
||||||
*/
|
*/
|
||||||
private String createColumnMethods (StringBuffer mandatory,
|
private String createColumnMethods (StringBuffer mandatory,
|
||||||
String columnName, boolean isUpdateable, boolean isMandatory,
|
String columnName, boolean isUpdateable, boolean isMandatory,
|
||||||
int displayType, int AD_Reference_ID, int fieldLength,
|
int displayType, int AD_Reference_ID, int fieldLength,
|
||||||
String defaultValue, String ValueMin, String ValueMax, String VFormat,
|
String defaultValue, String ValueMin, String ValueMax, String VFormat,
|
||||||
String Callout, String Name, String Description,
|
String Callout, String Name, String Description,
|
||||||
boolean virtualColumn, boolean IsEncrypted)
|
boolean virtualColumn, boolean IsEncrypted)
|
||||||
{
|
{
|
||||||
// Clazz
|
// Clazz
|
||||||
Class clazz = DisplayType.getClass(displayType, true);
|
Class<?> clazz = DisplayType.getClass(displayType, true);
|
||||||
if (defaultValue == null)
|
if (defaultValue == null)
|
||||||
defaultValue = "";
|
defaultValue = "";
|
||||||
if (DisplayType.isLOB(displayType)) // No length check for LOBs
|
if (DisplayType.isLOB(displayType)) // No length check for LOBs
|
||||||
|
@ -354,8 +359,8 @@ public class GenerateModel
|
||||||
|
|
||||||
// Handle Posted
|
// Handle Posted
|
||||||
if (columnName.equalsIgnoreCase("Posted")
|
if (columnName.equalsIgnoreCase("Posted")
|
||||||
|| columnName.equalsIgnoreCase("Processed")
|
|| columnName.equalsIgnoreCase("Processed")
|
||||||
|| columnName.equalsIgnoreCase("Processing"))
|
|| columnName.equalsIgnoreCase("Processing"))
|
||||||
{
|
{
|
||||||
clazz = Boolean.class;
|
clazz = Boolean.class;
|
||||||
AD_Reference_ID = 0;
|
AD_Reference_ID = 0;
|
||||||
|
@ -368,7 +373,7 @@ public class GenerateModel
|
||||||
}
|
}
|
||||||
// String Key
|
// String Key
|
||||||
else if (columnName.equalsIgnoreCase("AD_Language")
|
else if (columnName.equalsIgnoreCase("AD_Language")
|
||||||
|| columnName.equalsIgnoreCase("EntityType"))
|
|| columnName.equalsIgnoreCase("EntityType"))
|
||||||
{
|
{
|
||||||
clazz = String.class;
|
clazz = String.class;
|
||||||
}
|
}
|
||||||
|
@ -406,7 +411,7 @@ public class GenerateModel
|
||||||
setValue = "set_ValueNoCheckE";
|
setValue = "set_ValueNoCheckE";
|
||||||
}
|
}
|
||||||
sb.append("void set").append(columnName).append(" (").append(dataType).append(" ").append(columnName).append(")"
|
sb.append("void set").append(columnName).append(" (").append(dataType).append(" ").append(columnName).append(")"
|
||||||
+ "{");
|
+ "{");
|
||||||
// List Validation
|
// List Validation
|
||||||
if (AD_Reference_ID != 0)
|
if (AD_Reference_ID != 0)
|
||||||
{
|
{
|
||||||
|
@ -427,17 +432,17 @@ public class GenerateModel
|
||||||
{
|
{
|
||||||
int firstOK = 1; // Valid ID 0
|
int firstOK = 1; // Valid ID 0
|
||||||
if (columnName.equals("AD_Client_ID") || columnName.equals("AD_Org_ID")
|
if (columnName.equals("AD_Client_ID") || columnName.equals("AD_Org_ID")
|
||||||
|| columnName.equals("Record_ID") || columnName.equals("C_DocType_ID")
|
|| columnName.equals("Record_ID") || columnName.equals("C_DocType_ID")
|
||||||
|| columnName.equals("Node_ID") || columnName.equals("AD_Role_ID")
|
|| columnName.equals("Node_ID") || columnName.equals("AD_Role_ID")
|
||||||
|| columnName.equals("M_AttributeSet_ID") || columnName.equals("M_AttributeSetInstance_ID"))
|
|| columnName.equals("M_AttributeSet_ID") || columnName.equals("M_AttributeSetInstance_ID"))
|
||||||
firstOK = 0;
|
firstOK = 0;
|
||||||
sb.append("if (").append (columnName)
|
sb.append("if (").append (columnName)
|
||||||
.append (" < ").append(firstOK).append(") throw new IllegalArgumentException (\"")
|
.append (" < ").append(firstOK).append(") throw new IllegalArgumentException (\"")
|
||||||
.append(columnName).append(" is mandatory.\");");
|
.append(columnName).append(" is mandatory.\");");
|
||||||
}
|
}
|
||||||
else // set optional _ID to null if 0
|
else // set optional _ID to null if 0
|
||||||
sb.append("if (").append (columnName).append (" <= 0) ")
|
sb.append("if (").append (columnName).append (" <= 0) ")
|
||||||
.append(setValue).append(" (\"").append(columnName).append("\", null); else \n");
|
.append(setValue).append(" (\"").append(columnName).append("\", null); else \n");
|
||||||
}
|
}
|
||||||
sb.append(setValue).append(" (\"").append(columnName).append("\", Integer.valueOf(").append(columnName).append("));");
|
sb.append(setValue).append(" (\"").append(columnName).append("\", Integer.valueOf(").append(columnName).append("));");
|
||||||
}
|
}
|
||||||
|
@ -449,9 +454,9 @@ public class GenerateModel
|
||||||
if (isMandatory && AD_Reference_ID == 0) // does not apply to int/boolean
|
if (isMandatory && AD_Reference_ID == 0) // does not apply to int/boolean
|
||||||
{
|
{
|
||||||
sb.append("if (")
|
sb.append("if (")
|
||||||
.append (columnName).append (" == null)"
|
.append (columnName).append (" == null)"
|
||||||
+ " throw new IllegalArgumentException (\"")
|
+ " throw new IllegalArgumentException (\"")
|
||||||
.append(columnName).append(" is mandatory.\");");
|
.append(columnName).append(" is mandatory.\");");
|
||||||
}
|
}
|
||||||
// String length check
|
// String length check
|
||||||
if (clazz.equals(String.class) && fieldLength > 0)
|
if (clazz.equals(String.class) && fieldLength > 0)
|
||||||
|
@ -460,15 +465,15 @@ public class GenerateModel
|
||||||
if (!isMandatory)
|
if (!isMandatory)
|
||||||
sb.append(columnName).append(" != null && ");
|
sb.append(columnName).append(" != null && ");
|
||||||
sb.append(columnName).append(".length() > ").append(fieldLength)
|
sb.append(columnName).append(".length() > ").append(fieldLength)
|
||||||
.append("){log.warning(\"Length > ")
|
.append("){log.warning(\"Length > ")
|
||||||
.append(fieldLength).append(" - truncated\");")
|
.append(fieldLength).append(" - truncated\");")
|
||||||
.append(columnName).append(" = ")
|
.append(columnName).append(" = ")
|
||||||
.append(columnName).append(".substring(0,").append(fieldLength-1).append(");}");
|
.append(columnName).append(".substring(0,").append(fieldLength-1).append(");}");
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
sb.append (setValue).append(" (\"").append (columnName).append ("\", ")
|
sb.append (setValue).append(" (\"").append (columnName).append ("\", ")
|
||||||
.append (columnName).append (");");
|
.append (columnName).append (");");
|
||||||
}
|
}
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
|
|
||||||
|
@ -523,27 +528,27 @@ public class GenerateModel
|
||||||
sb.append("() {");
|
sb.append("() {");
|
||||||
if (clazz.equals(Integer.class))
|
if (clazz.equals(Integer.class))
|
||||||
sb.append("Integer ii = (Integer)")
|
sb.append("Integer ii = (Integer)")
|
||||||
.append(getValue).append("(\"").append(columnName).append("\");"
|
.append(getValue).append("(\"").append(columnName).append("\");"
|
||||||
+ "if (ii == null)"
|
+ "if (ii == null)"
|
||||||
+ " return 0;"
|
+ " return 0;"
|
||||||
+ "return ii.intValue();");
|
+ "return ii.intValue();");
|
||||||
else if (clazz.equals(BigDecimal.class))
|
else if (clazz.equals(BigDecimal.class))
|
||||||
sb.append("BigDecimal bd = (BigDecimal)").append(getValue)
|
sb.append("BigDecimal bd = (BigDecimal)").append(getValue)
|
||||||
.append("(\"").append(columnName).append("\");"
|
.append("(\"").append(columnName).append("\");"
|
||||||
+ "if (bd == null)"
|
+ "if (bd == null)"
|
||||||
+ " return Env.ZERO;"
|
+ " return Env.ZERO;"
|
||||||
+ "return bd;");
|
+ "return bd;");
|
||||||
else if (clazz.equals(Boolean.class))
|
else if (clazz.equals(Boolean.class))
|
||||||
sb.append("Object oo = ").append(getValue)
|
sb.append("Object oo = ").append(getValue)
|
||||||
.append("(\"").append(columnName).append("\");"
|
.append("(\"").append(columnName).append("\");"
|
||||||
+ "if (oo != null) { if (oo instanceof Boolean) return ((Boolean)oo).booleanValue(); return \"Y\".equals(oo);}"
|
+ "if (oo != null) { if (oo instanceof Boolean) return ((Boolean)oo).booleanValue(); return \"Y\".equals(oo);}"
|
||||||
+ "return false;");
|
+ "return false;");
|
||||||
else if (dataType.equals("Object"))
|
else if (dataType.equals("Object"))
|
||||||
sb.append("return ").append(getValue)
|
sb.append("return ").append(getValue)
|
||||||
.append("(\"").append(columnName).append("\");");
|
.append("(\"").append(columnName).append("\");");
|
||||||
else
|
else
|
||||||
sb.append("return (").append(dataType).append(")").append(getValue)
|
sb.append("return (").append(dataType).append(")").append(getValue)
|
||||||
.append("(\"").append(columnName).append("\");");
|
.append("(\"").append(columnName).append("\");");
|
||||||
sb.append("}");
|
sb.append("}");
|
||||||
//
|
//
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
@ -564,16 +569,16 @@ public class GenerateModel
|
||||||
public static final String NEXTACTION_FollowUp = "F";
|
public static final String NEXTACTION_FollowUp = "F";
|
||||||
*/
|
*/
|
||||||
private String addListValidation (StringBuffer sb, int AD_Reference_ID,
|
private String addListValidation (StringBuffer sb, int AD_Reference_ID,
|
||||||
String columnName, boolean nullable)
|
String columnName, boolean nullable)
|
||||||
{
|
{
|
||||||
StringBuffer retValue = new StringBuffer();
|
StringBuffer retValue = new StringBuffer();
|
||||||
retValue.append("\n/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */\n")
|
retValue.append("\n/** ").append(columnName).append(" AD_Reference_ID=").append(AD_Reference_ID) .append(" */\n")
|
||||||
.append("public static final int ").append(columnName.toUpperCase())
|
.append("public static final int ").append(columnName.toUpperCase())
|
||||||
.append("_AD_Reference_ID=").append(AD_Reference_ID).append(";");
|
.append("_AD_Reference_ID=").append(AD_Reference_ID).append(";");
|
||||||
//
|
//
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
StringBuffer values = new StringBuffer("Reference_ID=")
|
StringBuffer values = new StringBuffer("Reference_ID=")
|
||||||
.append(AD_Reference_ID);
|
.append(AD_Reference_ID);
|
||||||
StringBuffer statement = new StringBuffer();
|
StringBuffer statement = new StringBuffer();
|
||||||
if (nullable)
|
if (nullable)
|
||||||
statement.append("if (").append(columnName).append(" == null");
|
statement.append("if (").append(columnName).append(" == null");
|
||||||
|
@ -591,19 +596,19 @@ public class GenerateModel
|
||||||
values.append(" - ").append(value);
|
values.append(" - ").append(value);
|
||||||
if (statement.length() == 0)
|
if (statement.length() == 0)
|
||||||
statement.append("if (").append(columnName)
|
statement.append("if (").append(columnName)
|
||||||
.append(".equals(\"").append(value).append("\")");
|
.append(".equals(\"").append(value).append("\")");
|
||||||
else
|
else
|
||||||
statement.append(" || ").append(columnName)
|
statement.append(" || ").append(columnName)
|
||||||
.append(".equals(\"").append(value).append("\")");
|
.append(".equals(\"").append(value).append("\")");
|
||||||
//
|
//
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
if (!nullable)
|
if (!nullable)
|
||||||
sb.append("if (")
|
sb.append("if (")
|
||||||
.append (columnName).append (" == null)"
|
.append (columnName).append (" == null)"
|
||||||
+ " throw new IllegalArgumentException (\"")
|
+ " throw new IllegalArgumentException (\"")
|
||||||
.append(columnName).append(" is mandatory\");");
|
.append(columnName).append(" is mandatory\");");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -650,8 +655,8 @@ public class GenerateModel
|
||||||
}
|
}
|
||||||
retValue.append("/** ").append(name).append(" = ").append(value).append(" */\n");
|
retValue.append("/** ").append(name).append(" = ").append(value).append(" */\n");
|
||||||
retValue.append("public static final String ").append(columnName.toUpperCase())
|
retValue.append("public static final String ").append(columnName.toUpperCase())
|
||||||
.append("_").append(nameClean)
|
.append("_").append(nameClean)
|
||||||
.append(" = \"").append(value).append("\";");
|
.append(" = \"").append(value).append("\";");
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
|
@ -674,11 +679,11 @@ public class GenerateModel
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
statement.append(")"
|
statement.append(")"
|
||||||
+ "; "
|
+ "; "
|
||||||
+ "else "
|
+ "else "
|
||||||
+ "throw new IllegalArgumentException (\"").append(columnName)
|
+ "throw new IllegalArgumentException (\"").append(columnName)
|
||||||
.append(" Invalid value - \" + ").append(columnName)
|
.append(" Invalid value - \" + ").append(columnName)
|
||||||
.append(" + \" - ").append(values).append("\");");
|
.append(" + \" - ").append(values).append("\");");
|
||||||
//
|
//
|
||||||
if (found && !columnName.equals("EntityType"))
|
if (found && !columnName.equals("EntityType"))
|
||||||
sb.append (statement);
|
sb.append (statement);
|
||||||
|
@ -697,8 +702,8 @@ public class GenerateModel
|
||||||
if (displayType != DisplayType.String)
|
if (displayType != DisplayType.String)
|
||||||
method = "String.valueOf(" + method + ")";
|
method = "String.valueOf(" + method + ")";
|
||||||
StringBuffer sb = new StringBuffer("/** Get Record ID/ColumnName\n@return ID/ColumnName pair\n*/"
|
StringBuffer sb = new StringBuffer("/** Get Record ID/ColumnName\n@return ID/ColumnName pair\n*/"
|
||||||
+ "public KeyNamePair getKeyNamePair() "
|
+ "public KeyNamePair getKeyNamePair() "
|
||||||
+ "{return new KeyNamePair(get_ID(), ").append(method).append(");}");
|
+ "{return new KeyNamePair(get_ID(), ").append(method).append(");}");
|
||||||
return sb;
|
return sb;
|
||||||
} // createKeyNamePair
|
} // createKeyNamePair
|
||||||
|
|
||||||
|
@ -757,7 +762,7 @@ public class GenerateModel
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer sb = new StringBuffer ("GenerateModel[")
|
StringBuffer sb = new StringBuffer ("GenerateModel[")
|
||||||
.append("]");
|
.append("]");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} // toString
|
} // toString
|
||||||
|
|
||||||
|
@ -780,7 +785,7 @@ public class GenerateModel
|
||||||
{
|
{
|
||||||
org.compiere.Adempiere.startupEnvironment(true);
|
org.compiere.Adempiere.startupEnvironment(true);
|
||||||
CLogMgt.setLevel(Level.FINE);
|
CLogMgt.setLevel(Level.FINE);
|
||||||
// CLogMgt.setLevel(Level.ALL);
|
// CLogMgt.setLevel(Level.ALL);
|
||||||
log.info("Generate Model $Revision: 1.5 $");
|
log.info("Generate Model $Revision: 1.5 $");
|
||||||
log.info("----------------------------------");
|
log.info("----------------------------------");
|
||||||
// first parameter
|
// first parameter
|
||||||
|
@ -815,7 +820,7 @@ public class GenerateModel
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
StringBuffer sql = new StringBuffer("EntityType IN (")
|
StringBuffer sql = new StringBuffer("EntityType IN (")
|
||||||
.append(entityType).append(")");
|
.append(entityType).append(")");
|
||||||
log.info(sql.toString());
|
log.info(sql.toString());
|
||||||
log.info("----------------------------------");
|
log.info("----------------------------------");
|
||||||
|
|
||||||
|
@ -827,10 +832,10 @@ public class GenerateModel
|
||||||
|
|
||||||
// complete sql
|
// complete sql
|
||||||
sql.insert(0, "SELECT AD_Table_ID "
|
sql.insert(0, "SELECT AD_Table_ID "
|
||||||
+ "FROM AD_Table "
|
+ "FROM AD_Table "
|
||||||
+ "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" // special views
|
+ "WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')" // special views
|
||||||
+ " OR IsView='N')"
|
+ " OR IsView='N')"
|
||||||
+ " AND TableName NOT LIKE '%_Trl' AND ");
|
+ " AND TableName NOT LIKE '%_Trl' AND ");
|
||||||
// globalqss
|
// globalqss
|
||||||
sql.append(" AND TableName LIKE ").append(tableLike);
|
sql.append(" AND TableName LIKE ").append(tableLike);
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue