14.在數(shù)據庫中存儲知識庫

概述

在介紹安裝與配置一節時(shí),很(hěn)重要一點那(nà)就是需要設置好規則相關文件庫的存儲方式。URule Pro規則引擎中規則相關資源文件存儲機制(zhì)采用的是jackrabbit實現,默認情況下,我們隻需要通(tōng)過urule.repository.dir屬性來(lái)指定資源庫目錄,這樣就會(huì)在這個(gè)目錄下以文件形式存儲規則相關文件。

如果我想将讓資源庫存儲放到當前項目所在目錄,比如WEB-INF下的repo目錄中,那(nà)麽我們可(kě)以在當前項目的WEB-INF目錄中創建一個(gè)名為(wèi)repo的目錄,然後設置urule.repository.dir屬性值為(wèi)“/WEB-INF/repo”,這樣urule在啓動的時(shí)候會(huì)自動将這個(gè)目錄作(zuò)為(wèi)repository的工作(zuò)目錄。

将知識文件存儲到本地文件系統中,對于多(duō)人(rén)開(kāi)發的項目來(lái)說,就有(yǒu)些(xiē)不方便,對于這種情況,我們可(kě)以将知識庫存儲于數(shù)據庫中,這樣就可(kě)以解決上(shàng)述問題。

在數(shù)據庫中存儲知識庫有(yǒu)兩種方式,一種是采用Spring中配置數(shù)據源連接數(shù)據庫;另一種就是用戶自定義jackrabbit的存儲xml配置文件,通(tōng)過這個(gè)文件來(lái)自定義數(shù)據庫連接信息。當然這裏肯定推薦第一種采用Spring中配置數(shù)據源連接數(shù)據庫方式。

這裏需要強調的是,當采用xml配置方式來(lái)連接數(shù)據庫,那(nà)麽就需要手工配置集群信息,如果不配置使用過程中就可(kě)能會(huì)出現文件丢失的情況,就是說在未配置集群的情況下,一個(gè)應用在保存規則時(shí)會(huì)覆蓋整個(gè)知識庫,從而産生(shēng)另一個(gè)應用配置的規則丢失的情況,這點一定要注意;如果采用spring配置方式的話(huà),那(nà)麽引擎會(huì)自動配置好集群信息。

采用Spring中配置數(shù)據源連接數(shù)據庫

這種配置數(shù)據庫存儲的方式是我們強烈推薦的方法。具體(tǐ)做(zuò)法是删除屬性文件中對urule.repository.dir屬性的配置信息(當然注釋也可(kě)以),然後添加在properties文件中添加一面兩個(gè)屬性即可(kě):

屬性名 含義
urule.repository.datasourcename 當前在标準spring context中已配置的數(shù)據源的bean id
urule.repository.databasetype 當前采用數(shù)據源對應的數(shù)據庫類型,目前支持的類型有(yǒu)6種,分别是:mysql、mssql、oracle、db2、derby以及postgresql

下面這段是配置在Spring中的一個(gè)連接到Mysql數(shù)據庫的數(shù)據源連接配置,它的Bean的Id為(wèi)"mysqlDatasource",如下所示:

<bean id="mysqlDatasource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="url"
        value="jdbc:mysql://localhost:3306/urule_test?useUnicode=true&amp;characterEncoding=UTF-8" />
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="username" value="root" />
    <property name="password" value="root" />
    <property name="minIdle" value="5" />
    <property name="maxActive" value="10" />
    <property name="maxWait" value="1000" />
    <property name="removeAbandonedTimeout" value="60" />
    <property name="removeAbandoned" value="true" />
    <property name="logAbandoned" value="true" />
</bean>

要讓我們的知識庫使用這個(gè)數(shù)據源,我們隻需要在properties文件中添加一個(gè)名為(wèi)urule.repository.datasourcename屬性,值為(wèi)mysqlDatasource,同時(shí)該連接是一個(gè)mysql數(shù)據庫,所以還(hái)需要設置urule.repository.databasetype屬性值為(wèi)mysql,這樣就可(kě)以使用這個(gè)配置在Spring中的數(shù)據源來(lái)作(zuò)為(wèi)URule Pro中知識庫相關文件的存儲庫。

