IDEMPIERE-4746 Wrong usage of MTable.getColumnIndex (#640)

* IDEMPIERE-4746 Wrong usage of MTable.getColumnIndex

* Implementing suggestion from Andreas Sumerauer
* Fix issue in IDEMPIERE-3916 (Move Client) and IDEMPIERE-1026 (Create Window from Table)

* IDEMPIERE-4746 Wrong usage of MTable.getColumnIndex

* Change approach to discover real columns

* * Rename method as suggested by Andreas Sumerauer
This commit is contained in:
Carlos Ruiz 2021-04-07 15:34:37 +02:00 committed by GitHub
parent 44edbf4b07
commit 1a5eb5ce22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 20 deletions

View File

@ -122,8 +122,7 @@ public class CreateWindowFromTable extends SvrProcess
MWindow window; MWindow window;
int tabSeqNo = 0; int tabSeqNo = 0;
if (p_isNewWindow) { if (p_isNewWindow) {
if (MWindow.WINDOWTYPE_Transaction.equals(p_WindowType) && if (MWindow.WINDOWTYPE_Transaction.equals(p_WindowType) && ! table.columnExistsInDB("Processed"))
table.getColumnIndex("Processed") <= 0)
throw new AdempiereException(Msg.getMsg(getCtx(), "TrxWindowMandatoryProcessed")); throw new AdempiereException(Msg.getMsg(getCtx(), "TrxWindowMandatoryProcessed"));
int i = DB.getSQLValue(get_TrxName(), "SELECT 1 FROM AD_Window WHERE AD_Window.name = ?", table.getName()); int i = DB.getSQLValue(get_TrxName(), "SELECT 1 FROM AD_Window WHERE AD_Window.name = ?", table.getName());
@ -183,9 +182,9 @@ public class CreateWindowFromTable extends SvrProcess
tab.setIsSingleRow(true); //Default tab.setIsSingleRow(true); //Default
//Set order by //Set order by
if (table.getColumnIndex("Value") > 0 && !table.getColumn("Value").isVirtualColumn()) if (table.columnExistsInDB("Value"))
tab.setOrderByClause(table.getTableName() + ".Value"); tab.setOrderByClause(table.getTableName() + ".Value");
else if (table.getColumnIndex("Name") > 0 && !table.getColumn("Name").isVirtualColumn()) else if (table.columnExistsInDB("Name"))
tab.setOrderByClause(table.getTableName() + ".Name"); tab.setOrderByClause(table.getTableName() + ".Name");
else else
tab.setOrderByClause(table.getTableName() + ".Created DESC"); tab.setOrderByClause(table.getTableName() + ".Created DESC");

View File

@ -165,7 +165,7 @@ public class GenericZoomProvider implements IZoomProvider {
final MQuery query = new MQuery(); final MQuery query = new MQuery();
MTable table = MTable.get(ctx, targetTableName); MTable table = MTable.get(ctx, targetTableName);
if (table.getColumnIndex("AD_Client_ID") < 0) // table doesn't have AD_Client_ID if (! table.columnExistsInDB("AD_Client_ID")) // table doesn't have AD_Client_ID
return null; return null;
int tabIDLoop = AD_Tab_ID; int tabIDLoop = AD_Tab_ID;

View File

@ -67,7 +67,7 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
/** /**
* *
*/ */
private static final long serialVersionUID = 2951110137945905890L; private static final long serialVersionUID = -7981455044208282721L;
public final static int MAX_OFFICIAL_ID = 999999; public final static int MAX_OFFICIAL_ID = 999999;
@ -384,14 +384,10 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
{ {
if (columnName == null || columnName.length() == 0) if (columnName == null || columnName.length() == 0)
return null; return null;
getColumns(false); int idx = getColumnIndex(columnName);
// if (idx < 0)
for (int i = 0; i < m_columns.length; i++) return null;
{ return m_columns[idx];
if (columnName.equalsIgnoreCase(m_columns[i].getColumnName()))
return m_columns[i];
}
return null;
} // getColumn } // getColumn
/** /**
@ -410,6 +406,27 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
return -1; return -1;
} // getColumnIndex } // getColumnIndex
/**
* Column exists and is not virtual?
* @param ColumnName column name
* @return boolean - true indicating that the column exists in the table and is not virtual
*/
public synchronized boolean columnExistsInDB (String ColumnName)
{
MColumn column = getColumn(ColumnName);
return column != null && ! column.isVirtualColumn();
} // columnExistsInDB
/**
* Column exists?
* @param ColumnName column name
* @return boolean - true indicating that the column exists in dictionary
*/
public synchronized boolean columnExistsInDictionary (String ColumnName)
{
return getColumnIndex(ColumnName) >= 0;
} // columnExistsInDictionary
/** /**
* Get Column Index * Get Column Index
* @param AD_Column_ID column * @param AD_Column_ID column
@ -425,7 +442,7 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
return -1; return -1;
} // getColumnIndex } // getColumnIndex
/** /**
* Table has a single Key * Table has a single Key
* @return true if table has single key column * @return true if table has single key column

View File

@ -406,12 +406,12 @@ public class MTree_Base extends X_AD_Tree implements ImmutablePOSupport
String tableName = getSourceTableName(true); String tableName = getSourceTableName(true);
MTable table = MTable.get(getCtx(), tableName); MTable table = MTable.get(getCtx(), tableName);
if (table.getColumnIndex("IsSummary") < 0) { if (! table.columnExistsInDB("IsSummary")) {
// IsSummary is mandatory column to have a tree // IsSummary is mandatory column to have a tree
log.saveError("Error", "IsSummary column required for tree tables"); log.saveError("Error", "IsSummary column required for tree tables");
return false; return false;
} }
if (table.getColumnIndex("Value") < 0) { if (! table.columnExistsInDB("Value")) {
if (isTreeDrivenByValue()) { if (isTreeDrivenByValue()) {
// Value is mandatory column to have a tree driven by Value // Value is mandatory column to have a tree driven by Value
setIsTreeDrivenByValue(false); setIsTreeDrivenByValue(false);

View File

@ -831,7 +831,7 @@ public class MoveClient extends SvrProcess {
|| "AD_Language".equalsIgnoreCase(columnName) || "AD_Language".equalsIgnoreCase(columnName)
|| "EntityType".equalsIgnoreCase(columnName))) { || "EntityType".equalsIgnoreCase(columnName))) {
convertTable = ""; convertTable = "";
} else if ("Record_ID".equalsIgnoreCase(columnName) && table.getColumnIndex("AD_Table_ID") > 0) { } else if ("Record_ID".equalsIgnoreCase(columnName) && table.columnExistsInDB("AD_Table_ID")) {
// Special case for Record_ID // Special case for Record_ID
int tableId = rsGD.getInt("AD_Table_ID"); int tableId = rsGD.getInt("AD_Table_ID");
if (tableId > 0) { if (tableId > 0) {
@ -920,7 +920,7 @@ public class MoveClient extends SvrProcess {
// not found in the table - try to get it again - could be missed in first pass // not found in the table - try to get it again - could be missed in first pass
convertedId = getLocalIDFor(convertTable, id, tableName); convertedId = getLocalIDFor(convertTable, id, tableName);
if (convertedId < 0) { if (convertedId < 0) {
if (("Record_ID".equalsIgnoreCase(columnName) && table.getColumnIndex("AD_Table_ID") > 0) if (("Record_ID".equalsIgnoreCase(columnName) && table.columnExistsInDB("AD_Table_ID"))
|| (("Node_ID".equalsIgnoreCase(columnName) || "Parent_ID".equalsIgnoreCase(columnName)) || (("Node_ID".equalsIgnoreCase(columnName) || "Parent_ID".equalsIgnoreCase(columnName))
&& ( "AD_TreeNode".equalsIgnoreCase(tableName) && ( "AD_TreeNode".equalsIgnoreCase(tableName)
|| "AD_TreeNodeMM".equalsIgnoreCase(tableName) || "AD_TreeNodeMM".equalsIgnoreCase(tableName)

View File

@ -241,7 +241,7 @@ ContextMenuListener, IZoomableEditor
if (lookup != null && (lookup.getDisplayType() == DisplayType.TableDir || lookup.getDisplayType() == DisplayType.Table)) // only for Table & TableDir if (lookup != null && (lookup.getDisplayType() == DisplayType.TableDir || lookup.getDisplayType() == DisplayType.Table)) // only for Table & TableDir
{ {
MTable table = MTable.get(Env.getCtx(), tableName); MTable table = MTable.get(Env.getCtx(), tableName);
isShortListAvailable = (table.getColumnIndex("IsShortList") >= 0); isShortListAvailable = table.columnExistsInDB("IsShortList");
if (isShortListAvailable) if (isShortListAvailable)
{ {
onlyShortListItems=true; onlyShortListItems=true;