use of org.compiere.model.PO in project adempiere by adempiere.
the class Generator method generateExternalTables.
private void generateExternalTables(Properties ctx, HttpServletRequest httpRequest) {
HttpSession thisSession = httpRequest.getSession(false);
WebInfo wi = null;
if (thisSession != null)
if (thisSession.getAttribute(WebInfo.NAME) != null)
wi = (WebInfo) thisSession.getAttribute(WebInfo.NAME);
int[] tableKeys = X_CM_TemplateTable.getAllIDs("CM_TemplateTable", "CM_Template_ID=" + thisRequest.getCM_Container().getCM_Template_ID(), "WebCM");
if (tableKeys.length > 0) {
xmlCode.append("<externalTables>\n");
for (int i = 0; i < tableKeys.length; i++) {
X_CM_TemplateTable thisTemplateTable = new X_CM_TemplateTable(ctx, tableKeys[i], "WebCM");
try {
StringBuffer tempXML = new StringBuffer();
tempXML.append("<" + thisTemplateTable.getName() + ">\n");
MTable table = MTable.get(ctx, thisTemplateTable.getAD_Table_ID());
String trxName = null;
int[] ids = PO.getAllIDs(table.getTableName(), replaceSessionElements(wi, thisTemplateTable.getWhereClause()), trxName);
if (ids != null && ids.length > 0) {
for (int j = 0; j < ids.length; j++) {
PO po = null;
po = table.getPO(ids[j], null);
if (po != null) {
tempXML = po.get_xmlString(tempXML);
}
}
}
tempXML.append("\n</" + thisTemplateTable.getName() + ">\n");
xmlCode.append(tempXML);
} catch (Exception e) {
e.printStackTrace();
}
}
xmlCode.append("\n</externalTables>\n");
}
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method getReferencedObject.
/**
* Load object that is referenced by given property.
* Example: getReferencedObject("M_Product", method) should load the M_Product record
* with ID given by M_Product_ID property name;
* @param propertyName
* @param method
* @return
*/
private final Object getReferencedObject(String propertyName, Method method) {
int i = po.get_ColumnIndex(propertyName + "_ID");
if (i < 0)
return null;
// Fetch Record_ID
final Integer record_id = po.get_ValueAsInt(i);
if (record_id == null || record_id <= 0)
return null;
// Fetch TableName from returning class
Class<?> cl = method.getReturnType();
String tableName;
try {
tableName = (String) cl.getField("Table_Name").get(null);
} catch (Exception e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return null;
}
// Load Persistent Object
PO child = MTable.get(po.getCtx(), tableName).getPO(record_id, po.get_TrxName());
return child;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method getPO.
/**
*
* @param model
* @param checkOtherWrapper
* if the given <code>model</code> is handled by a {@link GridTabWrapper} and this param is
* <code>true</code>, then this method <b>loads a new PO from DB</b>, only using the given
* <code>model</code>'s table name and record ID. If this param is <code>false</code> and
* <code>model</code> is not handled by <code>POWrapper</code>, then this method returns
* <code>null</code>.
* @return
*/
@SuppressWarnings("unchecked")
public static <T extends PO> T getPO(Object model, boolean checkOtherWrapper) {
if (model == null)
return null;
if (model instanceof PO)
return (T) model;
if (Proxy.isProxyClass(model.getClass())) {
InvocationHandler ih = Proxy.getInvocationHandler(model);
if (ih instanceof POWrapper) {
POWrapper wrapper = (POWrapper) ih;
return (T) wrapper.getPO();
}
if (ih instanceof GridTabWrapper && checkOtherWrapper) {
// using the grid tab wrapper to load the PO
final GridTab gridTab = GridTabWrapper.getGridTab(model);
final String tableName = gridTab.get_TableName();
final int recordID = gridTab.getKeyID(gridTab.getCurrentRow());
return (T) MTable.get(Env.getCtx(), tableName).getPO(recordID, null);
}
}
return null;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method create.
@SuppressWarnings("unchecked")
public static <T> T create(Object obj, Class<T> cl, boolean useOldValues, String trlAdLanguage) {
if (obj == null) {
return null;
}
if (cl.isInstance(obj) && !useOldValues && trlAdLanguage == null) {
return (T) obj;
}
final PO po;
if (obj instanceof PO) {
po = (PO) obj;
} else {
po = getPO(obj);
}
if (!(po instanceof PO)) {
throw new AdempiereException("Not a PO object - " + obj);
}
//
// Check TableName
final String classTableName = InterfaceWrapperHelper.getTableNameOrNull(cl);
if (classTableName != null) {
final String poTableName = po.get_TableName();
if (!poTableName.equals(classTableName)) {
throw new IllegalArgumentException("PO " + po + " (TableName:" + poTableName + ") and class " + cl + " (TableName:" + classTableName + ") are not compatible");
}
}
return (T) Proxy.newProxyInstance(cl.getClassLoader(), new Class<?>[] { cl }, new POWrapper(cl, po, useOldValues, trlAdLanguage));
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method create.
/**
* Create a new instance of given interface
*
* @param <T> model interface
* @param ctx context
* @param tableName table name to be queried
* @param id record id
* @param cl model interface class
* @param trxName db transaction name
* @return new instance or null if not found
*/
public static <T> T create(Properties ctx, final String tableName, int id, Class<T> cl, String trxName) {
if (id < 0)
return null;
Check.assumeNotNull(tableName, "tableName not null");
PO po = MTable.get(ctx, tableName).getPO(id, trxName);
if (po == null || po.get_ID() != id) {
// throw new AdempiereException("@PONotFound@ @" + tableName + "@ (ID=" + record_id + ")");
return null;
}
return create(po, cl);
}
Aggregations