You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jens Greven <je...@greven.org> on 2009/11/19 20:59:35 UTC

Writable JNDI Naming Context?

Hi,


is there a way of having a writeable JNDI context in Tomcat? I need one 
to place dataSources in it, because I have a perfectly running 
DataSourceFactory that is used in other applications as well, so I'd 
prefer to use this one above everything else to avoid database 
configurations in multiple places. Or is there a way of telling 
hibernate to get connections from my DataSourceFactory, thus avoiding 
the JNDI hassle?


Regards,
Jens

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writable JNDI Naming Context?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jens,

On 11/19/2009 5:44 PM, Jens Greven wrote:
> My problem is that I do not only deal with web applications, but also
> common desktop applications using JDBC connections and partly hibernate.
> If it were only for webapps I would certainly use the Tomcat context ;-)

This just sounds like a deployment issue: if you're building a
non-webapp, provide the configuration and your own DataSource bundled
together to populate the JNDI context. If you are building a webapp,
provide the same configuration inside META-INF/context.xml.

In either case, the code always locates the DataSource within the JNDI
context.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksFy3AACgkQ9CaO5/Lv0PDrdACgiroN4lBNgqatvOugrqEG067F
sT8An15HhDcewXSTA1v0iIxqSC8CegBI
=/439
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writable JNDI Naming Context?

Posted by Jens Greven <je...@greven.org>.
Christopher Schultz schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Jens,
> 
> On 11/19/2009 5:22 PM, Jens Greven wrote:
>> Christopher Schultz schrieb:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> Jens,
>>>
>>> On 11/19/2009 2:59 PM, Jens Greven wrote:
>>>  
>>>> is there a way of having a writeable JNDI context in Tomcat? I need one
>>>> to place dataSources in it, because I have a perfectly running
>>>> DataSourceFactory that is used in other applications as well, so I'd
>>>> prefer to use this one above everything else to avoid database
>>>> configurations in multiple places. Or is there a way of telling
>>>> hibernate to get connections from my DataSourceFactory, thus avoiding
>>>> the JNDI hassle?
>>>>     
>>> What about using Tomcat's <Resource> configuration in context.xml which
>>> results in putting a DataSource into the JNDI context. Is there a
>>> compelling reason to use your own DataSourceFactory? If so, I believe
>>> you can configure <Resource> to use that.
>>>
>>> See http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
>>> for more information.
>>>
>>> - -chris
>>>   
>> Chris,
>>
>> The main reason for using my own DataSourceFactory is to have all
>> configuration in one place so in case of any changes to configuration
>> only one class has to be updated no matter what application uses the
>> DSF. As we have quite a heterogenous infrastructure, it currently
>> contains connection information for 7 Databases with individual
>> ConnectionCustomizers etc. (and changes appear quite frequently...). I
>> will try with the &lt;Resource&gt;, thanks a lot for the hint ;-)
> 
> I believe you can set shared configuration either in conf/context.xml
> (the default context.xml for all webapps, and will therefore be
> inherited by all deployed webapps) or you can put <Resource> elements
> into server.xml under <GlobalNamingResources> and then map them to each
> webapp you deploy.
> 
> See http://tomcat.apache.org/tomcat-6.0-doc/config/globalresources.html
> for more information, here.
> 

My problem is that I do not only deal with web applications, but also 
common desktop applications using JDBC connections and partly hibernate. 
If it were only for webapps I would certainly use the Tomcat context ;-)

My approach was to create my own DSF as mentioned above, for the desktop 
applications using hibernate I initialize the DataSources and bind them 
to a JNDI context, so I can access them for JDBC access as well as use 
them with my hibernate SessionFactory (which uses DataSources from JNDI 
context as well, of course). It worked well so far, just when I wanted 
to initialize the DataSources in my web app, I became aware of the fact 
that the Tomcat JNDI context is "read only"... Which explains my fist 
approach (as you can find in the subject ;-) to replace it with a 
writeable JNDI context.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writable JNDI Naming Context?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jens,

