public final class PreGetContext
extends java.lang.Object
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.| Modifier and Type | Method and Description |
|---|---|
T |
getCurrentElement()
Returns the element for which the callback has been invoked.
|
int |
getCurrentIndex()
Returns the index in the result of
CallbackContext.getElements() of the element for which the callback
has been invoked. |
Transaction |
getCurrentTransaction()
Returns the current transaction, or
null if there is no current transaction. |
java.util.List<T> |
getElements()
Returns an unmodifiable view of the elements involved in the operation that triggered the
callback..
|
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() |
public void setResultForCurrentElement(Entity entity)
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.entity - The entity to provide as the result for the current element.java.lang.IllegalArgumentException - If the key of the provided entity is not equal to the key
returned by getCurrentElement().public java.util.List<T> getElements()
CallbackContextgetElements in interface CallbackContext<T>public Transaction getCurrentTransaction()
CallbackContextnull if there is no current transaction.getCurrentTransaction in interface CallbackContext<T>public int getCurrentIndex()
CallbackContextCallbackContext.getElements() of the element for which the callback
has been invoked.getCurrentIndex in interface CallbackContext<T>public T getCurrentElement()
CallbackContextgetElements().getCurrentIndex().getCurrentElement in interface CallbackContext<T>public java.lang.String toString()
toString in class java.lang.Object