Configuring Document Library to store data in Database

 

To Configure Liferay to store data of Document Library in Mysql Database Follow these Steps:

1) Shutdown the Liferay tomcat server.

2) Add these lines in Portal-ext.properties:


#dl.hook.impl=com.liferay.documentlibrary.util.FileSystemHook

dl.hook.impl=com.liferay.documentlibrary.util.JCRHook



##

## JCR

##


jcr.initialize.on.startup=true


jcr.workspace.name=liferay

jcr.node.documentlibrary=documentlibrary


jcr.jackrabbit.repository.root=${liferay.home}/data/jackrabbit

jcr.jackrabbit.config.file.path=${jcr.jackrabbit.repository.root}/repository.xml

jcr.jackrabbit.repository.home=${jcr.jackrabbit.repository.root}/home

jcr.jackrabbit.credentials.username=none

jcr.jackrabbit.credentials.password=none



3) Changes in \liferay-portal-5.2.0\data\jackrabbit\repository.xml


<Repository>

<!-- Commented to remove filesystem

<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">

<param name="path" value="${rep.home}/repository" />

</FileSystem> -->


<!--

Database File System (Cluster Configuration)


This is sample configuration for mysql persistence that can be used for

clustering Jackrabbit. For other databases, change the connection,

credentials, and schema settings.

-->


<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">

<param name="driver" value="com.mysql.jdbc.Driver"/>

<param name="url" value="jdbc:mysql://localhost/training" />

<param name="user" value="root" />

<param name="password" value="root" />

<param name="schema" value="mysql"/>

<param name="schemaObjectPrefix" value="J_R_FS_"/>

</FileSystem>


<Security appName="Jackrabbit">

<AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager" />

<LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">

<param name="anonymousId" value="anonymous" />

</LoginModule>

</Security>

<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="liferay" />

<Workspace name="${wsp.name}">

<!-- Commented to remove filesystem

<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">

<param name="path" value="${wsp.home}" />

</FileSystem>

<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager" /> -->


<!--

Database File System and Persistence (Cluster Configuration)


This is sample configuration for mysql persistence that can be used for

clustering Jackrabbit. For other databases, change the connection,

credentials, and schema settings.

-->


<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">

<param name="driver" value="com.mysql.jdbc.Driver" />

<param name="url" value="jdbc:mysql://localhost/training" />

<param name="user" value="root" />

<param name="password" value="root" />

<param name="schema" value="mysql" />

<param name="schemaObjectPrefix" value="J_PM_${wsp.name}_" />

<param name="externalBLOBs" value="false" />

</PersistenceManager>

<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">

<param name="driver" value="com.mysql.jdbc.Driver"/>

<param name="url" value="jdbc:mysql://localhost/training" />

<param name="user" value="root" />

<param name="password" value="root" />

<param name="schema" value="mysql"/>

<param name="schemaObjectPrefix" value="J_FS_${wsp.name}_"/>

</FileSystem>

</Workspace>

<Versioning rootPath="${rep.home}/version">

<!-- Commented to remove filesystem

<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">

<param name="path" value="${rep.home}/version" />

</FileSystem>

<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager" /> -->


<!--

Database File System and Persistence (Cluster Configuration)


This is sample configuration for mysql persistence that can be used for

clustering Jackrabbit. For other databases, change the connection,

credentials, and schema settings.

-->


<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">

<param name="driver" value="com.mysql.jdbc.Driver"/>

<param name="url" value="jdbc:mysql://localhost/training" />

<param name="user" value="root" />

<param name="password" value="root" />

<param name="schema" value="mysql"/>

<param name="schemaObjectPrefix" value="J_V_FS_"/>

</FileSystem>

<PersistenceManager class="org.apache.jackrabbit.core.state.db.SimpleDbPersistenceManager">

<param name="driver" value="com.mysql.jdbc.Driver" />

<param name="url" value="jdbc:mysql://localhost/training" />

<param name="user" value="root" />

<param name="password" value="root" />

<param name="schema" value="mysql" />

<param name="schemaObjectPrefix" value="J_V_PM_" />

<param name="externalBLOBs" value="false" />

</PersistenceManager>

</Versioning>


<!--

Cluster Configuration


