Class RefUpdateContext

java.lang.Object
com.google.gerrit.server.update.context.RefUpdateContext
All Implemented Interfaces:
AutoCloseable

public class RefUpdateContext extends Object implements AutoCloseable
Passes additional information about an operation to the BatchRefUpdate#execute method.

To pass the additional information RefUpdateContext, wraps a code into an open RefUpdateContext, e.g.:


 try(RefUpdateContext ctx = RefUpdateContext.open(RefUpdateType.CHANGE_MODIFICATION)) {
   ...
   // some code which modifies a ref using BatchRefUpdate.execute method
 }
 
When the BatchRefUpdate#execute method is executed, it can get all opened contexts and use it for an additional actions, e.g. it can put it in the reflog.

The information provided by this class is used internally in google.

The InMemoryRepositoryManager file makes some validation to ensure that RefUpdateContext is used correctly within the code (see thee validateRefUpdateContext method).

The class includes only operations from open-source gerrit and can be extended (see TestActionRefUpdateContext for example how to extend it).

  • Constructor Details

    • RefUpdateContext

      protected RefUpdateContext(Optional<String> justification)
  • Method Details

    • open

      protected static <T extends RefUpdateContext> T open(T ctx)
      Opens a provided context.
    • open

      public static RefUpdateContext open(RefUpdateContext.RefUpdateType updateType)
      Opens a context of a give type.
    • openDirectPush

      public static RefUpdateContext openDirectPush(Optional<String> justification)
      Opens a direct push context with an optional justification.
    • getOpenedContexts

      public static com.google.common.collect.ImmutableList<RefUpdateContext> getOpenedContexts()
      Returns the list of opened contexts; the first element is the outermost context.
    • hasOpen

      public static boolean hasOpen(RefUpdateContext.RefUpdateType type)
      Checks if there is an open context of the given type.
    • getCurrent

      protected static final Deque<RefUpdateContext> getCurrent()
    • addCustomData

      public void addCustomData(Object data)
      Add custom data.

      Custom data is always stored on the top-level context, but can be added through any context.

    • getCustomData

      public <T> com.google.common.collect.ImmutableList<T> getCustomData(Class<T> clazz)
      Get all custom data that has a type that is assignable from the given class.

      Custom data is always stored on the top-level context, but can be retrieved through any context.

    • clearCustomData

      public <T> void clearCustomData(Class<T> clazz)
      Remove all custom data that has a type that is assignable from the given class.

      Custom data is only stored on the top-level context, but clearing custom data can be done through any context.

    • getUpdateType

      public final RefUpdateContext.RefUpdateType getUpdateType()
      Returns the type of RefUpdateContext.

      For descendants, always return RefUpdateContext.RefUpdateType.OTHER (except known descendants defined as nested classes).

    • getJustification

      public final Optional<String> getJustification()
      Returns the justification for the operation.
    • close

      public void close()
      Closes the current context.
      Specified by:
      close in interface AutoCloseable