db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caron, Roger A." <roger.ca...@pw.utc.com>
Subject RE: Torque JNDI with Weblogic
Date Fri, 26 Mar 2004 19:13:50 GMT
Thanks for all the help, but I found a core problem in the Torque code.
Either my Torque source is bad or the commons-configuration classes I use
are old.

I have found the problem.

In org.apache.torque.dsfactory.JndiDataSourceFactory.java, I've found a bug
in the initDataSource routine.

Typically, one would use the torque.dsfactory.dbname.datasource attributes
to define the Torque datasource to use in the Torque-generated
DataSourceFactory.  However, since I don't want to define Torque parameters
to create its own datasource because I ONLY want to use the Weblogic-defined
jndi datasource (thanks to our lovely architecture team), I do not specify
those parameters.  This means the DataSourceFactory will not find it's
connection parameters.

org.apache.torque.dsfactory.JndiDataSourceFactory's initialize method calls
both the initJNDI and initDataSource methods.

initJNDI looks in the properties for the proper jndi properties.  If found,
it uses them for a jndi connection.  

The true problem lies in the initDataSource method, which relies on the
commons-configuration class.  initDataSource runs
configuration.subset("datasource") which returns the properties relevant to
the datasource Torque will create.  Configuration.subset(String) will never
return a null configuration object.  Rather, it returns an empty
configuration object.

initDataSource tests the configuration if it's null, but not if it's empty.
It then uses the empty datasource configurations to create a datasource,
which then fails to bing the null datasource.

A while ago I had to get an updated version of the commons-configuration
libraries to run the factory.setConfigurationURL() command in place of
specifying a path.  In doing so, I don't know if the new Configuration class
returns an "empty" configuration where the former class used to return a
null configuration??

One option for a fix is to make the initJNDI and initDataSource methods
public, allowing my servlet to use one or the other based on business logic.
However, the code change below works just as well.

I made the following update in
org.apache.torque.dsfactory.JndiDataSourceFactory.java to make this work:

********************************************
**  old routine
********************************************
   private void initDataSource(Configuration configuration) throws
TorqueException {
        log.debug("Starting initDataSources");
        Configuration c = configuration.subset("datasource");
        try {
            if (c != null) {    // ******* THIS IS WHERE WE GET AN EMPTY
CONFIGURATION, NOT A NULL ONE
                Object ds = null;
                Iterator i = c.getKeys();
                while (i.hasNext()) {
                    String key = (String) i.next();
                    if (key.equals("classname")) {
                        String classname = c.getString(key);
                        log.debug("Datasource class: " + classname);

                        Class dsClass = Class.forName(classname);
                        ds = dsClass.newInstance();
                    }
                    else {
                        log.debug("Setting datasource property: " + key);
                        setProperty(key, c, ds);
                    }
                }
                bindDStoJndi(ctx, path, ds);  // ***** SINCE DS=null, 	THE
BIND FAILS
            } 
        }
        catch (Exception e) {
            log.error("", e);
            throw new TorqueException(e);
        }
    }

********************************************
** slightly modified;
** added && !c.isEmpty()
********************************************

   private void initDataSource(Configuration configuration) throws
TorqueException {
        log.debug("Starting initDataSources");
        Configuration c = configuration.subset("datasource");
        try {
            if (c != null && !c.isEmpty()) {  // ***** ADDING THIS WILL NOT
RUN THE BIND METHOD BELOW, WHICH ERRORS OUT ON NULL DATASOURCES
                Object ds = null;
                Iterator i = c.getKeys();
                while (i.hasNext()) {
                    String key = (String) i.next();
                    if (key.equals("classname")) {
                        String classname = c.getString(key);
                        log.debug("Datasource class: " + classname);

                        Class dsClass = Class.forName(classname);
                        ds = dsClass.newInstance();
                    }
                    else {
                        log.debug("Setting datasource property: " + key);
                        setProperty(key, c, ds);
                    }
                }
                bindDStoJndi(ctx, path, ds);
            } 
        }
        catch (Exception e) {
            log.error("", e);
            throw new TorqueException(e);
        }
    }


Roger



-----Original Message-----
From: Caron, Roger A. [mailto:roger.caron@pw.utc.com]
Sent: Friday, March 26, 2004 12:31 PM
To: 'Apache Torque Users List'
Subject: RE: Torque JNDI with Weblogic


One possibility that may be going wrong is in my declaration of my
Configuration object.  Should I set a "datasource" property with a
dataSource object on the Configuration object in the code below?

Thanks.