On 11/19/2009 5:22 PM, Jens Greven wrote:
> Christopher Schultz schrieb:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Jens,
>>
>> On 11/19/2009 2:59 PM, Jens Greven wrote:
>>  
>>> is there a way of having a writeable JNDI context in Tomcat? I need one
>>> to place dataSources in it, because I have a perfectly running
>>> DataSourceFactory that is used in other applications as well, so I'd
>>> prefer to use this one above everything else to avoid database
>>> configurations in multiple places. Or is there a way of telling
>>> hibernate to get connections from my DataSourceFactory, thus avoiding
>>> the JNDI hassle?
>>>     
>>
>> What about using Tomcat's <Resource> configuration in context.xml which
>> results in putting a DataSource into the JNDI context. Is there a
>> compelling reason to use your own DataSourceFactory? If so, I believe
>> you can configure <Resource> to use that.
>>
>> See http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
>> for more information.
>>
>> - -chris
>>   
> Chris,
> 
> The main reason for using my own DataSourceFactory is to have all
> configuration in one place so in case of any changes to configuration
> only one class has to be updated no matter what application uses the
> DSF. As we have quite a heterogenous infrastructure, it currently
> contains connection information for 7 Databases with individual
> ConnectionCustomizers etc. (and changes appear quite frequently...). I
> will try with the &lt;Resource&gt;, thanks a lot for the hint ;-)

I believe you can set shared configuration either in conf/context.xml
(the default context.xml for all webapps, and will therefore be
inherited by all deployed webapps) or you can put <Resource> elements
into server.xml under <GlobalNamingResources> and then map them to each
webapp you deploy.

See http://tomcat.apache.org/tomcat-6.0-doc/config/globalresources.html
for more information, here.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksFxngACgkQ9CaO5/Lv0PD/AgCbBeMCJoInrc2vsiTVnLPaeXx2
dUIAoJ2DQqrFLwRpVqfwaoyive3CrjTZ
=ZQut
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writable JNDI Naming Context?

Posted by Jens Greven <je...@greven.org>.
Christopher Schultz schrieb:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Jens,
>
> On 11/19/2009 2:59 PM, Jens Greven wrote:
>   
>> is there a way of having a writeable JNDI context in Tomcat? I need one
>> to place dataSources in it, because I have a perfectly running
>> DataSourceFactory that is used in other applications as well, so I'd
>> prefer to use this one above everything else to avoid database
>> configurations in multiple places. Or is there a way of telling
>> hibernate to get connections from my DataSourceFactory, thus avoiding
>> the JNDI hassle?
>>     
>
> What about using Tomcat's <Resource> configuration in context.xml which
> results in putting a DataSource into the JNDI context. Is there a
> compelling reason to use your own DataSourceFactory? If so, I believe
> you can configure <Resource> to use that.
>
> See http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
> for more information.
>
> - -chris
>   
Chris,

The main reason for using my own DataSourceFactory is to have all
configuration in one place so in case of any changes to configuration
only one class has to be updated no matter what application uses the
DSF. As we have quite a heterogenous infrastructure, it currently
contains connection information for 7 Databases with individual
ConnectionCustomizers etc. (and changes appear quite frequently...). I
will try with the &lt;Resource&gt;, thanks a lot for the hint ;-)

Jens


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Writable JNDI Naming Context?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jens,

On 11/19/2009 2:59 PM, Jens Greven wrote:
> is there a way of having a writeable JNDI context in Tomcat? I need one
> to place dataSources in it, because I have a perfectly running
> DataSourceFactory that is used in other applications as well, so I'd
> prefer to use this one above everything else to avoid database
> configurations in multiple places. Or is there a way of telling
> hibernate to get connections from my DataSourceFactory, thus avoiding
> the JNDI hassle?

What about using Tomcat's <Resource> configuration in context.xml which
results in putting a DataSource into the JNDI context. Is there a
compelling reason to use your own DataSourceFactory? If so, I believe
you can configure <Resource> to use that.

See http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
for more information.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksFv+YACgkQ9CaO5/Lv0PAJIgCgvrT1QD3g46pgYAuQitD5sc1t
dUQAn1xoH+KeZSe+SROKPVEMExtE/nHp
=bgnL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org