Difference between revisions of "ADempiere Best Practices"

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.
(How to return ARRAY of objects?)
(Team)
Line 15: Line 15:
  
 
[[User:vpj-cd|Victor Perez]] [http://e-evolution.com e-Evolution]
 
[[User:vpj-cd|Victor Perez]] [http://e-evolution.com e-Evolution]
 +
 +
[[User:dominik|Dominik Zajac]] [http://www.baycix.de]
  
 
=SVN Commit Policy=
 
=SVN Commit Policy=

Revision as of 13:06, 17 December 2008

 DISCLAIMER: Target of this document is developers who want to help us fixing and completing
 ADempiere's manufacturing functionality (libero).

Overview

Goal

Team

Teo Sarca Arhipac

Trifon D3Soft

Victor Perez e-Evolution

Dominik Zajac [1]

SVN Commit Policy

  • In SVN note always put full url to the bug 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
  • Commit when you have time to fix if somethings go bad

Reference

SVN Best Practices

Coding Standards

  • ...

Coding Style

See Eclipse Code Formatter Profile .

Known issues:

  1. 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})
		.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 = COLUMNNAME_PA_Measure_ID+"=? AND "+COLUMNNAME_IsAchieved+"=?"; 
	List<MAchievement> list = new Query(ctx, MAchievement.Table_Name, whereClause, null)
		.setParameters(new Object[]{PA_Measure_ID, true})
		.setOrderBy(COLUMNNAME_SeqNo+", "+COLUMNNAME_DateDoc)
		.list();
	for(MAchievement achievement : list)
	{
	  s_log.fine(" - " + achievement);
	  // do some processing here
	}
	return list.toArray(new MAchievement[list.size()]);
}

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

EE Best Practices

Precise Java

Test Units

  • ...

Document Policy