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