diff --git a/src/main/java/com/googlecode/objectify/ObjectifyFactory.java b/src/main/java/com/googlecode/objectify/ObjectifyFactory.java index 3f51c8ea..6a601209 100644 --- a/src/main/java/com/googlecode/objectify/ObjectifyFactory.java +++ b/src/main/java/com/googlecode/objectify/ObjectifyFactory.java @@ -371,19 +371,30 @@ public Objectify ofy() { *

This will be removed from the public API in the future.

*/ private ObjectifyImpl open() { - final ObjectifyImpl objectify = new ObjectifyImpl(this); + final ObjectifyImpl objectify = createObjectify(); stacks.get().add(objectify); return objectify; } /** This is for internal housekeeping and is not part of the public API */ public ObjectifyImpl open(final ObjectifyOptions opts, final Transactor transactor) { - final ObjectifyImpl objectify = new ObjectifyImpl(this, opts, transactor); + final ObjectifyImpl objectify = createObjectify(opts, transactor); stacks.get().add(objectify); return objectify; } - /** This is for internal housekeeping and is not part of the public API */ + /** Can be overridden if you want to subclass ObjectifyImpl */ + protected ObjectifyImpl createObjectify() { + return new ObjectifyImpl(this); + } + + /** This is only public because it is used from the impl package, and is not part of the + * public API. However, it can be overridden if you want to subclass ObjectifyImpl. */ + public ObjectifyImpl createObjectify(final ObjectifyOptions opts, final Transactor transactor) { + return new ObjectifyImpl(this, opts, transactor); + } + + /** This is for internal housekeeping and is not part of the public API */ public void close(final Objectify ofy) { final Deque stack = stacks.get(); if (stack.isEmpty()) @@ -527,4 +538,4 @@ public Ref ref(final Key key) { public Ref ref(final T value) { return ref(key(value)); } -} \ No newline at end of file +} diff --git a/src/main/java/com/googlecode/objectify/impl/ObjectifyImpl.java b/src/main/java/com/googlecode/objectify/impl/ObjectifyImpl.java index 2392db12..df412489 100644 --- a/src/main/java/com/googlecode/objectify/impl/ObjectifyImpl.java +++ b/src/main/java/com/googlecode/objectify/impl/ObjectifyImpl.java @@ -133,17 +133,12 @@ public Objectify mandatoryTransactions(boolean value) { /** Same transactor, different options */ ObjectifyImpl options(final ObjectifyOptions opts) { - return makeNew(opts, transactor); + return factory().createObjectify(opts, transactor); } /** Same options, different transactor */ ObjectifyImpl transactor(final Transactor transactor) { - return makeNew(options, transactor); - } - - /** Can be overriden if you want to subclass the ObjectifyImpl */ - protected ObjectifyImpl makeNew(final ObjectifyOptions opts, final Transactor transactor) { - return new ObjectifyImpl(factory, opts, transactor); + return factory().createObjectify(options, transactor); } /* (non-Javadoc) @@ -356,4 +351,4 @@ public void close() { factory().close(this); } -} \ No newline at end of file +}