IDEMPIERE-308 Performance: Replace use of StringBuffer and String concatenation with StringBuilder / review classes on org.adempiere.base.process / thanks to Richard Morales and David Peñuela

This commit is contained in:
Carlos Ruiz 2012-09-21 19:27:59 -05:00
parent ae107dbb64
commit 502bd015c1
14 changed files with 210 additions and 186 deletions

View File

@ -89,9 +89,9 @@ public class ASPGenerateFields extends SvrProcess
*/
protected String doIt () throws Exception
{
log.info("ASP_Status=" + p_ASP_Status
+ ", ASP_Tab_ID=" + p_ASP_Tab_ID
);
StringBuilder msglog = new StringBuilder("ASP_Status=").append(p_ASP_Status)
.append(", ASP_Tab_ID=").append(p_ASP_Tab_ID);
log.info(msglog.toString());
X_ASP_Tab asptab = new X_ASP_Tab(getCtx(), p_ASP_Tab_ID, get_TrxName());
p_ASP_Level_ID = asptab.getASP_Window().getASP_Level_ID();

View File

@ -107,10 +107,10 @@ public class ASPGenerateLevel extends SvrProcess
*/
protected String doIt () throws Exception
{
log.info("ASP_Status=" + p_ASP_Status
+ ", AD_Menu_ID=" + p_AD_Menu_ID
+ ", IsGenerateFields=" + p_IsGenerateFields
);
StringBuilder msglog = new StringBuilder("ASP_Status=").append(p_ASP_Status)
.append(", AD_Menu_ID=").append(p_AD_Menu_ID)
.append(", IsGenerateFields=").append(p_IsGenerateFields);
log.info(msglog.toString());
MClientInfo clientInfo = MClientInfo.get(getCtx(), getAD_Client_ID(), get_TrxName());
int AD_Tree_ID = clientInfo.getAD_Tree_Menu_ID();

View File

@ -51,16 +51,16 @@ public class ApplyMigrationScripts extends SvrProcess {
protected String doIt() throws Exception {
// TODO Auto-generated method stub
log.info("Applying migrations scripts");
String sql = "select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created";
PreparedStatement pstmt = DB.prepareStatement(sql, this.get_TrxName());
StringBuilder sql = new StringBuilder()
.append("select ad_migrationscript_id, script, name from ad_migrationscript where isApply = 'Y' and status = 'IP' order by name, created");
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
byte[] scriptArray = rs.getBytes(2);
int seqID = rs.getInt(1);
boolean execOk = true;
try {
StringBuffer tmpSql = new StringBuffer();
tmpSql = new StringBuffer(new String(scriptArray));
StringBuilder tmpSql = new StringBuilder(new String(scriptArray));
if (tmpSql.length() > 0) {
log.info("Executing script " + rs.getString(3));
@ -70,12 +70,12 @@ public class ApplyMigrationScripts extends SvrProcess {
} catch (SQLException e) {
execOk = false;
e.printStackTrace();
log.saveError("Error", "Script: " + rs.getString(3) + " - "
+ e.getMessage());
StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage());
log.saveError("Error", msglog.toString());
log.severe(e.getMessage());
} finally {
sql = "UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? ";
pstmt = DB.prepareStatement(sql, this.get_TrxName());
sql = new StringBuilder("UPDATE ad_migrationscript SET status = ? , isApply = 'N' WHERE ad_migrationscript_id = ? ");
pstmt = DB.prepareStatement(sql.toString(), this.get_TrxName());
if (execOk) {
pstmt.setString(1, "CO");
pstmt.setInt(2, seqID);
@ -91,8 +91,8 @@ public class ApplyMigrationScripts extends SvrProcess {
}
} catch (SQLException e) {
e.printStackTrace();
log.saveError("Error", "Script: " + rs.getString(3) + " - "
+ e.getMessage());
StringBuilder msglog = new StringBuilder("Script: ").append(rs.getString(3)).append(" - ").append(e.getMessage());
log.saveError("Error", msglog.toString());
log.severe(e.getMessage());
}
}
@ -110,7 +110,7 @@ public class ApplyMigrationScripts extends SvrProcess {
public boolean executeScript(String sql, String fileName) {
BufferedReader reader = new BufferedReader(new StringReader(sql));
StringBuffer sqlBuf = new StringBuffer();
StringBuilder sqlBuf = new StringBuilder();
String line;
boolean statementReady = false;
boolean execOk = true;
@ -151,8 +151,9 @@ public class ApplyMigrationScripts extends SvrProcess {
} catch (SQLException e) {
e.printStackTrace();
execOk = false;
log.saveError("Error", "Script: " + fileName + " - "
+ e.getMessage() + ". The line that caused the error is the following ==> " + sqlBuf);
StringBuilder msglog = new StringBuilder("Script: ").append(fileName).append(" - ")
.append(e.getMessage()).append(". The line that caused the error is the following ==> ").append(sqlBuf);
log.saveError("Error", msglog.toString());
log.severe(e.getMessage());
} finally {
stmt.close();

View File

@ -96,7 +96,8 @@ public class ClientAcctProcessor extends SvrProcess
*/
protected String doIt () throws Exception
{
log.info("C_AcctSchema_ID=" + p_C_AcctSchema_ID + ", AD_Table_ID=" + p_AD_Table_ID);
StringBuilder msglog = new StringBuilder("C_AcctSchema_ID=").append(p_C_AcctSchema_ID).append(", AD_Table_ID=").append(p_AD_Table_ID);
log.info(msglog.toString());
if (! MClient.isClientAccounting())
throw new AdempiereUserError(Msg.getMsg(getCtx(), "ClientAccountingNotEnabled"));
@ -145,7 +146,7 @@ public class ClientAcctProcessor extends SvrProcess
&& p_AD_Table_ID != AD_Table_ID)
continue;
StringBuffer sql = new StringBuffer ("SELECT DISTINCT ProcessedOn FROM ").append(TableName)
StringBuilder sql = new StringBuilder("SELECT DISTINCT ProcessedOn FROM ").append(TableName)
.append(" WHERE AD_Client_ID=? AND ProcessedOn<?")
.append(" AND Processed='Y' AND Posted='N' AND IsActive='Y'");
PreparedStatement pstmt = null;
@ -195,7 +196,7 @@ public class ClientAcctProcessor extends SvrProcess
&& p_AD_Table_ID != AD_Table_ID)
continue;
// SELECT * FROM table
StringBuffer sql = new StringBuffer ("SELECT * FROM ").append(TableName)
StringBuilder sql = new StringBuilder("SELECT * FROM ").append(TableName)
.append(" WHERE AD_Client_ID=? AND (ProcessedOn");
if (processedOn.compareTo(Env.ZERO) != 0)
sql.append("=?");
@ -263,10 +264,14 @@ public class ClientAcctProcessor extends SvrProcess
if (countError[i] > 0)
m_summary.append("(Errors=").append(countError[i]).append(")");
m_summary.append(" - ");
log.finer(getName() + ": " + m_summary.toString());
StringBuilder msglog = new StringBuilder(getName()).append(": ").append(m_summary.toString());
log.finer(msglog.toString());
}
else
log.finer(getName() + ": " + TableName + " - no work");
{
StringBuilder msglog = new StringBuilder(getName()).append(": ").append(TableName).append(" - no work");
log.finer(msglog.toString());
}
}
} // postSession

View File

@ -224,9 +224,9 @@ public class ExpenseTypesFromAccounts extends SvrProcess {
}
}
String returnStr = addCount + " products added.";
if (skipCount>0) returnStr += " " + skipCount + " products skipped.";
return(returnStr);
StringBuilder returnStr = new StringBuilder(addCount).append(" products added.");
if (skipCount>0) returnStr.append(" ").append(skipCount).append(" products skipped.");
return(returnStr.toString());
}

View File

@ -102,7 +102,7 @@ public class Export extends SvrProcess
AD_Table_ID = getTable_ID();
// C_Invoice; AD_Table_ID = 318
StringBuffer sb = new StringBuffer ("AD_Table_ID=").append(AD_Table_ID);
StringBuilder sb = new StringBuilder("AD_Table_ID=").append(AD_Table_ID);
sb.append("; Record_ID=").append(getRecord_ID());
// Parameter
ProcessInfoParameter[] para = getParameter();
@ -154,7 +154,7 @@ public class Export extends SvrProcess
}
MEXPFormat exportFormat = new MEXPFormat(getCtx(), EXP_Format_ID, get_TrxName());
StringBuffer sql = new StringBuffer("SELECT * ")
StringBuilder sql = new StringBuilder("SELECT * ")
.append("FROM ").append(table.getTableName()).append(" ")
.append("WHERE ").append(po.get_KeyColumns()[0]).append("=?")
;
@ -270,7 +270,8 @@ public class Export extends SvrProcess
}
}
}*/
log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value);
StringBuilder msglog = new StringBuilder("EXP Field - column=[").append(column.getColumnName()).append("]; value=").append(value);
log.info(msglog.toString());
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
Text newText = outDocument.createTextNode(valueString);
newElement.appendChild(newText);
@ -331,7 +332,8 @@ public class Export extends SvrProcess
}
}
}*/
log.info("EXP Field - column=["+column.getColumnName()+"]; value=" + value);
StringBuilder msglog = new StringBuilder("EXP Field - column=[").append(column.getColumnName()).append("]; value=").append(value);
log.info(msglog.toString());
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
rootElement.setAttribute(formatLine.getValue(), valueString);
elementHasValue = true;
@ -348,7 +350,7 @@ public class Export extends SvrProcess
MTable tableEmbedded = MTable.get(getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded);
StringBuffer sql = new StringBuffer("SELECT * ")
StringBuilder sql = new StringBuilder("SELECT * ")
.append("FROM ").append(tableEmbedded.getTableName()).append(" ")
.append("WHERE ").append(masterPO.get_KeyColumns()[0]).append("=?")
//+ "WHERE " + po.get_WhereClause(false)

