Difference between revisions of "ADempiere Best Practices"
From ADempiere
This Wiki is read-only for reference purposes to avoid broken links.
(→SVN Commit Policy) |
(→How to return ARRAY of objects?) |
||
Line 55: | Line 55: | ||
=== How to return ARRAY of objects? === | === How to return ARRAY of objects? === | ||
− | + | public static MAchievement[] getOfMeasure (Properties ctx, int PA_Measure_ID) | |
− | public static MAchievement[] getOfMeasure (Properties ctx, int PA_Measure_ID) | + | { |
− | { | + | final String whereClause = COLUMNNAME_PA_Measure_ID+"=?"; |
− | + | List<MAchievement> list = new Query(ctx, MAchievement.Table_Name, whereClause, null) | |
− | + | .setParameters(new Object[]{PA_Measure_ID, true}) | |
− | + | .setOrderBy(COLUMNNAME_SeqNo+", "+COLUMNNAME_DateDoc) | |
− | + | .list(); | |
− | + | return list.toArray(new MAchievement[list.size()]); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
− | + | ||
=== How to return ARRAY of objects and process elements? === | === How to return ARRAY of objects and process elements? === |
Revision as of 12:54, 17 December 2008
DISCLAIMER: Target of this document is developers who want to help us fixing and completing ADempiere's manufacturing functionality (libero).
Contents
Overview
Goal
Team
SVN Commit Policy
- In SVN note always put full url to the but report or contribution request:
[ 2354040 ] Implementation Replication Mode, Type, Event http://sourceforge.net/tracker/index.php?func=detail&aid=2354040&group_id=176962&atid=879335
Reference
Coding Standards
- ...
Coding Style
See Eclipse Code Formatter Profile .
Known issues:
- At present eclipse formatter is not supporting fluent interfaces (see eclipse bug #196001)
How to use Adempiere Query class?
How to return only ONE persistent object?
String whereClause = "AD_Client_ID=?" // #1 + " AND AD_Org_ID=?" // #2 + " AND C_AcctSchema_ID=?" // #3 + " AND Account_ID=?"; // #4 MAccount existingAccount = new Query(ctx, MAccount.Table_Name, whereClause, null) .setParameters(new Object[]{AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, Account_ID}) .first();
If you know that your query should return ONLY one result, then you can assert this, and use firstOnly method instead of first method:
MAccount existingAccount = new Query(ctx, MAccount.Table_Name, whereClause, null) .setParameters(new Object[]{AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, Account_ID}) .firstOnly();
How to return ARRAY of objects?
public static MAchievement[] getOfMeasure (Properties ctx, int PA_Measure_ID) { final String whereClause = COLUMNNAME_PA_Measure_ID+"=?"; List<MAchievement> list = new Query(ctx, MAchievement.Table_Name, whereClause, null) .setParameters(new Object[]{PA_Measure_ID, true}) .setOrderBy(COLUMNNAME_SeqNo+", "+COLUMNNAME_DateDoc) .list(); return list.toArray(new MAchievement[list.size()]); }
How to return ARRAY of objects and process elements?
public static MAchievement[] getOfMeasure (Properties ctx, int PA_Measure_ID) { String whereClause = "PA_Measure_ID=? AND IsAchieved='Y'"; List<MAchievement> list = new Query(ctx, MAchievement.Table_Name, whereClause, null) .setParameters(new Object[]{PA_Measure_ID}) .setOrderBy("SeqNo, DateDoc") .list() ; for(MAchievement achievement : list) { s_log.fine(" - " + achievement); } MAchievement[] retValue = new MAchievement[ list.size() ]; retValue = list.toArray (retValue); return retValue; }
How to pass Timestamp parameter?
Timestamp dateAcct = ...; String trxName = ...; String whereClause = "c.C_CashBook_ID=?" // #1 + " AND TRUNC(c.StatementDate)=?" // #2 + " AND c.Processed='N'"; MCash retValue = new Query(ctx, MCash.Table_Name, whereClause, trxName) .setParameters(new Object[]{C_CashBook_ID, TimeUtil.getDay(dateAcct)}) .first() ;
How to use Query class with complex where clause: EXISTS?
String whereClause = "C_Cash.AD_Org_ID=?" // #1 + " AND TRUNC(C_Cash.StatementDate)=?" // #2 + " AND C_Cash.Processed='N'" + " AND EXISTS (SELECT * FROM C_CashBook cb " + "WHERE C_Cash.C_CashBook_ID=cb.C_CashBook_ID AND cb.AD_Org_ID=C_Cash.AD_Org_ID" + " AND cb.C_Currency_ID=?)" // #3 ; MCash retValue = new Query(ctx, MCash.Table_Name, whereClause, trxName) .setParameters(new Object[]{AD_Org_ID,TimeUtil.getDay(dateAcct),C_Currency_ID}) .first() ;
References
Test Units
- ...