001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.exceptions;
038:
039: import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator;
040:
041: /**
042: * <P><B>Purpose</B>: Concurrency deadlock or interupts will raise this exception.
043: */
044: public class ConcurrencyException extends TopLinkException {
045: public final static int WAIT_WAS_INTERRUPTED = 2001;
046: public final static int WAIT_FAILURE_SERVER = 2002;
047: public final static int WAIT_FAILURE_CLIENT = 2003;
048: public final static int SIGNAL_ATTEMPTED_BEFORE_WAIT = 2004;
049: public final static int WAIT_FAILURE_SEQ_DATABASE_SESSION = 2005;
050: public final static int SEQUENCING_MULTITHREAD_THRU_CONNECTION = 2006;
051: public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE = 2007;
052: public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE = 2008;
053: public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_BUILD_OBJECT = 2009;
054:
055: /**
056: * INTERNAL:
057: * TopLink exceptions should only be thrown by TopLink.
058: */
059: protected ConcurrencyException(String theMessage) {
060: super (theMessage);
061: }
062:
063: /**
064: * INTERNAL:
065: * TopLink exceptions should only be thrown by TopLink.
066: */
067: protected ConcurrencyException(String theMessage,
068: Exception exception) {
069: super (theMessage, exception);
070: }
071:
072: public static ConcurrencyException maxTriesLockOnCloneExceded(
073: Object objectToClone) {
074: Object[] args = { objectToClone, CR };
075:
076: ConcurrencyException concurrencyException = new ConcurrencyException(
077: ExceptionMessageGenerator.buildMessage(
078: ConcurrencyException.class,
079: MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE, args));
080: concurrencyException
081: .setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE);
082: return concurrencyException;
083: }
084:
085: public static ConcurrencyException maxTriesLockOnMergeExceded(
086: Object objectToClone) {
087: Object[] args = { objectToClone, CR };
088:
089: ConcurrencyException concurrencyException = new ConcurrencyException(
090: ExceptionMessageGenerator.buildMessage(
091: ConcurrencyException.class,
092: MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE, args));
093: concurrencyException
094: .setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE);
095: return concurrencyException;
096: }
097:
098: public static ConcurrencyException maxTriesLockOnBuildObjectExceded(
099: Thread cacheKeyThread, Thread currentThread) {
100: Object[] args = { cacheKeyThread, currentThread, CR };
101:
102: ConcurrencyException concurrencyException = new ConcurrencyException(
103: ExceptionMessageGenerator.buildMessage(
104: ConcurrencyException.class,
105: MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE, args));
106: concurrencyException
107: .setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_BUILD_OBJECT);
108: return concurrencyException;
109: }
110:
111: public static ConcurrencyException signalAttemptedBeforeWait() {
112: Object[] args = { CR };
113:
114: ConcurrencyException concurrencyException = new ConcurrencyException(
115: ExceptionMessageGenerator.buildMessage(
116: ConcurrencyException.class,
117: SIGNAL_ATTEMPTED_BEFORE_WAIT, args));
118: concurrencyException.setErrorCode(SIGNAL_ATTEMPTED_BEFORE_WAIT);
119: return concurrencyException;
120: }
121:
122: public static ConcurrencyException waitFailureOnClientSession(
123: InterruptedException exception) {
124: Object[] args = {};
125:
126: ConcurrencyException concurrencyException = new ConcurrencyException(
127: ExceptionMessageGenerator.buildMessage(
128: ConcurrencyException.class,
129: WAIT_FAILURE_CLIENT, args), exception);
130: concurrencyException.setErrorCode(WAIT_FAILURE_CLIENT);
131: return concurrencyException;
132: }
133:
134: public static ConcurrencyException waitFailureOnServerSession(
135: InterruptedException exception) {
136: Object[] args = {};
137:
138: ConcurrencyException concurrencyException = new ConcurrencyException(
139: ExceptionMessageGenerator.buildMessage(
140: ConcurrencyException.class,
141: WAIT_FAILURE_SERVER, args), exception);
142: concurrencyException.setErrorCode(WAIT_FAILURE_SERVER);
143: return concurrencyException;
144: }
145:
146: public static ConcurrencyException waitWasInterrupted(String message) {
147: Object[] args = { CR, message };
148:
149: ConcurrencyException concurrencyException = new ConcurrencyException(
150: ExceptionMessageGenerator.buildMessage(
151: ConcurrencyException.class,
152: WAIT_WAS_INTERRUPTED, args));
153: concurrencyException.setErrorCode(WAIT_WAS_INTERRUPTED);
154: return concurrencyException;
155: }
156:
157: public static ConcurrencyException waitFailureOnSequencingForDatabaseSession(
158: InterruptedException exception) {
159: Object[] args = {};
160:
161: ConcurrencyException concurrencyException = new ConcurrencyException(
162: ExceptionMessageGenerator.buildMessage(
163: ConcurrencyException.class,
164: WAIT_FAILURE_SEQ_DATABASE_SESSION, args),
165: exception);
166: concurrencyException
167: .setErrorCode(WAIT_FAILURE_SEQ_DATABASE_SESSION);
168: return concurrencyException;
169: }
170:
171: public static ConcurrencyException sequencingMultithreadThruConnection(
172: String accessor) {
173: Object[] args = { accessor };
174:
175: ConcurrencyException concurrencyException = new ConcurrencyException(
176: ExceptionMessageGenerator.buildMessage(
177: ConcurrencyException.class,
178: SEQUENCING_MULTITHREAD_THRU_CONNECTION, args));
179: concurrencyException
180: .setErrorCode(SEQUENCING_MULTITHREAD_THRU_CONNECTION);
181: return concurrencyException;
182: }
183: }
|