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:
parent
4c46bf37cc
commit
06bc5898e0
|
@ -52,6 +52,7 @@ import org.compiere.model.MRole;
|
|||
import org.compiere.model.MSequence;
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.model.MSystem;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.PO;
|
||||
import org.compiere.model.POResultSet;
|
||||
import org.compiere.process.ProcessInfo;
|
||||
|
@ -1788,59 +1789,65 @@ public final class DB
|
|||
}
|
||||
//
|
||||
boolean isSOTrx = true;
|
||||
String sql = "SELECT IsSOTrx FROM " + TableName
|
||||
+ " WHERE " + whereClause;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement (sql, null);
|
||||
rs = pstmt.executeQuery ();
|
||||
if (rs.next ())
|
||||
isSOTrx = "Y".equals(rs.getString(1));
|
||||
boolean noIsSOTrxColumn = false;
|
||||
if (MTable.get(Env.getCtx(), TableName).getColumn("IsSOTrx") == null) {
|
||||
noIsSOTrxColumn = true;
|
||||
} else {
|
||||
String sql = "SELECT IsSOTrx FROM " + TableName
|
||||
+ " WHERE " + whereClause;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
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 (TableName.endsWith("Line"))
|
||||
{
|
||||
String hdr = TableName.substring(0, TableName.indexOf("Line"));
|
||||
// use IN instead of EXISTS as the subquery should be highly selective
|
||||
sql = "SELECT IsSOTrx FROM " + hdr
|
||||
+ " h WHERE h." + hdr + "_ID IN (SELECT l." + hdr + "_ID FROM " + TableName
|
||||
+ " l WHERE " + whereClause + ")";
|
||||
PreparedStatement pstmt2 = null;
|
||||
ResultSet rs2 = null;
|
||||
try
|
||||
{
|
||||
pstmt2 = DB.prepareStatement (sql, null);
|
||||
rs2 = pstmt2.executeQuery ();
|
||||
if (rs2.next ())
|
||||
isSOTrx = "Y".equals(rs2.getString(1));
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
ee = getSQLException(ee);
|
||||
log.log(Level.FINEST, sql + " - " + e.getMessage(), ee);
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(rs2, pstmt2);
|
||||
rs= null;
|
||||
pstmt = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.log(Level.FINEST, TableName + " - No SOTrx", e);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(rs);
|
||||
close(pstmt);
|
||||
rs= null;
|
||||
pstmt = null;
|
||||
if (noIsSOTrxColumn && TableName.endsWith("Line")) {
|
||||
noIsSOTrxColumn = false;
|
||||
String hdr = TableName.substring(0, TableName.indexOf("Line"));
|
||||
if (MTable.get(Env.getCtx(), hdr).getColumn("IsSOTrx") == null) {
|
||||
noIsSOTrxColumn = true;
|
||||
} else {
|
||||
// use IN instead of EXISTS as the subquery should be highly selective
|
||||
String sql = "SELECT IsSOTrx FROM " + hdr
|
||||
+ " h WHERE h." + hdr + "_ID IN (SELECT l." + hdr + "_ID FROM " + TableName
|
||||
+ " l WHERE " + whereClause + ")";
|
||||
PreparedStatement pstmt2 = null;
|
||||
ResultSet rs2 = null;
|
||||
try
|
||||
{
|
||||
pstmt2 = DB.prepareStatement (sql, null);
|
||||
rs2 = pstmt2.executeQuery ();
|
||||
if (rs2.next ())
|
||||
isSOTrx = "Y".equals(rs2.getString(1));
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
noIsSOTrxColumn = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
close(rs2, pstmt2);
|
||||
rs2= null;
|
||||
pstmt2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noIsSOTrxColumn)
|
||||
log.log(Level.FINEST, TableName + " - No SOTrx");
|
||||
return isSOTrx;
|
||||
} // isSOTrx
|
||||
|
||||
|
|
|
@ -1293,37 +1293,44 @@ public class VLookup extends JComponent
|
|||
if (m_lookup != null && m_lookup instanceof MLookup)
|
||||
{
|
||||
int AD_Reference_ID = ((MLookup)m_lookup).getAD_Reference_Value_ID();
|
||||
if (AD_Reference_ID != 0)
|
||||
{
|
||||
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=?";
|
||||
if (DisplayType.List == m_lookup.getDisplayType()) {
|
||||
keyColumnName = "AD_Ref_List_ID";
|
||||
keyTableName = "AD_Ref_List";
|
||||
value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
|
||||
} else {
|
||||
if (AD_Reference_ID != 0)
|
||||
{
|
||||
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;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(query, null);
|
||||
pstmt.setInt(1, AD_Reference_ID);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
keyColumnName = rs.getString(1);
|
||||
keyTableName = rs.getString(2);
|
||||
pstmt = DB.prepareStatement(query, null);
|
||||
pstmt.setInt(1, AD_Reference_ID);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
keyColumnName = rs.getString(1);
|
||||
keyTableName = rs.getString(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, query, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
} // Table Reference
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, query, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
} // Table Reference
|
||||
|
||||
}
|
||||
} // MLookup
|
||||
|
||||
if(keyColumnName != null && keyColumnName.length() !=0)
|
||||
|
|
|
@ -43,11 +43,13 @@ import org.compiere.acct.Doc;
|
|||
import org.compiere.model.GridWindowVO;
|
||||
import org.compiere.model.Lookup;
|
||||
import org.compiere.model.MAcctSchema;
|
||||
import org.compiere.model.MLookup;
|
||||
import org.compiere.model.MQuery;
|
||||
import org.compiere.util.CCache;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.CacheMgt;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Ini;
|
||||
import org.compiere.util.Language;
|
||||
|
@ -413,26 +415,33 @@ public final class AEnv
|
|||
// If not already exist or exact value
|
||||
if (zoomQuery == null || value != null)
|
||||
{
|
||||
zoomQuery = new MQuery(); // ColumnName might be changed in MTab.validateQuery
|
||||
String column = lookup.getColumnName();
|
||||
//strip off table name, fully qualify name doesn't work when zoom into detail tab
|
||||
if (column.indexOf(".") > 0)
|
||||
{
|
||||
int p = column.indexOf(".");
|
||||
String tableName = column.substring(0, p);
|
||||
column = column.substring(column.indexOf(".")+1);
|
||||
zoomQuery.setZoomTableName(tableName);
|
||||
zoomQuery.setZoomColumnName(column);
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
zoomQuery = new MQuery(); // ColumnName might be changed in MTab.validateQuery
|
||||
String column = lookup.getColumnName();
|
||||
// Check if it is a Table Reference
|
||||
if (lookup instanceof MLookup && DisplayType.List == lookup.getDisplayType())
|
||||
{
|
||||
int AD_Reference_ID = ((MLookup)lookup).getAD_Reference_Value_ID();
|
||||
column = "AD_Ref_List_ID";
|
||||
value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
|
||||
}
|
||||
//strip off table name, fully qualify name doesn't work when zoom into detail tab
|
||||
if (column.indexOf(".") > 0)
|
||||
{
|
||||
int p = column.indexOf(".");
|
||||
String tableName = column.substring(0, p);
|
||||
column = column.substring(column.indexOf(".")+1);
|
||||
zoomQuery.setZoomTableName(tableName);
|
||||
zoomQuery.setZoomColumnName(column);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
zoom(windowId, zoomQuery);
|
||||
|
|
Loading…
Reference in New Issue