Apache Jackrabbit : ConnectionPooling

Database connection pooling

The forthcoming 2.0 release of Jackrabbit will feature connection pooling for database components (also see JCR-1456). Connection pooling has been added to:

  1. The database data store components: org.apache.jackrabbit.core.data.db.Db{{`Data}}`Store and subclasses. 2. The database filesystem components: org.apache.jackrabbit.core.fs.db.Database{{`File}}`System and subclasses. 3. The database journal components: org.apache.jackrabbit.core.journal.DatabaseJournal and subclasses. 4. The database bundle persistence managers: org.apache.jackrabbit.core.persistence.pool.Bundle{{`Db}}Persistence`Manager and subclasses.

Important: Please note that the pooling implementations of the bundle persistence managers have not replaced the original implementation but have been added in a separate package.

The components can be configured in the same way as before via the repository descriptor (also see ConfigurationOverview and Jackrabbit configuration). The components that have the same database URL, driver and user will share the same connection pool (with an unlimited number of connections). Thus, existing deployments can easily be migrated to use pooling: The only change needed is to replace any bundle persistence manager class by it's twin brother from the pooling package.

A new configuration element has been added to the repository descriptor: the Data{{`Sources element in which you can explicitly configure one or more pooling data sources. Each Data}}`Source has a logical name which can be used in the configuration of the above mentioned components. Here follows an example.

Note: the logicalName parameter of the DataSource element has been replaced by the name attribute as of 2.0-beta5.

<?xml version="1.0"?>
<Repository>
    <DataSources>
        <DataSource name="ds1">
            <param name="driver" value="oracle.jdbc.driver.OracleDriver" />
            <param name="url" value="jdbc:oracle:thin:@localhost:1521:xe" />
            <param name="user" value="usr" />
            <param name="password" value="pwd" />
            <param name="databaseType" value="oracle"/>
            <param name="validationQuery" value="select 'validationQuery' from dual"/>
            <param name="maxPoolSize" value="10"/>
        </DataSource>
    </DataSources>
    <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
        <param name="dataSourceName" value="ds1"/>
        <param name="schemaObjectPrefix" value="fs_" />
    </FileSystem>
    <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="dataSourceName" value="ds1"/>
        <param name="schemaObjectPrefix" value="ds_" />
    </DataStore>
    <Security appName="Jackrabbit">
        <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security" />
        <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager" />
        <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
           <param name="anonymousId" value="anonymous"/>
           <param name="adminId" value="admin"/>
        </LoginModule>
    </Security>
    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" maxIdleTime="2"/>
    <Workspace name="${wsp.name}">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
            <param name="dataSourceName" value="ds1"/>
            <param name="schemaObjectPrefix" value="fs_${wsp.name}_" />
        </FileSystem>
        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager">
            <param name="dataSourceName" value="ds1"/>
            <param name="schemaObjectPrefix" value="pm_${wsp.name}_" />
        </PersistenceManager>
        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
            <param name="path" value="${wsp.home}/index"/>
        </SearchIndex>
    </Workspace>
    <Versioning rootPath="${rep.home}/version">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
            <param name="dataSourceName" value="ds1"/>
            <param name="schemaObjectPrefix" value="fs_ver_" />
        </FileSystem>
        <PersistenceManager class="rg.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager">
            <param name="dataSourceName" value="ds1"/>
            <param name="schemaObjectPrefix" value="pm_ver_" />
        </PersistenceManager>
    </Versioning>
    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
        <param name="path" value="${rep.home}/repository/index"/>
    </SearchIndex>
</Repository>

Note that you can use data sources from JNDI in both the configuration of the data sources and in configuration of the components (see UsingJNDIDataSource). Jackrabbit will use these JNDI data sources as-is and will not wrap pools around them.

The configuration options for the data source elements are the following:

Required properties:

  • name : the logical name of the data source which can be used in the configuration of database components
  • driver : the driver (which may be javax.naming.InitialContext for a JNDI data source)
  • url : the database URL (or the JNDI lookup name)
  • dbType : the database type (also called schema in the configuration of some database components)

Optional properties (typically used with non-JNDI data sources):

  • user : the database user
  • password : the password for the database user

Optional properties for non-JNDI data sources:

  • validationQuery : the validation query to use (Jackrabbit guesses a default if it is not specified and logs a warning if it has no proper default)
  • maxPoolSize : the maximum pool size (unlimited by default)