當采用Spring中配置的數(shù)據源連接數(shù)據庫時(shí),引擎會(huì)自動添加集群功能,所以這種配置方式是我們推薦的。

如果我們采用後面的配置XML的方式連接數(shù)據庫則需要手動配置集群,如果不添加集群配置的話(huà),那(nà)麽在使用中如有(yǒu)一個(gè)以上(shàng)應用連接同一個(gè)存儲知識庫的數(shù)據庫,在規則編寫定義時(shí)則可(kě)能會(huì)出現文件丢失情況。

用戶自定義jackrabbit的存儲xml配置文件

對于有(yǒu)過jackrabbit使用經驗的用戶來(lái)說,可(kě)能需要進一步控制(zhì)資源文件的存儲方式,對于這種情況,URule Pro提供了一個(gè)名為(wèi)“urule.repository.xml”的屬性,通(tōng)過設置這個(gè)屬性的值,指定一個(gè)定義好的jackrabbit配置文件的位置,這樣URule Pro中的jackrabbit就可(kě)以按這個(gè)配置文件配置方式運行(xíng),采用這種方式,需要我們将屬性文件中配置的urule.repository.dir屬性以及urule.repository.datasourcename和(hé)urule.repository.databasetype屬性删除或注釋。

如:urule.repository.xml=/WEB-INF/test.xml,那(nà)就表示系統将采用當前應用根下的WEB-INF目錄下的text.xml文件來(lái)運行(xíng)jackrabbit;urule.repository.xml=classpath:com/bstek/app/test.xml,則表示系統将采用當前應用classpath下com/bstek/app目錄下的test.xml文件來(lái)運行(xíng)jackrabbit。

下面是幾種常見的用數(shù)據庫來(lái)作(zuò)為(wèi)repository的xml配置文件,實際使用時(shí)我們隻需要修改其中的數(shù)據庫連接即可(kě)。

連接數(shù)據庫的配置方式有(yǒu)兩種,分别是連接池方式以及JNDI方式,我們先來(lái)看看連接池方式的XML配置。

連接池方式配置

MySQL連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
    <DataSources>
        <DataSource name="dataSource">
            <param name="driver" value="com.mysql.jdbc.Driver" />
            <param name="url" value="jdbc:mysql://localhost:3306/urule?useUnicode=true&amp;characterEncoding=UTF-8" />
            <param name="user" value="root" />
            <param name="password" value="qwertyuioplm" />
            <param name="databaseType" value="mysql"/>
            <param name="maxPoolSize" value="10"/>
        </DataSource>
    </DataSources>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

Oracle連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
    <DataSources>
        <DataSource name="dataSource">
            <param name="driver" value="oracle.jdbc.driver.OracleDriver"/>
            <param name="url" value="jdbc:oracle:thin:@192.168.18.140:1521:ORCL"/>
            <param name="user" value="bstek"/>
            <param name="password" value="bstek"/>
            <param name="databaseType" value="oracle"/>
            <param name="maxPoolSize" value="10"/>
        </DataSource>
    </DataSources>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.OracleFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

如果當前Oracle的版本Oracle9,那(nà)麽上(shàng)述配置中的"org.apache.jackrabbit.core.fs.db.OracleFileSystem"類要改成“org.apache.jackrabbit.core.fs.db.Oracle9FileSystem”;“org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager”類同樣也需要改“org.apache.jackrabbit.core.persistence.pool.Oracle9PersistenceManager”。

SQLServer連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
    <DataSources>
        <DataSource name="dataSource">
            <param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <param name="url" value="jdbc:sqlserver://192.168.18.108:1433;DatabaseName=urule"/>
            <param name="user" value="sa"/>
            <param name="password" value="helpdesk"/>
            <param name="databaseType" value="mssql"/>
            <param name="maxPoolSize" value="10"/>
        </DataSource>
    </DataSources>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.MSSqlFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.MSSqlFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MSSqlPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.MSSqlFileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MSSqlPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