This is sample configuration for mysql persistence that can be used for

clustering Jackrabbit. For other databases, change the connection,

credentials, and schema settings.

-->


<!--<Cluster id="node_1" syncDelay="5">

<Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">

<param name="revision" value="${rep.home}/revision"/>

<param name="driver" value="com.mysql.jdbc.Driver"/>

<param name="url" value="jdbc:mysql://localhost/jcr"/>

<param name="user" value=""/>

<param name="password" value=""/>

<param name="schema" value="mysql"/>

<param name="schemaObjectPrefix" value="J_C_"/>

</Journal>

</Cluster>-->

</Repository>


  1. Start Liferay Tomcat Server

  2. Now Create a Document and upload content in Document Library

  3. At time of uploding content more then few MB, If you get 'max_allowed_packet' related error. Then Shutdown the Liferay Tomcat Server.

  4. Edit \Program Files\MySQL\MySQL Server 5.0\my.ini

  5. Set the 'max_allowed_packet' property by adding the following line at the end [[mysqld] Section ]


# 16777216 = 16M so upto 16MB packet can be uploaded

      max_allowed_packet=16777216


  1. Restart MySql Service

  2. Start Liferay Tomcat Server and you can upload the Content in Document Library

 

Blogs
Tarun,

This will change for new documents upload. How to migrate existing documents in file system?

Vivek
Thanks for sharing this Tarun. I echo Vivek's question. Is there a way to migrate existing documents?
And could you tell something about the performance in relation to the file based storage? I mean, jackrabbit is by default using the filesystem.
Unless performance is horrible, I am all for moving over to the DB -- if for no other reason than easier maintenance and backups.
Can we limit directory size limits? Be it at per document library instance or at user level or community level etc?
I can't get this to work. Liferay is completely ignoring my repository.xml

I can even have an error in the XML file and Liferay will still happily load my existing (file base) repository emoticon
This is what I have working now with SQL Server:

<?xml version="1.0"?>

<Repository>

<!--
DbFileSystem is a generic JDBC-based FileSystem implementation for Jackrabbit
that persists file system entries in a database table.
-->
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="FS_"/>
</FileSystem>

<!--
Implements a trivially simple authentication mechanism that accepts any
username and any password as valid authentication credentials.
-->
<Security appName="Jackrabbit">
<AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager" />
<LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
<param name="anonymousId" value="anonymous" />
</LoginModule>
</Security>


<Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="frcop" />
<Workspace name="${wsp.name}">

<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.MSSqlPersistenceManager">
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="PM_${wsp.name}_" />
</PersistenceManager>
<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="FS_${wsp.name}_"/>
</FileSystem>
</Workspace>

<Versioning rootPath="${rep.home}/version">

<FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="V_FS_"/>
</FileSystem>
<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.MSSqlPersistenceManager">
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="V_PM_" />
</PersistenceManager>
</Versioning>

<!--
Cluster Configuration

This is sample configuration for mysql persistence that can be used for
clustering Jackrabbit. For other databases, change the connection,
credentials, and schema settings.

<Cluster id="w4" syncDelay="5">
<Journal class="org.apache.jackrabbit.core.journal.DatabaseJournal">
<param name="revision" value="${rep.home}/revision"/>
<param name="driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<param name="url" value="jdbc:sqlserver://localhost:1433;databaseName=dbname;SelectMethod=cursor;integratedSecurity=true"/>
<param name="schema" value="mssql" />
<param name="schemaObjectPrefix" value="J_C_"/>
</Journal>
</Cluster>
-->
</Repository>
MySql Table?
Thanks Tarun. I've been working on a company intranet in a number of Liferay testbed setups. So I have migrated data to different instances. It'll be useful to have document library in the database from a migration perspective. 2 questions that perhaps someone can answer:
1. Which table in MySql stores the documents?
2. Is there any way to migrate existing documents in the file system to MySql>
TIA
org.apache.jackrabbit.core.config.ConfigurationException: Configuration file syntax error. (Line: 23 Column: 15): Content is not allowed in trailing section.: Content is not allowed in trailing section.
Hi Jonas,
I'm using Liferay 6.0.5 and I want to configure document Library to store Data in data base
is that blog useful for my Liferay version?