001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence;
020:
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.io.ObjectOutputStream;
024: import java.io.PrintStream;
025: import java.io.PrintWriter;
026: import java.io.Serializable;
027:
028: import org.apache.openjpa.util.ExceptionInfo;
029: import org.apache.openjpa.util.Exceptions;
030:
031: /**
032: * General persistence exception.
033: *
034: * @author Abe White
035: * @since 0.4.0
036: * @nojavadoc
037: */
038: public class PersistenceException extends
039: javax.persistence.PersistenceException implements Serializable,
040: ExceptionInfo {
041:
042: private transient boolean _fatal = false;
043: private transient Object _failed = null;
044: private transient Throwable[] _nested = null;
045:
046: public PersistenceException(String msg, Throwable[] nested,
047: Object failed, boolean fatal) {
048: super (msg);
049: _nested = nested;
050: _failed = failed;
051: _fatal = fatal;
052: }
053:
054: public int getType() {
055: return GENERAL;
056: }
057:
058: public int getSubtype() {
059: return 0;
060: }
061:
062: public boolean isFatal() {
063: return _fatal;
064: }
065:
066: public Throwable getCause() {
067: return PersistenceExceptions.getCause(_nested);
068: }
069:
070: public Throwable[] getNestedThrowables() {
071: return (_nested == null) ? Exceptions.EMPTY_THROWABLES
072: : _nested;
073: }
074:
075: public Object getFailedObject() {
076: return _failed;
077: }
078:
079: public String toString() {
080: return Exceptions.toString(this );
081: }
082:
083: public void printStackTrace() {
084: printStackTrace(System.err);
085: }
086:
087: public void printStackTrace(PrintStream out) {
088: super .printStackTrace(out);
089: Exceptions.printNestedThrowables(this , out);
090: }
091:
092: public void printStackTrace(PrintWriter out) {
093: super .printStackTrace(out);
094: Exceptions.printNestedThrowables(this , out);
095: }
096:
097: private void writeObject(ObjectOutputStream out) throws IOException {
098: out.writeBoolean(_fatal);
099: out.writeObject(Exceptions.replaceFailedObject(_failed));
100: out.writeObject(Exceptions.replaceNestedThrowables(_nested));
101: }
102:
103: private void readObject(ObjectInputStream in) throws IOException,
104: ClassNotFoundException {
105: _fatal = in.readBoolean();
106: _failed = in.readObject();
107: _nested = (Throwable[]) in.readObject();
108: }
109: }
|