DB2連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.5//EN" "http://jackrabbit.apache.org/dtd/repository-1.5.dtd">
<Repository>
    <DataSources>
        <DataSource name="dataSource">
            <param name="driver" value="com.ibm.db2.jcc.DB2Driver"/>
            <param name="url" value="jdbc:db2:rule"/>
            <param name="user" value="bstek"/>
            <param name="password" value="bstek"/>
            <param name="databaseType" value="db2"/>
            <param name="maxPoolSize" value="10"/>
        </DataSource>
    </DataSources>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DB2FileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DB2FileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DB2FileSystem">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

值得(de)注意的是,一旦配置好基于數(shù)據庫的存儲方式,那(nà)麽在第一次啓動時(shí)jackrabbit會(huì)幫助我們自動創建所需要的表信息。

在我們通(tōng)過urule.repository.xml屬性指定一個(gè)文件采用數(shù)據庫方式存儲資源文件時(shí),系統啓動時(shí)還(hái)需要一個(gè)目錄來(lái)存儲一些(xiē)臨時(shí)文件,這時(shí)如果我們通(tōng)過urule.repository.dir屬性指定了一個(gè)目錄,那(nà)麽這些(xiē)臨時(shí)文件将會(huì)存儲在這個(gè)目錄中;如果沒有(yǒu)通(tōng)過urule.repository.dir屬性指定了一個(gè)目錄,那(nà)麽引擎将在JVM臨時(shí)目錄中存儲(通(tōng)過System.getProperty("java.io.tmpdir")獲取到的目錄)。

在實際使用當中,如果我們采用數(shù)據庫作(zuò)為(wèi)repository,同時(shí)有(yǒu)一個(gè)以上(shàng)URule Server應用将此庫作(zuò)為(wèi)repository,那(nà)麽對于jackrabbit來(lái)說,就是一個(gè)典型的cluster配置,在這種情況下,如果直接使用上(shàng)述數(shù)據庫配置,那(nà)麽各個(gè)URule Server應用中隻會(huì)看到應用啓動時(shí)數(shù)據庫中存儲的repository信息,而對于其它後續其它URule Server對庫的修改是看不到的,為(wèi)解決這一問題,需要在上(shàng)述xml配置中添加jackrabbit的cluster配置,這段cluster配置放在<Versioning/>節點之後即可(kě),不同數(shù)據庫的cluster配置如下。

  • SQLServer的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.MSSqlDatabaseJournal">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • Oracle的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.OracleDatabaseJournal">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • MySQL的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • DB2的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
      <param name="dataSourceName" value="dataSource"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>

在上(shàng)述配置當中,Cluster節點都有(yǒu)一個(gè)名為(wèi)syncDelay的屬性,該屬性用于定義當前節點每隔多(duō)久與數(shù)據庫進行(xíng)一次同步,單位是毫秒(miǎo),這裏設置的都是5000,就表示5000毫秒(miǎo),也就是每隔5秒(miǎo)與數(shù)據庫同步一次。同時(shí),如果運行(xíng)時(shí)出現下面錯誤,可(kě)以在Cluster節點還(hái)可(kě)以添加一個(gè)id屬性,用于标識當前節點的ID。

集群下沒有(yǒu)為(wèi)Cluster節點指定id屬性時(shí)出現的錯誤:

Failed to access cluster node id: \cluster_node.id

JNDI方式

MySQL連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
        <param name="databaseType" value="mysql"/>
        <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="mysql"/>
        <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="mysql"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

Oracle連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
        <param name="databaseType" value="oracle"/>
        <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="oracle"/>
        <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="oracle"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

如果當前Oracle的版本Oracle9,那(nà)麽上(shàng)述配置中的"org.apache.jackrabbit.core.fs.db.OracleFileSystem"類要改成“org.apache.jackrabbit.core.fs.db.Oracle9FileSystem”;“org.apache.jackrabbit.core.persistence.pool.OraclePersistenceManager”類同樣也需要改“org.apache.jackrabbit.core.persistence.pool.Oracle9PersistenceManager”。

SQLServer連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
        <param name="databaseType" value="mssql"/>
        <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="mssql"/>
        <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="mssql"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

