Caching Objects / POJOs in jbosscache
msakib Dec 18, 2003 12:15 PM
"msakib" wrote:"msakib" wrote:
Hello,
The jbosscache unit tests have a rich set of scenarios, but one big issue with these tests is that it only putting strings in the cache.
In a normal business application scenario, we will generally be putting objects (e.g. HashMaps, POJOs etc.).
I modified one of the simple unit tests (testPutRollback2() function in TxUnitTestCase.java in the jbosscache samples) to put a HashMap in the cache and modify in a transaction. The cache does not seem to rollback the value in the HashMap, if the transaction is rolledback. The modified function is pasted below.
I am following the general steps that mostly everybody will require when using the cache. i.e.
1) Start transaction
2) Get object out of the cache
3) call setters on the object
4) set the object on the cache
5) continue business processing
6) further processing may decide to rollback cache
7) rollback or commit the cache
If jbosscache does not support this basic scenario then it will be very difficult for us ( or i guess anybody) to use it in a real-world application where we want to cache objects.
May be I am missing some steps. Any help on this will be appreciated.
We are looking at using a caching solution for a distributed, high performance, high volume financial applications. jbosscache features seem good, but we came across the above issue.
Test Function code:
-----------------------------------------------------------------------------
// modified To test with a HashMap
public void testPutRollback2() {
try {
//Add a HashMap
HashMap testMap = new HashMap();
testMap.put("TESTMAP","ORIGMAPVALUE");
cache.put("/bela/ban", "map", testMap);
cache.put("/bela/ban", "name", "Bela"); // /bela/ban needs to exist
tx.begin();
//Get the HashMap modify it and put it back
HashMap testMap2= (HashMap)cache.get("/bela/ban", "map");
testMap2.put("TESTMAP","NEWMAPVALUE");
cache.put("/bela/ban", "map", testMap2);
cache.put("/bela/ban", "name", "Michelle");
assertEquals("Michelle", cache.get("/bela/ban", "name"));
tx.rollback();
assertEquals("Bela", cache.get("/bela/ban", "name"));
//Get the HashMap Value and Assert it
HashMap retMap = (HashMap)cache.get("/bela/ban", "map");
System.out.println(" Return Map Value="+"Return Value="+(String)retMap.get("TESTMAP"));
assertEquals("ORIGMAPVALUE", (String)retMap.get("TESTMAP"));
}
catch(Throwable t) {
t.printStackTrace();
fail(t.toString());
}
}
-----------------------------------------------------------------------------
Again any kind of help will be appreciated.
Best Regards,
Sakib