System.out.println("About to execute conn.rollback");
conn.rollback(save1);
conn.commit();
conn.close();
This new MLocation should now not be in the database right? Unfortunately it is. To be able to create a Savepoint for unit testing purposes is very useful. Does anyone know how I might do this in/with Adempiere?
-Tim
P.S.
This code was inside of a junit test.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Don't call DB.commit or conn.commit when using the Trx Api, use the method in Trx class instead.
It have been mention several time that use of System.out.println is bad, please note that. Also, it is very bad to just catch an exception and do System.out.println, you should use JUnit's fail method for that.
Regards,
Low
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you assist me with my large Libero functional test? I try the trx approach you mentioned and it is not working. In its current state it mostly works except it won't delete the products, it hangs. It appears that there is a database deadlock. Anyway, your help would be sooooo greatly appreciated as if I could just get this one large libero functional test I could write others to verify functionality of libero etc... Please take a look at:
I can't help with such messy code ( I stop half way reading it :) ).
I can advise you:
* clean up your code, format it nicely. It have to be readable for other to help :)
* stop using System.out and use the appropriate JUnit Api ( like failed ) in your unit test ( Ok, I promise this is the last time I mention this to you! ).
* Start small - Makesure it work for one small test then you can expand to put in others. It doesn't help to try to do all in one go.
What do u mean by the Trx approach not working ? If Trx.setSavepoint is not working, you can try Trx.getConnection().setSavepoint instead.
Regards,
Low
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
I am trying to do a postgres Connection Savepoint in Adempiere. I try something like this:
Connection conn = DB.createConnection (false, 1);
Savepoint save1 = conn.setSavepoint();
MLocation location = null;
try {
location = new MLocation(m_Ctx, 0, "test");
location.setC_Country_ID(getC_Country_ID("USA") );
location.setC_Region_ID(getC_Region_ID("CA"));
location.setCity("Windsor");
location.setAddress1("1234 Lane");
//location.setAddress2(rs.getString("Street2").trim());
location.setPostal("95492");
location.setPostal_Add("95492");
location.setAD_Org_ID(0);
assertEquals("save failed", location.save(), true);
} catch(Exception e) {
System.out.println("Exception in location.save: " + e.getMessage());
}
DB.commit();
System.out.println("About to execute conn.rollback");
conn.rollback(save1);
conn.commit();
conn.close();
This new MLocation should now not be in the database right? Unfortunately it is. To be able to create a Savepoint for unit testing purposes is very useful. Does anyone know how I might do this in/with Adempiere?
-Tim
P.S.
This code was inside of a junit test.
Tim,
you must use the Trx api correctly to use savepoint.
String trxName = Trx.createTrxName("test");
Trx trx = Trx.get(trxName, true);
Savepoint save1 = trx.setSavepoint("save1");
location = new MLocation(m_Ctx, 0, trxName);
...
trx.rollback(save1);
trx.commit();
trx.close();
Don't call DB.commit or conn.commit when using the Trx Api, use the method in Trx class instead.
It have been mention several time that use of System.out.println is bad, please note that. Also, it is very bad to just catch an exception and do System.out.println, you should use JUnit's fail method for that.
Regards,
Low
Hi Hengsin,
Can you assist me with my large Libero functional test? I try the trx approach you mentioned and it is not working. In its current state it mostly works except it won't delete the products, it hangs. It appears that there is a database deadlock. Anyway, your help would be sooooo greatly appreciated as if I could just get this one large libero functional test I could write others to verify functionality of libero etc... Please take a look at:
http://adempiere.svn.sourceforge.net/viewvc/adempiere/branches/libero/extend/src/test/functional/LiberoTest1.java?view=markup
P.S.
Check out my new screencasts at www.graysonconsulting.biz/files.html
Tim,
I can't help with such messy code ( I stop half way reading it :) ).
I can advise you:
* clean up your code, format it nicely. It have to be readable for other to help :)
* stop using System.out and use the appropriate JUnit Api ( like failed ) in your unit test ( Ok, I promise this is the last time I mention this to you! ).
* Start small - Makesure it work for one small test then you can expand to put in others. It doesn't help to try to do all in one go.
What do u mean by the Trx approach not working ? If Trx.setSavepoint is not working, you can try Trx.getConnection().setSavepoint instead.
Regards,
Low
Hi hengsin,
Is there a formal java coding format standard that Adempiere is following?
-Tim