Chapter 10. In-Memory Connector

10.1. The In-Memory Connector

The in-memory repository connector is a simple connector that creates a transient, in-memory repository. This repository is used as a very simple in-memory cache or as a standalone transient repository. This connector works well for a readable and writable repository source with small to moderate sized content that need not be permanently saved.

10.2. In-Memory Connector Properties

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

10.3. Configuring an In-Memory Connector

One way to configure the in-memory connector is to create JcrEngine instance with a repository source that uses the InMemoryRepositorySource class. For example:
JcrConfiguration config = ...
config.repositorySource("IMR Store")
      .usingClass(InMemoryRepositorySource.class)
      .setDescription("The repository for our content")
      .setProperty("predefinedWorkspaceNames", new String[] { "staging", "dev"})
      .setProperty("defaultWorkspaceName", workspaceName);
Another way to configure the in-memory connector is to create JcrConfiguration instance and load an XML configuration file that contains a repository source that uses the InMemoryRepositorySource class. For example a file named configRepository.xml can be created with these contents:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
    <!-- 
    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 'IMR Store' repository is an in-memory source with a single default workspace (though 
        others could be created, too).
        -->
        <mode:source jcr:name="IMR Store" 
                    mode:classname="org.modeshape.graph.connector.inmemory.InMemoryRepositorySource" 
                    mode:description="The repository for our content" 
                    mode:defaultWorkspaceName="default">
           <mode:predefinedWorkspaceNames>staging</mode:predefinedWorkspaceNames>
				   <mode:predefinedWorkspaceNames>dev</mode:predefinedWorkspaceNames>
				</mode:source>
				               
    </mode:sources>
    
	<!-- MIME type detectors and JCR repositories would be defined below --> 
</configuration>
The configuration can then be loaded from Java like this:
JcrConfiguration config = new JcrConfiguration().loadFrom("/configRepository.xml");