PageRenderTime 77ms CodeModel.GetById 19ms app.highlight 52ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/google/appengine/datanucleus/WrappedDatastoreService.java

http://datanucleus-appengine.googlecode.com/
Java | 313 lines | 261 code | 31 blank | 21 comment | 0 complexity | c548d70860ecf75186f476362fc91893 MD5 | raw file
  1/**********************************************************************
  2Copyright (c) 2009 Google Inc.
  3
  4Licensed under the Apache License, Version 2.0 (the "License");
  5you may not use this file except in compliance with the License.
  6You may obtain a copy of the License at
  7
  8http://www.apache.org/licenses/LICENSE-2.0
  9
 10Unless required by applicable law or agreed to in writing, software
 11distributed under the License is distributed on an "AS IS" BASIS,
 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13See the License for the specific language governing permissions and
 14limitations under the License.
 15**********************************************************************/
 16package com.google.appengine.datanucleus;
 17
 18import com.google.appengine.api.datastore.DatastoreAttributes;
 19import com.google.appengine.api.datastore.DatastoreFailureException;
 20import com.google.appengine.api.datastore.DatastoreService;
 21import com.google.appengine.api.datastore.Entity;
 22import com.google.appengine.api.datastore.EntityNotFoundException;
 23import com.google.appengine.api.datastore.Index;
 24import com.google.appengine.api.datastore.Key;
 25import com.google.appengine.api.datastore.KeyRange;
 26import com.google.appengine.api.datastore.PreparedQuery;
 27import com.google.appengine.api.datastore.Query;
 28import com.google.appengine.api.datastore.Transaction;
 29import com.google.appengine.api.datastore.TransactionOptions;
 30
 31import java.util.Collection;
 32import java.util.ConcurrentModificationException;
 33import java.util.List;
 34import java.util.Map;
 35
 36import static com.google.appengine.datanucleus.DatastoreExceptionTranslator.wrapConcurrentModificationException;
 37import static com.google.appengine.datanucleus.DatastoreExceptionTranslator.wrapDatastoreFailureException;
 38import static com.google.appengine.datanucleus.DatastoreExceptionTranslator.wrapIllegalArgumentException;
 39
 40/**
 41 * {@link DatastoreService} implementation that catches runtime exceptions
 42 * thrown and wraps them in the appropriate DataNucleus exception.
 43 *
 44 * @author Max Ross <maxr@google.com>
 45 */
 46public class WrappedDatastoreService implements DatastoreService {
 47
 48  private final DatastoreService inner;
 49
 50  public WrappedDatastoreService(DatastoreService inner) {
 51    this.inner = inner;
 52  }
 53
 54  public DatastoreService getDelegate() {
 55    return inner;
 56  }
 57
 58  public Entity get(Key key) throws EntityNotFoundException {
 59    try {
 60      return inner.get(key);
 61    } catch (IllegalArgumentException e) {
 62      throw wrapIllegalArgumentException(e);
 63    } catch (DatastoreFailureException e) {
 64      throw wrapDatastoreFailureException(e);
 65    }
 66  }
 67
 68  public Entity get(Transaction transaction, Key key) throws EntityNotFoundException {
 69    try {
 70      return inner.get(transaction, key);
 71    } catch (IllegalArgumentException e) {
 72      throw wrapIllegalArgumentException(e);
 73    } catch (DatastoreFailureException e) {
 74      throw wrapDatastoreFailureException(e);
 75    }
 76  }
 77
 78  public Map<Key, Entity> get(Iterable<Key> keyIterable) {
 79    try {
 80      return inner.get(keyIterable);
 81    } catch (IllegalArgumentException e) {
 82      throw wrapIllegalArgumentException(e);
 83    } catch (DatastoreFailureException e) {
 84      throw wrapDatastoreFailureException(e);
 85    }
 86  }
 87
 88  public Map<Key, Entity> get(Transaction transaction, Iterable<Key> keyIterable) {
 89    try {
 90      return inner.get(transaction, keyIterable);
 91    } catch (IllegalArgumentException e) {
 92      throw wrapIllegalArgumentException(e);
 93    } catch (DatastoreFailureException e) {
 94      throw wrapDatastoreFailureException(e);
 95    }
 96  }
 97
 98  public Key put(Entity entity) {
 99    try {
100      return inner.put(entity);
101    } catch (IllegalArgumentException e) {
102      throw wrapIllegalArgumentException(e);
103    } catch (ConcurrentModificationException e) {
104      throw wrapConcurrentModificationException(e);
105    } catch (DatastoreFailureException e) {
106      throw wrapDatastoreFailureException(e);
107    }
108  }
109
110  public Key put(Transaction transaction, Entity entity) {
111    try {
112      return inner.put(transaction, entity);
113    } catch (IllegalArgumentException e) {
114      throw wrapIllegalArgumentException(e);
115    } catch (ConcurrentModificationException e) {
116      throw wrapConcurrentModificationException(e);
117    } catch (DatastoreFailureException e) {
118      throw wrapDatastoreFailureException(e);
119    }
120  }
121
122  public List<Key> put(Iterable<Entity> entityIterable) {
123    try {
124      return inner.put(entityIterable);
125    } catch (IllegalArgumentException e) {
126      throw wrapIllegalArgumentException(e);
127    } catch (ConcurrentModificationException e) {
128      throw wrapConcurrentModificationException(e);
129    } catch (DatastoreFailureException e) {
130      throw wrapDatastoreFailureException(e);
131    }
132  }
133
134  public List<Key> put(Transaction transaction, Iterable<Entity> entityIterable) {
135    try {
136      return inner.put(transaction, entityIterable);
137    } catch (IllegalArgumentException e) {
138      throw wrapIllegalArgumentException(e);
139    } catch (ConcurrentModificationException e) {
140      throw wrapConcurrentModificationException(e);
141    } catch (DatastoreFailureException e) {
142      throw wrapDatastoreFailureException(e);
143    }
144  }
145
146  public void delete(Key... keys) {
147    try {
148      inner.delete(keys);
149    } catch (IllegalArgumentException e) {
150      throw wrapIllegalArgumentException(e);
151    } catch (ConcurrentModificationException e) {
152      throw wrapConcurrentModificationException(e);
153    } catch (DatastoreFailureException e) {
154      throw wrapDatastoreFailureException(e);
155    }
156  }
157
158  public void delete(Transaction transaction, Key... keys) {
159    try {
160      inner.delete(transaction, keys);
161    } catch (IllegalArgumentException e) {
162      throw wrapIllegalArgumentException(e);
163    } catch (ConcurrentModificationException e) {
164      throw wrapConcurrentModificationException(e);
165    } catch (DatastoreFailureException e) {
166      throw wrapDatastoreFailureException(e);
167    }
168  }
169
170  public void delete(Iterable<Key> keyIterable) {
171    try {
172      inner.delete(keyIterable);
173    } catch (IllegalArgumentException e) {
174      throw wrapIllegalArgumentException(e);
175    } catch (ConcurrentModificationException e) {
176      throw wrapConcurrentModificationException(e);
177    } catch (DatastoreFailureException e) {
178      throw wrapDatastoreFailureException(e);
179    }
180  }
181
182  public void delete(Transaction transaction, Iterable<Key> keyIterable) {
183    try {
184      inner.delete(transaction, keyIterable);
185    } catch (IllegalArgumentException e) {
186      throw wrapIllegalArgumentException(e);
187    } catch (ConcurrentModificationException e) {
188      throw wrapConcurrentModificationException(e);
189    } catch (DatastoreFailureException e) {
190      throw wrapDatastoreFailureException(e);
191    }
192  }
193
194  public PreparedQuery prepare(Query query) {
195    try {
196      return inner.prepare(query);
197    } catch (IllegalArgumentException e) {
198      throw wrapIllegalArgumentException(e);
199    } catch (DatastoreFailureException e) {
200      throw wrapDatastoreFailureException(e);
201    }
202  }
203
204  public PreparedQuery prepare(Transaction transaction, Query query) {
205    try {
206      return inner.prepare(transaction, query);
207    } catch (IllegalArgumentException e) {
208      throw wrapIllegalArgumentException(e);
209    } catch (DatastoreFailureException e) {
210      throw wrapDatastoreFailureException(e);
211    }
212  }
213
214  public Transaction beginTransaction() {
215    try {
216      return inner.beginTransaction();
217    } catch (IllegalArgumentException e) {
218      throw wrapIllegalArgumentException(e);
219    } catch (DatastoreFailureException e) {
220      throw wrapDatastoreFailureException(e);
221    }
222  }
223
224  public Transaction beginTransaction(TransactionOptions transactionOptions) {
225    try {
226      return inner.beginTransaction(transactionOptions);
227    } catch (IllegalArgumentException e) {
228      throw wrapIllegalArgumentException(e);
229    } catch (DatastoreFailureException e) {
230      throw wrapDatastoreFailureException(e);
231    }
232  }
233
234  public Transaction getCurrentTransaction() {
235    try {
236      return inner.getCurrentTransaction();
237    } catch (IllegalArgumentException e) {
238      throw wrapIllegalArgumentException(e);
239    } catch (DatastoreFailureException e) {
240      throw wrapDatastoreFailureException(e);
241    }
242  }
243
244  public Transaction getCurrentTransaction(Transaction transaction) {
245    try {
246      return inner.getCurrentTransaction(transaction);
247    } catch (IllegalArgumentException e) {
248      throw wrapIllegalArgumentException(e);
249    } catch (DatastoreFailureException e) {
250      throw wrapDatastoreFailureException(e);
251    }
252  }
253
254  public Collection<Transaction> getActiveTransactions() {
255    try {
256      return inner.getActiveTransactions();
257    } catch (IllegalArgumentException e) {
258      throw wrapIllegalArgumentException(e);
259    } catch (DatastoreFailureException e) {
260      throw wrapDatastoreFailureException(e);
261    }      
262  }
263
264  public KeyRange allocateIds(String kind, long num) {
265    try {
266      return inner.allocateIds(kind, num);
267    } catch (IllegalArgumentException e) {
268      throw wrapIllegalArgumentException(e);
269    } catch (DatastoreFailureException e) {
270      throw wrapDatastoreFailureException(e);
271    }
272  }
273
274  public KeyRange allocateIds(Key parent, String kind, long num) {
275    try {
276      return inner.allocateIds(parent, kind, num);
277    } catch (IllegalArgumentException e) {
278      throw wrapIllegalArgumentException(e);
279    } catch (DatastoreFailureException e) {
280      throw wrapDatastoreFailureException(e);
281    }
282  }
283
284  public KeyRangeState allocateIdRange(KeyRange keyRange) {
285    try {
286      return inner.allocateIdRange(keyRange);
287    } catch (IllegalArgumentException e) {
288      throw wrapIllegalArgumentException(e);
289    } catch (DatastoreFailureException e) {
290      throw wrapDatastoreFailureException(e);
291    }
292  }
293
294  public DatastoreAttributes getDatastoreAttributes() {
295    try {
296      return inner.getDatastoreAttributes();
297    } catch (IllegalArgumentException e) {
298      throw wrapIllegalArgumentException(e);
299    } catch (DatastoreFailureException e) {
300      throw wrapDatastoreFailureException(e);
301    }
302  }
303
304  public Map<Index, Index.IndexState> getIndexes() {
305    try {
306      return inner.getIndexes();
307    } catch (IllegalArgumentException e) {
308      throw wrapIllegalArgumentException(e);
309    } catch (DatastoreFailureException e) {
310      throw wrapDatastoreFailureException(e);
311    }
312  }
313}