Skip to content

Commit 7e0a9ae

Browse files
committed
Converted the wrappers to directly extending the impls.
1 parent 8da9451 commit 7e0a9ae

21 files changed

Lines changed: 626 additions & 763 deletions

src/main/java/com/googlecode/objectify/Objectify.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ public interface Objectify
6060
*/
6161
Deleter delete();
6262

63-
/**
64-
* <p>Get the underlying transaction object associated with this Objectify instance. You typically
65-
* do not need to use this; use transact() instead.</p>
66-
*
67-
* <p>Note that this is *not* the same as {@code DatastoreService.getCurrentTransaction()},
68-
* which uses the Low-Level API's implicit transaction management. Every transactional {@code Objectify}
69-
* instance is associated with a specific {@code Transaction} object.</p>
70-
*
71-
* @return the low-level transaction associated with this Objectify instance,
72-
* or null if no transaction is associated with this instance.
73-
*/
74-
public Transaction getTxn();
75-
7663
/**
7764
* Obtain the ObjectifyFactory from which this Objectify instance was created.
7865
*
@@ -123,18 +110,17 @@ public interface Objectify
123110
Objectify cache(boolean value);
124111

125112
/**
126-
* <p>Creates a new Objectify instance that wraps a transaction. The instance inherits any
127-
* settings, but the session cache will be empty. Upon successful commit, the contents
128-
* of the session cache will be loaded back into the main session.</p>
113+
* <p>Get the underlying transaction object associated with this Objectify instance. You typically
114+
* do not need to use this; use transact() instead.</p>
129115
*
130-
* <p>This method exists for low-level manipulation of transactions and does not modify
131-
* the transaction stack in {@code ObjectifyService}. It should only be used if you know
132-
* exactly what you are doing; for almost all use cases, you should use the {@code transact()}
133-
* method instead.</p>
116+
* <p>Note that this is *not* the same as {@code DatastoreService.getCurrentTransaction()},
117+
* which uses the Low-Level API's implicit transaction management. Every transactional {@code Objectify}
118+
* instance is associated with a specific {@code Transaction} object.</p>
134119
*
135-
* @return a new Objectify instance with a fresh transaction
120+
* @return the low-level transaction associated with this Objectify instance,
121+
* or null if no transaction is associated with this instance.
136122
*/
137-
Objectify transaction();
123+
public Transaction getTransaction();
138124

139125
/**
140126
* <p>If you are in a transaction, this provides you an objectify instance which is outside of the
@@ -217,20 +203,14 @@ public interface Objectify
217203
*/
218204
void clear();
219205

220-
/**
221-
* Sets the object instance that should be passed on by the base implementation in subsequent actions; for
222-
* example, the Objectify instance that is passed to transact() Work. You probably don't need to worry about
223-
* this method; just subclass ObjectifyWrapper.
224-
*/
225-
void setWrapper(Objectify ofy);
226-
227206
/**
228207
* Convert a POJO object to a native datastore Entity. This is like a save() operation but without actually saving
229208
* the data to the datastore.
230209
*
231210
* @param pojo must be an instance of a registered pojo entity type.
232211
* @return the native datastore Entity equivalent of the pojo; exactly what Objectify would save if you saved the POJO normally.
233212
*/
213+
@Deprecated
234214
Entity toEntity(Object pojo);
235215

236216
/**
@@ -241,6 +221,7 @@ public interface Objectify
241221
* @param entity is a native datastore entity which has an appropriate kind registered in the ObjectifyFactory.
242222
* @return the POJO equivalent, just as if you had loaded the entity directly from Objectify.
243223
*/
224+
@Deprecated
244225
<T> T toPojo(Entity entity);
245226

246227
/**

src/main/java/com/googlecode/objectify/cmd/Loader.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Map;
44
import java.util.Set;
55

6+
import com.google.appengine.api.datastore.Entity;
67
import com.googlecode.objectify.Key;
78
import com.googlecode.objectify.LoadResult;
89
import com.googlecode.objectify.Objectify;
@@ -193,7 +194,7 @@ public interface Loader extends SimpleQuery<Object>
193194
<E> Map<Key<E>, E> values(Object... keysOrEntities);
194195

195196
/**
196-
* @return the parent Objectify instance (possibly the wrapper)
197+
* @return the parent Objectify instance
197198
*/
198199
Objectify getObjectify();
199200

@@ -203,14 +204,19 @@ public interface Loader extends SimpleQuery<Object>
203204
Set<Class<?>> getLoadGroups();
204205

205206
/**
206-
* Sets the object instance that should be passed on by the base implementation in subsequent actions.
207-
* You probably don't need to worry about this method; just subclass LoaderWrapper.
207+
* Convert a native datastore Entity into a typed POJO. This is like a load() operation except that you start with
208+
* the native datastore type instead of fetching it from the datastore. However, note that because of @Load annotations,
209+
* it is possible that datastore operations will be executed during the translation.
210+
*
211+
* @param entity is a native datastore entity which has an appropriate kind registered in the ObjectifyFactory.
212+
* @return the POJO equivalent, just as if you had loaded the entity directly from Objectify.
208213
*/
209-
void setWrapper(Loader loader);
214+
<T> T fromEntity(Entity entity);
210215

211216
/**
212217
* Get the entity for a key immediately. You rarely, if ever, should want to use this; it exists to support
213218
* Ref<?> behavior. Value will be loaded from the session if available, but will go to the datastore if necessary.
219+
* It is synchronous.
214220
*/
215221
<E> E now(Key<E> key);
216222
}

