diff --git a/dbPort/src/org/compiere/model/MRole.java b/dbPort/src/org/compiere/model/MRole.java index 41702d8c43..89b9c3d567 100644 --- a/dbPort/src/org/compiere/model/MRole.java +++ b/dbPort/src/org/compiere/model/MRole.java @@ -533,6 +533,8 @@ public final class MRole extends X_AD_Role private HashMap m_tableName = null; /** View Name */ private Set m_viewName = null; + /** ID Column Name **/ + private HashMap m_tableIdName = null; /** Window Access */ private HashMap m_windowAccess = null; @@ -804,9 +806,11 @@ public final class MRole extends X_AD_Role return; m_tableAccessLevel = new HashMap(300); m_tableName = new HashMap(300); - m_viewName = new HashSet(300); + m_viewName = new HashSet(300); + m_tableIdName = new HashMap(300); PreparedStatement pstmt = null; - String sql = "SELECT AD_Table_ID, AccessLevel, TableName, IsView " + String sql = "SELECT AD_Table_ID, AccessLevel, TableName, IsView, " + + "(SELECT ColumnName FROM AD_COLUMN WHERE AD_COLUMN.AD_TABLE_ID = AD_TABLE.AD_TABLE_ID AND ISKEY='Y' AND COLUMNNAME LIKE '%ID') " + "FROM AD_Table WHERE IsActive='Y'"; try { @@ -821,7 +825,12 @@ public final class MRole extends X_AD_Role String isView = rs.getString(4); if ("Y".equals(isView)) { - m_viewName.add(tableName); + m_viewName.add(tableName.toUpperCase()); + } + String idColumn = rs.getString(5); + if (idColumn != null && idColumn.trim().length() > 0) + { + m_tableIdName.put(tableName.toUpperCase(), idColumn); } } rs.close(); @@ -852,7 +861,12 @@ public final class MRole extends X_AD_Role */ private boolean isView(String tableName) { - return m_viewName.contains(tableName); + return m_viewName.contains(tableName.toUpperCase()); + } + + private String getIdColumnName(String tableName) + { + return m_tableIdName.get(tableName.toUpperCase()); } /** @@ -1706,9 +1720,11 @@ public final class MRole extends X_AD_Role keyColumnName = TableName; keyColumnName += "."; } - keyColumnName += TableName + "_ID"; // derived from table + //keyColumnName += TableName + "_ID"; // derived from table + if (getIdColumnName(TableName) == null) continue; + keyColumnName += getIdColumnName(TableName); - // log.fine("addAccessSQL - " + TableName + "(" + AD_Table_ID + ") " + keyColumnName); + //log.fine("addAccessSQL - " + TableName + "(" + AD_Table_ID + ") " + keyColumnName); String recordWhere = getRecordWhere (AD_Table_ID, keyColumnName, rw); if (recordWhere.length() > 0) {