# Class PreGetContext (5.0.3)

    public final class PreGetContext extends BaseCallbackContext<Key>

Concrete [CallbackContext](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.CallbackContext) implementation that is specific to intercepted get() operations.
Methods annotated with [PreGet](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreGet) that receive instances of this class may modify the result
of the get() operation by calling [#setResultForCurrentElement(Entity)](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.PreGetContext#com_google_appengine_api_datastore_PreGetContext_setResultForCurrentElement_com_google_appengine_api_datastore_Entity_). Keys that receive
results via this method will not be fetched from the datastore. This is an effective way to
inject cached results.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> com.google.appengine.api.datastore.BaseCallbackContext \> PreGetContext

## Inherited Members

com.google.appengine.api.datastore.BaseCallbackContext.getCurrentElement() com.google.appengine.api.datastore.BaseCallbackContext.getCurrentIndex() com.google.appengine.api.datastore.BaseCallbackContext.getCurrentTransaction() com.google.appengine.api.datastore.BaseCallbackContext.getElements() com.google.appengine.api.datastore.BaseCallbackContext.toString() [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Methods

### setResultForCurrentElement(Entity entity)

    public void setResultForCurrentElement(Entity entity)

Set the [Entity](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Entity) that will be associated with the [Key](https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entity` | `https://docs.cloud.google.com/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.datastore.Entity` The entity to provide as the result for the current element. |