com.googlecode.objectify.impl
Class ObjectifyImpl

java.lang.Object
  extended by com.googlecode.objectify.impl.ObjectifyImpl
All Implemented Interfaces:
Objectify

public class ObjectifyImpl
extends java.lang.Object
implements Objectify

Implementation of the Objectify interface. This actually just calls through to the AsyncObjectify implementation and performs an immediate get().

Author:
Jeff Schnitzer

Field Summary
protected  AsyncObjectifyImpl async
          This must be passed in
protected  ObjectifyOpts opts
          Keep our original opts around so we can generate a DatastoreService when requested
 
Constructor Summary
ObjectifyImpl(ObjectifyOpts opts, AsyncObjectifyImpl async)
          Note that this sets the pointer back to the synchronous version in AsyncObjectifyImpl.
 
Method Summary
 AsyncObjectify async()
          Obtain the asynchronous version of the Objectify interface.
<T> void
delete(java.lang.Class<T> clazz, long id)
          A convenience method, shorthand for creating a key and deleting it.
<T> void
delete(java.lang.Class<T> clazz, java.lang.String name)
          A convenience method, shorthand for creating a key and deleting it.
 void delete(java.lang.Iterable<?> keysOrEntities)
          Deletes the specified entities in a parallel batch operation.
 void delete(java.lang.Object... keysOrEntities)
          Deletes the specified entity.
<T> T
find(java.lang.Class<? extends T> clazz, long id)
          Same as get(Class, long) but returns null instead of throwing NotFoundException
<T> T
find(java.lang.Class<? extends T> clazz, java.lang.String name)
          Same as get(Class, name) but returns null instead of throwing NotFoundException
<T> T
find(Key<? extends T> key)
          Same as get(Key) but returns null instead of throwing NotFoundException
<S,T> java.util.Map<S,T>
get(java.lang.Class<? extends T> clazz, java.lang.Iterable<S> ids)
          A convenience method that prevents you from having to assemble all the Keys yourself and calling get(Iterable<Key>).
<T> T
get(java.lang.Class<? extends T> clazz, long id)
          A convenience method, shorthand for creating a key and calling get()
<S,T> java.util.Map<S,T>
get(java.lang.Class<? extends T> clazz, S... idsOrNames)
          Convenient varargs alias for get(Class, Iterable)
<T> T
get(java.lang.Class<? extends T> clazz, java.lang.String name)
          A convenience method, shorthand for creating a key and calling get()
<T> java.util.Map<Key<T>,T>
get(java.lang.Iterable<? extends Key<? extends T>> keys)
          Performs a parallel batch get, returning your entities.
<T> java.util.Map<Key<T>,T>
get(Key<? extends T>... keys)
          Varargs version of get(Iterable)
<T> T
get(Key<? extends T> key)
          Gets one instance of your entity.
 com.google.appengine.api.datastore.DatastoreService getDatastore()
          Obtain a DatastoreService with parameters roughly equivalent to this Objectify instance.
 ObjectifyFactory getFactory()
          Obtain the ObjectifyFactory from which this Objectify instance was created.
 com.google.appengine.api.datastore.Transaction getTxn()
          Get the underlying transaction object associated with this Objectify instance.
<T> java.util.Map<Key<T>,T>
put(java.lang.Iterable<? extends T> objs)
          Saves multiple entities to the datastore in a single parallel batch operation.
<T> java.util.Map<Key<T>,T>
put(T... objs)
          Convenient varargs alias for put(Iterable)
<T> Key<T>
put(T obj)
          Puts an entity in the datastore.
<T> Query<T>
query()
          Create a typesafe query across all kinds of entities.
<T> Query<T>
query(java.lang.Class<T> clazz)
          Create a typesafe query across one specific kind of entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

opts

protected ObjectifyOpts opts
Keep our original opts around so we can generate a DatastoreService when requested


async

protected AsyncObjectifyImpl async
This must be passed in

Constructor Detail