DB2連接配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.6//EN" "view-source:http://jackrabbit.apache.org/dtd/repository-2.6-elements.dtd">
<Repository>
  <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_"/>
  </FileSystem>
  <Security appName="Jackrabbit">
    <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
    <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
      <param name="anonymousId" value="anonymous" />
      <param name="adminId" value="admin" />
    </LoginModule>
  </Security>
  <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
        <param name="databaseType" value="db2"/>
        <param name="schemaObjectPrefix" value="repo_ds_"/>
  </DataStore>
  <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
  <Workspace name="default">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_${wsp.name}_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="db2"/>
        <param name="schemaObjectPrefix" value="repo_pm_${wsp.name}_"/>
    </PersistenceManager>
  </Workspace>
  <Versioning rootPath="${rep.home}/version">
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
       <param name="driver" value="javax.naming.InitialContext"/>
       <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="repo_fsver_"/>
    </FileSystem>
    <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
        <param name="driver" value="javax.naming.InitialContext"/>
        <param name="url" value="java:comp/env/jdbc/Workspaces"/>
        <param name="schema" value="db2"/>
      <param name="schemaObjectPrefix" value="repo_ver_"/>
    </PersistenceManager>
  </Versioning>
</Repository>

一旦配置好基于數(shù)據庫的存儲方式,那(nà)麽在第一次啓動時(shí)jackrabbit會(huì)幫助我們自動創建所需要的表信息。

在我們通(tōng)過urule.repository.xml屬性指定一個(gè)文件采用數(shù)據庫方式存儲資源文件時(shí),系統啓動時(shí)還(hái)需要一個(gè)目錄來(lái)存儲一些(xiē)臨時(shí)文件,這時(shí)如果我們通(tōng)過urule.repository.dir屬性指定了一個(gè)目錄,那(nà)麽這些(xiē)臨時(shí)文件将會(huì)存儲在這個(gè)目錄中;如果沒有(yǒu)通(tōng)過urule.repository.dir屬性指定了一個(gè)目錄,那(nà)麽引擎将在JVM臨時(shí)目錄中存儲(通(tōng)過System.getProperty("java.io.tmpdir")獲取到的目錄)。

在實際使用當中,如果我們采用數(shù)據庫作(zuò)為(wèi)repository,同時(shí)有(yǒu)一個(gè)以上(shàng)URule Server應用将此庫作(zuò)為(wèi)repository,那(nà)麽對于jackrabbit來(lái)說,就是一個(gè)典型的cluster配置,在這種情況下,如果直接使用上(shàng)述數(shù)據庫配置,那(nà)麽各個(gè)URule Server應用中隻會(huì)看到應用啓動時(shí)數(shù)據庫中存儲的repository信息,而對于其它後續其它URule Server對庫的修改是看不到的,為(wèi)解決這一問題,需要在上(shàng)述xml配置中添加jackrabbit的cluster配置,這段cluster配置放在<Versioning/>節點之後即可(kě),不同數(shù)據庫的cluster配置如下。

  • SQLServer的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.MSSqlDatabaseJournal">
      <param name="driver" value="javax.naming.InitialContext"/>
      <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • Oracle的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.OracleDatabaseJournal">
      <param name="driver" value="javax.naming.InitialContext"/>
      <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • MySQL的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
      <param name="driver" value="javax.naming.InitialContext"/>
      <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>
  • DB2的Cluster配置

<Cluster syncDelay="5000">
    <Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
      <param name="driver" value="javax.naming.InitialContext"/>
      <param name="url" value="java:comp/env/jdbc/DataStore"/>
      <param name="schemaObjectPrefix" value="journal_"/>
    </Journal>
</Cluster>

在上(shàng)述配置當中,Cluster節點都有(yǒu)一個(gè)名為(wèi)syncDelay的屬性,該屬性用于定義當前節點每隔多(duō)久與數(shù)據庫進行(xíng)一次同步,單位是毫秒(miǎo),這裏設置的都是5000,就表示5000毫秒(miǎo),也就是每隔5秒(miǎo)與數(shù)據庫同步一次。同時(shí),如果運行(xíng)時(shí)出現下面錯誤,可(kě)以在Cluster節點還(hái)可(kě)以添加一個(gè)id屬性,用于标識當前節點的ID。

集群下沒有(yǒu)為(wèi)Cluster節點指定id屬性時(shí)出現的錯誤:

Failed to access cluster node id: \cluster_node.id

results matching ""

    No results matching ""