Class PreGetContext
java.lang.Object
com.google.appengine.api.datastore.PreGetContext
- All Implemented Interfaces:
CallbackContext<Key>
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
Modifier and TypeMethodDescriptionReturns the element for which the callback has been invoked.int
Returns the index in the result ofCallbackContext.getElements()
of the element for which the callback has been invoked.Returns the current transaction, ornull
if there is no current transaction.Returns an unmodifiable view of the elements involved in the operation that triggered the callback..void
setResultForCurrentElement
(Entity entity) Set theEntity
that will be associated with theKey
returned byCallbackContext.getCurrentElement()
in the result of the get() operation.toString()
-
Method Details
-
setResultForCurrentElement
Set theEntity
that will be associated with theKey
returned byCallbackContext.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:
IllegalArgumentException
- If the key of the provided entity is not equal to the key returned byCallbackContext.getCurrentElement()
.
-
getElements
Description copied from interface:CallbackContext
Returns an unmodifiable view of the elements involved in the operation that triggered the callback..- Specified by:
getElements
in interfaceCallbackContext<T>
-
getCurrentTransaction
Description copied from interface:CallbackContext
Returns the current transaction, ornull
if there is no current transaction.- Specified by:
getCurrentTransaction
in interfaceCallbackContext<T>
-
getCurrentIndex
public int getCurrentIndex()Description copied from interface:CallbackContext
Returns the index in the result ofCallbackContext.getElements()
of the element for which the callback has been invoked.- Specified by:
getCurrentIndex
in interfaceCallbackContext<T>
-
getCurrentElement
Description copied from interface:CallbackContext
Returns the element for which the callback has been invoked. Shortcut forgetElements().getCurrentIndex()
.- Specified by:
getCurrentElement
in interfaceCallbackContext<T>
-
toString
-