[JBossCache] - Re: Cache v2.0 Alpha2: Optimistic Locking + Explicit Version
by chasta
Hmmm. While trying to create a unit test method for you (for the latest version from CVS), I wrote the following method (added to ExplicitVersionsTest):
| Node root = cache.getRoot();
|
| TestVersion lev2V = new TestVersion("Lev2-v");
| cache.getInvocationContext().getOptionOverrides().setDataVersion(lev2V);
| root.addChild(Fqn.fromString("LEV2"));
|
| Node lev2 = root.getChild(Fqn.fromString("LEV2"));
|
| TestVersion lev3V = new TestVersion("Lev3-v");
| cache.getInvocationContext().getOptionOverrides().setDataVersion(lev3V);
| lev2.addChild(Fqn.fromString("LEV3"));
|
| Node lev3 = lev2.getChild(Fqn.fromString("LEV3"));
|
| if (lev3 == null)
| throw new Exception("Hay! lev3 is null!");
|
| TestVersion lev4V = new TestVersion("Lev4-v");
| cache.getInvocationContext().getOptionOverrides().setDataVersion(lev4V);
| lev3.addChild(Fqn.fromString("LEV4"))
|
The null check for lev3 was added because it is indeed null and the test fails because of that; that seems strange, and was not the behavior I was trying to reproduce...
After commenting out the explicit-versioning related code, everything seemed to work normally; lev3 was not null...
| Node root = cache.getRoot();
|
| // TestVersion lev2V = new TestVersion("Lev2-v");
| // cache.getInvocationContext().getOptionOverrides().setDataVersion(lev2V);
| root.addChild(Fqn.fromString("LEV2"));
|
| Node lev2 = root.getChild(Fqn.fromString("LEV2"));
|
| // TestVersion lev3V = new TestVersion("Lev3-v");
| // cache.getInvocationContext().getOptionOverrides().setDataVersion(lev3V);
| lev2.addChild(Fqn.fromString("LEV3"));
|
| Node lev3 = lev2.getChild(Fqn.fromString("LEV3"));
|
| if (lev3 == null)
| throw new Exception("Hay! lev3 is null!");
|
| // TestVersion lev4V = new TestVersion("Lev4-v");
| // cache.getInvocationContext().getOptionOverrides().setDataVersion(lev4V);
| lev3.addChild(Fqn.fromString("LEV4"))
|
Am I using the API incorrectly, or is this indeed a bug? I didn't yet manage to reproduce the same bug, but perhaps this is related... I guess in our application some other factor also takes a role in the failure.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4003294#4003294
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4003294
19 years, 3 months
[Installation, Configuration & Deployment] - Re: AS 4.0.5 GA complains about unclosed connections
by tekniklas
"PeterJ" wrote : You code should look like:
|
| DataSource ds = null;
| | try {
| | ds = ctx.lookup(...);
| | --do database stuff --
| | } finally {
| | if (ds != null) ds.close();
| | }
|
| If you don't close the datasource before exiting the method, you get that warning.
Thank you very much for your reply. Indeed I had forgotton to close a Connection object. But I cannot find a close() method for javax.sql.Datasource, is there one?
My code looks like this:
|
|
| public static Connection getConnection() {
| try {
| Context ctx = new javax.naming.InitialContext();
| javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:MySqlDS");
| try {
| return ds.getConnection("niklas", "password");
| }catch(SQLException se){
| log.error("SQLException in DB.getConnection: ", se);
| return getDMConnection();
|
| }
| }catch(NamingException ne){
| log.error("NamingException in DB.getConnection: ", ne);
| }
| return getDMConnection();
| }
| public static Connection getDMConnection() {
| try {
| Class.forName("com.mysql.jdbc.Driver").newInstance();
| Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/mydb?user=niklas&password=password");
| return conn;
| }catch(Exception ne){
| log.error("Exception in DB.getConnection: ", ne);
| }
| return null;
| }
|
It seems to be working now.
Thanks
Niklas
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4003291#4003291
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4003291
19 years, 3 months