Class Ofy


  • public class Ofy
    extends java.lang.Object
    A wrapper around ofy().

    The primary purpose of this class is to add functionality to support commit logs. It is simpler to wrap Objectify rather than extend it because this way we can remove some methods that we don't really want exposed and add some shortcuts.

    • Constructor Summary

      Constructors 
      Constructor Description
      Ofy​(Clock injectedClock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assertInTransaction()  
      void clearSessionCache()
      Clears the session cache.
      com.googlecode.objectify.cmd.Deleter delete()
      Delete, augmented to enroll the deleted entities in a commit log.
      com.googlecode.objectify.cmd.Deleter deleteIgnoringReadOnly()
      Delete, ignoring any backups or any read-only settings.
      com.googlecode.objectify.cmd.Deleter deleteWithoutBackup()
      Delete, without any augmentations except to check that we're not saving any virtual entities.
      <R> R doTransactionless​(java.util.function.Supplier<R> work)
      Execute some work in a transactionless context.
      <R> R doWithFreshSessionCache​(java.util.function.Supplier<R> work)
      Execute some work with a fresh session cache.
      com.googlecode.objectify.ObjectifyFactory factory()
      Returns the wrapped Objectify's ObjectifyFactory.
      com.googlecode.objectify.Key<CommitLogManifest> getCommitLogManifestKey()
      Returns key of CommitLogManifest that will be saved when the transaction ends.
      com.google.common.collect.ImmutableSet<com.googlecode.objectify.Key<?>> getSessionKeys()
      Returns keys read by Objectify during this transaction.
      com.googlecode.objectify.cmd.Loader load()
      Load from Datastore.
      com.googlecode.objectify.cmd.Saver save()
      Save, augmented to enroll the saved entities in a commit log and to check that we're not saving virtual entities.
      com.googlecode.objectify.cmd.Saver saveIgnoringReadOnly()
      Save, ignoring any backups or any read-only settings.
      com.googlecode.objectify.cmd.Saver saveWithoutBackup()
      Save, without any augmentations except to check that we're not saving any virtual entities.
      com.google.appengine.api.datastore.Entity toEntity​(java.lang.Object pojo)
      Convert an entity POJO to a datastore Entity.
      java.lang.Object toPojo​(com.google.appengine.api.datastore.Entity entity)
      Convert a datastore entity to a POJO.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Ofy

        @Inject
        public Ofy​(Clock injectedClock)
    • Method Detail

      • factory

        public com.googlecode.objectify.ObjectifyFactory factory()
        Returns the wrapped Objectify's ObjectifyFactory.
      • getSessionKeys

        public com.google.common.collect.ImmutableSet<com.googlecode.objectify.Key<?>> getSessionKeys()
        Returns keys read by Objectify during this transaction.

        This won't include the keys of asynchronous save and delete operations that haven't been reaped.

      • clearSessionCache

        public void clearSessionCache()
        Clears the session cache.
      • assertInTransaction

        public void assertInTransaction()
      • load

        public com.googlecode.objectify.cmd.Loader load()
        Load from Datastore.
      • delete

        public com.googlecode.objectify.cmd.Deleter delete()
        Delete, augmented to enroll the deleted entities in a commit log.

        We only allow this in transactions so commit logs can be written in tandem with the delete.

      • deleteWithoutBackup

        public com.googlecode.objectify.cmd.Deleter deleteWithoutBackup()
        Delete, without any augmentations except to check that we're not saving any virtual entities.

        No backups get written.

      • save

        public com.googlecode.objectify.cmd.Saver save()
        Save, augmented to enroll the saved entities in a commit log and to check that we're not saving virtual entities.

        We only allow this in transactions so commit logs can be written in tandem with the save.

      • saveWithoutBackup

        public com.googlecode.objectify.cmd.Saver saveWithoutBackup()
        Save, without any augmentations except to check that we're not saving any virtual entities.

        No backups get written.

      • saveIgnoringReadOnly

        public com.googlecode.objectify.cmd.Saver saveIgnoringReadOnly()
        Save, ignoring any backups or any read-only settings.
      • deleteIgnoringReadOnly

        public com.googlecode.objectify.cmd.Deleter deleteIgnoringReadOnly()
        Delete, ignoring any backups or any read-only settings.
      • doTransactionless

        public <R> R doTransactionless​(java.util.function.Supplier<R> work)
        Execute some work in a transactionless context.
      • doWithFreshSessionCache

        public <R> R doWithFreshSessionCache​(java.util.function.Supplier<R> work)
        Execute some work with a fresh session cache.

        This is useful in cases where we want to load the latest possible data from Datastore but don't need point-in-time consistency across loads and consequently don't need a transaction. Note that unlike a transaction's fresh session cache, the contents of this cache will be discarded once the work completes, rather than being propagated into the enclosing session.

      • getCommitLogManifestKey

        public com.googlecode.objectify.Key<CommitLogManifest> getCommitLogManifestKey()
        Returns key of CommitLogManifest that will be saved when the transaction ends.
      • toEntity

        public com.google.appengine.api.datastore.Entity toEntity​(java.lang.Object pojo)
        Convert an entity POJO to a datastore Entity.
      • toPojo

        public java.lang.Object toPojo​(com.google.appengine.api.datastore.Entity entity)
        Convert a datastore entity to a POJO.