KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > exceptions > ConcurrencyException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.exceptions;
23
24 import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator;
25
26 /**
27  * <P><B>Purpose</B>: Concurrency deadlock or interupts will raise this exception.
28  */

29 public class ConcurrencyException extends TopLinkException {
30     public final static int WAIT_WAS_INTERRUPTED = 2001;
31     public final static int WAIT_FAILURE_SERVER = 2002;
32     public final static int WAIT_FAILURE_CLIENT = 2003;
33     public final static int SIGNAL_ATTEMPTED_BEFORE_WAIT = 2004;
34     public final static int WAIT_FAILURE_SEQ_DATABASE_SESSION = 2005;
35     public final static int SEQUENCING_MULTITHREAD_THRU_CONNECTION = 2006;
36     public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE = 2007;
37     public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE = 2008;
38     public final static int MAX_TRIES_EXCEDED_FOR_LOCK_ON_BUILD_OBJECT = 2009;
39     /**
40      * INTERNAL:
41      * TopLink exceptions should only be thrown by TopLink.
42      */

43     protected ConcurrencyException(String JavaDoc theMessage) {
44         super(theMessage);
45     }
46
47     /**
48      * INTERNAL:
49      * TopLink exceptions should only be thrown by TopLink.
50      */

51     protected ConcurrencyException(String JavaDoc theMessage, Exception JavaDoc exception) {
52         super(theMessage, exception);
53     }
54
55     public static ConcurrencyException maxTriesLockOnCloneExceded(Object JavaDoc objectToClone) {
56         Object JavaDoc[] args = { objectToClone, CR };
57
58         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE, args));
59         concurrencyException.setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_CLONE);
60         return concurrencyException;
61     }
62
63     public static ConcurrencyException maxTriesLockOnMergeExceded(Object JavaDoc objectToClone) {
64         Object JavaDoc[] args = { objectToClone, CR };
65
66         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE, args));
67         concurrencyException.setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE);
68         return concurrencyException;
69     }
70
71     public static ConcurrencyException maxTriesLockOnBuildObjectExceded(Thread JavaDoc cacheKeyThread, Thread JavaDoc currentThread) {
72         Object JavaDoc[] args = { cacheKeyThread, currentThread, CR };
73
74         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, MAX_TRIES_EXCEDED_FOR_LOCK_ON_MERGE, args));
75         concurrencyException.setErrorCode(MAX_TRIES_EXCEDED_FOR_LOCK_ON_BUILD_OBJECT);
76         return concurrencyException;
77     }
78
79     public static ConcurrencyException signalAttemptedBeforeWait() {
80         Object JavaDoc[] args = { CR };
81
82         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, SIGNAL_ATTEMPTED_BEFORE_WAIT, args));
83         concurrencyException.setErrorCode(SIGNAL_ATTEMPTED_BEFORE_WAIT);
84         return concurrencyException;
85     }
86
87     public static ConcurrencyException waitFailureOnClientSession(InterruptedException JavaDoc exception) {
88         Object JavaDoc[] args = { };
89
90         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, WAIT_FAILURE_CLIENT, args), exception);
91         concurrencyException.setErrorCode(WAIT_FAILURE_CLIENT);
92         return concurrencyException;
93     }
94
95     public static ConcurrencyException waitFailureOnServerSession(InterruptedException JavaDoc exception) {
96         Object JavaDoc[] args = { };
97
98         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, WAIT_FAILURE_SERVER, args), exception);
99         concurrencyException.setErrorCode(WAIT_FAILURE_SERVER);
100         return concurrencyException;
101     }
102
103     public static ConcurrencyException waitWasInterrupted(String JavaDoc message) {
104         Object JavaDoc[] args = { CR, message };
105
106         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, WAIT_WAS_INTERRUPTED, args));
107         concurrencyException.setErrorCode(WAIT_WAS_INTERRUPTED);
108         return concurrencyException;
109     }
110
111     public static ConcurrencyException waitFailureOnSequencingForDatabaseSession(InterruptedException JavaDoc exception) {
112         Object JavaDoc[] args = { };
113
114         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, WAIT_FAILURE_SEQ_DATABASE_SESSION, args), exception);
115         concurrencyException.setErrorCode(WAIT_FAILURE_SEQ_DATABASE_SESSION);
116         return concurrencyException;
117     }
118
119     public static ConcurrencyException sequencingMultithreadThruConnection(String JavaDoc accessor) {
120         Object JavaDoc[] args = { accessor };
121
122         ConcurrencyException concurrencyException = new ConcurrencyException(ExceptionMessageGenerator.buildMessage(ConcurrencyException.class, SEQUENCING_MULTITHREAD_THRU_CONNECTION, args));
123         concurrencyException.setErrorCode(SEQUENCING_MULTITHREAD_THRU_CONNECTION);
124         return concurrencyException;
125     }
126 }
127
Popular Tags