Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / CacheValueUtil.java
blobaed0d55d8df3c9cb9ab9dce7ced90883933f70a6
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;
10 /**
11 * Utility methods for the {@link CacheValue} protocol buffer object.
14 final class CacheValueUtil {
16 /**
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();
28 if (entity != null) {
29 VersionedEntity versionedEntity = new VersionedEntity();
30 versionedEntity.setV3Entity(entity);
31 cacheValue.setEntity(versionedEntity);
33 return cacheValue;
34 } else {
35 checkArgument(entity == null, "An entity can only be specified with state " + State.ENTITY);
36 CacheValue cacheValue = new CacheValue();
37 cacheValue.setState(state);
38 return cacheValue;
42 /**
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() {