Class PreGetContext
- java.lang.Object
-
- com.google.appengine.api.datastore.PreGetContext
-
- All Implemented Interfaces:
CallbackContext<Key>
public final class PreGetContext extends Object
ConcreteCallbackContextimplementation that is specific to intercepted get() operations. Methods annotated withPreGetthat receive instances of this class may modify the result of the get() operation by callingsetResultForCurrentElement(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 Description TgetCurrentElement()Returns the element for which the callback has been invoked.intgetCurrentIndex()Returns the index in the result ofCallbackContext.getElements()of the element for which the callback has been invoked.TransactiongetCurrentTransaction()Returns the current transaction, ornullif there is no current transaction.List<T>getElements()Returns an unmodifiable view of the elements involved in the operation that triggered the callback..voidsetResultForCurrentElement(Entity entity)Set theEntitythat will be associated with theKeyreturned byCallbackContext.getCurrentElement()in the result of the get() operation.StringtoString()
-
-
-
Method Detail
-
setResultForCurrentElement
public void setResultForCurrentElement(Entity entity)
Set theEntitythat will be associated with theKeyreturned 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
public List<T> getElements()
Description copied from interface:CallbackContextReturns an unmodifiable view of the elements involved in the operation that triggered the callback..- Specified by:
getElementsin interfaceCallbackContext<T>
-
getCurrentTransaction
public Transaction getCurrentTransaction()
Description copied from interface:CallbackContextReturns the current transaction, ornullif there is no current transaction.- Specified by:
getCurrentTransactionin interfaceCallbackContext<T>
-
getCurrentIndex
public int getCurrentIndex()
Description copied from interface:CallbackContextReturns the index in the result ofCallbackContext.getElements()of the element for which the callback has been invoked.- Specified by:
getCurrentIndexin interfaceCallbackContext<T>
-
getCurrentElement
public T getCurrentElement()
Description copied from interface:CallbackContextReturns the element for which the callback has been invoked. Shortcut forgetElements().getCurrentIndex().- Specified by:
getCurrentElementin interfaceCallbackContext<T>
-
-