google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

Enhancement: Allow Factory to have default options #51

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

See:
http://groups.google.com/group/objectify-appengine/browse_thread/thread/dc3265b5
cab05db8

Suggested code:
private final ObjectifyOpts defaultOpts;

ObjectifyFactory() {
    this(new ObjectifyOpts());
}

ObjectifyFactory(ObjectifyOpts defaultOpts) {
    this.defaultOpts = defaultOpts;
}

public Objectify begin() {
    return begin(defaultOpts);
}

public Objectify beginTransaction() {
    // not 100% sure about consistency!
    return this.begin(defaultOpts.clone().setBeginTransaction(true)
    .setConsistency(Consistency.STRONG));
}

public ObjectifyOpts getDefaultOpts() {
    // defensive copy, so callers do not modify the default
    return defaultOpts.clone();
}

Requires ObjectifyOpts.clone() or an equivalent (public static ObjectifyOpts 
copy(ObjectifyOpts opts))

Original issue reported on code.google.com by twl.e...@gmail.com on 8 Sep 2010 at 3:07

GoogleCodeExporter commented 9 years ago
After thinking about this for a bit I prefer to add an overrideable protected 
createObjectifyOpts() method on ObjectifyFactory and if users want to make 
set/get methods on their own it's reasonable.  As it's probably rare, I'd 
rather keep this out of the public API.

I'll put a clone() method on ObjectifyOpts though.

Original comment by lhori...@gmail.com on 10 Sep 2010 at 4:20

GoogleCodeExporter commented 9 years ago
Added clone() to ObjectifyOpts and overrideable createDefaultOpts() to 
ObjectifyFactory.  This should be enough to get you what you want.

Original comment by lhori...@gmail.com on 27 Sep 2010 at 7:54