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