IDEMPIERE-4606: Adding support for generic method to get model using … (#580)
* IDEMPIERE-4606: Adding support for generic method to get model using UUID * IDEMPIERE-4606: Refactoring as per Hengsin's review comment. * IDEMPIERE-4606: reverting issue in IMappedModelFactory. * IDEMPIERE-4606: Fixing compilation errors * IDEMPIERE-4606: Resetting ModelFactory Class to original, removed instance variable m_uuid and used to pass UU. * IDEMPIERE-4606: Dropping constructor with UU argument from PO class. * IDEMPIERE-4606: Refactoring as per Hengsin's feedback * IDEMPIERE-4606: Correcting Java doc and updating serialized version. * IDEMPIERE-4606: Fixing uuID passing * IDEMPIERE-4606: Moving check for blank argument at top
This commit is contained in:
parent
2c899d3b49
commit
5ca8d44d48
|
@ -322,4 +322,5 @@ public class DefaultModelFactory implements IModelFactory {
|
|||
s_log.log(Level.SEVERE, "(rs) - Not found - Table=" + tableName);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4037560922339534982L;
|
||||
private static final long serialVersionUID = 2951110137945905890L;
|
||||
|
||||
public final static int MAX_OFFICIAL_ID = 999999;
|
||||
|
||||
|
@ -601,6 +601,21 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
|
|||
return po;
|
||||
} // getPO
|
||||
|
||||
/**
|
||||
* Get PO Class Instance
|
||||
*
|
||||
* @param uuID UUID
|
||||
* @param trxName transaction
|
||||
* @return PO for Record
|
||||
*/
|
||||
public PO getPOByUU (String uuID, String trxName)
|
||||
{
|
||||
PO po = getPO(0, trxName);
|
||||
po.loadByUU(uuID, trxName);
|
||||
|
||||
return po;
|
||||
} // getPOByUU
|
||||
|
||||
/**
|
||||
* Get PO Class Instance
|
||||
* @param whereClause where clause
|
||||
|
|
|
@ -112,7 +112,7 @@ public abstract class PO
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7231417421289556724L;
|
||||
private static final long serialVersionUID = -6130455457377290526L;
|
||||
|
||||
public static final String LOCAL_TRX_PREFIX = "POSave";
|
||||
|
||||
|
@ -1343,13 +1343,45 @@ public abstract class PO
|
|||
}
|
||||
} // load
|
||||
|
||||
/**
|
||||
* Load record with UUID
|
||||
*
|
||||
* @param uuID UUID
|
||||
* @param trxName transaction name
|
||||
*/
|
||||
public void loadByUU(String uuID, String trxName)
|
||||
{
|
||||
if (Util.isEmpty(uuID, true))
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid null or blank UU - Must pass valid UU");
|
||||
}
|
||||
|
||||
// reset new values
|
||||
m_newValues = new Object[get_ColumnCount()];
|
||||
checkImmutable();
|
||||
|
||||
if (log.isLoggable(Level.FINEST))
|
||||
log.finest("uuID=" + uuID);
|
||||
|
||||
load(uuID,trxName);
|
||||
} // loadByUU
|
||||
|
||||
/**
|
||||
* (re)Load record with m_ID[*]
|
||||
* @param trxName transaction
|
||||
* @return true if loaded
|
||||
*/
|
||||
public boolean load (String trxName)
|
||||
public boolean load (String trxName) {
|
||||
return load(null, trxName);
|
||||
}
|
||||
|
||||
/**
|
||||
* (re)Load record with uuID
|
||||
* @param uuID RecrodUU
|
||||
* @param trxName transaction
|
||||
* @return true if loaded
|
||||
*/
|
||||
protected boolean load (String uuID,String trxName)
|
||||
{
|
||||
m_trxName = trxName;
|
||||
boolean success = true;
|
||||
|
@ -1368,27 +1400,34 @@ public abstract class PO
|
|||
}
|
||||
sql.append(" FROM ").append(p_info.getTableName())
|
||||
.append(" WHERE ")
|
||||
.append(get_WhereClause(false));
|
||||
.append(get_WhereClause(false,uuID));
|
||||
|
||||
//
|
||||
// int index = -1;
|
||||
if (log.isLoggable(Level.FINEST)) log.finest(get_WhereClause(true));
|
||||
if (log.isLoggable(Level.FINEST)) log.finest(get_WhereClause(true,uuID));
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql.toString(), m_trxName); // local trx only
|
||||
for (int i = 0; i < m_IDs.length; i++)
|
||||
if (!Util.isEmpty(uuID, true))
|
||||
{
|
||||
Object oo = m_IDs[i];
|
||||
if (oo instanceof Integer)
|
||||
pstmt.setInt(i+1, ((Integer)m_IDs[i]).intValue());
|
||||
else if (oo instanceof Boolean)
|
||||
pstmt.setString(i+1, ((Boolean) m_IDs[i] ? "Y" : "N"));
|
||||
else if (oo instanceof Timestamp)
|
||||
pstmt.setTimestamp(i+1, (Timestamp)m_IDs[i]);
|
||||
else
|
||||
pstmt.setString(i+1, m_IDs[i].toString());
|
||||
pstmt.setString(1, uuID);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m_IDs.length; i++)
|
||||
{
|
||||
Object oo = m_IDs[i];
|
||||
if (oo instanceof Integer)
|
||||
pstmt.setInt(i+1, ((Integer)m_IDs[i]).intValue());
|
||||
else if (oo instanceof Boolean)
|
||||
pstmt.setString(i+1, ((Boolean) m_IDs[i] ? "Y" : "N"));
|
||||
else if (oo instanceof Timestamp)
|
||||
pstmt.setTimestamp(i+1, (Timestamp)m_IDs[i]);
|
||||
else
|
||||
pstmt.setString(i+1, m_IDs[i].toString());
|
||||
}
|
||||
}
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
|
@ -1397,7 +1436,7 @@ public abstract class PO
|
|||
}
|
||||
else
|
||||
{
|
||||
log.log(Level.SEVERE, "NO Data found for " + get_WhereClause(true), new Exception());
|
||||
log.log(Level.SEVERE, "NO Data found for " + get_WhereClause(true,uuID), new Exception());
|
||||
m_IDs = new Object[] {I_ZERO};
|
||||
success = false;
|
||||
// throw new DBException("NO Data found for " + get_WhereClause(true));
|
||||
|
@ -1411,7 +1450,7 @@ public abstract class PO
|
|||
String msg = "";
|
||||
if (m_trxName != null)
|
||||
msg = "[" + m_trxName + "] - ";
|
||||
msg += get_WhereClause(true)
|
||||
msg += get_WhereClause(true,uuID)
|
||||
// + ", Index=" + index
|
||||
// + ", Column=" + get_ColumnName(index)
|
||||
// + ", " + p_info.toString(index)
|
||||
|
@ -3164,15 +3203,37 @@ public abstract class PO
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Single/Multi Key Where Clause
|
||||
* @param withValues if true uses actual values otherwise ?
|
||||
* @return where clause
|
||||
*/
|
||||
public String get_WhereClause (boolean withValues)
|
||||
public String get_WhereClause (boolean withValues) {
|
||||
return get_WhereClause(withValues,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Single/Multi Key Where Clause
|
||||
* @param withValues if true uses actual values otherwise ?
|
||||
* @param uuID RecordUU
|
||||
* @return where clause
|
||||
*/
|
||||
public String get_WhereClause (boolean withValues, String uuID)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (!Util.isEmpty(uuID, true))
|
||||
{
|
||||
sb.append(getUUIDColumnName()).append("=");
|
||||
if (withValues)
|
||||
sb.append(DB.TO_STRING(uuID));
|
||||
else
|
||||
sb.append("?");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_IDs.length; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
|
|
Loading…
Reference in New Issue