1 21 package oracle.toplink.essentials.exceptions; 23 24 import java.util.Vector ; 25 import oracle.toplink.essentials.queryframework.*; 26 import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator; 27 import oracle.toplink.essentials.sessions.SessionProfiler; 28 29 34 public class OptimisticLockException extends TopLinkException { 35 36 37 protected transient ObjectLevelModifyQuery query; 38 39 public final static int NO_VERSION_NUMBER_WHEN_DELETING = 5001; 41 public final static int OBJECT_CHANGED_SINCE_LAST_READ_WHEN_DELETING = 5003; 42 public final static int NO_VERSION_NUMBER_WHEN_UPDATING = 5004; 43 public final static int OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING = 5006; 44 public final static int MUST_HAVE_MAPPING_WHEN_IN_OBJECT = 5007; 45 public final static int NEED_TO_MAP_JAVA_SQL_TIMESTAMP = 5008; 46 public final static int UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ = 5009; 47 public final static int OBJECT_CHANGED_SINCE_LAST_MERGE = 5010; 48 49 53 protected OptimisticLockException(String theMessage) { 54 super(theMessage); 55 } 56 57 61 protected OptimisticLockException(String theMessage, ObjectLevelModifyQuery query) { 62 super(theMessage); 63 this.query = query; 64 query.getSession().incrementProfile(SessionProfiler.OptimisticLockException); 65 66 } 67 68 72 public Object getObject() { 73 return getQuery().getObject(); 74 } 75 76 80 public ObjectLevelModifyQuery getQuery() { 81 return query; 82 } 83 84 public static OptimisticLockException mustHaveMappingWhenStoredInObject(Class aClass) { 85 Object [] args = { aClass }; 86 87 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, MUST_HAVE_MAPPING_WHEN_IN_OBJECT, args)); 88 optimisticLockException.setErrorCode(MUST_HAVE_MAPPING_WHEN_IN_OBJECT); 89 return optimisticLockException; 90 91 } 92 93 public static OptimisticLockException noVersionNumberWhenDeleting(Object object, ObjectLevelModifyQuery query) { 94 Vector key = new Vector (); 95 if (query.getSession() != null) { 96 key = query.getSession().keyFromObject(object); 97 } 98 Object [] args = { object, object.getClass().getName(), key, CR }; 99 100 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, NO_VERSION_NUMBER_WHEN_DELETING, args), query); 101 optimisticLockException.setErrorCode(NO_VERSION_NUMBER_WHEN_DELETING); 102 return optimisticLockException; 103 } 104 105 public static OptimisticLockException noVersionNumberWhenUpdating(Object object, ObjectLevelModifyQuery query) { 106 Vector key = new Vector (); 107 if (query.getSession() != null) { 108 key = query.getSession().keyFromObject(object); 109 } 110 Object [] args = { object, object.getClass().getName(), key, CR }; 111 112 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, NO_VERSION_NUMBER_WHEN_UPDATING, args), query); 113 optimisticLockException.setErrorCode(NO_VERSION_NUMBER_WHEN_UPDATING); 114 return optimisticLockException; 115 } 116 117 public static OptimisticLockException objectChangedSinceLastReadWhenDeleting(Object object, ObjectLevelModifyQuery query) { 118 Vector key = new Vector (); 119 if (query.getSession() != null) { 120 key = query.getSession().keyFromObject(object); 121 } 122 Object [] args = { object, object.getClass().getName(), key, CR }; 123 124 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, OBJECT_CHANGED_SINCE_LAST_READ_WHEN_DELETING, args), query); 125 optimisticLockException.setErrorCode(OBJECT_CHANGED_SINCE_LAST_READ_WHEN_DELETING); 126 return optimisticLockException; 127 } 128 129 public static OptimisticLockException objectChangedSinceLastReadWhenUpdating(Object object, ObjectLevelModifyQuery query) { 130 Vector key = new Vector (); 131 if (query.getSession() != null) { 132 key = query.getSession().keyFromObject(object); 133 } 134 Object [] args = { object, object.getClass().getName(), key, CR }; 135 136 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING, args), query); 137 optimisticLockException.setErrorCode(OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING); 138 return optimisticLockException; 139 } 140 141 public static OptimisticLockException objectChangedSinceLastMerge(Object object) { 142 Object [] args = { object, object.getClass().getName(), CR }; 143 144 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, OBJECT_CHANGED_SINCE_LAST_MERGE, args)); 145 optimisticLockException.setErrorCode(OBJECT_CHANGED_SINCE_LAST_MERGE); 146 return optimisticLockException; 147 } 148 149 public static OptimisticLockException unwrappingObjectDeletedSinceLastRead(Vector pkVector, String className) { 150 Object [] args = { pkVector, className }; 151 152 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ, args)); 153 optimisticLockException.setErrorCode(UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ); 154 return optimisticLockException; 155 } 156 157 public static OptimisticLockException needToMapJavaSqlTimestampWhenStoredInObject() { 159 Object [] args = { }; 160 161 OptimisticLockException optimisticLockException = new OptimisticLockException(ExceptionMessageGenerator.buildMessage(OptimisticLockException.class, NEED_TO_MAP_JAVA_SQL_TIMESTAMP, args)); 162 optimisticLockException.setErrorCode(NEED_TO_MAP_JAVA_SQL_TIMESTAMP); 163 return optimisticLockException; 164 } 165 166 170 public void setQuery(ObjectLevelModifyQuery query) { 171 this.query = query; 172 } 173 } 174 | Popular Tags |