1 package com
.google
.appengine
.api
.datastore
;
3 import static com
.google
.common
.base
.Preconditions
.checkArgument
;
5 import com
.google
.apphosting
.datastore
.EntityStorage
.CacheValue
;
6 import com
.google
.apphosting
.datastore
.EntityStorage
.CacheValue
.State
;
7 import com
.google
.apphosting
.datastore
.EntityStorage
.VersionedEntity
;
8 import com
.google
.storage
.onestore
.v3
.OnestoreEntity
.EntityProto
;
11 * Utility methods for the {@link CacheValue} protocol buffer object.
14 final class CacheValueUtil
{
17 * Creates a {@link CacheValue} object.
19 * @param state the state of the cache value.
20 * @param entity the entity to store in the cache value.
21 * @return a {@code CacheValue} object for the specified {@code state} and {@code entity}.
22 * @throws IllegalArgumentException if a non-null {@code entity} is specified with
23 * a {@code state} other than {@link State#ENTITY}.
25 public static CacheValue
createCacheValue(State state
, EntityProto entity
) {
26 if (state
== State
.ENTITY
) {
27 CacheValue cacheValue
= new CacheValue();
29 VersionedEntity versionedEntity
= new VersionedEntity();
30 versionedEntity
.setV3Entity(entity
);
31 cacheValue
.setEntity(versionedEntity
);
35 checkArgument(entity
== null, "An entity can only be specified with state " + State
.ENTITY
);
36 CacheValue cacheValue
= new CacheValue();
37 cacheValue
.setState(state
);
43 * @return {@code true} if the {@code state} is used to demarcate datastore operations.
45 public static boolean isDatastoreOpState(State state
) {
46 return (state
== State
.READ_IN_PROGRESS
) || (state
== State
.MUTATION_IN_PROGRESS
);
49 private CacheValueUtil() {