com.google.appengine.api.datastore

## Class PreGetContext

- java.lang.Object
- - com.google.appengine.api.datastore.PreGetContext

- All Implemented Interfaces:
    CallbackContext<Key>

      public final class PreGetContext
      extends java.lang.Object

  Concrete `CallbackContext` implementation that is specific to intercepted get() operations. Methods annotated with `PreGet` that receive instances of this class may modify the result of the get() operation by calling `setResultForCurrentElement(Entity)`. Keys that receive results via this method will not be fetched from the datastore. This is an effective way to inject cached results.

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `getCurrentElement()`
    `int` | `getCurrentIndex()`
    `Transaction` | `getCurrentTransaction()`
    `java.util.List<T>` | `getElements()`
    `void` | `setResultForCurrentElement(Entity entity)` Set the `Entity` that will be associated with the `Key` returned by `getCurrentElement()` in the result of the get() operation.
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### setResultForCurrentElement

          public void setResultForCurrentElement(Entity entity)

      Set the `Entity` that will be associated with the `Key` returned by `getCurrentElement()` in the result of the get() operation. This will prevent the get() operation from fetching the Entity from the datastore. This is an effective way to inject cached results.
      Parameters:
        `entity` - The entity to provide as the result for the current element.
      Throws:
        `java.lang.IllegalArgumentException` - If the key of the provided entity is not equal to the key returned by `getCurrentElement()`.

    - #### getElements

          public java.util.List<T> getElements()

      Specified by:
        `getElements` in interface `CallbackContext<T>`
      Returns:
        An unmodifiable view of the elements involved in the operation that triggered the callback..

    - #### getCurrentTransaction

          public Transaction getCurrentTransaction()

      Specified by:
        `getCurrentTransaction` in interface `CallbackContext<T>`
      Returns:
        The current transaction, or `null` if there is no current transaction.

    - #### getCurrentIndex

          public int getCurrentIndex()

      Specified by:
        `getCurrentIndex` in interface `CallbackContext<T>`
      Returns:
        The index in the result of `CallbackContext.getElements()` of the element for which the callback has been invoked.

    - #### getCurrentElement

          public T getCurrentElement()

      Specified by:
        `getCurrentElement` in interface `CallbackContext<T>`
      Returns:
        The element for which the callback has been invoked. Shortcut for `getElements().getCurrentIndex()`.

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`