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
;
19 import java
.util
.concurrent
.Future
;
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
;
37 public Future
<Entity
> get(Key key
) {
39 return datastore
.get(txn
, key
);
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");
49 public Future
<Map
<Key
, Entity
>> get(Iterable
<Key
> keys
) {
51 return datastore
.get(txn
, keys
);
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");
61 public Future
<Key
> put(Entity entity
) {
63 return datastore
.put(txn
, entity
);
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");
73 public Future
<List
<Key
>> put(Iterable
<Entity
> entities
) {
74 checkNotNull(entities
);
75 return datastore
.put(txn
, entities
);
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");
85 public Future
<Void
> delete(Key
... keys
) {
86 return datastore
.delete(txn
, keys
);
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");
96 public Future
<Void
> delete(Iterable
<Key
> keys
) {
98 return datastore
.delete(txn
, keys
);
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");
108 public Future
<Transaction
> beginTransaction() {
109 return datastore
.beginTransaction();
113 public Future
<Transaction
> beginTransaction(TransactionOptions options
) {
114 checkNotNull(options
);
115 return datastore
.beginTransaction(options
);
119 public Future
<KeyRange
> allocateIds(String kind
, long num
) {
121 return datastore
.allocateIds(kind
, num
);
125 public Future
<KeyRange
> allocateIds(Key parent
, String kind
, long num
) {
126 checkNotNull(parent
);
128 return datastore
.allocateIds(parent
, kind
, num
);
132 public Future
<DatastoreAttributes
> getDatastoreAttributes() {
133 return datastore
.getDatastoreAttributes();
137 public Future
<Map
<Index
, Index
.IndexState
>> getIndexes() {
138 return datastore
.getIndexes();
142 public PreparedQuery
prepare(Query query
) {
144 return datastore
.prepare(txn
, query
);
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");
154 public Transaction
getCurrentTransaction() {
155 return datastore
.getCurrentTransaction();
159 public Transaction
getCurrentTransaction(Transaction returnedIfNoTxn
) {
160 return datastore
.getCurrentTransaction(returnedIfNoTxn
);
164 public Collection
<Transaction
> getActiveTransactions() {
165 return datastore
.getActiveTransactions();