KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > map > DeleteRule


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
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
20 package org.apache.cayenne.map;
21
22 /**
23  * Defines constants for the possible values of ObjRelationship delete rules.
24  *
25  * @author Craig Miskell
26  */

27 public class DeleteRule {
28     public static final int NO_ACTION = 0;
29     private static final String JavaDoc NO_ACTION_NAME = "No Action";
30     
31     /**
32      * Remove the reference that the destination has to this source (if the
33      * inverse relationship is toOne, nullify, if toMany, remove the source
34      * object)
35      */

36     public static final int NULLIFY = 1;
37     private static final String JavaDoc NULLIFY_NAME = "Nullify";
38
39     /** Delete the destination object(s)
40      */

41     public static final int CASCADE = 2;
42     private static final String JavaDoc CASCADE_NAME = "Cascade";
43
44     /** If the relationship has any objects (toOne or toMany), deny the delete.
45      * (Destination objects would therefore have to be deleted manually first)
46      */

47     public static final int DENY = 3;
48     private static final String JavaDoc DENY_NAME = "Deny";
49
50     /**
51      * Returns String label for a delete rule state. Used for save/load (xml),
52      * display in modeler etc. Must remain the same, or else great care taken
53      * with loading old maps.
54      */

55     public static String JavaDoc deleteRuleName(int deleteRule) {
56         switch (deleteRule) {
57             case DeleteRule.NULLIFY :
58                 return NULLIFY_NAME;
59             case DeleteRule.CASCADE :
60                 return CASCADE_NAME;
61             case DeleteRule.DENY :
62                 return DENY_NAME;
63             default :
64                 return NO_ACTION_NAME;
65         }
66     }
67
68     /**
69      * Translates a possible delete rule name (typically returned from
70      * deleteRuleName at some stage), into a deleteRule constant
71      */

72     public static int deleteRuleForName(String JavaDoc name) {
73         if (DENY_NAME.equals(name)) {
74             return DENY;
75         } else if (CASCADE_NAME.equals(name)) {
76             return CASCADE;
77         } else if (NULLIFY_NAME.equals(name)) {
78             return NULLIFY;
79         }
80         return NO_ACTION;
81     }
82
83 }
84
Popular Tags