Revert revision 8307
http://adempiere.svn.sourceforge.net/viewvc/adempiere?view=rev&revision=8307 FR-1976008 - 2Pack can replicate Data with FK integrity
This commit is contained in:
parent
6caee9c9dd
commit
090d4e1072
|
@ -106,26 +106,22 @@ public abstract class AbstractElementHandler implements ElementHandler {
|
|||
.append( "AD_PACKAGE_IMP_DETAIL_ID, AD_PACKAGE_IMP_ID, TYPE, NAME," )
|
||||
.append( " ACTION, SUCCESS, AD_ORIGINAL_ID, AD_BACKUP_ID, TABLENAME, AD_TABLE_ID)" )
|
||||
.append( "VALUES(" )
|
||||
.append( " ?")
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?" )
|
||||
.append( ", ?")
|
||||
.append( " "+ Env.getAD_Client_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_Org_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", "+ Env.getAD_User_ID(ctx) )
|
||||
.append( ", " + id )
|
||||
.append( ", " + getPackageImpId(ctx) )
|
||||
.append( ", '" + objectType )
|
||||
.append( "', '" + objectName )
|
||||
.append( "', '" + objectStatus )
|
||||
.append( "', 'Success'" )
|
||||
.append( ", "+objectID )
|
||||
.append( ", "+objectIDBackup )
|
||||
.append( ", '"+tableName )
|
||||
.append( "', "+AD_Table_ID )
|
||||
.append(")");
|
||||
Object[] param = new Object[] { Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx), Env.getAD_User_ID(ctx), Env.getAD_User_ID(ctx),
|
||||
id, getPackageImpId(ctx) , objectType, objectName, objectStatus, "Success", objectID, objectIDBackup, tableName,
|
||||
AD_Table_ID
|
||||
};
|
||||
int no = DB.executeUpdate (sqlB.toString(), param, true, getTrxName(ctx));
|
||||
int no = DB.executeUpdate (sqlB.toString(), getTrxName(ctx));
|
||||
if (no == -1)
|
||||
log.info("Insert to import detail failed");
|
||||
|
||||
|
|
|
@ -816,7 +816,7 @@ public class PackInHandler extends DefaultHandler {
|
|||
log.severe("Unresolved: " + d.element.getElementValue() + " - " + d.element.attributes.getValue(0) + ", " + d.element.unresolved);
|
||||
}
|
||||
}
|
||||
//throw new RuntimeException("Failed to resolve dependency for " + count + " elements."); //commented by Joyce (12 Nov 2008)
|
||||
throw new RuntimeException("Failed to resolve dependency for " + count + " elements.");
|
||||
//System.err.println("Failed to resolve dependency for " + count + " elements.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ import java.sql.ResultSetMetaData;
|
|||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
@ -38,7 +39,6 @@ import org.compiere.model.PO;
|
|||
import org.compiere.model.POInfo;
|
||||
import org.compiere.model.X_AD_Package_Exp_Detail;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -101,65 +101,13 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
String elementValue = element.getElementValue();
|
||||
Attributes atts = element.attributes;
|
||||
log.info(elementValue+" "+atts.getValue("name"));
|
||||
|
||||
MTable table = MTable.get(ctx, d_tablename);
|
||||
// use keyXname and lookupkeyXname if available
|
||||
if (atts.getValue("key1name") != null && atts.getValue("key1name").trim().length() > 0)
|
||||
{
|
||||
String sql = "select * from "+d_tablename;
|
||||
String whereand = " where";
|
||||
|
||||
List<String>params = new ArrayList<String>();
|
||||
int keyIndex = 1;
|
||||
while (true) {
|
||||
String currentKey = "key" + keyIndex + "name";
|
||||
if (atts.getValue(currentKey) != null && !atts.getValue(currentKey).equals("")) {
|
||||
params.add(atts.getValue("lookup"+currentKey));
|
||||
sql = sql+whereand+" "+atts.getValue(currentKey)+"=?";
|
||||
whereand = " and";
|
||||
keyIndex++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
String d_rowname = atts.getValue("name");
|
||||
|
||||
if (getClientId(ctx) > 0) {
|
||||
sql = sql + whereand + " " + d_tablename + ".AD_Client_ID in (0, " + getClientId(ctx) + ")";
|
||||
sql = sql + " Order by " + d_tablename + ".AD_Client_ID Desc";
|
||||
} else {
|
||||
sql = sql + whereand + " " + d_tablename + ".AD_Client_ID = 0";
|
||||
}
|
||||
|
||||
// Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value
|
||||
try {
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
pstmt.setString(i+1, params.get(i));
|
||||
}
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
objectStatus = "Update";
|
||||
genericPO = table.getPO(rs, getTrxName(ctx));
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
else {
|
||||
genericPO = table.getPO(0, getTrxName(ctx));
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
objectStatus = "New";
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
}
|
||||
} else {
|
||||
//fallback to name attribute
|
||||
String nameAttribute = atts.getValue("name");
|
||||
int id = get_ID(ctx, d_tablename, nameAttribute);
|
||||
// name can be null if there are keyXname attributes.
|
||||
if (!d_rowname.equals("")){
|
||||
int id = get_ID(ctx, d_tablename, d_rowname);
|
||||
genericPO = table.getPO(id, getTrxName(ctx));
|
||||
if (id > 0){
|
||||
if (genericPO == null || genericPO.get_ID() != id)
|
||||
|
@ -172,6 +120,66 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
AD_Backup_ID =0;
|
||||
}
|
||||
}
|
||||
// keyXname and lookupkeyXname.
|
||||
else {
|
||||
String sql = "select * from "+d_tablename;
|
||||
String whereand = " where";
|
||||
String CURRENT_KEY = "key1name";
|
||||
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
|
||||
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
|
||||
whereand = " and";
|
||||
}
|
||||
CURRENT_KEY = "key2name";
|
||||
if (atts.getValue(CURRENT_KEY) != null && !atts.getValue(CURRENT_KEY).equals("")) {
|
||||
sql = sql+whereand+" "+atts.getValue(CURRENT_KEY)+"="+atts.getValue("lookup"+CURRENT_KEY);
|
||||
whereand = " and";
|
||||
}
|
||||
if (whereand.equals(" where"))
|
||||
log.warning("no name or keyXname attribute defined.");
|
||||
// Load GenericPO from rs, in fact ID could not exist e.g. Attribute Value
|
||||
try {
|
||||
PreparedStatement pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
objectStatus = "Update";
|
||||
genericPO = table.getPO(rs, getTrxName(ctx));
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
else {
|
||||
rs.close();
|
||||
rs = null;
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
objectStatus = "New";
|
||||
genericPO = table.getPO(0, getTrxName(ctx));
|
||||
// set keyXname.
|
||||
CURRENT_KEY = "key1name";
|
||||
if (!atts.getValue(CURRENT_KEY).equals("")) {
|
||||
String colName = atts.getValue(CURRENT_KEY);
|
||||
String valueObject = atts.getValue("lookup"+CURRENT_KEY);
|
||||
if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
|
||||
valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject);
|
||||
genericPO.set_ValueOfColumn(colName, valueObject);
|
||||
}
|
||||
CURRENT_KEY = "key2name";
|
||||
if (!atts.getValue(CURRENT_KEY).equals("")) {
|
||||
String colName = atts.getValue(CURRENT_KEY);
|
||||
String valueObject = atts.getValue("lookup"+CURRENT_KEY);
|
||||
if (colName.endsWith("_ID") && valueObject.contains("SELECT"))
|
||||
valueObject = DB.getSQLValueString(getTrxName(ctx), valueObject);
|
||||
genericPO.set_ValueOfColumn(colName, valueObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warning ("keyXname attribute. init from rs error."+e);
|
||||
throw new SAXException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// for debug GenericPO.
|
||||
if (false) {
|
||||
|
@ -185,6 +193,28 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
// 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("Name", d_rowname);
|
||||
// Set defaults.
|
||||
//TODO: get defaults from configuration
|
||||
HashMap defaults = new HashMap();
|
||||
HashMap thisDefault = (HashMap)defaults.get(d_tablename);
|
||||
if (thisDefault != null) {
|
||||
Iterator iter = thisDefault.values().iterator();
|
||||
ArrayList thisValue = null;
|
||||
while (iter.hasNext()) {
|
||||
thisValue = (ArrayList)iter.next();
|
||||
if (((String)(thisValue.get(2))).equals("String"))
|
||||
genericPO.set_ValueOfColumn((String)thisValue.get(0), (String)thisValue.get(1));
|
||||
else if (((String)(thisValue.get(2))).equals("Integer"))
|
||||
genericPO.set_ValueOfColumn((String)thisValue.get(0), Integer.valueOf((String)thisValue.get(1)));
|
||||
else if (((String)(thisValue.get(2))).equals("Boolean"))
|
||||
genericPO.set_ValueOfColumn((String)thisValue.get(0), new Boolean(((String)thisValue.get(1)).equals("true") ? true : false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(Properties ctx, Element element) throws SAXException {
|
||||
|
@ -215,10 +245,6 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
String columnName = atts.getValue("name");
|
||||
int tableid = get_IDWithColumn(ctx, "AD_Table", "TableName", d_tablename);
|
||||
int id =get_IDWithMasterAndColumn (ctx,"AD_Column", "ColumnName", columnName, "AD_Table", tableid);
|
||||
if (id <= 0) {
|
||||
log.log(Level.WARNING, "Column not found in AD_Column, TableName=" + d_tablename + " ColumnName=" + columnName);
|
||||
return;
|
||||
}
|
||||
StringBuffer sql = new StringBuffer ("SELECT IsUpdateable FROM AD_column WHERE AD_Column_ID = ?");
|
||||
String isUpdateable = DB.getSQLValueString(getTrxName(ctx), sql.toString(),id);
|
||||
sql = new StringBuffer ("SELECT IsKey FROM AD_column WHERE AD_Column_ID = ?");
|
||||
|
@ -226,44 +252,37 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
if (("New".equals(objectStatus)) || (isKey.equals("N") &&
|
||||
isUpdateable.equals("Y") &&
|
||||
(!atts.getValue("name").equals("CreatedBy")||!atts.getValue("name").equals("UpdatedBy")))) {
|
||||
String value = atts.getValue("value");
|
||||
if (value != null && !value.equals("null") && value.trim().length() > 0) {
|
||||
if (atts.getValue("value") != null && !atts.getValue("value").equals("null")) {
|
||||
if (atts.getValue("class").equals("String") || atts.getValue("class").equals("Text")
|
||||
|| atts.getValue("class").equals("List")|| atts.getValue("class").equals("Yes-No")
|
||||
|| atts.getValue("class").equals("Button")
|
||||
|| atts.getValue("class").equals("Memo")|| atts.getValue("class").equals("Text Long")
|
||||
|| atts.getValue("name").equals("AD_Language") || atts.getValue("name").equals("EntityType")) {
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), value);
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), atts.getValue("value").toString());
|
||||
}
|
||||
else if (atts.getValue("class").equals("Number") || atts.getValue("class").equals("Amount")
|
||||
|| atts.getValue("class").equals("Quantity")|| atts.getValue("class").equals("Costs+Prices")){
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), new BigDecimal(value));
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), new BigDecimal(atts.getValue("value")));
|
||||
}
|
||||
else if (atts.getValue("class").equals("Integer") || atts.getValue("class").equals("ID")
|
||||
|| atts.getValue("class").equals("Table Direct")|| atts.getValue("class").equals("Table")
|
||||
|| atts.getValue("class").equals("Location (Address)")|| atts.getValue("class").equals("Account")
|
||||
|| atts.getValue("class").equals("Color)")|| atts.getValue("class").equals("Search")
|
||||
|| atts.getValue("class").equals("Locator (WH)")|| atts.getValue("class").equals("Product Attribute")) {
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), Integer.valueOf(value));
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Integer.valueOf(atts.getValue("value")));
|
||||
}
|
||||
else if (atts.getValue("class").equals("Boolean")) {
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(value.equals("true") ? true : false));
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), new Boolean(atts.getValue("value").equals("true") ? true : false));
|
||||
}
|
||||
else if (atts.getValue("class").equals("Date") || atts.getValue("class").equals("Date+Time")
|
||||
|| atts.getValue("class").equals("Time")) {
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), Timestamp.valueOf(value));
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name").toString(), Timestamp.valueOf(atts.getValue("value")));
|
||||
}//Binary, Radio, RowID, Image not supported
|
||||
} else { // value is null
|
||||
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);
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), new Integer(getIDbyName(ctx, m_tablename, atts.getValue("lookupname"))));
|
||||
} else if ( atts.getValue("sql") != null && atts.getValue("sql").trim().length() > 0) {
|
||||
String idSql = atts.getValue("sql");
|
||||
idSql = idSql.replace("@AD_Client_ID@", Integer.toString(getClientId(ctx)));
|
||||
int result = DB.getSQLValue(getTrxName(ctx), idSql);
|
||||
if (result >= 0)
|
||||
genericPO.set_ValueOfColumn(atts.getValue("name"), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -278,10 +297,6 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ctx
|
||||
* @param document
|
||||
*/
|
||||
public void create(Properties ctx, TransformerHandler document)
|
||||
throws SAXException {
|
||||
String sql = Env.getContext(ctx, X_AD_Package_Exp_Detail.COLUMNNAME_SQLStatement);
|
||||
|
@ -302,53 +317,37 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
document.startElement("","","dtable",atts);
|
||||
while (rs.next()){
|
||||
atts.clear();
|
||||
int keyIndex = 0;
|
||||
int key1 = 0;
|
||||
String nameatts = "";
|
||||
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");
|
||||
String sql2 = "SELECT ColumnName FROM AD_Column "
|
||||
+ "WHERE isIdentifier = 'Y' AND "
|
||||
+ "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)){
|
||||
keyIndex++;
|
||||
atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName);
|
||||
atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name));
|
||||
if (cName.toUpperCase().equals(col_Name) && key1 == 0 ){
|
||||
atts.addAttribute("","","key1name","CDATA",cName);
|
||||
atts.addAttribute("","","lookupkey1name","CDATA",""+rs.getObject(col_Name));
|
||||
key1 = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fall back to Id
|
||||
if (keyIndex == 0) {
|
||||
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");
|
||||
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)){
|
||||
keyIndex++;
|
||||
atts.addAttribute("","","key" + keyIndex + "name","CDATA",cName);
|
||||
atts.addAttribute("","","lookupkey" + keyIndex + "name","CDATA",""+rs.getObject(col_Name));
|
||||
}
|
||||
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);
|
||||
if ( keyIndex == 0 ){
|
||||
if ( key1 == 0 ){
|
||||
atts.addAttribute("","","key1name","CDATA","");
|
||||
atts.addAttribute("","","lookupkey1name","CDATA","");
|
||||
keyIndex++;
|
||||
key1 = 1;
|
||||
}
|
||||
if ( keyIndex == 1 ){
|
||||
if ( key1 == 1 ){
|
||||
atts.addAttribute("","","key2name","CDATA","");
|
||||
atts.addAttribute("","","lookupkey2name","CDATA","");
|
||||
}
|
||||
|
@ -356,12 +355,11 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
for (i=1 ;i <= columns;i++){
|
||||
atts.clear();
|
||||
col_Name = meta.getColumnName(i).toUpperCase();
|
||||
String sql2 = "Select A.ColumnName, B.Name, A.AD_Reference_ID, A.AD_Reference_Value_ID "
|
||||
String sql2 = "Select A.ColumnName, B.Name "
|
||||
+ "From AD_Column A, AD_Reference B "
|
||||
+ "Where Upper(A.columnname) = ? and "
|
||||
+ "A.AD_TABLE_ID = ? and "
|
||||
+ "A.AD_Reference_ID = B.AD_Reference_ID "
|
||||
+ "AND A.ColumnName != 'AD_Client_ID' ";
|
||||
+ "A.AD_Reference_ID = B.AD_Reference_ID";
|
||||
PreparedStatement pstmt = null;
|
||||
try
|
||||
{
|
||||
|
@ -374,50 +372,11 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
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
|
||||
atts.addAttribute("","","value","CDATA", "" + rs.getObject(i));
|
||||
|
||||
//rs1.getString("ColumnName") : NAME / VALUE
|
||||
//rs1.getString("Name") : STRING
|
||||
//rs1.getString("AD_Reference_ID") : number (table/table direct/ search)
|
||||
//rs1.getString("AD_Reference_Value_ID") : number (null when type is table direct)
|
||||
|
||||
if (rs1.getInt("AD_Reference_ID") == DisplayType.Table || rs1.getInt("AD_Reference_ID") == DisplayType.Search
|
||||
|| rs1.getInt("AD_Reference_ID") == DisplayType.TableDir ){
|
||||
String tableName = "";
|
||||
|
||||
if (rs1.getInt("AD_Reference_ID") == DisplayType.TableDir){
|
||||
//if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT
|
||||
tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3);
|
||||
}else{
|
||||
//ad_ref_table.ad_reference_id = ad_reference_value_id
|
||||
int referenceId = rs1.getInt("AD_Reference_Value_ID");
|
||||
|
||||
if (referenceId != 0)
|
||||
tableName = getTableNameFromReferenceId(referenceId);
|
||||
else
|
||||
tableName = rs1.getString("ColumnName").substring(0,rs1.getString("ColumnName").length()-3);
|
||||
}
|
||||
|
||||
if (rs.getObject(i) == null)
|
||||
atts.addAttribute("","","value","CDATA", "");
|
||||
else{
|
||||
String insertSql = getSqlFromTableName(tableName,Integer.parseInt(rs.getObject(i).toString()),ctx);
|
||||
|
||||
String parentSql = getParentSql(tableName,ctx,Integer.parseInt(rs.getObject(i).toString()));
|
||||
if (!parentSql.equals(""))
|
||||
insertSql = insertSql + parentSql;
|
||||
|
||||
insertSql = insertSql + " Order By " + tableName + ".AD_Client_ID Desc ";
|
||||
|
||||
atts.addAttribute("","","value","CDATA", "");
|
||||
atts.addAttribute("", "", "sql", "CDATA", insertSql);
|
||||
}
|
||||
|
||||
} else {
|
||||
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
|
||||
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);
|
||||
|
@ -448,94 +407,4 @@ public class DataElementHandler extends AbstractElementHandler {
|
|||
|
||||
}
|
||||
|
||||
private String getTableNameFromReferenceId(int referenceId){
|
||||
String tableName = "";
|
||||
String sql = " SELECT t.TableName FROM AD_Table T, AD_Ref_Table R "
|
||||
+" WHERE T.AD_Table_ID=R.AD_Table_ID AND R.AD_Reference_ID=? ";
|
||||
tableName= DB.getSQLValueString(null,sql,referenceId);
|
||||
|
||||
return tableName;
|
||||
}
|
||||
|
||||
private String getSqlFromTableName(String tableName, int id, Properties ctx) throws Exception{
|
||||
String result = null;
|
||||
|
||||
String sql = "SELECT count(a.ad_table_id) FROM ad_table a INNER JOIN ad_column b ON (a.ad_table_id = b.ad_table_id) "
|
||||
+ "AND a.tablename = '" + tableName + "' AND UPPER(b.columnname) = 'VALUE'";
|
||||
int count = DB.getSQLValue(null, sql);
|
||||
|
||||
String insertSqlValue = count <= 0
|
||||
? ( "SELECT Name FROM "+tableName+" WHERE "+tableName+"_ID=?" )
|
||||
: ( "SELECT Value FROM "+tableName+" WHERE "+tableName+"_ID=?" );
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try{
|
||||
pstmt = DB.prepareStatement(insertSqlValue, getTrxName(ctx));
|
||||
pstmt.setInt(1, id);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()){
|
||||
|
||||
if (count <= 0)
|
||||
result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Name='"+rs.getString(1)+"'";
|
||||
else
|
||||
result = "SELECT " +tableName+"_ID FROM "+tableName+" WHERE Value='"+rs.getString(1)+"'";
|
||||
result = result + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )";
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} finally {
|
||||
DB.close(rs, pstmt);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getParentSql(String tableName, Properties ctx, int recordId) throws Exception{
|
||||
String parentSql = "";
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try{
|
||||
String sql = "SELECT A.ColumnName, A.AD_Reference_ID, A.AD_Reference_Value_ID "
|
||||
+ "FROM AD_Column A, AD_Table T "
|
||||
+ "Where A.AD_TABLE_ID = T.AD_Table_ID AND A.IsParent = 'Y' "
|
||||
+ "AND UPPER(T.TableName)=? "
|
||||
+ "AND A.ColumnName != 'AD_Client_ID' ";
|
||||
|
||||
pstmt = DB.prepareStatement(sql, getTrxName(ctx));
|
||||
pstmt.setString(1,tableName.toUpperCase());
|
||||
rs = pstmt.executeQuery();
|
||||
|
||||
while(rs.next()){
|
||||
if (rs.getInt("AD_Reference_ID") == DisplayType.Table || rs.getInt("AD_Reference_ID") == DisplayType.Search || rs.getInt("AD_Reference_ID") == DisplayType.TableDir){
|
||||
String parentTableName = "";
|
||||
|
||||
if (rs.getInt("AD_Reference_ID") == DisplayType.TableDir){
|
||||
//if rs1.getString("ColumnName") = C_EDIFORMAT_ID, tablename = C_EDIFORMAT
|
||||
parentTableName = rs.getString("ColumnName").substring(0,rs.getString("ColumnName").length()-3);
|
||||
}else{
|
||||
//ad_ref_table.ad_reference_id = ad_reference_value_id
|
||||
int referenceId = rs.getInt("AD_Reference_Value_ID");
|
||||
parentTableName = getTableNameFromReferenceId(referenceId);
|
||||
}
|
||||
|
||||
String parentIdSql = "SELECT "+parentTableName+"_ID FROM "+tableName+" WHERE "+tableName+"_ID = "+recordId;
|
||||
int parentRecordId = DB.getSQLValue(null, parentIdSql);
|
||||
|
||||
parentSql = " AND "+rs.getString("ColumnName")+ " IN (" +getParentSql(parentTableName, ctx, parentRecordId)+")";
|
||||
parentSql = parentSql + " AND " + tableName + ".AD_Client_ID IN ( @AD_Client_ID@ , 0 )";
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
} finally{
|
||||
DB.close(rs, pstmt);
|
||||
}
|
||||
|
||||
return parentSql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ public class FieldElementHandler extends AbstractElementHandler {
|
|||
if (element.parent != null && element.parent.getElementValue().equals("tab") &&
|
||||
element.parent.defer) {
|
||||
element.defer = true;
|
||||
element.unresolved = element.parent.unresolved;
|
||||
return;
|
||||
}
|
||||
String name = atts.getValue("Name");
|
||||
|
@ -61,7 +60,6 @@ public class FieldElementHandler extends AbstractElementHandler {
|
|||
packIn.addTable(tableName, tableid);
|
||||
}
|
||||
if (tableid <= 0) {
|
||||
element.unresolved = "AD_Table=" + tableName;
|
||||
element.defer = true;
|
||||
return;
|
||||
}
|
||||
|
@ -69,7 +67,6 @@ public class FieldElementHandler extends AbstractElementHandler {
|
|||
.getValue("ADWindowNameID"));
|
||||
if (windowid <= 0) {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Window=" + atts.getValue("ADWindowNameID");
|
||||
return;
|
||||
}
|
||||
int columnid = packIn.getColumnId(tableName, colname);
|
||||
|
@ -81,7 +78,6 @@ public class FieldElementHandler extends AbstractElementHandler {
|
|||
}
|
||||
if (columnid <= 0) {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Column"+ colname;
|
||||
return;
|
||||
}
|
||||
int tabid = 0;
|
||||
|
@ -176,7 +172,6 @@ public class FieldElementHandler extends AbstractElementHandler {
|
|||
}
|
||||
} else {
|
||||
element.defer = true;
|
||||
element.unresolved = "AD_Tab=" + tabname;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
-- Aug 6, 2008 10:39:44 AM SGT
|
||||
-- Packin to any client
|
||||
UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:39:57 AM SGT
|
||||
-- Packin to any client
|
||||
UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:31 AM SGT
|
||||
-- Packin to any client
|
||||
DELETE FROM AD_Window_Access WHERE AD_Role_ID=102
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1')
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
DELETE FROM AD_Process_Access WHERE AD_Role_ID=102
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', SysDate,100, SysDate,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1')
|
||||
;
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
-- Aug 6, 2008 10:39:44 AM SGT
|
||||
-- Packin to any client
|
||||
UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50008
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:39:57 AM SGT
|
||||
-- Packin to any client
|
||||
UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2008-08-06 10:39:57','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=50003
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
DELETE FROM AD_Window_Access WHERE AD_Role_ID=102
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
INSERT INTO AD_Window_Access (AD_Window_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT w.AD_Window_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Window w INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID) INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) WHERE t.SeqNo=(SELECT MIN(SeqNo) FROM AD_Tab xt WHERE xt.AD_Window_ID=w.AD_Window_ID)AND tt.AccessLevel IN ('7','6','3','2','1')
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
DELETE FROM AD_Process_Access WHERE AD_Role_ID=102
|
||||
;
|
||||
|
||||
-- Aug 6, 2008 10:40:32 AM SGT
|
||||
-- Packin to any client
|
||||
INSERT INTO AD_Process_Access (AD_Process_ID, AD_Role_ID, AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadWrite) SELECT DISTINCT p.AD_Process_ID, 102,11,0,'Y', CURRENT_TIMESTAMP,100, CURRENT_TIMESTAMP,100,'Y' FROM AD_Process p WHERE AccessLevel IN ('7','6','3','2','1')
|
||||
;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue