KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > ObjectOptimisticLockingFailureException


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm;
18
19 import org.springframework.dao.OptimisticLockingFailureException;
20
21 /**
22  * Exception thrown on an optimistic locking violation for a mapped object.
23  * Provides information about the persistent class and the identifier.
24  *
25  * @author Juergen Hoeller
26  * @since 13.10.2003
27  */

28 public class ObjectOptimisticLockingFailureException extends OptimisticLockingFailureException {
29
30     private Object JavaDoc persistentClass;
31
32     private Object JavaDoc identifier;
33
34
35     /**
36      * Create a general ObjectOptimisticLockingFailureException with the given message,
37      * without any information on the affected object.
38      * @param msg the detail message
39      * @param cause the source exception
40      */

41     public ObjectOptimisticLockingFailureException(String JavaDoc msg, Throwable JavaDoc cause) {
42         super(msg, cause);
43     }
44
45     /**
46      * Create a new ObjectOptimisticLockingFailureException for the given object,
47      * with the default "optimistic locking failed" message.
48      * @param persistentClass the persistent class
49      * @param identifier the ID of the object for which the locking failed
50      */

51     public ObjectOptimisticLockingFailureException(Class JavaDoc persistentClass, Object JavaDoc identifier) {
52         this(persistentClass, identifier, null);
53     }
54
55     /**
56      * Create a new ObjectOptimisticLockingFailureException for the given object,
57      * with the default "optimistic locking failed" message.
58      * @param persistentClass the persistent class
59      * @param identifier the ID of the object for which the locking failed
60      * @param cause the source exception
61      */

62     public ObjectOptimisticLockingFailureException(
63             Class JavaDoc persistentClass, Object JavaDoc identifier, Throwable JavaDoc cause) {
64
65         this(persistentClass, identifier,
66                 "Object of class [" + persistentClass.getName() + "] with identifier [" + identifier +
67                 "]: optimistic locking failed", cause);
68     }
69
70     /**
71      * Create a new ObjectOptimisticLockingFailureException for the given object,
72      * with the given explicit message.
73      * @param persistentClass the persistent class
74      * @param identifier the ID of the object for which the locking failed
75      * @param msg the detail message
76      * @param cause the source exception
77      */

78     public ObjectOptimisticLockingFailureException(
79             Class JavaDoc persistentClass, Object JavaDoc identifier, String JavaDoc msg, Throwable JavaDoc cause) {
80
81         super(msg, cause);
82         this.persistentClass = persistentClass;
83         this.identifier = identifier;
84     }
85
86     /**
87      * Create a new ObjectOptimisticLockingFailureException for the given object,
88      * with the default "optimistic locking failed" message.
89      * @param persistentClassName the name of the persistent class
90      * @param identifier the ID of the object for which the locking failed
91      */

92     public ObjectOptimisticLockingFailureException(String JavaDoc persistentClassName, Object JavaDoc identifier) {
93         this(persistentClassName, identifier, null);
94     }
95
96     /**
97      * Create a new ObjectOptimisticLockingFailureException for the given object,
98      * with the default "optimistic locking failed" message.
99      * @param persistentClassName the name of the persistent class
100      * @param identifier the ID of the object for which the locking failed
101      * @param cause the source exception
102      */

103     public ObjectOptimisticLockingFailureException(
104             String JavaDoc persistentClassName, Object JavaDoc identifier, Throwable JavaDoc cause) {
105
106         this(persistentClassName, identifier,
107                 "Object of class [" + persistentClassName + "] with identifier [" + identifier +
108                 "]: optimistic locking failed", cause);
109     }
110
111     /**
112      * Create a new ObjectOptimisticLockingFailureException for the given object,
113      * with the given explicit message.
114      * @param persistentClassName the name of the persistent class
115      * @param identifier the ID of the object for which the locking failed
116      * @param msg the detail message
117      * @param cause the source exception
118      */

119     public ObjectOptimisticLockingFailureException(
120             String JavaDoc persistentClassName, Object JavaDoc identifier, String JavaDoc msg, Throwable JavaDoc cause) {
121
122         super(msg, cause);
123         this.persistentClass = persistentClassName;
124         this.identifier = identifier;
125     }
126
127
128     /**
129      * Return the persistent class of the object for which the locking failed.
130      * If no Class was specified, this method returns null.
131      */

132     public Class JavaDoc getPersistentClass() {
133         return (this.persistentClass instanceof Class JavaDoc ? (Class JavaDoc) this.persistentClass : null);
134     }
135
136     /**
137      * Return the name of the persistent class of the object for which the locking failed.
138      * Will work for both Class objects and String names.
139      */

140     public String JavaDoc getPersistentClassName() {
141         if (this.persistentClass instanceof Class JavaDoc) {
142             return ((Class JavaDoc) this.persistentClass).getName();
143         }
144         return (this.persistentClass != null ? this.persistentClass.toString() : null);
145     }
146
147     /**
148      * Return the identifier of the object for which the locking failed.
149      */

150     public Object JavaDoc getIdentifier() {
151         return identifier;
152     }
153
154 }
155
Popular Tags