ObjectifyImpl

public ObjectifyImpl(ObjectifyOpts opts,
                     AsyncObjectifyImpl async)
Note that this sets the pointer back to the synchronous version in AsyncObjectifyImpl.

Method Detail

get

public <T> java.util.Map<Key<T>,T> get(java.lang.Iterable<? extends Key<? extends T>> keys)
Description copied from interface: Objectify

Performs a parallel batch get, returning your entities. This is faster and more efficient than fetching entities one at a time.

You can fetch entities of many different kinds in a single call. Entities not present in the datastore will be absent from the returned map. Otherwise, the iteration order of the result will match the order in the parameter.

Specified by:
get in interface Objectify
Parameters:
keys - are the keys to fetch; you can mix and match the types of objects.
Returns:
the keys that were found in the datastore, mapped to the related entity. The iteration order of the map will match the order of the keys argument. A empty map is returned if no keys are found in the datastore.
See Also:
DatastoreService.get(Iterable)

get

public <T> java.util.Map<Key<T>,T> get(Key<? extends T>... keys)
Description copied from interface: Objectify

Varargs version of get(Iterable)

Specified by:
get in interface Objectify

get

public <T> T get(Key<? extends T> key)
      throws NotFoundException
Description copied from interface: Objectify

Gets one instance of your entity.

Specified by:
get in interface Objectify
Throws:
NotFoundException - if the key does not exist in the datastore
See Also:
DatastoreService.get(Key)

get

public <T> T get(java.lang.Class<? extends T> clazz,
                 long id)
      throws NotFoundException
Description copied from interface: Objectify

A convenience method, shorthand for creating a key and calling get()

Specified by:
get in interface Objectify
Throws:
NotFoundException - if the key does not exist in the datastore

get

public <T> T get(java.lang.Class<? extends T> clazz,
                 java.lang.String name)
      throws NotFoundException
Description copied from interface: Objectify

A convenience method, shorthand for creating a key and calling get()

Specified by:
get in interface Objectify
Throws:
NotFoundException - if the key does not exist in the datastore

get

public <S,T> java.util.Map<S,T> get(java.lang.Class<? extends T> clazz,
                                    java.lang.Iterable<S> ids)
Description copied from interface: Objectify

A convenience method that prevents you from having to assemble all the Keys yourself and calling get(Iterable<Key>).

Note that unlike the standard batch get method, this method only gets a homogeneous set of objects.

Specified by:
get in interface Objectify
ids - must be of type Iterable (which translates to id keys) or of type Iterable (which translates to name keys).
Returns:
a map of the id/name to the entity pojo.

get

public <S,T> java.util.Map<S,T> get(java.lang.Class<? extends T> clazz,
                                    S... idsOrNames)
Description copied from interface: Objectify
Convenient varargs alias for get(Class, Iterable)

Specified by:
get in interface Objectify

find

public <T> T find(Key<? extends T> key)
Description copied from interface: Objectify
Same as get(Key) but returns null instead of throwing NotFoundException

Specified by:
find in interface Objectify

find

public <T> T find(java.lang.Class<? extends T> clazz,
                  long id)
Description copied from interface: Objectify
Same as get(Class, long) but returns null instead of throwing NotFoundException

Specified by:
find in interface Objectify

find

public <T> T find(java.lang.Class<? extends T> clazz,
                  java.lang.String name)
Description copied from interface: Objectify
Same as get(Class, name) but returns null instead of throwing NotFoundException

Specified by:
find in interface Objectify

put

public <T> Key<T> put(T obj)
Description copied from interface: Objectify

Puts an entity in the datastore.

If your entity has a null Long id, a fresh id will be generated and a new entity will be created in the database. If your entity already has an id (either long, Long, or String) value, any existing entity in the datastore with that id will be overwritten.

Generated ids are stored in the entity itself. If you put() an entity with a null Long id, it will be set before the method returns.

