Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / labs / datastore / overlay / TransactionLinkedDatastoreServiceImpl.java
blob5f84ffc0868cecbc0e899dbf47bf7da0bce4bac6
1 package com.google.appengine.api.labs.datastore.overlay;
3 import static com.google.common.base.Preconditions.checkNotNull;
5 import com.google.appengine.api.datastore.BaseDatastoreService;
6 import com.google.appengine.api.datastore.DatastoreAttributes;
7 import com.google.appengine.api.datastore.DatastoreService;
8 import com.google.appengine.api.datastore.Entity;
9 import com.google.appengine.api.datastore.EntityNotFoundException;
10 import com.google.appengine.api.datastore.Index;
11 import com.google.appengine.api.datastore.Key;
12 import com.google.appengine.api.datastore.KeyRange;
13 import com.google.appengine.api.datastore.Transaction;
14 import com.google.appengine.api.datastore.TransactionOptions;
16 import java.util.List;
17 import java.util.Map;
19 /**
20 * A simple wrapper class that combines a {@link DatastoreService} with a {@link Transaction}. The
21 * purpose of this class is to avoid code duplication between the transaction and non-transaction
22 * versions of several API methods.
24 final class TransactionLinkedDatastoreServiceImpl extends TransactionLinkedBaseDatastoreServiceImpl
25 implements DatastoreService {
26 private final DatastoreService datastore;
28 public TransactionLinkedDatastoreServiceImpl(DatastoreService datastore, Transaction txn) {
29 super(txn);
30 this.datastore = datastore;
33 @Override
34 public Entity get(Key key) throws EntityNotFoundException {
35 checkNotNull(key);
36 return datastore.get(txn, key);
39 @Override
40 public Entity get( Transaction txn, Key key) throws EntityNotFoundException {
41 throw new UnsupportedOperationException(
42 "if you want to pass a txn explicitly, don't use this class");
45 @Override
46 public Map<Key, Entity> get(Iterable<Key> keys) {
47 checkNotNull(keys);
48 return datastore.get(txn, keys);
51 @Override
52 public Map<Key, Entity> get( Transaction txn, Iterable<Key> keys) {
53 throw new UnsupportedOperationException(
54 "if you want to pass a txn explicitly, don't use this class");
57 @Override
58 public Key put(Entity entity) {
59 checkNotNull(entity);
60 return datastore.put(txn, entity);
63 @Override
64 public Key put( Transaction txn, Entity entity) {
65 throw new UnsupportedOperationException(
66 "if you want to pass a txn explicitly, don't use this class");
69 @Override
70 public List<Key> put(Iterable<Entity> entities) {
71 checkNotNull(entities);
72 return datastore.put(txn, entities);
75 @Override
76 public List<Key> put( Transaction txn, Iterable<Entity> entities) {
77 throw new UnsupportedOperationException(
78 "if you want to pass a txn explicitly, don't use this class");
81 @Override
82 public void delete(Key... keys) {
83 datastore.delete(txn, keys);
86 @Override
87 public void delete( Transaction txn, Key... keys) {
88 throw new UnsupportedOperationException(
89 "if you want to pass a txn explicitly, don't use this class");
92 @Override
93 public void delete(Iterable<Key> keys) {
94 checkNotNull(keys);
95 datastore.delete(txn, keys);
98 @Override
99 public void delete( Transaction txn, Iterable<Key> keys) {
100 throw new UnsupportedOperationException(
101 "if you want to pass a txn explicitly, don't use this class");
104 @Override
105 public Transaction beginTransaction() {
106 return datastore.beginTransaction();
109 @Override
110 public Transaction beginTransaction(TransactionOptions options) {
111 checkNotNull(options);
112 return datastore.beginTransaction(options);
115 @Override
116 public KeyRange allocateIds(String kind, long num) {
117 checkNotNull(kind);
118 return datastore.allocateIds(kind, num);
121 @Override
122 public KeyRange allocateIds(Key parent, String kind, long num) {
123 checkNotNull(parent);
124 checkNotNull(kind);
125 return datastore.allocateIds(parent, kind, num);
128 @Override
129 public KeyRangeState allocateIdRange(KeyRange range) {
130 checkNotNull(range);
131 return datastore.allocateIdRange(range);
134 @Override
135 public DatastoreAttributes getDatastoreAttributes() {
136 return datastore.getDatastoreAttributes();
139 @Override
140 public Map<Index, Index.IndexState> getIndexes() {
141 return datastore.getIndexes();
144 @Override
145 protected BaseDatastoreService getUnderlyingBaseDatastoreService() {
146 return datastore;