IDEMPIERE-4910 Performance - Discover of UUID column not cached in PO (#826)
This commit is contained in:
parent
184e8191e6
commit
729fc4a61e
|
@ -3776,16 +3776,19 @@ public abstract class PO
|
|||
//check whether db have working generate_uuid function.
|
||||
boolean uuidFunction = DB.isGenerateUUIDSupported();
|
||||
|
||||
//uuid column
|
||||
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=?",
|
||||
tableName+"_Trl", PO.getUUIDColumnName(tableName+"_Trl"));
|
||||
String trlTableName = tableName + "_Trl";
|
||||
MTable trlTable = MTable.get(getCtx(), trlTableName, get_TrxName());
|
||||
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 ")
|
||||
.append(tableName).append("_Trl (AD_Language,")
|
||||
.append(keyColumn).append(", ")
|
||||
.append(iColumns)
|
||||
.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(" ) ");
|
||||
else
|
||||
sql.append(" ) ");
|
||||
|
@ -3793,7 +3796,7 @@ public abstract class PO
|
|||
.append(keyColumn).append(", ")
|
||||
.append(sColumns)
|
||||
.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() ");
|
||||
else
|
||||
sql.append(" ");
|
||||
|
@ -3804,9 +3807,8 @@ public abstract class PO
|
|||
.append("_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.")
|
||||
.append(keyColumn).append("=t.").append(keyColumn).append(")");
|
||||
int no = DB.executeUpdate(sql.toString(), m_trxName);
|
||||
if (uuidColumnId > 0 && !uuidFunction) {
|
||||
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName());
|
||||
UUIDGenerator.updateUUID(column, get_TrxName());
|
||||
if (uuidColumn != null && !uuidFunction) {
|
||||
UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
|
||||
}
|
||||
if (log.isLoggable(Level.FINE)) log.fine("#" + no);
|
||||
return no > 0;
|
||||
|
@ -3958,16 +3960,16 @@ public abstract class PO
|
|||
|
||||
/**
|
||||
* Insert Accounting Records
|
||||
* @param acctTable accounting sub table
|
||||
* @param acctTableName accounting sub table
|
||||
* @param acctBaseTable acct table to get data from
|
||||
* @param whereClause optional where clause with alias "p" for acctBaseTable
|
||||
* @return true if records inserted
|
||||
*/
|
||||
protected boolean insert_Accounting (String acctTable,
|
||||
protected boolean insert_Accounting (String acctTableName,
|
||||
String acctBaseTable, String whereClause)
|
||||
{
|
||||
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>();
|
||||
String sql = "SELECT c.ColumnName "
|
||||
|
@ -3978,14 +3980,14 @@ public abstract class PO
|
|||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
pstmt.setString (1, acctTable);
|
||||
pstmt.setString (1, acctTableName);
|
||||
rs = pstmt.executeQuery ();
|
||||
while (rs.next ())
|
||||
s_acctColumns.add (rs.getString(1));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, acctTable, e);
|
||||
log.log(Level.SEVERE, acctTableName, e);
|
||||
}
|
||||
finally {
|
||||
DB.close(rs, pstmt);
|
||||
|
@ -3993,14 +3995,14 @@ public abstract class PO
|
|||
}
|
||||
if (s_acctColumns.size() == 0)
|
||||
{
|
||||
log.severe ("No Columns for " + acctTable);
|
||||
log.severe ("No Columns for " + acctTableName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Create SQL Statement - INSERT
|
||||
StringBuilder sb = new StringBuilder("INSERT INTO ")
|
||||
.append(acctTable)
|
||||
.append(acctTableName)
|
||||
.append(" (").append(get_TableName())
|
||||
.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++)
|
||||
|
@ -4009,26 +4011,27 @@ public abstract class PO
|
|||
//check whether db have working generate_uuid function.
|
||||
boolean uuidFunction = DB.isGenerateUUIDSupported();
|
||||
|
||||
//uuid column
|
||||
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=?",
|
||||
acctTable, PO.getUUIDColumnName(acctTable));
|
||||
if (uuidColumnId > 0 && uuidFunction)
|
||||
sb.append(",").append(PO.getUUIDColumnName(acctTable));
|
||||
MTable acctTable = MTable.get(getCtx(), acctTableName, get_TrxName());
|
||||
if (acctTableName == null) {
|
||||
throw new AdempiereException("Accounting table " + acctTableName + " does not exist");
|
||||
}
|
||||
MColumn uuidColumn = acctTable.getColumn(PO.getUUIDColumnName(acctTableName));
|
||||
if (uuidColumn != null && uuidFunction)
|
||||
sb.append(",").append(PO.getUUIDColumnName(acctTableName));
|
||||
// .. SELECT
|
||||
sb.append(") SELECT ").append(get_ID())
|
||||
.append(", p.C_AcctSchema_ID, p.AD_Client_ID,0,'Y', getDate(),")
|
||||
.append(getUpdatedBy()).append(",getDate(),").append(getUpdatedBy());
|
||||
for (int i = 0; i < s_acctColumns.size(); i++)
|
||||
sb.append(",p.").append(s_acctColumns.get(i));
|
||||
//uuid column
|
||||
if (uuidColumnId > 0 && uuidFunction)
|
||||
if (uuidColumn != null && uuidFunction)
|
||||
sb.append(",generate_uuid()");
|
||||
// .. FROM
|
||||
sb.append(" FROM ").append(acctBaseTable)
|
||||
.append(" p WHERE p.AD_Client_ID=").append(getAD_Client_ID());
|
||||
if (whereClause != null && whereClause.length() > 0)
|
||||
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(get_TableName()).append("_ID=").append(get_ID()).append(")");
|
||||
//
|
||||
|
@ -4037,13 +4040,12 @@ public abstract class PO
|
|||
if (log.isLoggable(Level.FINE)) log.fine("#" + no);
|
||||
} else {
|
||||
log.warning("#" + no
|
||||
+ " - Table=" + acctTable + " from " + acctBaseTable);
|
||||
+ " - Table=" + acctTableName + " from " + acctBaseTable);
|
||||
}
|
||||
|
||||
//fall back to the slow java client update code
|
||||
if (uuidColumnId > 0 && !uuidFunction) {
|
||||
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName());
|
||||
UUIDGenerator.updateUUID(column, get_TrxName());
|
||||
if (uuidColumn != null && !uuidFunction) {
|
||||
UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
|
||||
}
|
||||
return no > 0;
|
||||
} // insert_Accounting
|
||||
|
@ -4079,26 +4081,28 @@ public abstract class PO
|
|||
*/
|
||||
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.
|
||||
boolean uuidFunction = DB.isGenerateUUIDSupported();
|
||||
|
||||
//uuid column
|
||||
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=?",
|
||||
tableName, PO.getUUIDColumnName(tableName));
|
||||
MTable treeTable = MTable.get(getCtx(), treeTableName, get_TrxName());
|
||||
if (treeTable == null) {
|
||||
throw new AdempiereException("Tree table " + treeTableName + " does not exist");
|
||||
}
|
||||
MColumn uuidColumn = treeTable.getColumn(PO.getUUIDColumnName(treeTableName));
|
||||
|
||||
StringBuilder sb = new StringBuilder ("INSERT INTO ")
|
||||
.append(tableName)
|
||||
.append(treeTableName)
|
||||
.append(" (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, "
|
||||
+ "AD_Tree_ID, Node_ID, Parent_ID, SeqNo");
|
||||
if (uuidColumnId > 0 && uuidFunction)
|
||||
sb.append(", ").append(PO.getUUIDColumnName(tableName)).append(") ");
|
||||
if (uuidColumn != null && uuidFunction)
|
||||
sb.append(", ").append(PO.getUUIDColumnName(treeTableName)).append(") ");
|
||||
else
|
||||
sb.append(") ");
|
||||
sb.append("SELECT t.AD_Client_ID, 0, 'Y', getDate(), "+getUpdatedBy()+", getDate(), "+getUpdatedBy()+","
|
||||
+ "t.AD_Tree_ID, ").append(get_ID()).append(", 0, 999");
|
||||
if (uuidColumnId > 0 && uuidFunction)
|
||||
if (uuidColumn != null && uuidFunction)
|
||||
sb.append(", Generate_UUID() ");
|
||||
else
|
||||
sb.append(" ");
|
||||
|
@ -4123,10 +4127,8 @@ public abstract class PO
|
|||
log.warning("#" + no + " - TreeType=" + treeType);
|
||||
}
|
||||
|
||||
if (uuidColumnId > 0 && !uuidFunction )
|
||||
{
|
||||
MColumn column = new MColumn(getCtx(), uuidColumnId, get_TrxName());
|
||||
UUIDGenerator.updateUUID(column, get_TrxName());
|
||||
if (uuidColumn != null && !uuidFunction ) {
|
||||
UUIDGenerator.updateUUID(uuidColumn, get_TrxName());
|
||||
}
|
||||
return no > 0;
|
||||
} // insert_Tree
|
||||
|
|
Loading…
Reference in New Issue