diff --git a/base/src/org/adempiere/pipo/AbstractElementHandler.java b/base/src/org/adempiere/pipo/AbstractElementHandler.java index 142bc86b68..4da8d38423 100644 --- a/base/src/org/adempiere/pipo/AbstractElementHandler.java +++ b/base/src/org/adempiere/pipo/AbstractElementHandler.java @@ -49,13 +49,7 @@ public abstract class AbstractElementHandler implements ElementHandler { * */ public int get_ID (Properties ctx, String tableName, String name) { - return IDFinder.get_ID("Name", tableName, name, getClientId(ctx), getTrxName(ctx)); - } - /** red1 - overloading to handle extra Name or DocumentNo argument - * occurs for cases that doesn't use name in Data such as C_Order.DocumentNo - */ - public int get_ID (String lookUpName, Properties ctx, String tableName, String name) { - return IDFinder.get_ID(lookUpName, tableName, name, getClientId(ctx), getTrxName(ctx)); + return IDFinder.get_ID(tableName, name, getClientId(ctx), getTrxName(ctx)); } /** @@ -229,8 +223,8 @@ public abstract class AbstractElementHandler implements ElementHandler { * @param tableName * @param name */ - public int getIDbyName (Properties ctx, String tableName, String name, String lookupField) { - return IDFinder.getIDbyName(lookupField, tableName, name, getClientId(ctx), getTrxName(ctx)); + public int getIDbyName (Properties ctx, String tableName, String name) { + return IDFinder.getIDbyName(tableName, name, getClientId(ctx), getTrxName(ctx)); } /** diff --git a/base/src/org/adempiere/pipo/IDFinder.java b/base/src/org/adempiere/pipo/IDFinder.java index 70a62d0e6c..cb612b4adb 100644 --- a/base/src/org/adempiere/pipo/IDFinder.java +++ b/base/src/org/adempiere/pipo/IDFinder.java @@ -47,13 +47,13 @@ public class IDFinder { * @param trxName * */ - public static int get_ID (String lookUpField, String tableName, String name, int AD_Client_ID, String trxName) { + public static int get_ID (String tableName, String name, int AD_Client_ID, String trxName) { int id = 0; //construct cache key StringBuffer key = new StringBuffer(); key.append(tableName) - .append("."+lookUpField+"=") //red1 - to allow for DocumentNo in C_Orders + .append(".Name=") .append(name); if (!tableName.startsWith("AD_")) key.append(" and AD_Client_ID=").append(AD_Client_ID); @@ -66,7 +66,7 @@ public class IDFinder { .append(tableName) .append("_ID from ") .append(tableName) - .append(" where "+lookUpField+"=?");//red1 - to allow for DocumentNo in C_Orders + .append(" where name=?"); if (!tableName.startsWith("AD_")) sqlB = sqlB.append(" and AD_Client_ID=?"); @@ -351,7 +351,7 @@ public class IDFinder { * @param AD_Client_ID * @param trxName */ - public static int getIDbyName (String lookupField, String tableName, String name, int AD_Client_ID, String trxName) { + public static int getIDbyName (String tableName, String name, int AD_Client_ID, String trxName) { int id = 0; //construct cache key @@ -371,9 +371,8 @@ public class IDFinder { .append("_ID ") .append("FROM ") .append(tableName) - .append(" WHERE ") - .append(lookupField) //red1 - i.e. Name or DocumentNo - .append("=?"); + .append(" ") + .append("WHERE name=?"); if (!tableName.startsWith("AD_")) sql.append(" AND AD_Client_ID=?"); try { diff --git a/base/src/org/adempiere/pipo/handler/DataElementHandler.java b/base/src/org/adempiere/pipo/handler/DataElementHandler.java index 11f871d7f1..d628691f40 100644 --- a/base/src/org/adempiere/pipo/handler/DataElementHandler.java +++ b/base/src/org/adempiere/pipo/handler/DataElementHandler.java @@ -62,7 +62,7 @@ public class DataElementHandler extends AbstractElementHandler { if (elementValue.equals("adempieredata") || elementValue.equals("data")) { log.info(elementValue); if (atts.getValue("clientname") != null) { - int AD_Client_ID = IDFinder.get_ID("Name","AD_Client", atts.getValue("clientname"), getClientId(ctx), getTrxName(ctx)); + int AD_Client_ID = IDFinder.get_ID("AD_Client", atts.getValue("clientname"), getClientId(ctx), getTrxName(ctx)); Env.setContext(ctx, "AD_Client_ID", AD_Client_ID); log.info("adempieredata: client set to "+AD_Client_ID+" "+atts.getValue("clientname")); } @@ -97,25 +97,19 @@ public class DataElementHandler extends AbstractElementHandler { String d_rowname = atts.getValue("name"); // name can be null if there are keyXname attributes. - //red1 - Using DocumentNo also (done in CREATE routine at bottom) - String lookUpField = "Name"; - if ("C_Order_ID".equals(atts.getValue("key1name"))) - lookUpField = "DocumentNo"; if (!d_rowname.equals("")){ - int id = get_ID(lookUpField, ctx, d_tablename, d_rowname); + int id = get_ID(ctx, d_tablename, d_rowname); genericPO = new GenericPO(d_tablename, ctx, id, getTrxName(ctx)); if (id > 0){ AD_Backup_ID = copyRecord(ctx,d_tablename,genericPO); objectStatus = "Update"; - //TODO red1 - new problem arises where child details i.e. OrderLines need to be updated, complex and so easiest may be to delete all first, then create. } else{ objectStatus = "New"; AD_Backup_ID =0; } } - // keyXname and lookupkeyXname. - //red1 - this should be redundant, because u cannot safely look up via PK ID as key, when above Name/DocNo is sufficient + // keyXname and lookupkeyXname. else { String sql = "select * from "+d_tablename; String whereand = " where"; @@ -137,7 +131,7 @@ public class DataElementHandler extends AbstractElementHandler { ResultSet rs = pstmt.executeQuery(); if (rs.next()) { - objectStatus = "New"; //red1 - not "Update" as lookUpName in effect + objectStatus = "Update"; genericPO = new GenericPO(d_tablename, ctx, rs, getTrxName(ctx)); rs.close(); pstmt.close(); @@ -168,20 +162,20 @@ public class DataElementHandler extends AbstractElementHandler { // for debug GenericPO. if (false) { - POInfo poInfo = POInfo.getPOInfo(ctx, get_ID(lookUpField,ctx, "AD_Table", d_tablename), getTrxName(ctx)); + POInfo poInfo = POInfo.getPOInfo(ctx, get_ID(ctx, "AD_Table", d_tablename), getTrxName(ctx)); if (poInfo == null) log.info("poInfo is null."); for (int i = 0; i < poInfo.getColumnCount(); i++) { log.info(d_tablename+" column: "+poInfo.getColumnName(i)); } } - // globalqss: set AD_Client_ID to the client set in adempieredata + // globalqss: set AD_Client_ID to the client setted in adempieredata if (getClientId(ctx) > 0 && genericPO.getAD_Client_ID() != getClientId(ctx)) genericPO.set_ValueOfColumn("AD_Client_ID", getClientId(ctx)); // if new. TODO: no defaults for keyXname. if (!d_rowname.equals("") && ((Integer)(genericPO.get_Value(d_tablename+"_ID"))).intValue() == 0) { log.info("new genericPO, table: "+d_tablename+" name:"+d_rowname); - genericPO.set_ValueOfColumn(lookUpField, d_rowname); //red1 - to handle Name or DocumentName for SO + genericPO.set_ValueOfColumn("Name", d_rowname); // Set defaults. //TODO: get defaults from configuration HashMap defaults = new HashMap(); @@ -266,13 +260,7 @@ public class DataElementHandler extends AbstractElementHandler { if (atts.getValue("lookupname") != null && !"".equals(atts.getValue("lookupname"))) { // globalqss - bring support from XML2AD to lookupname String m_tablename = atts.getValue("name").substring(0, atts.getValue("name").length()-3); - //red1 - convert other names to proper names i.e. SalesRep > AD_User - if (m_tablename.equals("SalesRep")) - m_tablename="AD_User"; - String lookupIDentifier = "Name"; //red1 - lookupIDentifier such as Name or DocumentNo - if (atts.getValue("name").equals("C_Order_ID")) - lookupIDentifier = "DocumentNo"; - genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname"), lookupIDentifier))); + genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname")))); } } } @@ -312,35 +300,26 @@ public class DataElementHandler extends AbstractElementHandler { for (i=1 ;i <= columns;i++){ col_Name = meta.getColumnName(i).toUpperCase(); if (col_Name.equals("NAME") && rs.getObject("name") != null) - nameatts = ""+rs.getObject("name"); - //red1 - capture PK other name for lookup also - if (col_Name.equals("DOCUMENTNO") && rs.getObject("DOCUMENTNO") != null) - nameatts = ""+rs.getObject("DocumentNo"); - - //red1 - only for fields ending in _ID to save redundant processing time - if ("_ID".equals(col_Name.substring(col_Name.length()-3, col_Name.length()))) - { - String sql2 = "SELECT ColumnName FROM AD_Column " - + "WHERE isKey = 'Y' AND " - + "AD_Table_ID = ? AND " - + "Upper(ColumnName)= '"+col_Name+"'"; - String cName = DB.getSQLValueString(null,sql2,table_id); - if (cName != null){ - if (key1 == 0 ){ //red1 - remove cName.toUpperCase().equals(col_Name) && - atts.addAttribute("","","key1name","CDATA",cName); - atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name)); - key1 = 1; - } - else if (key1 == 1 ){ //red1 - remove cName.toUpperCase().equals(col_Name) && - atts.addAttribute("","","key2name","CDATA",cName); - atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name)); - key1 = 2; - } - } + nameatts = ""+rs.getObject("name"); + String sql2 = "SELECT ColumnName FROM AD_Column " + + "WHERE isKey = 'Y' AND " + + "AD_Table_ID = ? AND " + + "Upper(ColumnName)= '"+col_Name+"'"; + String cName = DB.getSQLValueString(null,sql2,table_id); + if (cName != null){ + if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){ + atts.addAttribute("","","key1name","CDATA",cName); + atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name)); + key1 = 1; + } + else if (cName.toUpperCase().equals(col_Name) && key1 == 1 ){ + atts.addAttribute("","","key2name","CDATA",cName); + atts.addAttribute("","","lookupkey2name","CDATA",""+rs.getObject(col_Name)); + key1 = 2; } } + } atts.addAttribute("","","name","CDATA",nameatts); - // this is to ensure flushing of old values if ( key1 == 0 ){ atts.addAttribute("","","key1name","CDATA",""); atts.addAttribute("","","lookupkey1name","CDATA",""); @@ -353,10 +332,10 @@ public class DataElementHandler extends AbstractElementHandler { document.startElement("","","drow",atts); for (i=1 ;i <= columns;i++){ atts.clear(); - col_Name = meta.getColumnName(i).toUpperCase(); + col_Name = meta.getColumnName(i).toUpperCase(); String sql2 = "Select A.ColumnName, B.Name " + "From AD_Column A, AD_Reference B " - + "Where Upper(A.columnname) = ? and " + + "Where Upper(A.columnname) = ? and " + "A.AD_TABLE_ID = ? and " + "A.AD_Reference_ID = B.AD_Reference_ID"; PreparedStatement pstmt = null; @@ -368,45 +347,14 @@ public class DataElementHandler extends AbstractElementHandler { ResultSet rs1 = pstmt.executeQuery(); while (rs1.next()){ //added 9/3/05 - //red1 20/05/08 - FK ID Begins where commented - String exactCase = rs1.getString("ColumnName"); // red1 to retain the leading cap case for exact = table column's content - int flag = 0; //red1 - flag to ensure value if lookupname not done atts.clear(); atts.addAttribute("","","name","CDATA", rs1.getString("ColumnName")); atts.addAttribute("","","class","CDATA", rs1.getString("Name")); if (rs1.getString("Name").equals("Date")||rs1.getString("Name").equals("Date+Time")||rs1.getString("Name").equals("Time")) atts.addAttribute("","","value","CDATA", "" + rs.getTimestamp(i)); else - //red1 - here is where the FK ID lookup check happens - //red1 - looking for fields ending in _ID, confirm its a tablename and return its Name from its ID in the FK table - if ("_ID".equals(col_Name.substring(col_Name.length()-3, col_Name.length()))) - { - String colName_without_ID = exactCase.substring(0, exactCase.length()-3); - if (!colName_without_ID.equals(table_Name)) - { - //red1 - need to convert other names to proper names i.e. SalesRep > AD_User - if (colName_without_ID.equals("SalesRep")) colName_without_ID="AD_User"; - String sqlvalue = "Select TableName from AD_Table where TableName = '"+colName_without_ID+"'"; - //red1 - Select TableName from AD_Table where TableName = colName_without_ID - String tableName = DB.getSQLValueByValue(null, sqlvalue); - //red1 - lookup DB>TableName(present_ID) - if (tableName!=null && rs.getObject(i)!=null){ // red1 - to skip if nothing in field - sqlvalue = "Select Name, AD_Client_ID from "+tableName+" where "+colName_without_ID+"_ID="+rs.getObject(i); //red1 colName_without_ID+"_ID is to solve SalesRep>AD_User case - //red1 - to handle DocumentNo FK IDentifier in C_OrderLine //AD_Client_ID to resolve that for System record do not do lookupName, just return native ID - if (table_Name.equals("C_OrderLine") && (colName_without_ID.equals("C_Order"))) - sqlvalue = "SELECT DocumentNo, AD_Client_ID FROM "+tableName+" where "+colName_without_ID+"_ID="+rs.getObject(i); - String valueName = DB.getSQLValueByValueClient(null, sqlvalue); - if (valueName!=null){ - atts.addAttribute("","","lookupname","CDATA", "" + valueName); - flag = 1; - //red1 - FK ID end - } - } - } - } - if (flag==0) - atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); - + atts.addAttribute("","","value","CDATA", "" + rs.getObject(i)); + if (!rs1.getString("ColumnName").equals("Created")&&!rs1.getString("ColumnName").equals("CreatedBy")&& !rs1.getString("ColumnName").equals("Updated")&&!rs1.getString("ColumnName").equals("UpdatedBy")){ document.startElement("","","dcolumn",atts); diff --git a/base/src/org/compiere/util/DB.java b/base/src/org/compiere/util/DB.java index d7ed8bf160..ca7c4d114c 100644 --- a/base/src/org/compiere/util/DB.java +++ b/base/src/org/compiere/util/DB.java @@ -1104,73 +1104,7 @@ public final class DB } return retValue; } // getRowSet - /** -- red1 -- - * Get One String Value from sql - * @param trxName trx - * @param sql sql - * @return only value or null - */ - public static String getSQLValueByValue (String trxName, String sql) - { - String retValue = null; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = prepareStatement(sql, trxName); - rs = pstmt.executeQuery(); - if (rs.next()) - retValue = rs.getString(1); - else - log.fine("No Value " + sql); - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - close(rs); - close(pstmt); - rs= null; - pstmt = null; - } - return retValue; - } // getSQLValue String - - public static String getSQLValueByValueClient (String trxName, String sql) - { - String retValue = null; - int AD_Client_ID = 0; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = prepareStatement(sql, trxName); - rs = pstmt.executeQuery(); - if (rs.next()){ - retValue = rs.getString(1); - AD_Client_ID = rs.getInt(2); //red1 - to check if Client is SYSTEM then do not lookup - if (AD_Client_ID==0) retValue = null; - } - - else - log.fine("No Value " + sql); - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - finally - { - close(rs); - close(pstmt); - rs= null; - pstmt = null; - } - return retValue; - } // getSQLValueClient String - + /** * Get Value from sql * @param trxName trx