users@glassfish.java.net

Dynamically created jdbc resource is not accessible. Is this a bug?

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Sep 2007 14:34:06 PDT

I am trying to dynamically create a jdbc resource and access it.
The resource gets created successfully however when I try to look it up using jndi.
I get the following exception.

[#|2007-09-18T14:12:51.818-0700|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=19;_ThreadName=httpSSLWorkerThread-8080-0;_RequestID=1f70f223-e144-4dd7-9c41-1898175da2ef;|javax.naming.NameNotFoundException: DB1 not found
        at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
        at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
        at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:192)
        at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
        at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
        at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:339)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)


I then tried a little experiment.
I logged into the admin console and deleted the jdbc/DB1 resource from it.
i recreated it using the admin console.
I ran my code again and this time the JNDI lookup succeeded.
Dynamically creating pools is essential for our application.
Is there something else that needs to be done in addition to what I am doing.

The following is my test code.


            String connectionPoolName = "DB_DB1";
            String resourceName = "jdbc/DB1";

                        try {
                                        AppserverConnectionSource appserver =
                                                new AppserverConnectionSource(AppserverConnectionSource.PROTOCOL_RMI, "localhost", 8686 , "admin", "adminadmin", null);

                        DomainRoot domainRoot = appserver.getDomainRoot();
                    
                    //Its a 2 step process
                    //First create the pool
                    Map<String, JDBCConnectionPoolConfig> conPoolMap = domainRoot.getDomainConfig().getJDBCConnectionPoolConfigMap();
                    if(conPoolMap.containsKey(connectionPoolName))
                    {
                            System.out.println("pool exists");
                    }
                    else
                    {
                              Map<String, String> map = new HashMap<String, String>();
                          map.put("property.user", "user");
                          map.put("ResType", "javax.sql.DataSource");
                          map.put("property.password", "password");
                          map.put("property.url", "url");

                          domainRoot.getDomainConfig().createJDBCConnectionPoolConfig(connectionPoolName, "oracle.jdbc.pool.OracleDataSource", map);
                          
                              System.out.println("JDBC Pool : " + connectionPoolName + " created !");
                    }
                    
                    //Second create the resource
                    Map<String, JDBCResourceConfig> resMap = (Map<String, JDBCResourceConfig>) domainRoot.getDomainConfig().getJDBCResourceConfigMap();
                    if (resMap.containsKey(resourceName))
                    {
                        System.out.println("JDBC Resource : " + resourceName + " already exists");
                    }
                    else
                    {
                            domainRoot.getDomainConfig().createJDBCResourceConfig(resourceName, connectionPoolName, null);
                        System.out.println("JDBC Resource : " + resourceName + " created !");
                    }
                InitialContext ic = new InitialContext();
                System.out.println(ic.lookup(resourceName));
                
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
            catch (NamingException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
[Message sent by forum member 'roshan_ail' (roshan_ail)]

http://forums.java.net/jive/thread.jspa?messageID=235915