Class JcrHashUtil


  • public final class JcrHashUtil
    extends Object
    Support of storing large flat data structures or lists of nodes in JCR. JSR-170 content repositories are designed for handling hierarchical data structures, and not for flat relational database style data. A consequence of this is that JCR implementations typically do not perform well when a node contains too many child nodes. This utility case provides support for storing large numbers of nodes under onder one parent node. This is simply achieved by maintaining a JCR friendly tree data structure / hash, to hold all of the child nodes. When declaring a node type that uses a node hashing for child nodes of a particular name, use the node type JcrHashUtil.WM_HASH_NAME. This child node definition should not be manditory or multiple. Note that child node order is not preserved for nodes stored in a hash.
    Author:
    Simon Edwards
    • Field Detail

      • WM_HASH_NAME

        public static String WM_HASH_NAME
      • WM_HASH_QUALIFIED_NAME

        public static String WM_HASH_QUALIFIED_NAME
    • Method Detail

      • registerNodeTypes

        public static void registerNodeTypes​(JcrRepository jcrRepository,
                                             javax.jcr.Session session)
                                      throws javax.jcr.RepositoryException
        Prepare the JCR. Sets up a required node types needed by the other methods.
        Parameters:
        jcrRepository -
        session -
        Throws:
        javax.jcr.RepositoryException
      • getHashNode

        public static javax.jcr.Node getHashNode​(javax.jcr.Node parent,
                                                 String relPath)
                                          throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException
      • addHashedNode

        public static javax.jcr.Node addHashedNode​(javax.jcr.Node parent,
                                                   String relPath,
                                                   String primaryNodeTypeName)
                                            throws javax.jcr.RepositoryException
        Create a new node at relPath Creates a new node at relPath relative to the given parent node, and manages all of the details of inserting the node into the hash structure.
        Parameters:
        parent - The node where the new node will be placed under.
        relPath - The relative path where the new node will be placed. This relative to the parent node, and should be of type JcrHashUtil.WM_HASH_NAME.
        primaryNodeTypeName - the type of node to create.
        Returns:
        the newly created node.
        Throws:
        javax.jcr.RepositoryException
      • addHashedNode

        public static javax.jcr.Node addHashedNode​(javax.jcr.Node parent,
                                                   String relPath)
                                            throws javax.jcr.RepositoryException
        Create a new node at relPath This is same as addHashedNode() except it uses the default node type.
        Parameters:
        parent - The node where the new node will be placed under.
        relPath - The relative path where the new node will be placed. This relative to the parent node, and should be of type JcrHashUtil.WM_HASH_NAME.
        Returns:
        the newly created node.
        Throws:
        javax.jcr.RepositoryException
      • moveHashedNode

        public static void moveHashedNode​(javax.jcr.Node sourceNode,
                                          javax.jcr.Node destParent,
                                          String relPath)
                                   throws javax.jcr.RepositoryException
        Move a node into a hash. Moves the given node from somewhere in the repository, to the new parent node.
        Parameters:
        sourceNode - The node to move.
        destParent - The node where the new node will be placed under.
        relPath - The relative path where the new node will be placed. This relative to the parent node, and should be of type JcrHashUtil.WM_HASH_NAME.
        Throws:
        javax.jcr.RepositoryException
      • copyHashedNode

        public static javax.jcr.Node copyHashedNode​(javax.jcr.Node sourceNode,
                                                    javax.jcr.Node destParent,
                                                    String relPath)
                                             throws javax.jcr.nodetype.ConstraintViolationException,
                                                    javax.jcr.version.VersionException,
                                                    javax.jcr.AccessDeniedException,
                                                    javax.jcr.PathNotFoundException,
                                                    javax.jcr.ItemExistsException,
                                                    javax.jcr.lock.LockException,
                                                    javax.jcr.RepositoryException
        Copy a node into a hash. Copies the given node from somewhere in the repository, to the new parent node.
        Parameters:
        sourceNode - The node to copy.
        destParent - The node where the new node will be placed under.
        relPath - The relative path where the new node will be placed. This relative to the parent node, and should be of type JcrHashUtil.WM_HASH_NAME.
        Throws:
        javax.jcr.RepositoryException
        javax.jcr.nodetype.ConstraintViolationException
        javax.jcr.version.VersionException
        javax.jcr.AccessDeniedException
        javax.jcr.PathNotFoundException
        javax.jcr.ItemExistsException
        javax.jcr.lock.LockException