Class GraphTraversal


  • public class GraphTraversal
    extends java.lang.Object
    An alternative implementation of model object graph traversal, relying on SELECTing in advance for making decisions, instead of rolling back to savepoints to recover from failed attempts to act.
    Since:
    5.1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  GraphTraversal.PlanExecutor
      Executor that allows callers to actually perform the planned action.
      static interface  GraphTraversal.Processor
      Executes the planned operation.
    • Constructor Summary

      Constructors 
      Constructor Description
      GraphTraversal​(org.hibernate.Session session, ome.system.EventContext eventContext, ACLVoter aclVoter, GraphPathBean graphPathBean, com.google.common.collect.SetMultimap<java.lang.String,​java.lang.String> unnullable, GraphPolicy policy, GraphTraversal.Processor processor)
      Construct a new instance of a graph traversal manager.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void assertNoPolicyViolations()
      Check that there are no policy violations matched by p:error policy rules.
      void assertNoUnlinking()
      Assert that unlinkTargets(boolean) need not be called.
      com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> getLinkeds​(java.lang.String propertyValueClass, java.lang.String propertyName, java.lang.Long id)
      Get the model objects that are linked to by the given object via the given property.
      com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> getLinkers​(java.lang.String propertyValueClass, java.lang.String propertyName, java.lang.Long id)
      Get the model objects that link to the given object via the given property.
      java.util.Map.Entry<com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long>,​com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long>> planOperation​(com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> objects, boolean include, boolean applyRules)
      Traverse model object graph to determine steps for the proposed operation.
      java.util.Map.Entry<java.util.Collection<ome.model.IObject>,​java.util.Collection<ome.model.IObject>> planOperation​(java.util.Collection<? extends ome.model.IObject> objectInstances, boolean include, boolean applyRules)
      Traverse model object graph to determine steps for the proposed operation.
      GraphTraversal.PlanExecutor processTargets()
      Prepare to process the targeted model objects.
      void setOwnsAll()
      Deprecated.
      An ugly expedient hack that requires review and may be removed without notice.
      GraphTraversal.PlanExecutor unlinkTargets​(boolean isUnlinkIncludeFromExclude)
      Prepare to remove links between the targeted model objects and the remainder of the model object graph.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GraphTraversal

        public GraphTraversal​(org.hibernate.Session session,
                              ome.system.EventContext eventContext,
                              ACLVoter aclVoter,
                              GraphPathBean graphPathBean,
                              com.google.common.collect.SetMultimap<java.lang.String,​java.lang.String> unnullable,
                              GraphPolicy policy,
                              GraphTraversal.Processor processor)
        Construct a new instance of a graph traversal manager.
        Parameters:
        session - the Hibernate session
        eventContext - the current event context
        aclVoter - ACL voter for permissions checking
        graphPathBean - the graph path bean
        unnullable - properties that, while nullable, may not be nulled by a graph traversal operation
        policy - how to determine which related objects to include in the operation
        processor - how to operate on the resulting target object graph
    • Method Detail

      • planOperation

        public java.util.Map.Entry<com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long>,​com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long>> planOperation​(com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> objects,
                                                                                                                                                                                                                  boolean include,
                                                                                                                                                                                                                  boolean applyRules)
                                                                                                                                                                                                           throws GraphException
        Traverse model object graph to determine steps for the proposed operation.
        Parameters:
        objects - the model objects to process
        include - if the given model objects are to be included (instead of just deleted)
        applyRules - if the given model objects should have the policy rules applied to them
        Returns:
        the model objects included in the operation, and the deleted objects
        Throws:
        GraphException - if the model objects were not as expected
      • planOperation

        public java.util.Map.Entry<java.util.Collection<ome.model.IObject>,​java.util.Collection<ome.model.IObject>> planOperation​(java.util.Collection<? extends ome.model.IObject> objectInstances,
                                                                                                                                        boolean include,
                                                                                                                                        boolean applyRules)
                                                                                                                                 throws GraphException
        Traverse model object graph to determine steps for the proposed operation.
        Parameters:
        objectInstances - the model objects to process, may be unloaded with ID only
        include - if the given model objects are to be included (instead of just deleted)
        applyRules - if the given model objects should have the policy rules applied to them
        Returns:
        the model objects included in the operation, and the deleted objects, may be unloaded with ID only
        Throws:
        GraphException - if the model objects were not as expected
      • assertNoPolicyViolations

        public void assertNoPolicyViolations()
                                      throws GraphException
        Check that there are no policy violations matched by p:error policy rules.
        Throws:
        GraphException - if the policy rules are violated
      • unlinkTargets

        public GraphTraversal.PlanExecutor unlinkTargets​(boolean isUnlinkIncludeFromExclude)
                                                  throws GraphException
        Prepare to remove links between the targeted model objects and the remainder of the model object graph.
        Parameters:
        isUnlinkIncludeFromExclude - if GraphPolicy.Action.EXCLUDE objects must be unlinked from GraphPolicy.Action.INCLUDE objects and vice versa
        Returns:
        the actual unlinker for the targeted model objects, to be used by the caller
        Throws:
        GraphException - if the user does not have permission to unlink the targets
      • processTargets

        public GraphTraversal.PlanExecutor processTargets()
                                                   throws GraphException
        Prepare to process the targeted model objects.
        Returns:
        the actual processor for the targeted model objects, to be used by the caller
        Throws:
        GraphException - if the user does not have permission to process the targets or if a cycle is detected in the model object graph
      • getLinkeds

        public com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> getLinkeds​(java.lang.String propertyValueClass,
                                                                                                       java.lang.String propertyName,
                                                                                                       java.lang.Long id)
        Get the model objects that are linked to by the given object via the given property. Provides a window into the model object cache accumulated in planning a graph operation.
        Parameters:
        propertyValueClass - the full name of the model class that declares the given property
        propertyName - a property name, may be nested
        id - the ID of the model object doing the linking
        Returns:
        the class and ID of the model objects that are linked to by the given object, never null
      • getLinkers

        public com.google.common.collect.SetMultimap<java.lang.String,​java.lang.Long> getLinkers​(java.lang.String propertyValueClass,
                                                                                                       java.lang.String propertyName,
                                                                                                       java.lang.Long id)
        Get the model objects that link to the given object via the given property. Provides a window into the model object cache accumulated in planning a graph operation.
        Parameters:
        propertyValueClass - the full name of the model class that declares the given property
        propertyName - a property name, may be nested
        id - the ID of the model object being linked to
        Returns:
        the class and ID of the model objects that link to the given object, never null