KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > TriggerEvent


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.TriggerEvent
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 /**
25  * This is a simple class that we use to track
26  * trigger events. This is not expected to
27  * be used directly, instead there is a static
28  * TriggerEvent in TriggerEvents for each event
29  * found in this file.
30  *
31  * @author jamie
32  */

33 public class TriggerEvent
34 {
35     static final int BEFORE_INSERT = 0;
36     static final int BEFORE_DELETE = 1;
37     static final int BEFORE_UPDATE = 2;
38     static final int LAST_BEFORE_EVENT = BEFORE_UPDATE;
39     static final int AFTER_INSERT = 3;
40     static final int AFTER_DELETE = 4;
41     static final int AFTER_UPDATE = 5;
42     static final int MAX_EVENTS = 6;
43
44     private static final String JavaDoc Names[] = { "BEFORE INSERT",
45                                             "BEFORE DELETE",
46                                             "BEFORE UPDATE",
47                                             "AFTER INSERT",
48                                             "AFTER DELETE",
49                                             "AFTER UPDATE"
50                                         };
51
52     private boolean before;
53     private int type;
54
55     /**
56      * Create a trigger event of the given type
57      *
58      * @param type the type
59      */

60     TriggerEvent(int type)
61     {
62         this.type = type;
63         switch(type)
64         {
65             case BEFORE_INSERT:
66             case BEFORE_DELETE:
67             case BEFORE_UPDATE:
68                 before = true;
69                 break;
70
71             case AFTER_INSERT:
72             case AFTER_DELETE:
73             case AFTER_UPDATE:
74                 before = false;
75                 break;
76         }
77     }
78
79     /**
80      * Get the type number of this trigger
81      *
82      * @return the type number
83      */

84     int getNumber()
85     {
86         return type;
87     }
88
89     /**
90      * Get the type number of this trigger
91      *
92      * @return the type number
93      */

94     String JavaDoc getName()
95     {
96         return Names[type];
97     }
98
99     /**
100      * Is this a before trigger
101      *
102      * @return true if before
103      */

104     boolean isBefore()
105     {
106         return before;
107     }
108
109     /**
110      * Is this an after trigger
111      *
112      * @return true if after
113      */

114     boolean isAfter()
115     {
116         return !before;
117     }
118 }
119
Popular Tags