14.在數據庫中(zhōng)存儲知識庫
概述
在介紹安(ān)裝(zhuāng)與配置一節時,很(hěn)重要一點那就是需要設置好規則相關文(wén)件庫的存儲方式。URule Pro規則引擎中(zhōng)規則相關資源文(wén)件存儲機制采用(yòng)的是jackrabbit實現,默認情況下,我們隻需要通過urule.repository.dir屬性來指定資源庫目錄,這樣就會在這個目錄下以文(wén)件形式存儲規則相關文(wén)件。
如果我想将讓資源庫存儲放到當前項目所在目錄,比如WEB-INF下的repo目錄中(zhōng),那麽我們可(kě)以在當前項目的WEB-INF目錄中(zhōng)創建一個名(míng)為(wèi)repo的目錄,然後設置urule.repository.dir屬性值為(wèi)“/WEB-INF/repo”,這樣urule在啓動的時候會自動将這個目錄作(zuò)為(wèi)repository的工(gōng)作(zuò)目錄。
将知識文(wén)件存儲到本地文(wén)件系統中(zhōng),對于多(duō)人開發的項目來說,就有(yǒu)些不方便,對于這種情況,我們可(kě)以将知識庫存儲于數據庫中(zhōng),這樣就可(kě)以解決上述問題。
在數據庫中(zhōng)存儲知識庫有(yǒu)兩種方式,一種是采用(yòng)Spring中(zhōng)配置數據源連接數據庫;另一種就是用(yòng)戶自定義jackrabbit的存儲xml配置文(wén)件,通過這個文(wén)件來自定義數據庫連接信息。當然這裏肯定推薦第一種采用(yòng)Spring中(zhōng)配置數據源連接數據庫方式。
這裏需要強調的是,當采用(yòng)xml配置方式來連接數據庫,那麽就需要手工(gōng)配置集群信息,如果不配置使用(yòng)過程中(zhōng)就可(kě)能(néng)會出現文(wén)件丢失的情況,就是說在未配置集群的情況下,一個應用(yòng)在保存規則時會覆蓋整個知識庫,從而産(chǎn)生另一個應用(yòng)配置的規則丢失的情況,這點一定要注意;如果采用(yòng)spring配置方式的話,那麽引擎會自動配置好集群信息。
采用(yòng)Spring中(zhōng)配置數據源連接數據庫
這種配置數據庫存儲的方式是我們強烈推薦的方法。具(jù)體(tǐ)做法是删除屬性文(wén)件中(zhōng)對urule.repository.dir屬性的配置信息(當然注釋也可(kě)以),然後添加在properties文(wén)件中(zhōng)添加一面兩個屬性即可(kě):
屬性名(míng) | 含義 |
---|---|
urule.repository.datasourcename | 當前在标準spring context中(zhōng)已配置的數據源的bean id |
urule.repository.databasetype | 當前采用(yòng)數據源對應的數據庫類型,目前支持的類型有(yǒu)6種,分(fēn)别是:mysql、mssql、oracle、db2、derby以及postgresql |
下面這段是配置在Spring中(zhōng)的一個連接到Mysql數據庫的數據源連接配置,它的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&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>
要讓我們的知識庫使用(yòng)這個數據源,我們隻需要在properties文(wén)件中(zhōng)添加一個名(míng)為(wèi)urule.repository.datasourcename屬性,值為(wèi)mysqlDatasource,同時該連接是一個mysql數據庫,所以還需要設置urule.repository.databasetype屬性值為(wèi)mysql,這樣就可(kě)以使用(yòng)這個配置在Spring中(zhōng)的數據源來作(zuò)為(wèi)URule Pro中(zhōng)知識庫相關文(wén)件的存儲庫。
當采用(yòng)Spring中(zhōng)配置的數據源連接數據庫時,引擎會自動添加集群功能(néng),所以這種配置方式是我們推薦的。
如果我們采用(yòng)後面的配置XML的方式連接數據庫則需要手動配置集群,如果不添加集群配置的話,那麽在使用(yòng)中(zhōng)如有(yǒu)一個以上應用(yòng)連接同一個存儲知識庫的數據庫,在規則編寫定義時則可(kě)能(néng)會出現文(wén)件丢失情況。
用(yòng)戶自定義jackrabbit的存儲xml配置文(wén)件
對于有(yǒu)過jackrabbit使用(yòng)經驗的用(yòng)戶來說,可(kě)能(néng)需要進一步控制資源文(wén)件的存儲方式,對于這種情況,URule Pro提供了一個名(míng)為(wèi)“urule.repository.xml”的屬性,通過設置這個屬性的值,指定一個定義好的jackrabbit配置文(wén)件的位置,這樣URule Pro中(zhōng)的jackrabbit就可(kě)以按這個配置文(wén)件配置方式運行,采用(yòng)這種方式,需要我們将屬性文(wén)件中(zhōng)配置的urule.repository.dir屬性以及urule.repository.datasourcename和urule.repository.databasetype屬性删除或注釋。
如:urule.repository.xml=/WEB-INF/test.xml,那就表示系統将采用(yòng)當前應用(yòng)根下的WEB-INF目錄下的text.xml文(wén)件來運行jackrabbit;urule.repository.xml=classpath:com/bstek/app/test.xml,則表示系統将采用(yòng)當前應用(yòng)classpath下com/bstek/app目錄下的test.xml文(wén)件來運行jackrabbit。
下面是幾種常見的用(yòng)數據庫來作(zuò)為(wèi)repository的xml配置文(wén)件,實際使用(yòng)時我們隻需要修改其中(zhōng)的數據庫連接即可(kě)。
連接數據庫的配置方式有(yǒu)兩種,分(fēn)别是連接池方式以及JNDI方式,我們先來看看連接池方式的XML配置。
連接池方式配置
MySQL連接配置文(wén)件
<?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&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連接配置文(wén)件
<?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,那麽上述配置中(zhō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連接配置文(wén)件
<?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連接配置文(wén)件
<?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>
值得注意的是,一旦配置好基于數據庫的存儲方式,那麽在第一次啓動時jackrabbit會幫助我們自動創建所需要的表信息。
在我們通過urule.repository.xml屬性指定一個文(wén)件采用(yòng)數據庫方式存儲資源文(wén)件時,系統啓動時還需要一個目錄來存儲一些臨時文(wén)件,這時如果我們通過urule.repository.dir屬性指定了一個目錄,那麽這些臨時文(wén)件将會存儲在這個目錄中(zhōng);如果沒有(yǒu)通過urule.repository.dir屬性指定了一個目錄,那麽引擎将在JVM臨時目錄中(zhōng)存儲(通過System.getProperty("java.io.tmpdir")獲取到的目錄)。
在實際使用(yòng)當中(zhōng),如果我們采用(yòng)數據庫作(zuò)為(wèi)repository,同時有(yǒu)一個以上URule Server應用(yòng)将此庫作(zuò)為(wèi)repository,那麽對于jackrabbit來說,就是一個典型的cluster配置,在這種情況下,如果直接使用(yòng)上述數據庫配置,那麽各個URule Server應用(yòng)中(zhōng)隻會看到應用(yòng)啓動時數據庫中(zhōng)存儲的repository信息,而對于其它後續其它URule Server對庫的修改是看不到的,為(wèi)解決這一問題,需要在上述xml配置中(zhōng)添加jackrabbit的cluster配置,這段cluster配置放在<Versioning/>節點之後即可(kě),不同數據庫的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>
在上述配置當中(zhōng),Cluster節點都有(yǒu)一個名(míng)為(wèi)syncDelay的屬性,該屬性用(yòng)于定義當前節點每隔多(duō)久與數據庫進行一次同步,單位是毫秒(miǎo),這裏設置的都是5000,就表示5000毫秒(miǎo),也就是每隔5秒(miǎo)與數據庫同步一次。同時,如果運行時出現下面錯誤,可(kě)以在Cluster節點還可(kě)以添加一個id屬性,用(yòng)于标識當前節點的ID。
集群下沒有(yǒu)為(wèi)Cluster節點指定id屬性時出現的錯誤:
Failed to access cluster node id: \cluster_node.id
JNDI方式
MySQL連接配置文(wén)件
<?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連接配置文(wén)件
<?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,那麽上述配置中(zhō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連接配置文(wén)件
<?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連接配置文(wén)件
<?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>
一旦配置好基于數據庫的存儲方式,那麽在第一次啓動時jackrabbit會幫助我們自動創建所需要的表信息。
在我們通過urule.repository.xml屬性指定一個文(wén)件采用(yòng)數據庫方式存儲資源文(wén)件時,系統啓動時還需要一個目錄來存儲一些臨時文(wén)件,這時如果我們通過urule.repository.dir屬性指定了一個目錄,那麽這些臨時文(wén)件将會存儲在這個目錄中(zhōng);如果沒有(yǒu)通過urule.repository.dir屬性指定了一個目錄,那麽引擎将在JVM臨時目錄中(zhōng)存儲(通過System.getProperty("java.io.tmpdir")獲取到的目錄)。
在實際使用(yòng)當中(zhōng),如果我們采用(yòng)數據庫作(zuò)為(wèi)repository,同時有(yǒu)一個以上URule Server應用(yòng)将此庫作(zuò)為(wèi)repository,那麽對于jackrabbit來說,就是一個典型的cluster配置,在這種情況下,如果直接使用(yòng)上述數據庫配置,那麽各個URule Server應用(yòng)中(zhōng)隻會看到應用(yòng)啓動時數據庫中(zhōng)存儲的repository信息,而對于其它後續其它URule Server對庫的修改是看不到的,為(wèi)解決這一問題,需要在上述xml配置中(zhōng)添加jackrabbit的cluster配置,這段cluster配置放在<Versioning/>節點之後即可(kě),不同數據庫的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>
在上述配置當中(zhōng),Cluster節點都有(yǒu)一個名(míng)為(wèi)syncDelay的屬性,該屬性用(yòng)于定義當前節點每隔多(duō)久與數據庫進行一次同步,單位是毫秒(miǎo),這裏設置的都是5000,就表示5000毫秒(miǎo),也就是每隔5秒(miǎo)與數據庫同步一次。同時,如果運行時出現下面錯誤,可(kě)以在Cluster節點還可(kě)以添加一個id屬性,用(yòng)于标識當前節點的ID。
集群下沒有(yǒu)為(wèi)Cluster節點指定id屬性時出現的錯誤:
Failed to access cluster node id: \cluster_node.id