Specified by:
put in interface Objectify
Parameters:
obj - must be an object of a registered entity type.
Returns:
the key associated with the object.
See Also:
DatastoreService.put(com.google.appengine.api.datastore.Entity)

put

public <T> java.util.Map<Key<T>,T> put(java.lang.Iterable<? extends T> objs)
Description copied from interface: Objectify

Saves multiple entities to the datastore in a single parallel batch operation.

All the rules regarding generated ids in put() apply.

Note that the iteration order of the return value will be the same as the order of the parameter.

Specified by:
put in interface Objectify
Parameters:
objs - must all be objects of registered entity type
Returns:
a map of the keys to the very same object instances passed in
See Also:
DatastoreService.put(Iterable)

put

public <T> java.util.Map<Key<T>,T> put(T... objs)
Description copied from interface: Objectify
Convenient varargs alias for put(Iterable)

Specified by:
put in interface Objectify

delete

public void delete(java.lang.Object... keysOrEntities)
Description copied from interface: Objectify
Deletes the specified entity.

Specified by:
delete in interface Objectify
Parameters:
keysOrEntities - can be Keys, datastore Keys, or pojo entities. If it includes entities, only the id fields are relevant.

delete

public <T> void delete(java.lang.Class<T> clazz,
                       long id)
Description copied from interface: Objectify
A convenience method, shorthand for creating a key and deleting it.

Specified by:
delete in interface Objectify

delete

public <T> void delete(java.lang.Class<T> clazz,
                       java.lang.String name)
Description copied from interface: Objectify
A convenience method, shorthand for creating a key and deleting it.

Specified by:
delete in interface Objectify

delete

public void delete(java.lang.Iterable<?> keysOrEntities)
Description copied from interface: Objectify
Deletes the specified entities in a parallel batch operation. This is faster and more efficient than deleting them one by one.

Specified by:
delete in interface Objectify
Parameters:
keysOrEntities - can contain any mix of Key, datastore Key, or pojo entities. They need not be of the same type. If a pojo is used, only its id fields are relevant.
See Also:
DatastoreService.delete(Iterable)

query

public <T> Query<T> query()
Description copied from interface: Objectify

Create a typesafe query across all kinds of entities.

Specified by:
query in interface Objectify

query

public <T> Query<T> query(java.lang.Class<T> clazz)
Description copied from interface: Objectify

Create a typesafe query across one specific kind of entity.

Specified by:
query in interface Objectify

getTxn

public com.google.appengine.api.datastore.Transaction getTxn()
Description copied from interface: Objectify

Get the underlying transaction object associated with this Objectify instance.

Note that this is *not* the same as DatastoreService.getCurrentTransaction(), which uses implicit transaction management. Objectify does not use implicit (thread local) transactions.

Specified by:
getTxn in interface Objectify
Returns:
the transaction associated with this Objectify instance, or null if no transaction is associated with this instance.

getFactory

public ObjectifyFactory getFactory()
Description copied from interface: Objectify
Obtain the ObjectifyFactory from which this Objectify instance was created.

Specified by:
getFactory in interface Objectify
Returns:
the ObjectifyFactory associated with this Objectify instance.

async

public AsyncObjectify async()
Description copied from interface: Objectify
Obtain the asynchronous version of the Objectify interface. Provides async versions of get/put/delete calls. Note that all queries are automatically asynchronous; just create multiple Iterators before iterating them.

Specified by:
async in interface Objectify

getDatastore

public com.google.appengine.api.datastore.DatastoreService getDatastore()
Description copied from interface: Objectify

Obtain a DatastoreService with parameters roughly equivalent to this Objectify instance.

This should not normally be necessary. It allows you to work with raw Entity objects, allocate ids, and examine thread local transactions.

Note that Objectify does not actually use this DatastoreService in any way; all requests go through an AsyncDatastoreService. Also, even Google's DatastoreService implementation is just a facade around AsyncDatastoreService.

Specified by:
getDatastore in interface Objectify


Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1