IDEMPIERE-4910 Performance - Discover of UUID column not cached in PO (#826)

This commit is contained in:
Carlos Ruiz 2021-08-12 16:14:46 +02:00 committed by GitHub
parent 184e8191e6
commit 729fc4a61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 39 deletions

View File

@ -3776,16 +3776,19 @@ public abstract class PO
//check whether db have working generate_uuid function. //check whether db have working generate_uuid function.
boolean uuidFunction = DB.isGenerateUUIDSupported(); boolean uuidFunction = DB.isGenerateUUIDSupported();
//uuid column String trlTableName = tableName + "_Trl";
int uuidColumnId = DB.getSQLValue(get_TrxName(), "SELECT col.AD_Column_ID FROM AD_Column col INNER JOIN AD_Table tbl ON col.AD_Table_ID = tbl.AD_Table_ID WHERE tbl.TableName=? AND col.ColumnName=?", MTable trlTable = MTable.get(getCtx(), trlTableName, get_TrxName());
tableName+"_Trl", PO.getUUIDColumnName(tableName+"_Trl")); if (trlTable == null) {
throw new AdempiereException("Translation table " + trlTableName + " does not exist");
}
MColumn uuidColumn = trlTable.getColumn(PO.getUUIDColumnName(trlTableName));
StringBuilder sql = new StringBuilder ("INSERT INTO ") StringBuilder sql = new StringBuilder ("INSERT INTO ")
.append(tableName).append("_Trl (AD_Language,") .append(tableName).append("_Trl (AD_Language,")
.append(keyColumn).append(", ") .append(keyColumn).append(", ")
.append(iColumns) .append(iColumns)
.append(" IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy"); .append(" IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy");
if (uuidColumnId > 0 && uuidFunction) if (uuidColumn != null && uuidFunction)
sql.append(",").append(PO.getUUIDColumnName(tableName+"_Trl")).append(" ) "); sql.append(",").append(PO.getUUIDColumnName(tableName+"_Trl")).append(" ) ");
else else
sql.append(" ) "); sql.append(" ) ");
@ -3793,7 +3796,7 @@ public abstract class PO
.append(keyColumn).append(", ") .append(keyColumn).append(", ")
.append(sColumns) .append(sColumns)
.append(" 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy"); .append(" 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy");
if (uuidColumnId > 0 && uuidFunction) if (uuidColumn != null && uuidFunction)
sql.append(",Generate_UUID() "); sql.append(",Generate_UUID() ");
else else
sql.append(" "); sql.append(" ");
@ -3804,9 +3807,8 @@ public abstract class PO
.append("_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.") .append("_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.")
.append(keyColumn).append("=t.").append(keyColumn).append(")"); .append(keyColumn).append("=t.").append(keyColumn).append(")");
int no = DB.executeUpdate(sql.toString(), m_trxName); int no = DB.executeUpdate(sql.toString(), m_trxName);
if (uuidColumnId > 0 && !uuidFunction) { if (uuidColumn != null && !uuidFunction) {
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName()); UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
UUIDGenerator.updateUUID(column, get_TrxName());
} }
if (log.isLoggable(Level.FINE)) log.fine("#" + no); if (log.isLoggable(Level.FINE)) log.fine("#" + no);
return no > 0; return no > 0;
@ -3958,16 +3960,16 @@ public abstract class PO
/** /**
* Insert Accounting Records * Insert Accounting Records
* @param acctTable accounting sub table * @param acctTableName accounting sub table
* @param acctBaseTable acct table to get data from * @param acctBaseTable acct table to get data from
* @param whereClause optional where clause with alias "p" for acctBaseTable * @param whereClause optional where clause with alias "p" for acctBaseTable
* @return true if records inserted * @return true if records inserted
*/ */
protected boolean insert_Accounting (String acctTable, protected boolean insert_Accounting (String acctTableName,
String acctBaseTable, String whereClause) String acctBaseTable, String whereClause)
{ {
if (s_acctColumns == null // cannot cache C_BP_*_Acct as there are 3 if (s_acctColumns == null // cannot cache C_BP_*_Acct as there are 3
|| acctTable.startsWith("C_BP_")) || acctTableName.startsWith("C_BP_"))
{ {
s_acctColumns = new ArrayList<String>(); s_acctColumns = new ArrayList<String>();
String sql = "SELECT c.ColumnName " String sql = "SELECT c.ColumnName "
@ -3978,14 +3980,14 @@ public abstract class PO
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setString (1, acctTable); pstmt.setString (1, acctTableName);
rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
s_acctColumns.add (rs.getString(1)); s_acctColumns.add (rs.getString(1));
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, acctTable, e); log.log(Level.SEVERE, acctTableName, e);
} }
finally { finally {
DB.close(rs, pstmt); DB.close(rs, pstmt);
@ -3993,14 +3995,14 @@ public abstract class PO
} }
if (s_acctColumns.size() == 0) if (s_acctColumns.size() == 0)
{ {
log.severe ("No Columns for " + acctTable); log.severe ("No Columns for " + acctTableName);
return false; return false;
} }
} }
// Create SQL Statement - INSERT // Create SQL Statement - INSERT
StringBuilder sb = new StringBuilder("INSERT INTO ") StringBuilder sb = new StringBuilder("INSERT INTO ")
.append(acctTable) .append(acctTableName)
.append(" (").append(get_TableName()) .append(" (").append(get_TableName())
.append("_ID, C_AcctSchema_ID, AD_Client_ID,AD_Org_ID,IsActive, Created,CreatedBy,Updated,UpdatedBy "); .append("_ID, C_AcctSchema_ID, AD_Client_ID,AD_Org_ID,IsActive, Created,CreatedBy,Updated,UpdatedBy ");
for (int i = 0; i < s_acctColumns.size(); i++) for (int i = 0; i < s_acctColumns.size(); i++)
@ -4009,26 +4011,27 @@ public abstract class PO
//check whether db have working generate_uuid function. //check whether db have working generate_uuid function.
boolean uuidFunction = DB.isGenerateUUIDSupported(); boolean uuidFunction = DB.isGenerateUUIDSupported();
//uuid column MTable acctTable = MTable.get(getCtx(), acctTableName, get_TrxName());
int uuidColumnId = DB.getSQLValue(get_TrxName(), "SELECT col.AD_Column_ID FROM AD_Column col INNER JOIN AD_Table tbl ON col.AD_Table_ID = tbl.AD_Table_ID WHERE tbl.TableName=? AND col.ColumnName=?", if (acctTableName == null) {
acctTable, PO.getUUIDColumnName(acctTable)); throw new AdempiereException("Accounting table " + acctTableName + " does not exist");
if (uuidColumnId > 0 && uuidFunction) }
sb.append(",").append(PO.getUUIDColumnName(acctTable)); MColumn uuidColumn = acctTable.getColumn(PO.getUUIDColumnName(acctTableName));
if (uuidColumn != null && uuidFunction)
sb.append(",").append(PO.getUUIDColumnName(acctTableName));
// .. SELECT // .. SELECT
sb.append(") SELECT ").append(get_ID()) sb.append(") SELECT ").append(get_ID())
.append(", p.C_AcctSchema_ID, p.AD_Client_ID,0,'Y', getDate(),") .append(", p.C_AcctSchema_ID, p.AD_Client_ID,0,'Y', getDate(),")
.append(getUpdatedBy()).append(",getDate(),").append(getUpdatedBy()); .append(getUpdatedBy()).append(",getDate(),").append(getUpdatedBy());
for (int i = 0; i < s_acctColumns.size(); i++) for (int i = 0; i < s_acctColumns.size(); i++)
sb.append(",p.").append(s_acctColumns.get(i)); sb.append(",p.").append(s_acctColumns.get(i));
//uuid column if (uuidColumn != null && uuidFunction)
if (uuidColumnId > 0 && uuidFunction)
sb.append(",generate_uuid()"); sb.append(",generate_uuid()");
// .. FROM // .. FROM
sb.append(" FROM ").append(acctBaseTable) sb.append(" FROM ").append(acctBaseTable)
.append(" p WHERE p.AD_Client_ID=").append(getAD_Client_ID()); .append(" p WHERE p.AD_Client_ID=").append(getAD_Client_ID());
if (whereClause != null && whereClause.length() > 0) if (whereClause != null && whereClause.length() > 0)
sb.append (" AND ").append(whereClause); sb.append (" AND ").append(whereClause);
sb.append(" AND NOT EXISTS (SELECT * FROM ").append(acctTable) sb.append(" AND NOT EXISTS (SELECT * FROM ").append(acctTableName)
.append(" e WHERE e.C_AcctSchema_ID=p.C_AcctSchema_ID AND e.") .append(" e WHERE e.C_AcctSchema_ID=p.C_AcctSchema_ID AND e.")
.append(get_TableName()).append("_ID=").append(get_ID()).append(")"); .append(get_TableName()).append("_ID=").append(get_ID()).append(")");
// //
@ -4037,13 +4040,12 @@ public abstract class PO
if (log.isLoggable(Level.FINE)) log.fine("#" + no); if (log.isLoggable(Level.FINE)) log.fine("#" + no);
} else { } else {
log.warning("#" + no log.warning("#" + no
+ " - Table=" + acctTable + " from " + acctBaseTable); + " - Table=" + acctTableName + " from " + acctBaseTable);
} }
//fall back to the slow java client update code //fall back to the slow java client update code
if (uuidColumnId > 0 && !uuidFunction) { if (uuidColumn != null && !uuidFunction) {
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName()); UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
UUIDGenerator.updateUUID(column, get_TrxName());
} }
return no > 0; return no > 0;
} // insert_Accounting } // insert_Accounting
@ -4079,26 +4081,28 @@ public abstract class PO
*/ */
protected boolean insert_Tree (String treeType, int C_Element_ID) protected boolean insert_Tree (String treeType, int C_Element_ID)
{ {
String tableName = MTree_Base.getNodeTableName(treeType); String treeTableName = MTree_Base.getNodeTableName(treeType);
//check whether db have working generate_uuid function. //check whether db have working generate_uuid function.
boolean uuidFunction = DB.isGenerateUUIDSupported(); boolean uuidFunction = DB.isGenerateUUIDSupported();
//uuid column MTable treeTable = MTable.get(getCtx(), treeTableName, get_TrxName());
int uuidColumnId = DB.getSQLValue(get_TrxName(), "SELECT col.AD_Column_ID FROM AD_Column col INNER JOIN AD_Table tbl ON col.AD_Table_ID = tbl.AD_Table_ID WHERE tbl.TableName=? AND col.ColumnName=?", if (treeTable == null) {
tableName, PO.getUUIDColumnName(tableName)); throw new AdempiereException("Tree table " + treeTableName + " does not exist");
}
MColumn uuidColumn = treeTable.getColumn(PO.getUUIDColumnName(treeTableName));
StringBuilder sb = new StringBuilder ("INSERT INTO ") StringBuilder sb = new StringBuilder ("INSERT INTO ")
.append(tableName) .append(treeTableName)
.append(" (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, " .append(" (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, "
+ "AD_Tree_ID, Node_ID, Parent_ID, SeqNo"); + "AD_Tree_ID, Node_ID, Parent_ID, SeqNo");
if (uuidColumnId > 0 && uuidFunction) if (uuidColumn != null && uuidFunction)
sb.append(", ").append(PO.getUUIDColumnName(tableName)).append(") "); sb.append(", ").append(PO.getUUIDColumnName(treeTableName)).append(") ");
else else
sb.append(") "); sb.append(") ");
sb.append("SELECT t.AD_Client_ID, 0, 'Y', getDate(), "+getUpdatedBy()+", getDate(), "+getUpdatedBy()+"," sb.append("SELECT t.AD_Client_ID, 0, 'Y', getDate(), "+getUpdatedBy()+", getDate(), "+getUpdatedBy()+","
+ "t.AD_Tree_ID, ").append(get_ID()).append(", 0, 999"); + "t.AD_Tree_ID, ").append(get_ID()).append(", 0, 999");
if (uuidColumnId > 0 && uuidFunction) if (uuidColumn != null && uuidFunction)
sb.append(", Generate_UUID() "); sb.append(", Generate_UUID() ");
else else
sb.append(" "); sb.append(" ");
@ -4123,10 +4127,8 @@ public abstract class PO
log.warning("#" + no + " - TreeType=" + treeType); log.warning("#" + no + " - TreeType=" + treeType);
} }
if (uuidColumnId > 0 && !uuidFunction ) if (uuidColumn != null && !uuidFunction ) {
{ UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName());
UUIDGenerator.updateUUID(column, get_TrxName());
} }
return no > 0; return no > 0;
} // insert_Tree } // insert_Tree