PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://datanucleus-appengine.googlecode.com/
Java | 68 lines | 34 code | 10 blank | 24 comment | 0 complexity | 732bf07fbd3668ada1ddff6910846625 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.DatastoreFailureException;
19import com.google.appengine.api.datastore.DatastoreTimeoutException;
20import com.google.appengine.api.datastore.EntityNotFoundException;
21import com.google.appengine.api.datastore.Key;
22
23import org.datanucleus.exceptions.NucleusDataStoreException;
24import org.datanucleus.exceptions.NucleusException;
25import org.datanucleus.exceptions.NucleusObjectNotFoundException;
26import org.datanucleus.exceptions.NucleusFatalUserException;
27import org.datanucleus.store.query.QueryTimeoutException;
28
29import java.util.ConcurrentModificationException;
30
31/**
32 * Utility class that knows how to translate exceptions thrown by the datastore
33 * api into the corresponding {@link NucleusException}.
34 *
35 * @author Max Ross <maxr@google.com>
36 */
37public final class DatastoreExceptionTranslator {
38
39  private DatastoreExceptionTranslator() {
40  }
41
42  public static NucleusException wrapIllegalArgumentException(IllegalArgumentException e) {
43    // Bad input, so mark fatal to let user know not to retry.
44    return new NucleusFatalUserException("Illegal argument", e);
45  }
46
47  public static NucleusDataStoreException wrapDatastoreFailureException(
48      DatastoreFailureException e) {
49    // could be a transient error so don't mark fatal
50    return new NucleusDataStoreException("Datastore Failure", e);
51  }
52
53  static NucleusDataStoreException wrapConcurrentModificationException(
54      ConcurrentModificationException e) {
55    // do not mark fatal
56    return new NucleusDataStoreException("Concurrent Modification", e);
57  }
58
59  static NucleusObjectNotFoundException wrapEntityNotFoundException(
60      EntityNotFoundException e, Key key) {
61    return new NucleusObjectNotFoundException(
62        "Could not retrieve entity of kind " + key.getKind() + " with key " + key);
63  }
64
65  public static QueryTimeoutException wrapDatastoreTimeoutExceptionForQuery(final DatastoreTimeoutException e) {
66    return new QueryTimeoutException(e.getMessage(), e);
67  }
68}