Roger

  ConfigurationFactory factory = new ConfigurationFactory();
  URL configURL = getClass().getResource("/Torque.properties.xml"); // xml
file pointing to location of properties file
  factory.setConfigurationURL(configURL);
  Configuration configuration = factory.getConfiguration();
  Torque.init(configuration);



-----Original Message-----
From: Caron, Roger A. [mailto:roger.caron@pw.utc.com]
Sent: Friday, March 26, 2004 8:37 AM
To: 'Apache Torque Users List'
Cc: Fischer,Christian
Subject: RE: Torque JNDI with Weblogic


I'm using BEA version 8.1 and have two parallel setups, PC and Solaris.
Neither are working against the datasource properly.

I too, have changed my DS name to jdbc/ssha-datasource to no avail.

Today I plan to add debug statements to the TorqueInstance class to see what
it's getting for a datasource in the dsf.getDataSource().getConnection()
command, where it's currently gettting the nullPointerException.  I'm
guessing the map is incomplete.

I'll let you know what I find and what's going on.

Roger 



-----Original Message-----
From: "Göschl,Siegfried" [mailto:Siegfried.Goeschl@drei.com]
Sent: Friday, March 26, 2004 2:33 AM
To: Apache Torque Users List
Cc: Fischer,Christian
Subject: RE: Torque JNDI with Weblogic


Hi Caron,

let's dig a little bit deeper ... :-)

+) which version of BEA are using?!
+) as far as I remember we changed the DS name of BEA to 'jdbc/H3G_WebShop'
as well.
+) we are probably looking at using JNDI datasource with BEA WebLogic 8.2
today so I keep you informed

Cheers,

Siegfried Goeschl


-----Original Message-----
From: Caron, Roger A. [mailto:roger.caron@pw.utc.com]
Sent: Thursday, March 25, 2004 8:28 PM
To: 'Apache Torque Users List'
Subject: RE: Torque JNDI with Weblogic


Thank you for the suggestion.  I've tried it, and I'm still getting the same
results.  I have a separate connection class to test the data-source which
works fine so I know the datasource is OK.  But Torque cannot use it.

I don't get it.

Can you think of any other setting I might be missing, either on the BEA
side or in the Torque properties?

Thanks.

Roger



-----Original Message-----
From: "Göschl,Siegfried" [mailto:Siegfried.Goeschl@drei.com]
Sent: Thursday, March 25, 2004 1:06 PM
To: Apache Torque Users List
Subject: RE: Torque JNDI with Weblogic


Hi Caron,

I'm using the following definition

torque.database.default=WEBSHOP
torque.database.WEBSHOP.adapter=oracle
torque.dsfactory.WEBSHOP.jndi.path=jdbc/H3G_WebShop
torque.dsfactory.WEBSHOP.factory=org.apache.torque.dsfactory.JndiDataSourceF
actory

My initial problem was that the JNDI name was initially 'H3G_WebShop' which
did not work with BEA. Prefixing with 'jdbc' did the trick


Cheers,

Siegfried Goeschl

-----Original Message-----
From: Caron, Roger A. [mailto:roger.caron@pw.utc.com]
Sent: Thursday, March 25, 2004 6:44 PM
To: 'torque-user@db.apache.org'
Subject: Torque JNDI with Weblogic



> I have a JNDI connection enabled on my weblogic server.  I've specified
> the following in my torque.properties:
> 
> ===================================
> torque.database.default          = ORAT017
> torque.database.ORAT017.adapter  = oracle
> torque.database.ORAT017.driver   = oracle.jdbc.driver.OracleDriver
> 
> torque.dsfactory.ORAT017.factory=org.apache.torque.dsfactory.JndiDataSourc
> eFactory
> torque.dsfactory.ORAT017.jndi.path=ssha-datasource
> 
> torque.dsfactory.ORAT017.jndi.java.naming.factory.initial=org.apache.namin
> g.java.javaURLContextFactory
> torque.dsfactory.ORAT017.jndi.java.naming.factory.url.pkgs=org.apache.nami
> ng
> ===================================
> 
> The Weblogic datasource name is ssha-datasource.  I've tried all different
> combinations for the jndi.path including 
> java:/comp/env/jdbc/ssha-datasource
> java:/comp/env/ssha-datasource
> java:/ssha-datasource
> 
> And just about any permutaion you can imagine.
> 
> I consistently get a NullPointerException in the
> TorqueInstance.getConnection method.  What am I missing?  
> 
> Thanks.
> 
> Roger

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message