[ 1752801 ] mtable.getPo should return null when query return no result

[ 1752808 ] MTable.getPO doesn't load virtual column
This commit is contained in:
Heng Sin Low 2007-07-13 00:31:39 +00:00
parent e72c2ba60d
commit 60e152fb02
2 changed files with 46 additions and 5 deletions

View File

@ -529,19 +529,44 @@ public class MTable extends X_AD_Table
* @return PO for Record or null * @return PO for Record or null
*/ */
public PO getPO (String whereClause, String trxName) public PO getPO (String whereClause, String trxName)
{
return getPO(whereClause, null, trxName);
} // getPO
/**
* Get PO class instance
* @param whereClause
* @param params
* @param trxName
* @return
*/
public PO getPO(String whereClause, Object[] params, String trxName)
{ {
if (whereClause == null || whereClause.length() == 0) if (whereClause == null || whereClause.length() == 0)
return null; return null;
// //
PO po = null; PO po = null;
String sql = "SELECT * FROM " + getTableName() + " WHERE " + whereClause; POInfo info = POInfo.getPOInfo(getCtx(), getAD_Table_ID());
if (info == null) return null;
StringBuffer sqlBuffer = info.buildSelect();
sqlBuffer.append(" WHERE ").append(whereClause);
String sql = sqlBuffer.toString();
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
if (params != null && params.length > 0)
{
for (int i = 0; i < params.length; i++)
{
pstmt.setObject(i+1, params[i]);
}
}
ResultSet rs = pstmt.executeQuery (); ResultSet rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
{
po = getPO(rs, trxName); po = getPO(rs, trxName);
}
rs.close (); rs.close ();
pstmt.close (); pstmt.close ();
pstmt = null; pstmt = null;
@ -561,11 +586,9 @@ public class MTable extends X_AD_Table
{ {
pstmt = null; pstmt = null;
} }
if (po == null)
return getPO(0, trxName);
return po; return po;
} // getPO }
/** /**
* Before Save * Before Save

View File

@ -624,5 +624,23 @@ public class POInfo implements Serializable
} }
return null; return null;
} // validate } // validate
/**
* Build select clause
* @return stringbuffer
*/
public StringBuffer buildSelect()
{
StringBuffer sql = new StringBuffer("SELECT ");
int size = getColumnCount();
for (int i = 0; i < size; i++)
{
if (i != 0)
sql.append(",");
sql.append(getColumnSQL(i)); // Normal and Virtual Column
}
sql.append(" FROM ").append(getTableName());
return sql;
}
} // POInfo } // POInfo