View File

@ -83,10 +83,10 @@ public class HouseKeeping extends SvrProcess{
int nodel = 0;
if (houseKeeping.isSaveInHistoric()){
String sql = "INSERT INTO hst_"+tableName + " SELECT * FROM " + tableName;
StringBuilder sql = new StringBuilder("INSERT INTO hst_").append(tableName).append(" SELECT * FROM ").append(tableName);
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
noins = DB.executeUpdate(sql, get_TrxName());
sql.append(" WHERE ").append(whereClause);
noins = DB.executeUpdate(sql.toString(), get_TrxName());
if (noins == -1)
throw new AdempiereSystemError("Cannot insert into hst_"+tableName);
addLog("@Inserted@ " + noins);
@ -98,15 +98,15 @@ public class HouseKeeping extends SvrProcess{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = dateFormat.format(date);
FileWriter file = new FileWriter(pathFile+File.separator+tableName+dateString+".xml");
String sql = "SELECT * FROM " + tableName;
StringBuilder sql = new StringBuilder("SELECT * FROM ").append(tableName);
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
sql.append(" WHERE ").append(whereClause);
PreparedStatement pstmt = null;
ResultSet rs = null;
StringBuffer linexml = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
rs = pstmt.executeQuery();
while (rs.next()) {
GenericPO po = new GenericPO(tableName, getCtx(), rs, get_TrxName());
@ -130,10 +130,10 @@ public class HouseKeeping extends SvrProcess{
addLog("@Exported@ " + noexp);
}//XmlExport
String sql = "DELETE FROM " + tableName;
StringBuilder sql = new StringBuilder("DELETE FROM ").append(tableName);
if (whereClause != null && whereClause.length() > 0)
sql = sql + " WHERE " + whereClause;
nodel = DB.executeUpdate(sql, get_TrxName());
sql.append(" WHERE ").append(whereClause);
nodel = DB.executeUpdate(sql.toString(), get_TrxName());
if (nodel == -1)
throw new AdempiereSystemError("Cannot delete from " + tableName);
Timestamp time = new Timestamp(date.getTime());
@ -141,7 +141,7 @@ public class HouseKeeping extends SvrProcess{
houseKeeping.setLastDeleted(nodel);
houseKeeping.saveEx();
addLog("@Deleted@ " + nodel);
String msg = Msg.getElement(getCtx(), tableName + "_ID") + " #" + nodel;
return msg;
StringBuilder msg = new StringBuilder(Msg.getElement(getCtx(), tableName + "_ID")).append(" #").append(nodel);
return msg.toString();
}//doIt
}

View File

@ -114,10 +114,11 @@ public class ImmediateBankTransfer extends SvrProcess
*/
protected String doIt() throws Exception
{
log.info("From Bank="+p_From_C_BankAccount_ID+" - To Bank="+p_To_C_BankAccount_ID
+ " - C_CashBook_ID="+p_C_CashBook_ID+" - Amount="+p_Amount+" - Name="+p_Name
+ " - Description="+p_Description+ " - Statement Date="+p_StatementDate+
" - Date Account="+p_DateAcct);
StringBuilder msglog = new StringBuilder("From Bank=").append(p_From_C_BankAccount_ID).append(" - To Bank=").append(p_To_C_BankAccount_ID)
.append(" - C_CashBook_ID=").append(p_C_CashBook_ID).append(" - Amount=").append(p_Amount).append(" - Name=").append(p_Name)
.append(" - Description=").append(p_Description).append(" - Statement Date=").append(p_StatementDate)
.append(" - Date Account=").append(p_DateAcct);
log.info(msglog.toString());
if (p_To_C_BankAccount_ID == 0 || p_From_C_BankAccount_ID == 0)
throw new IllegalArgumentException("Banks required");
@ -248,17 +249,18 @@ public class ImmediateBankTransfer extends SvrProcess
MCash cash = createCash();
MCashLine cashLines[]= createCashLines(cash);
StringBuffer processMsg = new StringBuffer(cash.getDocumentNo());
StringBuilder processMsg = new StringBuilder(cash.getDocumentNo());
cash.setDocAction(p_docAction);
if (!cash.processIt(p_docAction))
{
processMsg.append(" (NOT Processed)");
log.warning("Cash Processing failed: " + cash + " - " + cash.getProcessMsg());
addLog(cash.getC_Cash_ID(), cash.getStatementDate(), null,
"Cash Processing failed: " + cash + " - "
+ cash.getProcessMsg()
+ " / please complete it manually");
StringBuilder msglog = new StringBuilder("Cash Processing failed: ").append(cash).append(" - ").append(cash.getProcessMsg());
log.warning(msglog.toString());
msglog = new StringBuilder("Cash Processing failed: ").append(cash).append(" - ")
.append(cash.getProcessMsg())
.append(" / please complete it manually");
addLog(cash.getC_Cash_ID(), cash.getStatementDate(), null,msglog.toString());
throw new IllegalStateException("Cash Processing failed: " + cash + " - " + cash.getProcessMsg());
}
if (!cash.save())

View File

@ -88,9 +88,9 @@ public class ImportPriceList extends SvrProcess
*/
protected String doIt() throws Exception
{
StringBuffer sql = null;
StringBuilder sql = null;
int no = 0;
String clientCheck = " AND AD_Client_ID=" + m_AD_Client_ID;
StringBuilder clientCheck = new StringBuilder(" AND AD_Client_ID=").append(m_AD_Client_ID);
int m_discountschema_id = DB.getSQLValue(get_TrxName(),
"SELECT MIN(M_DiscountSchema_ID) FROM M_DiscountSchema WHERE DiscountType='P' AND IsActive='Y' AND AD_Client_ID=?",
@ -103,81 +103,81 @@ public class ImportPriceList extends SvrProcess
// Delete Old Imported
if (m_deleteOldImported)
{
sql = new StringBuffer ("DELETE I_PriceList "
sql = new StringBuilder("DELETE I_PriceList "
+ "WHERE I_IsImported='Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("Delete Old Impored =" + no);
}
// Set Client, Org, IsActive, Created/Updated, EnforcePriceLimit, IsSOPriceList, IsTaxIncluded, PricePrecision
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),"
+ " AD_Org_ID = COALESCE (AD_Org_ID, 0),"
+ " IsActive = COALESCE (IsActive, 'Y'),"
+ " Created = COALESCE (Created, SysDate),"
+ " CreatedBy = COALESCE (CreatedBy, 0),"
+ " Updated = COALESCE (Updated, SysDate),"
+ " UpdatedBy = COALESCE (UpdatedBy, 0),"
+ " EnforcePriceLimit = COALESCE (EnforcePriceLimit, 'N'),"
+ " IsSOPriceList = COALESCE (IsSOPriceList, 'N'),"
+ " IsTaxIncluded = COALESCE (IsTaxIncluded, 'N'),"
+ " PricePrecision = COALESCE (PricePrecision, 2),"
+ " I_ErrorMsg = ' ',"
+ " I_IsImported = 'N' "
+ "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
sql = new StringBuilder("UPDATE I_PriceList ")
.append("SET AD_Client_ID = COALESCE (AD_Client_ID, ").append(m_AD_Client_ID).append("),")
.append(" AD_Org_ID = COALESCE (AD_Org_ID, 0),")
.append(" IsActive = COALESCE (IsActive, 'Y'),")
.append(" Created = COALESCE (Created, SysDate),")
.append(" CreatedBy = COALESCE (CreatedBy, 0),")
.append(" Updated = COALESCE (Updated, SysDate),")
.append(" UpdatedBy = COALESCE (UpdatedBy, 0),")
.append(" EnforcePriceLimit = COALESCE (EnforcePriceLimit, 'N'),")
.append(" IsSOPriceList = COALESCE (IsSOPriceList, 'N'),")
.append(" IsTaxIncluded = COALESCE (IsTaxIncluded, 'N'),")
.append(" PricePrecision = COALESCE (PricePrecision, 2),")
.append(" I_ErrorMsg = ' ',")
.append(" I_IsImported = 'N' ")
.append("WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("Reset=" + no);
// Set Optional BPartner
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p"
+ " WHERE I_PriceList.BPartner_Value=p.Value AND I_PriceList.AD_Client_ID=p.AD_Client_ID) "
+ "WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET C_BPartner_ID=(SELECT C_BPartner_ID FROM C_BPartner p")
.append(" WHERE I_PriceList.BPartner_Value=p.Value AND I_PriceList.AD_Client_ID=p.AD_Client_ID) ")
.append("WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("BPartner=" + no);
//
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner,' "
+ "WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid BPartner,' ")
.append("WHERE C_BPartner_ID IS NULL AND BPartner_Value IS NOT NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid BPartner=" + no);
// Product
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p"
+ " WHERE I_PriceList.ProductValue=p.Value AND I_PriceList.AD_Client_ID=p.AD_Client_ID) "
+ "WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL"
+ " AND I_IsImported<>'Y'").append (clientCheck);
sql = new StringBuilder("UPDATE I_PriceList ")
.append("SET M_Product_ID=(SELECT MAX(M_Product_ID) FROM M_Product p")
.append(" WHERE I_PriceList.ProductValue=p.Value AND I_PriceList.AD_Client_ID=p.AD_Client_ID) ")
.append("WHERE M_Product_ID IS NULL AND ProductValue IS NOT NULL")
.append(" AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Product from Value=" + no);
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, ' "
+ "WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL)"
+ " AND I_IsImported<>'Y'").append (clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Product, ' ")
.append("WHERE M_Product_ID IS NULL AND (ProductValue IS NOT NULL)")
.append(" AND I_IsImported<>'Y'").append (clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning ("Invalid Product=" + no);
// **** Find Price List
// Name
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET M_PriceList_ID=(SELECT M_PriceList_ID FROM M_PriceList p"
+ " WHERE I_PriceList.Name=p.Name AND I_PriceList.AD_Client_ID=p.AD_Client_ID) "
+ "WHERE M_PriceList_ID IS NULL"
+ " AND I_IsImported='N'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET M_PriceList_ID=(SELECT M_PriceList_ID FROM M_PriceList p")
.append(" WHERE I_PriceList.Name=p.Name AND I_PriceList.AD_Client_ID=p.AD_Client_ID) ")
.append("WHERE M_PriceList_ID IS NULL")
.append(" AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("Price List Existing Value=" + no);
// **** Find Price List Version
// List Name (ID) + ValidFrom
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET M_PriceList_Version_ID=(SELECT M_PriceList_Version_ID FROM M_PriceList_Version p"
+ " WHERE I_PriceList.ValidFrom=p.ValidFrom AND I_PriceList.M_PriceList_ID=p.M_PriceList_ID) "
+ "WHERE M_PriceList_ID IS NOT NULL AND M_PriceList_Version_ID IS NULL"
+ " AND I_IsImported='N'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET M_PriceList_Version_ID=(SELECT M_PriceList_Version_ID FROM M_PriceList_Version p")
.append(" WHERE I_PriceList.ValidFrom=p.ValidFrom AND I_PriceList.M_PriceList_ID=p.M_PriceList_ID) ")
.append("WHERE M_PriceList_ID IS NOT NULL AND M_PriceList_Version_ID IS NULL")
.append(" AND I_IsImported='N'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("Price List Version Existing Value=" + no);
@ -208,55 +208,55 @@ public class ImportPriceList extends SvrProcess
*/
// Set Currency
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET ISO_Code=(SELECT ISO_Code FROM C_Currency c"
+ " INNER JOIN C_AcctSchema a ON (a.C_Currency_ID=c.C_Currency_ID)"
+ " INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)"
+ " WHERE ci.AD_Client_ID=I_PriceList.AD_Client_ID) "
+ "WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder("UPDATE I_PriceList ")
.append("SET ISO_Code=(SELECT ISO_Code FROM C_Currency c")
.append(" INNER JOIN C_AcctSchema a ON (a.C_Currency_ID=c.C_Currency_ID)")
.append(" INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)")
.append(" WHERE ci.AD_Client_ID=I_PriceList.AD_Client_ID) ")
.append("WHERE C_Currency_ID IS NULL AND ISO_Code IS NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Currency Default=" + no);
//
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c"
+ " WHERE I_PriceList.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,I_PriceList.AD_Client_ID)) "
+ "WHERE C_Currency_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET C_Currency_ID=(SELECT C_Currency_ID FROM C_Currency c")
.append(" WHERE I_PriceList.ISO_Code=c.ISO_Code AND c.AD_Client_ID IN (0,I_PriceList.AD_Client_ID)) ")
.append("WHERE C_Currency_ID IS NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("doIt- Set Currency=" + no);
//
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Currency,' "
+ "WHERE C_Currency_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Currency,' ")
.append("WHERE C_Currency_ID IS NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid Currency=" + no);
// Mandatory Name or PriceListID
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Mandatory Name or PriceListID,' "
+ "WHERE Name IS NULL AND M_PriceList_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Mandatory Name or PriceListID,' ")
.append("WHERE Name IS NULL AND M_PriceList_ID IS NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("No Mandatory Name=" + no);
// Mandatory ValidFrom or PriceListVersionID
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Mandatory ValidFrom or PriceListVersionID,' "
+ "WHERE ValidFrom IS NULL AND M_PriceList_Version_ID IS NULL"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Mandatory ValidFrom or PriceListVersionID,' ")
.append("WHERE ValidFrom IS NULL AND M_PriceList_Version_ID IS NULL")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("No Mandatory ValidFrom=" + no);
// Mandatory BreakValue if BPartner set
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory BreakValue,' "
+ "WHERE BreakValue IS NULL AND (C_BPartner_ID IS NOT NULL OR BPartner_Value IS NOT NULL)"
+ " AND I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=No Mandatory BreakValue,' ")
.append("WHERE BreakValue IS NULL AND (C_BPartner_ID IS NOT NULL OR BPartner_Value IS NOT NULL)")
.append(" AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("No Mandatory BreakValue=" + no);
@ -273,7 +273,7 @@ public class ImportPriceList extends SvrProcess
// Go through Records
log.fine("start inserting/updating ...");
sql = new StringBuffer ("SELECT * FROM I_PriceList WHERE I_IsImported='N'")
sql = new StringBuilder ("SELECT * FROM I_PriceList WHERE I_IsImported='N'")
.append(clientCheck);
PreparedStatement pstmt_setImported = null;
PreparedStatement pstmt = null;
@ -300,7 +300,8 @@ public class ImportPriceList extends SvrProcess
M_PriceList_ID = 0;
}
boolean newPriceList = M_PriceList_ID == 0;
log.fine("I_PriceList_ID=" + I_PriceList_ID + ", M_PriceList_ID=" + M_PriceList_ID);
StringBuilder msglog = new StringBuilder("I_PriceList_ID=").append(I_PriceList_ID).append(", M_PriceList_ID=").append(M_PriceList_ID);
log.fine(msglog.toString());
MPriceList pricelist = null;
// PriceList
@ -315,8 +316,8 @@ public class ImportPriceList extends SvrProcess
}
else
{
StringBuffer sql0 = new StringBuffer ("UPDATE I_PriceList i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Price List failed"))
StringBuilder sql0 = new StringBuilder ("UPDATE I_PriceList i ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Price List failed"))
.append("WHERE I_PriceList_ID=").append(I_PriceList_ID);
DB.executeUpdate(sql0.toString(), get_TrxName());
continue;
@ -334,7 +335,8 @@ public class ImportPriceList extends SvrProcess
M_PriceList_Version_ID = 0;
}
boolean newPriceListVersion = M_PriceList_Version_ID == 0;
log.fine("I_PriceList_ID=" + I_PriceList_ID + ", M_PriceList_Version_ID=" + M_PriceList_Version_ID);
msglog = new StringBuilder("I_PriceList_ID=").append(I_PriceList_ID).append(", M_PriceList_Version_ID=").append(M_PriceList_Version_ID);
log.fine(msglog.toString());
MPriceListVersion pricelistversion = null;
// PriceListVersion
@ -352,8 +354,8 @@ public class ImportPriceList extends SvrProcess
}
else
{
StringBuffer sql0 = new StringBuffer ("UPDATE I_PriceList i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Price List Version failed"))
StringBuilder sql0 = new StringBuilder ("UPDATE I_PriceList i ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert Price List Version failed"))
.append("WHERE I_PriceList_ID=").append(I_PriceList_ID);
DB.executeUpdate(sql0.toString(), get_TrxName());
continue;
@ -401,8 +403,8 @@ public class ImportPriceList extends SvrProcess
}
else
{
StringBuffer sql0 = new StringBuffer ("UPDATE I_PriceList i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert/Update Product Price Vendor Break Version failed"))
StringBuilder sql0 = new StringBuilder ("UPDATE I_PriceList i ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert/Update Product Price Vendor Break Version failed"))
.append("WHERE I_PriceList_ID=").append(I_PriceList_ID);
DB.executeUpdate(sql0.toString(), get_TrxName());
continue;
@ -432,8 +434,8 @@ public class ImportPriceList extends SvrProcess
}
else
{
StringBuffer sql0 = new StringBuffer ("UPDATE I_PriceList i "
+ "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert/Update Product Price failed"))
StringBuilder sql0 = new StringBuilder ("UPDATE I_PriceList i ")
.append("SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||").append(DB.TO_STRING("Insert/Update Product Price failed"))
.append("WHERE I_PriceList_ID=").append(I_PriceList_ID);
DB.executeUpdate(sql0.toString(), get_TrxName());
continue;
@ -460,9 +462,9 @@ public class ImportPriceList extends SvrProcess
}
// Set Error to indicator to not imported
sql = new StringBuffer ("UPDATE I_PriceList "
+ "SET I_IsImported='N', Updated=SysDate "
+ "WHERE I_IsImported<>'Y'").append(clientCheck);
sql = new StringBuilder ("UPDATE I_PriceList ")
.append("SET I_IsImported='N', Updated=SysDate ")
.append("WHERE I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
addLog (0, null, new BigDecimal (no), "@Errors@");
addLog (0, null, new BigDecimal (noInsertpl), "@M_PriceList_ID@: @Inserted@");

View File

@ -236,8 +236,9 @@ public class InOutGenerateRMA extends SvrProcess
if (shipmentLines.length == 0)
{
log.log(Level.WARNING, "No shipment lines created: M_RMA_ID="
+ M_RMA_ID + ", M_InOut_ID=" + shipment.get_ID());
StringBuilder msglog = new StringBuilder("No shipment lines created: M_RMA_ID=")
.append(M_RMA_ID).append(", M_InOut_ID=").append(shipment.get_ID());
log.log(Level.WARNING, msglog.toString());
}
StringBuffer processMsg = new StringBuffer(shipment.getDocumentNo());
@ -245,7 +246,8 @@ public class InOutGenerateRMA extends SvrProcess
if (!shipment.processIt(p_docAction))
{
processMsg.append(" (NOT Processed)");
log.warning("Shipment Processing failed: " + shipment + " - " + shipment.getProcessMsg());
StringBuilder msglog = new StringBuilder("Shipment Processing failed: ").append(shipment).append(" - ").append(shipment.getProcessMsg());
log.warning(msglog.toString());
throw new IllegalStateException("Shipment Processing failed: " + shipment + " - " + shipment.getProcessMsg());
}

View File

@ -149,24 +149,26 @@ public class InitialClientSetup extends SvrProcess
*/
protected String doIt () throws Exception
{
log.info("InitialClientSetup"
+ ": ClientName=" + p_ClientName
+ ", OrgValue=" + p_OrgValue
+ ", OrgName=" + p_OrgName
+ ", AdminUserName=" + p_AdminUserName
+ ", NormalUserName=" + p_NormalUserName
+ ", C_Currency_ID=" + p_C_Currency_ID
+ ", C_Country_ID=" + p_C_Country_ID
+ ", C_Region_ID=" + p_C_Region_ID
+ ", CityName=" + p_CityName
+ ", C_City_ID=" + p_C_City_ID
+ ", IsUseBPDimension=" + p_IsUseBPDimension
+ ", IsUseProductDimension=" + p_IsUseProductDimension
+ ", IsUseProjectDimension=" + p_IsUseProjectDimension
+ ", IsUseCampaignDimension=" + p_IsUseCampaignDimension
+ ", IsUseSalesRegionDimension=" + p_IsUseSalesRegionDimension
+ ", CoAFile=" + p_CoAFile
);
StringBuilder msglog = new StringBuilder("InitialClientSetup")
.append(": ClientName=").append(p_ClientName)
.append(", OrgValue=").append(p_OrgValue)
.append(", OrgName=").append(p_OrgName)
.append(", AdminUserName=").append(p_AdminUserName)
.append(", NormalUserName=").append(p_NormalUserName)
.append(", C_Currency_ID=").append(p_C_Currency_ID)
.append(", C_Country_ID=").append(p_C_Country_ID)
.append(", C_Region_ID=").append(p_C_Region_ID)
.append(", CityName=").append(p_CityName)
.append(", C_City_ID=").append(p_C_City_ID)
.append(", IsUseBPDimension=").append(p_IsUseBPDimension)
.append(", IsUseProductDimension=").append(p_IsUseProductDimension)
.append(", IsUseProjectDimension=").append(p_IsUseProjectDimension)
.append(", IsUseCampaignDimension=").append(p_IsUseCampaignDimension)
.append(", IsUseSalesRegionDimension=").append(p_IsUseSalesRegionDimension)
.append(", CoAFile=").append(p_CoAFile);
log.info(msglog.toString());
// Validations
@ -196,7 +198,8 @@ public class InitialClientSetup extends SvrProcess
if (p_C_City_ID > 0) {
MCity city = MCity.get(getCtx(), p_C_City_ID);
if (! city.getName().equals(p_CityName)) {
log.info("City name changed from " + p_CityName + " to " + city.getName());
msglog = new StringBuilder("City name changed from ").append(p_CityName).append(" to ").append(city.getName());
log.info(msglog.toString());
p_CityName = city.getName();
}
}

View File

@ -165,8 +165,9 @@ public class InvoiceGenerateRMA extends SvrProcess
{
if (rmaLine.getM_InOutLine_ID() == 0)
{
throw new IllegalStateException("No customer return line - RMA = "
+ rma.getDocumentNo() + ", Line = " + rmaLine.getLine());
StringBuilder msgiste = new StringBuilder("No customer return line - RMA = ")
.append(rma.getDocumentNo()).append(", Line = ").append(rmaLine.getLine());
throw new IllegalStateException(msgiste.toString());
}
MInvoiceLine invLine = new MInvoiceLine(invoice);
@ -197,17 +198,19 @@ public class InvoiceGenerateRMA extends SvrProcess
if (invoiceLines.length == 0)
{
log.log(Level.WARNING, "No invoice lines created: M_RMA_ID="
+ M_RMA_ID + ", M_Invoice_ID=" + invoice.get_ID());
StringBuilder msglog = new StringBuilder("No invoice lines created: M_RMA_ID=")
.append(M_RMA_ID).append(", M_Invoice_ID=").append(invoice.get_ID());
log.log(Level.WARNING, msglog.toString());
}
StringBuffer processMsg = new StringBuffer(invoice.getDocumentNo());
StringBuilder processMsg = new StringBuilder(invoice.getDocumentNo());
if (!invoice.processIt(p_docAction))
{
processMsg.append(" (NOT Processed)");
log.warning("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
throw new IllegalStateException("Invoice Processing failed: " + invoice + " - " + invoice.getProcessMsg());
StringBuilder msg = new StringBuilder("Invoice Processing failed: ").append(invoice).append(" - ").append(invoice.getProcessMsg());
log.warning(msg.toString());
throw new IllegalStateException(msg.toString());
}
if (!invoice.save())

View File

@ -72,18 +72,19 @@ public class PrepareMigrationScripts extends SvrProcess {
};
dirList = dir.listFiles(filter);
log.info("Searching for SQL files in the " + dir + " directory");
StringBuilder msglog = new StringBuilder("Searching for SQL files in the ").append(dir).append(" directory");
log.info(msglog.toString());
String msg = "";
StringBuilder msg = new StringBuilder();
// Get Filenames
for (int i = 0; i < dirList.length; i++) {
fileName.add(dirList[i].toString()
.substring(directory.length() + 1));
log
.fine("Found file ["
+ fileName.get(i)
+ "]. Finding out if the script has or hasn't been applied yet...");
msglog = new StringBuilder("Found file [")
.append(fileName.get(i))
.append("]. Finding out if the script has or hasn't been applied yet...");
log.fine(msglog.toString());
try {
// First of all, check if the script hasn't been applied yet...
String checkScript = "select ad_migrationscript_id from ad_migrationscript where name = ?";
@ -92,15 +93,16 @@ public class PrepareMigrationScripts extends SvrProcess {
pstmt.setString(1, fileName.get(i));
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
log.warning("Script " + fileName.get(i)
+ " already in the database");
msglog = new StringBuilder("Script ").append(fileName.get(i))
.append(" already in the database");
log.warning(msglog.toString());
pstmt.close();
continue;
}
pstmt.close();
// first use a Scanner to get each line
Scanner scanner = new Scanner(dirList[i]);
StringBuffer body = new StringBuffer();
StringBuilder body = new StringBuilder();
boolean blHeader = false;
boolean blBody = false;
boolean isFirstLine = true;
@ -215,8 +217,9 @@ public class PrepareMigrationScripts extends SvrProcess {
if (result > 0)
log.info("Header inserted. Now inserting the script body");
else {
log.severe("Script " + fileName.get(i) + " failed!");
msg = msg + "Script " + fileName.get(i) + " failed!";
msglog = new StringBuilder("Script ").append(fileName.get(i)).append(" failed!");
log.severe(msglog.toString());
msg.append(msglog);
continue;
}
sql = "UPDATE AD_MigrationScript SET script = ? WHERE AD_MigrationScript_ID = ?";
@ -228,8 +231,9 @@ public class PrepareMigrationScripts extends SvrProcess {
if (result > 0)
log.info("Script Body inserted.");
else {
log.severe("Script Body " + fileName.get(i) + " failed!");
msg = msg + "Script Body " + fileName.get(i) + " failed!";
msglog = new StringBuilder("Script Body ").append(fileName.get(i)).append(" failed!");
log.severe(msglog.toString());
msg.append(msglog.toString());
pstmt = DB
.prepareStatement(
"DELETE FROM ad_migrationscript WHERE ad_migrationscript_id = ?",

View File

@ -38,9 +38,9 @@ public class UpdateRoleMenu extends SvrProcess
private MRoleMenu addUpdateRole(Properties ctx, int roleId, int menuId, boolean active, String trxName)
{
String whereClause = "AD_Role_ID=" + roleId + " AND U_WebMenu_ID=" + menuId;
StringBuilder whereClause = new StringBuilder("AD_Role_ID=").append(roleId).append(" AND U_WebMenu_ID=").append(menuId);
int roleMenuIds[] = MRoleMenu.getAllIDs(MRoleMenu.Table_Name, whereClause, trxName);
int roleMenuIds[] = MRoleMenu.getAllIDs(MRoleMenu.Table_Name, whereClause.toString(), trxName);
MRoleMenu roleMenu;