[ 1752801 ] mtable.getPo should return null when query return no result
[ 1752808 ] MTable.getPO doesn't load virtual column
This commit is contained in:
parent
e72c2ba60d
commit
60e152fb02
|
@ -529,19 +529,44 @@ public class MTable extends X_AD_Table
|
|||
* @return PO for Record or null
|
||||
*/
|
||||
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)
|
||||
return 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;
|
||||
try
|
||||
{
|
||||
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 ();
|
||||
if (rs.next ())
|
||||
{
|
||||
po = getPO(rs, trxName);
|
||||
}
|
||||
rs.close ();
|
||||
pstmt.close ();
|
||||
pstmt = null;
|
||||
|
@ -561,11 +586,9 @@ public class MTable extends X_AD_Table
|
|||
{
|
||||
pstmt = null;
|
||||
}
|
||||
if (po == null)
|
||||
return getPO(0, trxName);
|
||||
|
||||
return po;
|
||||
} // getPO
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Before Save
|
||||
|
|
|
@ -624,5 +624,23 @@ public class POInfo implements Serializable
|
|||
}
|
||||
return null;
|
||||
} // 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
|
||||
|
|
Loading…
Reference in New Issue