Alternate Primrose Configuration for Tomcat versions 5.0 and below
Note for new users - this method is an alternative. Before you choose it, make sure you are aware of the "normal" install process, defined in the guides below :
Tomcat v5.5 and above ::: Tomcat v5.0 and below
This configuration method allows you to load all pools, using just one <Resource> tag entry in server.xml. It will not bind each pool under java:comp/env, but will provide access to the pools like the example below.
Note that this approach is not right for everyone, because it means that you have to write some Primrose-Specific code in your applications, but is provided in case this suits some people.
Below is an example of how you might use this approach. Note that 'AllPrimrosePools' must be the JNDI name specified in the server.xml ; and 'myPoolName' must be a pool defined in the primrose.config file.
public static Connection getPrimroseConnection() throws Exception {
InitialContext ctx = new InitialContext();
PoolLoader pl = (PoolLoader)ctx.lookup("java:comp/env/AllPrimrosePools");
Pool myPool = pl.findExistingPool("myPoolName");
if (myPool != null) {
return myPool.getConnection();
} else {
// Can't find pool ... handle error
throw new Exception("Cannot find pool");
}
}
There are 3 main steps for enabling primrose to run within Tomcat.
Install jar file
Copy primrose.jar into Tomcat's user lib directory (eg TOMCAT_HOME/common/lib)
Configure server.xml to load primrose:
UnderGlobalNamingResourcestag in server.xml, define a pool loader, and a web console. There are two sections to add :
-
Tell Tomcat to load all pools
Make sure that the primroseConfigFile exists, and is configured correctly (see primroseConfig.html).<!-- Tell Tomcat to load all the pools in the defined config file --> <Resource name="AllPrimrosePools" auth="Container" type="uk.org.primrose.pool.core.PoolLoader" description="All Primrose pool loader"> </Resource> <ResourceParams name="AllPrimrosePools"> <parameter> <name>factory</name> <value>uk.org.primrose.vendor.tomcat.NoJndiLoaderFactory</value> </parameter> <name>primroseConfigFile</name> <value>/usr/tomcat/conf/primrose.config</value> </parameter> </ResourceParams>
-
Define an webconsole to provide web access to all pools (optional)
Make sure that the logFile directory exists, and can be written to by tomcat.<!-- Define a webconsole to provide web access to all pools (optional) --> <Resource name="webconsole" auth="Container" type="uk.org.primrose.vendor.tomcat.WebConsoleFactory" description="The anotherPool database pool"> </Resource> <ResourceParams name="webconsole"> <parameter> <name>factory</name> <value>uk.org.primrose.vendor.tomcat.WebConsoleFactory</value> </parameter> <parameter> <name>username</name> <value>admin</value> </parameter> <parameter> <name>password</name> <value>admin</value> </parameter> <parameter> <name>port</name> <value>8090</value> </parameter> <parameter> <name>logFile</name> <value>/usr/tomcat/logs/wbconsole.log</value> </parameter> <parameter> <name>logLevel</name> <value>verbose,info,warn,error,crisis</value> </parameter> </ResourceParams>
Also make sure that the port is available.
You may password protect the webconsole - if you not wish to, then just leave out the username and password elements.
-
Configure server.xml to link the configured pools to your webapps:
At the end of yourHosttag, add/alter theContexttags :<Context path="/RequestServices" debug="0" reloadable="true" crossContext="true"> <ResourceLink global="AllPrimrosePools" name="AllPrimrosePools" type="uk.org.primrose.pool.core.PoolLoader"/> </Context>


