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.lib.util.Localizer.Message;
029: import org.apache.openjpa.util.ExceptionInfo;
030: import org.apache.openjpa.util.Exceptions;
031: import org.apache.openjpa.util.UserException;
032:
033: /**
034: * Transaction required.
035: *
036: * @author Abe White
037: * @since 0.4.0
038: * @nojavadoc
039: */
040: public class TransactionRequiredException extends
041: javax.persistence.TransactionRequiredException implements
042: Serializable, ExceptionInfo {
043:
044: private transient boolean _fatal = false;
045: private transient Object _failed = null;
046: private transient Throwable[] _nested = null;
047:
048: public TransactionRequiredException(Message msg,
049: Throwable[] nested, Object failed, boolean fatal) {
050: this (msg.getMessage(), nested, failed, fatal);
051: }
052:
053: public TransactionRequiredException(String msg, Throwable[] nested,
054: Object failed, boolean fatal) {
055: super (msg);
056: _nested = nested;
057: _failed = failed;
058: _fatal = fatal;
059: }
060:
061: public int getType() {
062: return USER;
063: }
064:
065: public int getSubtype() {
066: return UserException.NO_TRANSACTION;
067: }
068:
069: public boolean isFatal() {
070: return _fatal;
071: }
072:
073: public Throwable getCause() {
074: return PersistenceExceptions.getCause(_nested);
075: }
076:
077: public Throwable[] getNestedThrowables() {
078: return (_nested == null) ? Exceptions.EMPTY_THROWABLES
079: : _nested;
080: }
081:
082: public Object getFailedObject() {
083: return _failed;
084: }
085:
086: public String toString() {
087: return Exceptions.toString(this );
088: }
089:
090: public void printStackTrace() {
091: printStackTrace(System.err);
092: }
093:
094: public void printStackTrace(PrintStream out) {
095: super .printStackTrace(out);
096: Exceptions.printNestedThrowables(this , out);
097: }
098:
099: public void printStackTrace(PrintWriter out) {
100: super .printStackTrace(out);
101: Exceptions.printNestedThrowables(this , out);
102: }
103:
104: private void writeObject(ObjectOutputStream out) throws IOException {
105: out.writeBoolean(_fatal);
106: out.writeObject(Exceptions.replaceFailedObject(_failed));
107: out.writeObject(Exceptions.replaceNestedThrowables(_nested));
108: }
109:
110: private void readObject(ObjectInputStream in) throws IOException,
111: ClassNotFoundException {
112: _fatal = in.readBoolean();
113: _failed = in.readObject();
114: _nested = (Throwable[]) in.readObject();
115: }
116: }
|