RE: Dyamic datasource configuration (2.1.7) is this possible? [JNDI]

2006-01-18 Thread Rob Gregory
Thanks for the advice Geert and for taking it the time to provide a complete
solution/example for others to follow.

Unfortunately, with the exception of the flowscript I have been doing this
approach from the start with the exception of duplicating database
connection details in both cocoon and our own context.xml. I say
unfortunately because my original approach is no longer acceptable and I
really can't get my alternative to work! 

We provide an application that utilises the excellent benefits of Cocoon
while still using our own in house framework. I need to provide datasources
on-the-fly and on-demand during servlet startup. I think I can do this via
Tomcat by manually creating the pools and binding them to Tomcat's initial
context via JNDI (I'm also struggling to get this working as the context is
read-only but I think binding elsewhere will work?!?). I have also managed
to get Cocoon to use the same J2EE binding that I provide in Tomcat.

Problem is that my solution for dynamic means it can't be binded to the
standard JNDI namespace of java:comp/env/jdbc as this seems to be read-only
and Cocoon config of:-

   j2ee name=logindb
 dbnamelogindb/dbname
   /j2ee

Doesn't specify the jndi lookup location (java:comp/env/jdbc) so can't find
my alternative binding.

I not sure if my problem is with Tomcat, Cocoon or my lack of knowledge on
JNDI. But after trying to explain it I'm now thinking it's my miss
understanding of JNDI and try to get the dynamically created datasource
registered in the correct location java:comp/env/jdbc some other way and
ignore the Tomcat read-only context.

Food for Thought.

Thanks again for your time.

Rob





-Original Message-
From: Geert Josten [mailto:[EMAIL PROTECTED] 
Sent: 18 January 2006 07:07
To: users@cocoon.apache.org
Subject: Re: Dyamic datasource configuration (2.1.7) is this possible?

 After posting I thought my description may be a little vague...

(snip)

 Any keywords for Google or code samples are more than welcome in my
pursuit
 to get this working...

I'll just supply some code snippets, they might give you new ideas.. (or
not) :-P

One additional note: we decided to code pretty much all business logic in
plain Java and connect to 
these classes from FlowScript. (that is really easy)

Tomcat 5.0 server.xml config snippets (I removed customer specific details):
   ...
   GlobalNamingResources
 !-- 1. Define the global datasource (MYDS) --
 Resource name=jdbc/MYDS auth=Container scope=Shareable
type=javax.sql.DataSource/

(you can probably name as many as you like, but dynamically as in
without restarting tomcat I don't 
know..)

 !-- 2. Define the datasource config params --
 ResourceParams name=jdbc/MYDS
   parameter
 namedriverClassName/name
 valueoracle.jdbc.OracleDriver/value
   /parameter
   parameter
 nameurl/name
 
valuejdbc:oracle:thin:@myoracleserver:myoracleport:myoracledbname/value
   /parameter
   parameter
 nameusername/name
 valuemyuser/value
   /parameter
   parameter
 namepassword/name
 valuemypassword/value
   /parameter
   parameter
 namemaxActive/name
 value20/value
   /parameter
   parameter
 namemaxIdle/name
 value10/value
   /parameter
   parameter
 namemaxWait/name
 value-1/value
   /parameter
 /ResourceParams
   /GlobalNamingResources
   ...
   Service name=Catalina
 Connector port=8080/
 Engine name=Catalina defaultHost=localhost
   Logger className=org.apache.catalina.logger.FileLogger/
   Realm className=org.apache.catalina.realm.UserDatabaseRealm
resourceName=UserDatabase/
   Host name=localhost appBase=webapps

 !-- 3. Define a resourcelink in the defaultcontext that links to
the global datasource --
 DefaultContext
   ResourceLink name=jdbc/MYDS global=jdbc/MYDS
type=javax.sql.DataSource/
 /DefaultContext

 !-- 4. Optional. Define an extra context that points to the
webapps folder in the 
project-development environment (for easy reloading) --
 Context path=/test_site docBase=C:\Projects\cocoon\webapp/
   /Host
 /Engine
   /Service
   ...

