Fix [3159033] - List fields zoom incorrectly

http://sourceforge.net/support/tracker.php?aid=3159033
Refactored DB.isSOTrx to avoid launching log errors on postgresql
This commit is contained in:
Carlos Ruiz 2011-03-26 01:01:25 -05:00
parent 4c46bf37cc
commit 06bc5898e0
3 changed files with 122 additions and 99 deletions

View File

@ -52,6 +52,7 @@ import org.compiere.model.MRole;
import org.compiere.model.MSequence; import org.compiere.model.MSequence;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.MSystem; import org.compiere.model.MSystem;
import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.POResultSet; import org.compiere.model.POResultSet;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
@ -1788,59 +1789,65 @@ public final class DB
} }
// //
boolean isSOTrx = true; boolean isSOTrx = true;
String sql = "SELECT IsSOTrx FROM " + TableName boolean noIsSOTrxColumn = false;
+ " WHERE " + whereClause; if (MTable.get(Env.getCtx(), TableName).getColumn("IsSOTrx") == null) {
PreparedStatement pstmt = null; noIsSOTrxColumn = true;
ResultSet rs = null; } else {
try String sql = "SELECT IsSOTrx FROM " + TableName
{ + " WHERE " + whereClause;
pstmt = DB.prepareStatement (sql, null); PreparedStatement pstmt = null;
rs = pstmt.executeQuery (); ResultSet rs = null;
if (rs.next ()) try
isSOTrx = "Y".equals(rs.getString(1)); {
pstmt = DB.prepareStatement (sql, null);
rs = pstmt.executeQuery ();
if (rs.next ())
isSOTrx = "Y".equals(rs.getString(1));
}
catch (Exception e)
{
noIsSOTrxColumn = true;
}
finally
{
close(rs, pstmt);
rs= null;
pstmt = null;
}
} }
catch (Exception e) if (noIsSOTrxColumn && TableName.endsWith("Line")) {
{ noIsSOTrxColumn = false;
if (TableName.endsWith("Line")) String hdr = TableName.substring(0, TableName.indexOf("Line"));
{ if (MTable.get(Env.getCtx(), hdr).getColumn("IsSOTrx") == null) {
String hdr = TableName.substring(0, TableName.indexOf("Line")); noIsSOTrxColumn = true;
// use IN instead of EXISTS as the subquery should be highly selective } else {
sql = "SELECT IsSOTrx FROM " + hdr // use IN instead of EXISTS as the subquery should be highly selective
+ " h WHERE h." + hdr + "_ID IN (SELECT l." + hdr + "_ID FROM " + TableName String sql = "SELECT IsSOTrx FROM " + hdr
+ " l WHERE " + whereClause + ")"; + " h WHERE h." + hdr + "_ID IN (SELECT l." + hdr + "_ID FROM " + TableName
PreparedStatement pstmt2 = null; + " l WHERE " + whereClause + ")";
ResultSet rs2 = null; PreparedStatement pstmt2 = null;
try ResultSet rs2 = null;
{ try
pstmt2 = DB.prepareStatement (sql, null); {
rs2 = pstmt2.executeQuery (); pstmt2 = DB.prepareStatement (sql, null);
if (rs2.next ()) rs2 = pstmt2.executeQuery ();
isSOTrx = "Y".equals(rs2.getString(1)); if (rs2.next ())
} isSOTrx = "Y".equals(rs2.getString(1));
catch (Exception ee) }
{ catch (Exception ee)
ee = getSQLException(ee); {
log.log(Level.FINEST, sql + " - " + e.getMessage(), ee); noIsSOTrxColumn = true;
} }
finally finally
{ {
close(rs2, pstmt2); close(rs2, pstmt2);
rs= null; rs2= null;
pstmt = null; pstmt2 = null;
} }
} }
else
{
log.log(Level.FINEST, TableName + " - No SOTrx", e);
}
}
finally
{
close(rs);
close(pstmt);
rs= null;
pstmt = null;
} }
if (noIsSOTrxColumn)
log.log(Level.FINEST, TableName + " - No SOTrx");
return isSOTrx; return isSOTrx;
} // isSOTrx } // isSOTrx

View File

