Chapter 13. Disk Connector

13.1. The Disk Connector

This connector stores content in a ModeShape-specific file format on disk. Although this may seem similar in concept to the File System Connector (Chapter 11, File System Connector), this connector actually serves a much different purpose. While the File System Connector is designed to expose existing files and folders on the disk and allows ModeShape users to create content that can be read directly by other applications, the Disk Connector is designed for efficiency and stores content in a serialized representation that is not readily accessible to other applications. Conversely, the Disk Connector supports referenceable nodes and can efficiently access nodes by UUID, unlike the File System Connector.

13.2. Disk Connector Properties

The DiskSource class provides a number of JavaBean properties that control its behavior. For more information about these properties, refer to org.modeshape.connector.disk.DiskSource in the Data Services JavaDoc.

13.3. Configuring a Disk Connector

One way to configure the file system connector is to create a JcrConfiguration instance with a repository source that uses the DiskSource class. For example:
JcrConfiguration config = ...
config.repositorySource("Disk Store")
      .setDescription("The repository for our content")
      .setProperty("repositoryRootPath", "/home/content/someApp")
      .setProperty("defaultWorkspaceName", "prod")
      .setProperty("predefinedWorkspaceNames", new String[] { "staging", "dev"})
      .setProperty("rootNodeUuid", UUID.fromString("fd129c12-81a8-42ed-aa4b-820dba49e6f0")
      .setProperty("updatesAllowed", "true")
      .setProperty("creatingWorkspaceAllowed", "false");
Another way to configure the file system connector is to create a JcrConfiguration instance and load an XML configuration file that contains a repository source that uses the DiskSource class. For example a file named configRepository.xml can be created with these contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:mode="" xmlns:jcr="">
    Define the sources for the content.  These sources are directly accessible using the 
    ModeShape-specific Graph API. In fact, this is how the ModeShape JCR implementation works.  You can 
    think of these as being similar to JDBC DataSource objects, except that they expose graph 
    content via the Graph API instead of records via SQL or JDBC. 
    <mode:sources jcr:primaryType="nt:unstructured">
        The 'Disk Store' repository is a disk source with a three predefined workspaces 
        ("prod", "staging", and "dev").
        <mode:source jcr:name="Disk Store" 
        	mode:description="The repository for our content"
        	mode:updatesAllowed="true" >
      	    If desired, specify a cache policy that caches items in memory for 5 minutes (300 s).
      	    This fragment can be left out if the connector should not cache any content.
      	    <mode:cachePolicy jcr:name="nodeCachePolicy" 
      	      mode:timeToLive="300" />

	<!-- MIME type detectors and JCR repositories would be defined below --> 
The configuration can then be loaded from Java like this:
JcrConfiguration config = new JcrConfiguration().loadFrom("/configRepository.xml");