IDEMPIERE-4254 get oracle error ORA-01795 when has more than 1000 org (#109)

This commit is contained in:
Carlos Ruiz 2020-06-09 18:26:44 +02:00 committed by GitHub
parent 940885c38c
commit 10771a7408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -1137,17 +1137,22 @@ public final class MRole extends X_AD_Role
// //
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Iterator<String> it = set.iterator(); Iterator<String> it = set.iterator();
boolean oneOnly = true; final int MAX_ORACLE_ELEMENTS_IN_ORACLE = 1000;
int idx = 0;
while (it.hasNext()) while (it.hasNext())
{ {
idx++;
if (sb.length() > 0) if (sb.length() > 0)
{ {
sb.append(","); if (DB.isOracle() && (idx-1) % MAX_ORACLE_ELEMENTS_IN_ORACLE == 0) { // prevent ORA-01795
oneOnly = false; sb.append(") OR AD_Org_ID IN (");
} else {
sb.append(",");
}
} }
sb.append(it.next()); sb.append(it.next());
} }
if (oneOnly) if (sb.indexOf(",") < 0) // only one org
{ {
if (sb.length() > 0) if (sb.length() > 0)
return "AD_Org_ID=" + sb.toString(); return "AD_Org_ID=" + sb.toString();
@ -1157,8 +1162,8 @@ public final class MRole extends X_AD_Role
return "AD_Org_ID=-1"; // No Access Record return "AD_Org_ID=-1"; // No Access Record
} }
} }
return "AD_Org_ID IN(" + sb.toString() + ")"; return "(AD_Org_ID IN (" + sb.toString() + "))";
} // getOrgWhereValue } // getOrgWhere
/** /**
* Access to Org * Access to Org
@ -1997,9 +2002,10 @@ public final class MRole extends X_AD_Role
if (!isAccessAllOrgs()) if (!isAccessAllOrgs())
{ {
retSQL.append(" AND "); retSQL.append(" AND ");
String orgWhere = getOrgWhere(rw);
if (fullyQualified) if (fullyQualified)
retSQL.append(tableName).append("."); orgWhere = orgWhere.replaceAll("AD_Org_ID", tableName + ".AD_Org_ID");
retSQL.append(getOrgWhere(rw)); retSQL.append(orgWhere);
} }
} else { } else {
retSQL.append("1=1"); retSQL.append("1=1");

View File

@ -428,7 +428,8 @@ public class InvoicePrint extends SvrProcess
} }
String orgWhere = MRole.getDefault(getCtx(), false).getOrgWhere(MRole.SQL_RO); String orgWhere = MRole.getDefault(getCtx(), false).getOrgWhere(MRole.SQL_RO);
if (!Util.isEmpty(orgWhere, true)) { if (!Util.isEmpty(orgWhere, true)) {
sql.append(" AND i."); orgWhere = orgWhere.replaceAll("AD_Org_ID", "i.AD_Org_ID");
sql.append(" AND ");
sql.append(orgWhere); sql.append(orgWhere);
} }
sql.append(" ORDER BY i.C_Invoice_ID, pf.AD_Org_ID DESC"); // more than 1 PF record sql.append(" ORDER BY i.C_Invoice_ID, pf.AD_Org_ID DESC"); // more than 1 PF record