@ -1293,37 +1293,44 @@ public class VLookup extends JComponent
if (m_lookup != null && m_lookup instanceof MLookup) if (m_lookup != null && m_lookup instanceof MLookup)
{ {
int AD_Reference_ID = ((MLookup)m_lookup).getAD_Reference_Value_ID(); int AD_Reference_ID = ((MLookup)m_lookup).getAD_Reference_Value_ID();
if (AD_Reference_ID != 0) if (DisplayType.List == m_lookup.getDisplayType()) {
{ keyColumnName = "AD_Ref_List_ID";
String query = "SELECT kc.ColumnName, kt.TableName" keyTableName = "AD_Ref_List";
+ " FROM AD_Ref_Table rt" value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
+ " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" } else {
+ " INNER JOIN AD_Table kt ON (rt.AD_Table_ID=kt.AD_Table_ID)" if (AD_Reference_ID != 0)
+ " WHERE rt.AD_Reference_ID=?"; {
String query = "SELECT kc.ColumnName, kt.TableName"
+ " FROM AD_Ref_Table rt"
+ " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)"
+ " INNER JOIN AD_Table kt ON (rt.AD_Table_ID=kt.AD_Table_ID)"
+ " WHERE rt.AD_Reference_ID=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
try try
{
pstmt = DB.prepareStatement(query, null);
pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next())
{ {
keyColumnName = rs.getString(1); pstmt = DB.prepareStatement(query, null);
keyTableName = rs.getString(2); pstmt.setInt(1, AD_Reference_ID);
rs = pstmt.executeQuery();
if (rs.next())
{
keyColumnName = rs.getString(1);
keyTableName = rs.getString(2);
}
} }
} catch (Exception e)
catch (Exception e) {
{ log.log(Level.SEVERE, query, e);
log.log(Level.SEVERE, query, e); }
} finally
finally {
{ DB.close(rs, pstmt);
DB.close(rs, pstmt); rs = null; pstmt = null;
rs = null; pstmt = null; }
} } // Table Reference
} // Table Reference
}
} // MLookup } // MLookup
if(keyColumnName != null && keyColumnName.length() !=0) if(keyColumnName != null && keyColumnName.length() !=0)

View File

@ -43,11 +43,13 @@ import org.compiere.acct.Doc;
import org.compiere.model.GridWindowVO; import org.compiere.model.GridWindowVO;
import org.compiere.model.Lookup; import org.compiere.model.Lookup;
import org.compiere.model.MAcctSchema; import org.compiere.model.MAcctSchema;
import org.compiere.model.MLookup;
import org.compiere.model.MQuery; import org.compiere.model.MQuery;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.CacheMgt; import org.compiere.util.CacheMgt;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Ini; import org.compiere.util.Ini;
import org.compiere.util.Language; import org.compiere.util.Language;
@ -413,26 +415,33 @@ public final class AEnv
// If not already exist or exact value // If not already exist or exact value
if (zoomQuery == null || value != null) if (zoomQuery == null || value != null)
{ {
zoomQuery = new MQuery(); // ColumnName might be changed in MTab.validateQuery zoomQuery = new MQuery(); // ColumnName might be changed in MTab.validateQuery
String column = lookup.getColumnName(); String column = lookup.getColumnName();
//strip off table name, fully qualify name doesn't work when zoom into detail tab // Check if it is a Table Reference
if (column.indexOf(".") > 0) if (lookup instanceof MLookup && DisplayType.List == lookup.getDisplayType())
{ {
int p = column.indexOf("."); int AD_Reference_ID = ((MLookup)lookup).getAD_Reference_Value_ID();
String tableName = column.substring(0, p); column = "AD_Ref_List_ID";
column = column.substring(column.indexOf(".")+1); value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
zoomQuery.setZoomTableName(tableName); }
zoomQuery.setZoomColumnName(column); //strip off table name, fully qualify name doesn't work when zoom into detail tab
} if (column.indexOf(".") > 0)
else {
{ int p = column.indexOf(".");
zoomQuery.setZoomColumnName(column); String tableName = column.substring(0, p);
//remove _ID to get table name column = column.substring(column.indexOf(".")+1);
zoomQuery.setZoomTableName(column.substring(0, column.length() - 3)); zoomQuery.setZoomTableName(tableName);
} zoomQuery.setZoomColumnName(column);
zoomQuery.setZoomValue(value); }
zoomQuery.addRestriction(column, MQuery.EQUAL, value); else
zoomQuery.setRecordCount(1); // guess {
zoomQuery.setZoomColumnName(column);
//remove _ID to get table name
zoomQuery.setZoomTableName(column.substring(0, column.length() - 3));
}
zoomQuery.setZoomValue(value);
zoomQuery.addRestriction(column, MQuery.EQUAL, value);
zoomQuery.setRecordCount(1); // guess
} }
int windowId = lookup.getZoom(zoomQuery); int windowId = lookup.getZoom(zoomQuery);
zoom(windowId, zoomQuery); zoom(windowId, zoomQuery);