IDEMPIERE-4756 2pack import problem (#648)

This commit is contained in:
Carlos Ruiz 2021-04-09 12:38:41 +02:00 committed by GitHub
parent 26f88e6fd2
commit ad558ed7ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.DBException;
import org.compiere.db.AdempiereDatabase;
import org.compiere.db.Database;
@ -54,7 +55,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
/**
*
*/
private static final long serialVersionUID = -1841918268550762201L;
private static final long serialVersionUID = 4379933682905553553L;
/**
* Get MColumn from Cache (immutable)
@ -128,6 +129,20 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
return table.getColumn(columnName);
} // get
/**
* Get MColumn given TableName and ColumnName
* @param ctx context
* @param TableName
* @param ColumnName
* @param TrxName
* @return MColumn
*/
public static MColumn get (Properties ctx, String tableName, String columnName, String trxName)
{
MTable table = MTable.get(ctx, tableName, trxName);
return table.getColumn(columnName);
} // get
public static String getColumnName (Properties ctx, int AD_Column_ID)
{
return getColumnName (ctx, AD_Column_ID, null);
@ -795,8 +810,13 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport
int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM AD_Ref_Table WHERE AD_Reference_ID=?", getAD_Reference_Value_ID());
if (cnt == 1) {
MRefTable rt = MRefTable.get(getCtx(), getAD_Reference_Value_ID(), get_TrxName());
if (rt != null)
foreignTable = rt.getAD_Table().getTableName();
if (rt != null) {
MTable table = MTable.get(getCtx(), rt.getAD_Table_ID(), get_TrxName());
if (table == null) {
throw new AdempiereException("Table " + rt.getAD_Table_ID() + " not found");
}
foreignTable = table.getTableName();
}
}
}
} else if (DisplayType.Button == refid) {

View File

@ -26,6 +26,7 @@ import java.util.logging.Level;
import javax.xml.transform.sax.TransformerHandler;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pipo2.AbstractElementHandler;
import org.adempiere.pipo2.Element;
import org.adempiere.pipo2.PIPOContext;
@ -182,9 +183,14 @@ public class ColumnElementHandler extends AbstractElementHandler {
}
private void deferFK(Element element, MColumn mColumn) {
String foreignTable = mColumn.getReferenceTableName();
if (foreignTable != null && ! "AD_Ref_List".equals(foreignTable))
try {
String foreignTable = mColumn.getReferenceTableName();
if (foreignTable != null && ! "AD_Ref_List".equals(foreignTable))
element.deferFKColumnID = mColumn.getAD_Column_ID();
} catch (AdempiereException e) {
// AdempiereException thrown in mColumn.getReferenceTableName() when the table is not created yet
element.deferFKColumnID = mColumn.getAD_Column_ID();
}
}
private void syncColumn(PIPOContext ctx, MColumn mColumn, String action,

View File

@ -186,11 +186,11 @@ public class PoFiller{
}
}
if (po.get_ColumnIndex(columnName) >= 0) {
MColumn col = MColumn.get(ctx.ctx, po.get_TableName(), columnName);
MColumn col = MColumn.get(ctx.ctx, po.get_TableName(), columnName, po.get_TrxName());
MTable foreignTable = null;
String refTableName = col.getReferenceTableName();
if (refTableName != null) {
foreignTable = MTable.get(Env.getCtx(), refTableName);
foreignTable = MTable.get(Env.getCtx(), refTableName, po.get_TrxName());
} else {
if ("Record_ID".equalsIgnoreCase(columnName)) {
// special case - get the foreign table using AD_Table_ID
@ -207,7 +207,7 @@ public class PoFiller{
}
}
if (tableID > 0) {
foreignTable = MTable.get(Env.getCtx(), tableID);
foreignTable = MTable.get(Env.getCtx(), tableID, po.get_TrxName());
refTableName = foreignTable.getTableName();
}
}