IDEMPIERE-6102 Performance: avoid SQL on AD_TreeNode when the table doesn't have a custom tree (#2309)
This commit is contained in:
parent
7cd0c88e3a
commit
fb594a5f56
|
|
@ -67,7 +67,11 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -167824144142429242L;
|
private static final long serialVersionUID = -2459194178797758731L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public final static int MAX_OFFICIAL_ID = 999999;
|
public final static int MAX_OFFICIAL_ID = 999999;
|
||||||
|
|
||||||
|
|
@ -1098,6 +1102,20 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
|
||||||
return indexName.toString();
|
return indexName.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Boolean hasCustomTree = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the table has a custom tree defined
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean hasCustomTree() {
|
||||||
|
if (hasCustomTree == null) {
|
||||||
|
int exists = DB.getSQLValueEx(get_TrxName(), "SELECT 1 FROM AD_Tree WHERE TreeType=? AND AD_Table_ID=? AND IsActive='Y'", MTree_Base.TREETYPE_CustomTable, getAD_Table_ID());
|
||||||
|
hasCustomTree = Boolean.valueOf(exists == 1);
|
||||||
|
}
|
||||||
|
return hasCustomTree.booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Partition Name of the table of the given level
|
* Get Partition Name of the table of the given level
|
||||||
* @param tableName
|
* @param tableName
|
||||||
|
|
|
||||||
|
|
@ -2641,10 +2641,10 @@ public abstract class PO
|
||||||
|
|
||||||
// table with potential tree
|
// table with potential tree
|
||||||
if (get_ColumnIndex("IsSummary") >= 0) {
|
if (get_ColumnIndex("IsSummary") >= 0) {
|
||||||
if (newRecord)
|
if (newRecord && getTable().hasCustomTree())
|
||||||
insert_Tree(MTree_Base.TREETYPE_CustomTable);
|
insert_Tree(MTree_Base.TREETYPE_CustomTable);
|
||||||
int idxValue = get_ColumnIndex("Value");
|
int idxValue = get_ColumnIndex("Value");
|
||||||
if (newRecord || (idxValue >= 0 && is_ValueChanged(idxValue)))
|
if (getTable().hasCustomTree() && (newRecord || (idxValue >= 0 && is_ValueChanged(idxValue))))
|
||||||
update_Tree(MTree_Base.TREETYPE_CustomTable);
|
update_Tree(MTree_Base.TREETYPE_CustomTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2749,8 +2749,16 @@ public abstract class PO
|
||||||
} // saveFinish
|
} // saveFinish
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Value or create new record.
|
* Get the MTable object associated to this PO
|
||||||
* To reload call load() - not updated
|
* @return MTable
|
||||||
|
*/
|
||||||
|
private MTable getTable() {
|
||||||
|
return MTable.get(getCtx(), get_TableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update or insert new record.<br/>
|
||||||
|
* To reload call load().
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
* @return true if saved
|
* @return true if saved
|
||||||
*/
|
*/
|
||||||
|
|
@ -4063,7 +4071,7 @@ public abstract class PO
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
deleteTranslations(localTrxName);
|
deleteTranslations(localTrxName);
|
||||||
if (get_ColumnIndex("IsSummary") >= 0) {
|
if (get_ColumnIndex("IsSummary") >= 0 && getTable().hasCustomTree()) {
|
||||||
delete_Tree(MTree_Base.TREETYPE_CustomTable);
|
delete_Tree(MTree_Base.TREETYPE_CustomTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue