01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.util;
20:
21: import java.io.IOException;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectOutputStream;
24:
25: import org.apache.openjpa.lib.util.Localizer;
26:
27: /**
28: * Exception type reserved for violations of integrity constraints.
29: *
30: * @author Patrick Linskey
31: */
32: public class ReferentialIntegrityException extends StoreException {
33:
34: public static final int IV_UNKNOWN = 0;
35: public static final int IV_DUPLICATE_OID = 1;
36: public static final int IV_UNIQUE = 2;
37: public static final int IV_REFERENCE = 3;
38: public static final int IV_MIXED = 4;
39:
40: private static final transient Localizer _loc = Localizer
41: .forPackage(ReferentialIntegrityException.class);
42:
43: private int _iv = IV_UNKNOWN;
44:
45: public ReferentialIntegrityException(String msg) {
46: super (msg);
47: }
48:
49: public ReferentialIntegrityException(int iv) {
50: this (getMessage(iv));
51: setIntegrityViolation(iv);
52: }
53:
54: private static String getMessage(int iv) {
55: switch (iv) {
56: case IV_DUPLICATE_OID:
57: return _loc.get("dup-oid").getMessage();
58: case IV_UNIQUE:
59: return _loc.get("unique").getMessage();
60: default:
61: return _loc.get("ref-integrity").getMessage();
62: }
63: }
64:
65: public int getSubtype() {
66: return REFERENTIAL_INTEGRITY;
67: }
68:
69: /**
70: * The type of integrity violation that occurred.
71: */
72: public int getIntegrityViolation() {
73: return _iv;
74: }
75:
76: /**
77: * The type of integrity violation that occurred.
78: */
79: public ReferentialIntegrityException setIntegrityViolation(int iv) {
80: _iv = iv;
81: return this ;
82: }
83:
84: private void writeObject(ObjectOutputStream out) throws IOException {
85: out.writeInt(_iv);
86: }
87:
88: private void readObject(ObjectInputStream in) throws IOException,
89: ClassNotFoundException {
90: _iv = in.readInt();
91: }
92: }
|