Cocoon's web.xml snippet:
   ...
   resource-ref
 res-ref-namejdbc/MYDS/res-ref-name
 res-typejavax.sql.DataSource/res-type
 res-authContainer/res-auth
   /resource-ref
   env-entry
 env-entry-namedatasource.ref/env-entry-name
 env-entry-valuejdbc/MYDS/env-entry-value
 env-entry-typejava.lang.String/env-entry-type
   /env-entry
   env-entry
 env-entry-namedatabase.sortingkey.default/env-entry-name
 env-entry-value5-1;4-0;2-1/env-entry-value
 env-entry-typejava.lang.String/env-entry-type
   /env-entry
   ...

Java code that creates a DataSource by looking up a setting from web.xml:
...
 Context context = new InitialContext();
 Context env = (Context

Re: Dyamic datasource configuration (2.1.7) is this possible?

2006-01-17 Thread Geert Josten

Errr, how dynamic is dynamic?

I have worked on an implementation that uses JNDI internally and configures datasources in the 
webapp server (Oracle in this case.. :-P)


In Oracle webserver you have the opportunity to define datasources on a maintenance webinterface. 
I'm not sure you can do that with Tomcat. What we more or less did in Tomcat for testing is define a 
Resource (with Params) and pointed to it with a ResourceLink in Host/Context. web.xml contains a 
resource-ref as well and some env-entry elements with additional information...


By the way: the database management doesn't hook into any of the Cocoon's objects/lifecycle 
management parts in this case. It could have, but configuration would have been totally different, I 
guess..


HTH,
Geert

Rob Gregory wrote:


Hello People,  thanks in advance for any assistance…

 

I am running Cocoon 2.1.7 under Tomcat 5.5.9 and have a desperate 
requirement to provide the database (datasources/connection pools) 
dynamically aka ‘on-the-fly’.


 

After ‘Googling’ for about six months now and getting as far as Cocoon 
using the same connections provided to Tomcat by using the format:-


 


  j2ee name=logindb

dbnamelogindb/dbname

  /j2ee

 


Over my previous attempt of:-

 


jdbc name=MyConnectionName

 


  pool-controller min=5 max=10/

  dburljdbc:oracle:thin:@localhost:1521:mydatabase/dburl

  usermylogin/user

  passwordmyPassword/password

/jdbc

 

Any pointers towards creating or configuring the datasources available 
to actions  esql would be great.


 


Thanks Again.

Rob



--
Drs. G.P.H. Josten
Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl


De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is 
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken 
wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Dyamic datasource configuration (2.1.7) is this possible?

2006-01-17 Thread Rob Gregory
Hi Geert,  firstly many thanks for your comments - much appreciated.

After posting I thought my description may be a little vague...

To clarify, by dynamic I need to be able to read from the database (I
originally connect with an external manual single connection) to read the
available environments and I then need to provide as many
datasources/connection pools as needed. These datasources need to be
available to both Tomcat (i.e. normal java classes) and Cocoon (xsp  esql).


I'm very interested in your Oracle solution (reverse engineering and all
that) while struggling to understand JNDI under both Tomcat  Cocoon (these
two are lovers and I don't want to separate them by going OC4J)

Any keywords for Google or code samples are more than welcome in my pursuit
to get this working...

Again thanks in advance. 
Rob


-Original Message-
From: Geert Josten [mailto:[EMAIL PROTECTED] 
Sent: 17 January 2006 20:08
To: users@cocoon.apache.org
Subject: Re: Dyamic datasource configuration (2.1.7) is this possible?

Errr, how dynamic is dynamic?

I have worked on an implementation that uses JNDI internally and configures
datasources in the 
webapp server (Oracle in this case.. :-P)

In Oracle webserver you have the opportunity to define datasources on a
maintenance webinterface. 
I'm not sure you can do that with Tomcat. What we more or less did in Tomcat
for testing is define a 
Resource (with Params) and pointed to it with a ResourceLink in
Host/Context. web.xml contains a 
resource-ref as well and some env-entry elements with additional
information...

By the way: the database management doesn't hook into any of the Cocoon's
objects/lifecycle 
management parts in this case. It could have, but configuration would have
been totally different, I 
guess..

HTH,
Geert

Rob Gregory wrote:

 Hello People,  thanks in advance for any assistance.
 
  
 
 I am running Cocoon 2.1.7 under Tomcat 5.5.9 and have a desperate 
 requirement to provide the database (datasources/connection pools) 
 dynamically aka 'on-the-fly'.
 
  
 
 After 'Googling' for about six months now and getting as far as Cocoon 
 using the same connections provided to Tomcat by using the format:-
 
  
 
   j2ee name=logindb
 
 dbnamelogindb/dbname
 
   /j2ee
 
  
 
 Over my previous attempt of:-
 
  
 
 jdbc name=MyConnectionName
 
  
 
   pool-controller min=5 max=10/
 
   dburljdbc:oracle:thin:@localhost:1521:mydatabase/dburl
 
   usermylogin/user
 
   passwordmyPassword/password
 
 /jdbc
 
  
 
 Any pointers towards creating or configuring the datasources available 
 to actions  esql would be great.
 
  
 
 Thanks Again.
 
 Rob
 

-- 
Drs. G.P.H. Josten
Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl


De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is 
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld
hebt ontvangen, verzoeken 
wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden
ontleend.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Dyamic datasource configuration (2.1.7) is this possible?

2006-01-17 Thread Geert Josten

After posting I thought my description may be a little vague...


(snip)


Any keywords for Google or code samples are more than welcome in my pursuit
to get this working...


I'll just supply some code snippets, they might give you new ideas.. (or not) 
:-P

One additional note: we decided to code pretty much all business logic in plain Java and connect to 
these classes from FlowScript. (that is really easy)


Tomcat 5.0 server.xml config snippets (I removed customer specific details):
  ...
  GlobalNamingResources
!-- 1. Define the global datasource (MYDS) --
Resource name=jdbc/MYDS auth=Container scope=Shareable 
type=javax.sql.DataSource/

	(you can probably name as many as you like, but dynamically as in without restarting tomcat I don't 
know..)


!-- 2. Define the datasource config params --
ResourceParams name=jdbc/MYDS
  parameter
namedriverClassName/name
valueoracle.jdbc.OracleDriver/value
  /parameter
  parameter
nameurl/name

valuejdbc:oracle:thin:@myoracleserver:myoracleport:myoracledbname/value
  /parameter
  parameter
nameusername/name
valuemyuser/value
  /parameter
  parameter
namepassword/name
valuemypassword/value
  /parameter
  parameter
namemaxActive/name
value20/value
  /parameter
  parameter
namemaxIdle/name
value10/value
  /parameter
  parameter
namemaxWait/name
value-1/value
  /parameter
/ResourceParams
  /GlobalNamingResources
  ...
  Service name=Catalina
Connector port=8080/
Engine name=Catalina defaultHost=localhost
  Logger className=org.apache.catalina.logger.FileLogger/
  Realm className=org.apache.catalina.realm.UserDatabaseRealm 
resourceName=UserDatabase/
  Host name=localhost appBase=webapps

!-- 3. Define a resourcelink in the defaultcontext that links to the 
global datasource --
DefaultContext
  ResourceLink name=jdbc/MYDS global=jdbc/MYDS 
type=javax.sql.DataSource/
/DefaultContext

!-- 4. Optional. Define an extra context that points to the webapps folder in the 
project-development environment (for easy reloading) --

Context path=/test_site docBase=C:\Projects\cocoon\webapp/
  /Host
/Engine
  /Service
  ...

Cocoon's web.xml snippet:
  ...
  resource-ref
res-ref-namejdbc/MYDS/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
  /resource-ref
  env-entry
env-entry-namedatasource.ref/env-entry-name
env-entry-valuejdbc/MYDS/env-entry-value
env-entry-typejava.lang.String/env-entry-type
  /env-entry
  env-entry
env-entry-namedatabase.sortingkey.default/env-entry-name
env-entry-value5-1;4-0;2-1/env-entry-value
env-entry-typejava.lang.String/env-entry-type
  /env-entry
  ...

Java code that creates a DataSource by looking up a setting from web.xml:
...
Context context = new InitialContext();
Context env = (Context) context.lookup(java:comp/env);

// lookup the datasource reference
String dataSourceRef = (String) config.get(GPS_AS_DATASOURCE_REF);

// get the datasource
dataSource = (DataSource) env.lookup(dataSourceRef);
...

The java-classes are wrapped in a jar, dropped in the web-inf/lib/ directory of Cocoon and in 
FlowScript we do an importPackage(Package.our.package.path) and create and access objects from 
them just as you would create and access any other class in Flowscript.


So you see, this isn't really Cocoon-specific. Nor does it tell how to use the datasource from 
cocoon components. On the other hand. You could handle database connectivity solely in Flowscript 
and pass any data relevant to components to them through parameters and alike..


HTH,
Geert

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]