IDEMPIERE-90 Restricted items on Combobox / refactor to avoid direct SQL and use cache
This commit is contained in:
parent
9d593123c9
commit
1640fec333
|
@ -20,8 +20,10 @@ 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.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ public class MTable extends X_AD_Table
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8264472455498363565L;
|
private static final long serialVersionUID = -8904670462021706436L;
|
||||||
|
|
||||||
public final static int MAX_OFFICIAL_ID = 999999;
|
public final static int MAX_OFFICIAL_ID = 999999;
|
||||||
|
|
||||||
|
@ -211,6 +213,10 @@ public class MTable extends X_AD_Table
|
||||||
|
|
||||||
/** Columns */
|
/** Columns */
|
||||||
private MColumn[] m_columns = null;
|
private MColumn[] m_columns = null;
|
||||||
|
/** column name to index map **/
|
||||||
|
private Map<String, Integer> m_columnNameMap;
|
||||||
|
/** ad_column_id to index map **/
|
||||||
|
private Map<Integer, Integer> m_columnIdMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Columns
|
* Get Columns
|
||||||
|
@ -221,6 +227,8 @@ public class MTable extends X_AD_Table
|
||||||
{
|
{
|
||||||
if (m_columns != null && !requery)
|
if (m_columns != null && !requery)
|
||||||
return m_columns;
|
return m_columns;
|
||||||
|
m_columnNameMap = new HashMap<String, Integer>();
|
||||||
|
m_columnIdMap = new HashMap<Integer, Integer>();
|
||||||
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID=? ORDER BY ColumnName";
|
String sql = "SELECT * FROM AD_Column WHERE AD_Table_ID=? ORDER BY ColumnName";
|
||||||
ArrayList<MColumn> list = new ArrayList<MColumn>();
|
ArrayList<MColumn> list = new ArrayList<MColumn>();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
@ -229,8 +237,12 @@ public class MTable extends X_AD_Table
|
||||||
pstmt = DB.prepareStatement (sql, get_TrxName());
|
pstmt = DB.prepareStatement (sql, get_TrxName());
|
||||||
pstmt.setInt (1, getAD_Table_ID());
|
pstmt.setInt (1, getAD_Table_ID());
|
||||||
ResultSet rs = pstmt.executeQuery ();
|
ResultSet rs = pstmt.executeQuery ();
|
||||||
while (rs.next ())
|
while (rs.next ()) {
|
||||||
list.add (new MColumn (getCtx(), rs, get_TrxName()));
|
MColumn column = new MColumn (getCtx(), rs, get_TrxName());
|
||||||
|
list.add (column);
|
||||||
|
m_columnNameMap.put(column.getColumnName().toUpperCase(), list.size() - 1);
|
||||||
|
m_columnIdMap.put(column.getAD_Column_ID(), list.size() - 1);
|
||||||
|
}
|
||||||
rs.close ();
|
rs.close ();
|
||||||
pstmt.close ();
|
pstmt.close ();
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
|
@ -274,6 +286,38 @@ public class MTable extends X_AD_Table
|
||||||
return null;
|
return null;
|
||||||
} // getColumn
|
} // getColumn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Column Index
|
||||||
|
* @param ColumnName column name
|
||||||
|
* @return index of column with ColumnName or -1 if not found
|
||||||
|
*/
|
||||||
|
public int getColumnIndex (String ColumnName)
|
||||||
|
{
|
||||||
|
if (m_columns == null)
|
||||||
|
getColumns(false);
|
||||||
|
Integer i = m_columnNameMap.get(ColumnName.toUpperCase());
|
||||||
|
if (i != null)
|
||||||
|
return i.intValue();
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
} // getColumnIndex
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Column Index
|
||||||
|
* @param AD_Column_ID column
|
||||||
|
* @return index of column with ColumnName or -1 if not found
|
||||||
|
*/
|
||||||
|
public int getColumnIndex (int AD_Column_ID)
|
||||||
|
{
|
||||||
|
if (m_columns == null)
|
||||||
|
getColumns(false);
|
||||||
|
Integer i = m_columnIdMap.get(AD_Column_ID);
|
||||||
|
if (i != null)
|
||||||
|
return i.intValue();
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
} // getColumnIndex
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table has a single Key
|
* Table has a single Key
|
||||||
* @return true if table has single key column
|
* @return true if table has single key column
|
||||||
|
|
|
@ -281,11 +281,8 @@ public class VLookup extends JComponent
|
||||||
String tableName_temp = m_lookup.getColumnName(); // Returns AD_Org.AD_Org_ID
|
String tableName_temp = m_lookup.getColumnName(); // Returns AD_Org.AD_Org_ID
|
||||||
int posPoint = tableName_temp.indexOf(".");
|
int posPoint = tableName_temp.indexOf(".");
|
||||||
String tableName = tableName_temp.substring(0, posPoint);
|
String tableName = tableName_temp.substring(0, posPoint);
|
||||||
int table_id = MTable.getTable_ID(tableName); // now we got the ad_table_id
|
MTable table = MTable.get(Env.getCtx(), tableName);
|
||||||
|
isShortListAvailable = (table.getColumnIndex("IsShortList") >= 0);
|
||||||
String sql = "SELECT COUNT(*) FROM AD_Column WHERE ColumnName = 'IsShortList' AND IsActive='Y' AND AD_Table_ID = " + table_id;
|
|
||||||
isShortListAvailable = DB.getSQLValue(null, sql) == 1; // if the table has an active IsShortList column, we could use the restrict search !
|
|
||||||
|
|
||||||
if (isShortListAvailable)
|
if (isShortListAvailable)
|
||||||
{
|
{
|
||||||
setComboShortList(true);
|
setComboShortList(true);
|
||||||
|
|
|
@ -38,7 +38,6 @@ import org.compiere.model.MBPartnerLocation;
|
||||||
import org.compiere.model.MLocation;
|
import org.compiere.model.MLocation;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.KeyNamePair;
|
import org.compiere.util.KeyNamePair;
|
||||||
|
@ -173,11 +172,8 @@ ContextMenuListener, IZoomableEditor
|
||||||
String tableName_temp = lookup.getColumnName(); // Returns AD_Org.AD_Org_ID
|
String tableName_temp = lookup.getColumnName(); // Returns AD_Org.AD_Org_ID
|
||||||
int posPoint = tableName_temp.indexOf(".");
|
int posPoint = tableName_temp.indexOf(".");
|
||||||
String tableName = tableName_temp.substring(0, posPoint);
|
String tableName = tableName_temp.substring(0, posPoint);
|
||||||
int table_id = MTable.getTable_ID(tableName); // now we got the ad_table_id
|
MTable table = MTable.get(Env.getCtx(), tableName);
|
||||||
|
isShortListAvailable = (table.getColumnIndex("IsShortList") >= 0);
|
||||||
String sql = "SELECT COUNT(*) FROM AD_Column WHERE ColumnName = 'IsShortList' AND IsActive='Y' AND AD_Table_ID = " + table_id;
|
|
||||||
isShortListAvailable = DB.getSQLValue(null, sql) == 1; // if the table has an active isShortList column, we could use the restrict search !
|
|
||||||
|
|
||||||
if (isShortListAvailable)
|
if (isShortListAvailable)
|
||||||
{
|
{
|
||||||
onlyShortListItems=true;
|
onlyShortListItems=true;
|
||||||
|
|
Loading…
Reference in New Issue