src/main/java/com/googlecode/objectify/cmd/Saver.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,55 @@
22

33
import java.util.Map;
44

5+
import com.google.appengine.api.datastore.Entity;
56
import com.googlecode.objectify.Key;
67
import com.googlecode.objectify.Result;
78

89

910
/**
1011
* <p>The top element in the command chain for saving entities in the datastore.</p>
11-
*
12+
*
1213
* @author Jeff Schnitzer <jeff@infohazard.org>
1314
*/
1415
public interface Saver
1516
{
1617
/**
1718
* <p>Asynchronously save a single entity in the datastore.<p>
18-
*
19+
*
1920
* <p>If the entity has a null Long id, the value will be autogenerated and populated on the entity object
2021
* when the async operation completes. If you require this value, call now() on the result.</p>
21-
*
22+
*
2223
* <p>Puts do not cascade.</p>
23-
*
24+
*
2425
* @param entity must be a registered entity type
2526
* @return an asynchronous result. To force a synchronous save, call Result.now().
2627
*/
2728
<E> Result<Key<E>> entity(E entity);
28-
29+
2930
/**
3031
* <p>Asynchronously save a batch of entities in the datastore.</p>
31-
*
32+
*
3233
* <p>If any entities have null Long ids, the values will be autogenerated and populated on the entity objects
3334
* when the async operation completes. If you require these values, call now() on the result.</p>
34-
*
35+
*
3536
* <p>Puts do not cascade.</p>
36-
*
37+
*
3738
* @param entities must be registered entity types
3839
* @return an asynchronous result. To force a synchronous save, call Result.now().
3940
*/
4041
<E> Result<Map<Key<E>, E>> entities(Iterable<E> entities);
41-
42+
4243
/**
4344
* A convenience method for entities(Iterable)
4445
*/
4546
<E> Result<Map<Key<E>, E>> entities(E... entities);
47+
48+
/**
49+
* Convert a POJO object to a native datastore Entity. This is like a save() operation but without actually saving
50+
* the data to the datastore.
51+
*
52+
* @param pojo must be an instance of a registered pojo entity type.
53+
* @return the native datastore Entity equivalent of the pojo; exactly what Objectify would save if you saved the POJO normally.
54+
*/
55+
Entity toEntity(Object pojo);
4656
}

src/main/java/com/googlecode/objectify/impl/cmd/LoaderImpl.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010
import java.util.Set;
1111

12+
import com.google.appengine.api.datastore.Entity;
1213
import com.google.common.base.Predicates;
1314
import com.google.common.collect.Maps;
1415
import com.googlecode.objectify.Key;
@@ -21,6 +22,7 @@
2122
import com.googlecode.objectify.impl.Keys;
2223
import com.googlecode.objectify.impl.engine.LoadEngine;
2324
import com.googlecode.objectify.impl.engine.QueryEngine;
25+
import com.googlecode.objectify.impl.translate.LoadContext;
2426
import com.googlecode.objectify.util.ResultCache;
2527
import com.googlecode.objectify.util.ResultNowFunction;
2628
import com.googlecode.objectify.util.ResultProxy;
@@ -33,17 +35,14 @@
3335
*/
3436
public class LoaderImpl extends Queryable<Object> implements Loader
3537
{
36-
/** */
37-
protected Loader wrapper = this;
38-
3938
/** */
4039
protected ObjectifyImpl ofy;
4140

4241
/** */
4342
protected Set<Class<?>> loadGroups;
4443

4544
/** */
46-
LoaderImpl(ObjectifyImpl ofy) {
45+
public LoaderImpl(ObjectifyImpl ofy) {
4746
super(null);
4847
this.ofy = ofy;
4948
this.loadGroups = Collections.<Class<?>>emptySet();
@@ -52,7 +51,7 @@ public class LoaderImpl extends Queryable<Object> implements Loader
5251
/**
5352
* Takes ownership of the fetch groups set.
5453
*/
55-
LoaderImpl(ObjectifyImpl ofy, Set<Class<?>> loadGroups) {
54+
public LoaderImpl(ObjectifyImpl ofy, Set<Class<?>> loadGroups) {
5655
super(null);
5756
this.ofy = ofy;
5857
this.loadGroups = Collections.unmodifiableSet(loadGroups);
@@ -215,7 +214,7 @@ public Map<Key<E>, E> nowUncached() {
215214
*/
216215
@Override
217216
public Objectify getObjectify() {
218-
return ofy.getWrapper();
217+
return ofy;
219218
}
220219

221220
/* (non-Javadoc)
@@ -227,14 +226,6 @@ public Set<Class<?>> getLoadGroups() {
227226
return loadGroups;
228227
}
229228

230-
/* (non-Javadoc)
231-
* @see com.googlecode.objectify.cmd.Loader#setWrapper(com.googlecode.objectify.cmd.Loader)
232-
*/
233-
@Override
234-
public void setWrapper(Loader loader) {
235-
this.wrapper = loader;
236-
}
237-
238229
/** */
239230
public ObjectifyImpl getObjectifyImpl() {
240231
return this.ofy;
@@ -264,4 +255,12 @@ public <E> E now(Key<E> key) {
264255
return createLoadEngine().load(key).now();
265256
}
266257

258+
/* (non-Javadoc)
259+
* @see com.googlecode.objectify.Objectify#toPojo(com.google.appengine.api.datastore.Entity)
260+
*/
261+
@Override
262+
public <T> T fromEntity(Entity entity) {
263+
return ofy.load(entity, new LoadContext(this, createLoadEngine()));
264+
}
265+
267266
}

0 commit comments

Comments
 (0)