Title: Using JNDI
Cayenne can be setup to obtain a DataSource via JNDI, instead of using its own connection pool. To do that Cayenne DataNodes must be configured to use JNDIDataSourceFactory. This can be done in the modeler as shown on the pictures below.
1. Select JNDIDataSourceFactory:
2. Enter DataSource JNDI Name:
To be able to connect to the database from CayenneModeler when JNDIDataSourceFactory is specified (and thus no explicit connection information is associated with the DataNode), you may configure a "local DataSource" (see a corresponding Modeler Guide chapter).
Cayenne also supports container-less runtime operation of the JNDI node. It works like this:
This way Modeler preferences database works as a substitute of a JNDI provider, saving extra configuration steps in development mode, when an application may be run from the IDE. Requirements to use this feature:
Depending on how the DataSource is mapped in the container, you may optionally need to add a "resource-ref" entry to the web.xml file:
<resource-ref> <res-ref-name>jdbc/myds</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
Below are sample DataSource configurations for Tomcat 5.5 and newer. The XML should be pasted into $CATALINA_HOME/conf/server.xml file between the <Host>...</Host> tags. Of course the application name and database parameters should be replaced with the correct values for the target environment.
<Context path="/myapp" docBase="myapp"> <Resource name="jdbc/myds" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:dbname" username="userName" password="secret" maxActive="5" maxIdle="2"/> </Context>