Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / labs / datastore / overlay / TransactionLinkedAsyncDatastoreServiceImpl.java
blobd502a3c1b8612c55a8d8b6d0860f9b31b89d2e1b
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.AsyncDatastoreService;
6 import com.google.appengine.api.datastore.DatastoreAttributes;
7 import com.google.appengine.api.datastore.Entity;
8 import com.google.appengine.api.datastore.Index;
9 import com.google.appengine.api.datastore.Key;
10 import com.google.appengine.api.datastore.KeyRange;
11 import com.google.appengine.api.datastore.PreparedQuery;
12 import com.google.appengine.api.datastore.Query;
13 import com.google.appengine.api.datastore.Transaction;
14 import com.google.appengine.api.datastore.TransactionOptions;
16 import java.util.Collection;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.concurrent.Future;
21 /**
22 * A simple wrapper class that combines an {@link AsyncDatastoreService} with a {@link Transaction}.
23 * The purpose of this class is to avoid code duplication between the transaction and
24 * non-transaction versions of several API methods.
26 final class TransactionLinkedAsyncDatastoreServiceImpl implements AsyncDatastoreService {
28 private final AsyncDatastoreService datastore;
29 private final Transaction txn;
31 public TransactionLinkedAsyncDatastoreServiceImpl(AsyncDatastoreService datastore, Transaction txn) {
32 this.datastore = datastore;
33 this.txn = txn;
36 @Override
37 public Future<Entity> get(Key key) {
38 checkNotNull(key);
39 return datastore.get(txn, key);
42 @Override
43 public Future<Entity> get( Transaction txn, Key key) {
44 throw new UnsupportedOperationException(
45 "if you want to pass a txn explicitly, don't use this class");
48 @Override
49 public Future<Map<Key, Entity>> get(Iterable<Key> keys) {
50 checkNotNull(keys);
51 return datastore.get(txn, keys);
54 @Override
55 public Future<Map<Key, Entity>> get( Transaction txn, Iterable<Key> keys) {
56 throw new UnsupportedOperationException(
57 "if you want to pass a txn explicitly, don't use this class");
60 @Override
61 public Future<Key> put(Entity entity) {
62 checkNotNull(entity);
63 return datastore.put(txn, entity);
66 @Override
67 public Future<Key> put( Transaction txn, Entity entity) {
68 throw new UnsupportedOperationException(
69 "if you want to pass a txn explicitly, don't use this class");
72 @Override
73 public Future<List<Key>> put(Iterable<Entity> entities) {
74 checkNotNull(entities);
75 return datastore.put(txn, entities);
78 @Override
79 public Future<List<Key>> put( Transaction txn, Iterable<Entity> entities) {
80 throw new UnsupportedOperationException(
81 "if you want to pass a txn explicitly, don't use this class");
84 @Override
85 public Future<Void> delete(Key... keys) {
86 return datastore.delete(txn, keys);
89 @Override
90 public Future<Void> delete( Transaction txn, Key... keys) {
91 throw new UnsupportedOperationException(
92 "if you want to pass a txn explicitly, don't use this class");
95 @Override
96 public Future<Void> delete(Iterable<Key> keys) {
97 checkNotNull(keys);
98 return datastore.delete(txn, keys);
101 @Override
102 public Future<Void> delete( Transaction txn, Iterable<Key> keys) {
103 throw new UnsupportedOperationException(
104 "if you want to pass a txn explicitly, don't use this class");
107 @Override
108 public Future<Transaction> beginTransaction() {
109 return datastore.beginTransaction();
112 @Override
113 public Future<Transaction> beginTransaction(TransactionOptions options) {
114 checkNotNull(options);
115 return datastore.beginTransaction(options);
118 @Override
119 public Future<KeyRange> allocateIds(String kind, long num) {
120 checkNotNull(kind);
121 return datastore.allocateIds(kind, num);
124 @Override
125 public Future<KeyRange> allocateIds(Key parent, String kind, long num) {
126 checkNotNull(parent);
127 checkNotNull(kind);
128 return datastore.allocateIds(parent, kind, num);
131 @Override
132 public Future<DatastoreAttributes> getDatastoreAttributes() {
133 return datastore.getDatastoreAttributes();
136 @Override
137 public Future<Map<Index, Index.IndexState>> getIndexes() {
138 return datastore.getIndexes();
141 @Override
142 public PreparedQuery prepare(Query query) {
143 checkNotNull(query);
144 return datastore.prepare(txn, query);
147 @Override
148 public PreparedQuery prepare(Transaction txn, Query query) {
149 throw new UnsupportedOperationException(
150 "if you want to pass a txn explicitly, don't use this class");
153 @Override
154 public Transaction getCurrentTransaction() {
155 return datastore.getCurrentTransaction();
158 @Override
159 public Transaction getCurrentTransaction(Transaction returnedIfNoTxn) {
160 return datastore.getCurrentTransaction(returnedIfNoTxn);
163 @Override
164 public Collection<Transaction> getActiveTransactions() {
165 return datastore.getActiveTransactions();