IDEMPIERE-3635 Cache getLookupInfo method to avoid multiple queries execution
This commit is contained in:
parent
45e1f0c654
commit
969d02f63c
|
@ -1312,9 +1312,8 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
public void setLinkColumnName (String linkColumnName)
|
public void setLinkColumnName (String linkColumnName)
|
||||||
{
|
{
|
||||||
// set parent column name
|
// set parent column name
|
||||||
String sql = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
|
|
||||||
if (m_vo.Parent_Column_ID > 0)
|
if (m_vo.Parent_Column_ID > 0)
|
||||||
m_parentColumnName = DB.getSQLValueString(null, sql, m_vo.Parent_Column_ID );
|
m_parentColumnName = MColumn.getColumnName(m_vo.ctx, m_vo.Parent_Column_ID);
|
||||||
if ( m_parentColumnName == null )
|
if ( m_parentColumnName == null )
|
||||||
m_parentColumnName = "";
|
m_parentColumnName = "";
|
||||||
|
|
||||||
|
@ -1329,27 +1328,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
||||||
// we have a link column identified (primary parent column)
|
// we have a link column identified (primary parent column)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String SQL = "SELECT ColumnName FROM AD_Column WHERE AD_Column_ID=?";
|
m_linkColumnName = MColumn.getColumnName(m_vo.ctx, m_vo.AD_Column_ID); // Parent Link Column
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(SQL, null);
|
|
||||||
pstmt.setInt(1, m_vo.AD_Column_ID); // Parent Link Column
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
m_linkColumnName = rs.getString(1);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("AD_Column_ID=" + m_vo.AD_Column_ID + " - " + m_linkColumnName);
|
if (log.isLoggable(Level.FINE)) log.fine("AD_Column_ID=" + m_vo.AD_Column_ID + " - " + m_linkColumnName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,42 +91,18 @@ public class MLookupFactory
|
||||||
|
|
||||||
public static MLookupInfo getLookupInfo(Properties ctx, int WindowNo, int TabNo, int Column_ID, int AD_Reference_ID)
|
public static MLookupInfo getLookupInfo(Properties ctx, int WindowNo, int TabNo, int Column_ID, int AD_Reference_ID)
|
||||||
{
|
{
|
||||||
String ColumnName = "";
|
MColumn column = MColumn.get(ctx, Column_ID);
|
||||||
int AD_Reference_Value_ID = 0;
|
if (column.get_ID() == 0)
|
||||||
boolean IsParent = false;
|
s_log.log(Level.SEVERE, "Column Not Found - AD_Column_ID=" + Column_ID);
|
||||||
|
|
||||||
|
String ColumnName = column.getColumnName();
|
||||||
|
int AD_Reference_Value_ID = column.getAD_Reference_Value_ID();
|
||||||
|
boolean IsParent = column.isParent();
|
||||||
String ValidationCode = "";
|
String ValidationCode = "";
|
||||||
//
|
|
||||||
String sql = "SELECT c.ColumnName, c.AD_Reference_Value_ID, c.IsParent, vr.Code "
|
if (column.getAD_Val_Rule_ID() > 0) {
|
||||||
+ "FROM AD_Column c"
|
MValRule valRule = MValRule.get(ctx, column.getAD_Val_Rule_ID());
|
||||||
+ " LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID) "
|
ValidationCode = valRule.getCode();
|
||||||
+ "WHERE c.AD_Column_ID=?";
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
|
||||||
pstmt.setInt(1, Column_ID);
|
|
||||||
//
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
{
|
|
||||||
ColumnName = rs.getString(1);
|
|
||||||
AD_Reference_Value_ID = rs.getInt(2);
|
|
||||||
IsParent = "Y".equals(rs.getString(3));
|
|
||||||
ValidationCode = rs.getString(4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
s_log.log(Level.SEVERE, "Column Not Found - AD_Column_ID=" + Column_ID);
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, "create", ex);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
MLookupInfo info = getLookupInfo (ctx, WindowNo, TabNo, Column_ID, AD_Reference_ID,
|
MLookupInfo info = getLookupInfo (ctx, WindowNo, TabNo, Column_ID, AD_Reference_ID,
|
||||||
|
@ -993,41 +969,12 @@ public class MLookupFactory
|
||||||
} // getLookup_TableDirEmbed
|
} // getLookup_TableDirEmbed
|
||||||
|
|
||||||
private static ArrayList<LookupDisplayColumn> getListIdentifiers(String TableName) {
|
private static ArrayList<LookupDisplayColumn> getListIdentifiers(String TableName) {
|
||||||
// get display column name (first identifier column)
|
|
||||||
String sql = "SELECT c.ColumnName,c.IsTranslated,c.AD_Reference_ID,c.AD_Reference_Value_ID "
|
|
||||||
+ ", c.ColumnSQL " // 5
|
|
||||||
+ "FROM AD_Table t INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID) "
|
|
||||||
+ "WHERE TableName=?"
|
|
||||||
+ " AND c.IsIdentifier='Y' "
|
|
||||||
+ "ORDER BY c.SeqNo";
|
|
||||||
//
|
|
||||||
ArrayList<LookupDisplayColumn> list = new ArrayList<LookupDisplayColumn>();
|
ArrayList<LookupDisplayColumn> list = new ArrayList<LookupDisplayColumn>();
|
||||||
//
|
MTable table = MTable.get(Env.getCtx(), TableName);
|
||||||
PreparedStatement pstmt = null;
|
for (String idColumnName : table.getIdentifierColumns()) {
|
||||||
ResultSet rs = null;
|
MColumn column = table.getColumn(idColumnName);
|
||||||
try
|
LookupDisplayColumn ldc = new LookupDisplayColumn(column.getColumnName(), column.getColumnSQL(), column.isTranslated(), column.getAD_Reference_ID(), column.getAD_Reference_Value_ID());
|
||||||
{
|
list.add (ldc);
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
|
||||||
pstmt.setString(1, TableName);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
LookupDisplayColumn ldc = new LookupDisplayColumn (rs.getString(1),
|
|
||||||
rs.getString(5),
|
|
||||||
"Y".equals(rs.getString(2)), rs.getInt(3), rs.getInt(4));
|
|
||||||
list.add (ldc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, sql, e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.compiere.model;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,6 +35,7 @@ import org.adempiere.model.GenericPO;
|
||||||
import org.compiere.util.CCache;
|
import org.compiere.util.CCache;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.KeyNamePair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persistent Table Model
|
* Persistent Table Model
|
||||||
|
@ -356,19 +359,26 @@ public class MTable extends X_AD_Table
|
||||||
* Get Identifier Columns of Table
|
* Get Identifier Columns of Table
|
||||||
* @return Identifier columns
|
* @return Identifier columns
|
||||||
*/
|
*/
|
||||||
public String[] getIdentifierColumns()
|
public String[] getIdentifierColumns() {
|
||||||
{
|
ArrayList<KeyNamePair> listkn = new ArrayList<KeyNamePair>();
|
||||||
getColumns(false);
|
for (MColumn column : getColumns(false)) {
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
|
||||||
//
|
|
||||||
for (int i = 0; i < m_columns.length; i++)
|
|
||||||
{
|
|
||||||
MColumn column = m_columns[i];
|
|
||||||
if (column.isIdentifier())
|
if (column.isIdentifier())
|
||||||
list.add(column.getColumnName());
|
listkn.add(new KeyNamePair(column.getSeqNo(), column.getColumnName()));
|
||||||
|
}
|
||||||
|
// Order by SeqNo
|
||||||
|
Collections.sort(listkn, new Comparator<KeyNamePair>(){
|
||||||
|
public int compare(KeyNamePair s1,KeyNamePair s2){
|
||||||
|
if (s1.getKey() < s2.getKey())
|
||||||
|
return -1;
|
||||||
|
else if (s1.getKey() > s2.getKey())
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}});
|
||||||
|
String[] retValue = new String[listkn.size()];
|
||||||
|
for (int i = 0; i < listkn.size(); i++) {
|
||||||
|
retValue[i] = listkn.get(i).getName();
|
||||||
}
|
}
|
||||||
String[] retValue = new String[list.size()];
|
|
||||||
retValue = list.toArray(retValue);
|
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getIdentifierColumns
|
} // getIdentifierColumns
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ import org.adempiere.webui.window.WFieldSuggestion;
|
||||||
import org.compiere.model.GridField;
|
import org.compiere.model.GridField;
|
||||||
import org.compiere.model.Lookup;
|
import org.compiere.model.Lookup;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.model.MZoomCondition;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
|
@ -134,16 +136,14 @@ public class WEditorPopupMenu extends Menupopup implements EventListener<Event>
|
||||||
this.updateEnabled = false;
|
this.updateEnabled = false;
|
||||||
|
|
||||||
// check possible zoom conditions to enable back zoom
|
// check possible zoom conditions to enable back zoom
|
||||||
for (int zoomCondWinID :
|
MTable table = MTable.get(Env.getCtx(), tableName);
|
||||||
DB.getIDsEx(null,
|
for (MZoomCondition zoomCondition : MZoomCondition.getConditions(table.getAD_Table_ID())) {
|
||||||
"SELECT AD_Window_ID FROM AD_ZoomCondition WHERE IsActive='Y' AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE TableName=?)",
|
Boolean canAccessZoom = MRole.getDefault().getWindowAccess(zoomCondition.getAD_Window_ID());
|
||||||
tableName)) {
|
|
||||||
Boolean canAccessZoom = MRole.getDefault().getWindowAccess(zoomCondWinID);
|
|
||||||
if (canAccessZoom != null && canAccessZoom) {
|
if (canAccessZoom != null && canAccessZoom) {
|
||||||
this.zoomEnabled = true;
|
this.zoomEnabled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int cnt = DB.getSQLValueEx(null,
|
int cnt = DB.getSQLValueEx(null,
|
||||||
"SELECT COUNT(*) "
|
"SELECT COUNT(*) "
|
||||||
|
|
Loading…
Reference in New Issue