01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence;
20:
21: import java.io.IOException;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectOutputStream;
24: import java.io.PrintStream;
25: import java.io.PrintWriter;
26: import java.io.Serializable;
27:
28: import org.apache.openjpa.util.ExceptionInfo;
29: import org.apache.openjpa.util.Exceptions;
30:
31: /**
32: * Rollback occurred on attempt to commit.
33: *
34: * @author Abe White
35: * @since 0.4.0
36: * @nojavadoc
37: */
38: public class RollbackException extends
39: javax.persistence.RollbackException implements Serializable,
40: ExceptionInfo {
41:
42: private transient Throwable[] _nested;
43:
44: public RollbackException(Exception e) {
45: super (e.getMessage());
46: _nested = new Throwable[] { e };
47: }
48:
49: public int getType() {
50: return STORE;
51: }
52:
53: public int getSubtype() {
54: return GENERAL;
55: }
56:
57: public boolean isFatal() {
58: return true;
59: }
60:
61: public Throwable getCause() {
62: return PersistenceExceptions.getCause(_nested);
63: }
64:
65: public Throwable[] getNestedThrowables() {
66: return _nested;
67: }
68:
69: public Object getFailedObject() {
70: return null;
71: }
72:
73: public String toString() {
74: return Exceptions.toString(this );
75: }
76:
77: public void printStackTrace() {
78: printStackTrace(System.err);
79: }
80:
81: public void printStackTrace(PrintStream out) {
82: super .printStackTrace(out);
83: Exceptions.printNestedThrowables(this , out);
84: }
85:
86: public void printStackTrace(PrintWriter out) {
87: super .printStackTrace(out);
88: Exceptions.printNestedThrowables(this , out);
89: }
90:
91: private void writeObject(ObjectOutputStream out) throws IOException {
92: out.writeObject(Exceptions.replaceNestedThrowables(_nested));
93: }
94:
95: private void readObject(ObjectInputStream in) throws IOException,
96: ClassNotFoundException {
97: _nested = (Throwable[]) in.readObject();
98: }
99: }
|