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
;
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
) {
30 this.datastore
= datastore
;
34 public Entity
get(Key key
) throws EntityNotFoundException
{
36 return datastore
.get(txn
, key
);
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");
46 public Map
<Key
, Entity
> get(Iterable
<Key
> keys
) {
48 return datastore
.get(txn
, keys
);
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");
58 public Key
put(Entity entity
) {
60 return datastore
.put(txn
, entity
);
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");
70 public List
<Key
> put(Iterable
<Entity
> entities
) {
71 checkNotNull(entities
);
72 return datastore
.put(txn
, entities
);
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");
82 public void delete(Key
... keys
) {
83 datastore
.delete(txn
, keys
);
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");
93 public void delete(Iterable
<Key
> keys
) {
95 datastore
.delete(txn
, keys
);
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");
105 public Transaction
beginTransaction() {
106 return datastore
.beginTransaction();
110 public Transaction
beginTransaction(TransactionOptions options
) {
111 checkNotNull(options
);
112 return datastore
.beginTransaction(options
);
116 public KeyRange
allocateIds(String kind
, long num
) {
118 return datastore
.allocateIds(kind
, num
);
122 public KeyRange
allocateIds(Key parent
, String kind
, long num
) {
123 checkNotNull(parent
);
125 return datastore
.allocateIds(parent
, kind
, num
);
129 public KeyRangeState
allocateIdRange(KeyRange range
) {
131 return datastore
.allocateIdRange(range
);
135 public DatastoreAttributes
getDatastoreAttributes() {
136 return datastore
.getDatastoreAttributes();
140 public Map
<Index
, Index
.IndexState
> getIndexes() {
141 return datastore
.getIndexes();
145 protected BaseDatastoreService
getUnderlyingBaseDatastoreService() {