KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > requests > RequestType


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Emmanuel Cecchet.
20  * Contributor(s): Mathieu Peltier.
21  */

22
23 package org.continuent.sequoia.controller.requests;
24
25 /**
26  * Defines static types values for request. This class publicizes internal
27  * implementation details (like bitmasks for instance) and importing it should
28  * be avoided as far as possible. Use public methods from AbstractRequest
29  * instead.
30  *
31  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
32  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
33  * @author <a HREF="mailto:Marc.Herbert@emicnetworks.com">Marc Herbert </a>
34  * @version 1.0
35  */

36 public final class RequestType
37 {
38   // it looks like we rely on: CACHEABLE <=> no init
39
/** Type value for cacheable request. */
40   public static final int CACHEABLE = 0;
41
42   /** Type value for uncacheable request. */
43   public static final int UNCACHEABLE = 1;
44
45   /**
46    * Type value for cacheable request that are not affected by an
47    * <code>INSERT</code> (select based on a primary key for example).
48    */

49   public static final int UNIQUE_CACHEABLE = 2;
50
51   /** Value for an undefined request type */
52   public static final int UNDEFINED = 0;
53   /** Value for a delete request type */
54   public static final int DELETE = 1;
55   /** Value for an insert request type */
56   public static final int INSERT = 2;
57   /** Value for an update request type */
58   public static final int UPDATE = 3;
59   /** Value for a select request type */
60   public static final int SELECT = 4;
61   /** Value for an unknown read request type */
62   public static final int UNKNOWN_READ = 5;
63   /** Value for an unknown write request type */
64   public static final int UNKNOWN_WRITE = 6;
65
66   // All DML statements should be defined above this line and have values lower
67
// than STORED_PROCEDURE
68

69   /** Value for a stored procedure request type */
70   public static final int STORED_PROCEDURE = 10;
71
72   // All DDL statements should be defined below this line and have values
73
// greater than STORED_PROCEDURE
74

75   /** Value for a create request type */
76   public static final int CREATE = 20;
77   /** Value for an alter request type */
78   public static final int ALTER = 21;
79   /** Value for a drop request type */
80   public static final int DROP = 22;
81
82   /**
83    * Returns <code>true</code> if this request is a DDL (Data Definition
84    * Language) statement such as CREATE, ALTER or DROP. Not supported yet are:
85    * TRUNCATE, COMMENT, GRANT and REVOKE (see
86    * http://www.orafaq.com/faq/Server_Utilities/SQL/faq53.htm)
87    * <p>
88    * Note that stored procedures are both considered as DDL and DML as they can
89    * include both.
90    *
91    * @param requestType the request type
92    * @return true if this request is a DDL
93    */

94   static boolean isDDL(int requestType)
95   {
96     return RequestType.STORED_PROCEDURE >= requestType;
97   }
98
99   /**
100    * Returns <code>true</code> if this request is a DML (Data Manipulation
101    * Language) statement such SELECT, INSERT, UPDATE or DELETE (see
102    * http://www.orafaq.com/faq/Server_Utilities/SQL/faq53.htm)
103    * <p>
104    * Note that stored procedures are both considered as DDL and DML as they can
105    * include both.
106    *
107    * @param requestType the request type
108    * @return true if this request is a DDL
109    */

110   static boolean isDML(int requestType)
111   {
112     return RequestType.STORED_PROCEDURE <= requestType;
113   }
114
115   /**
116    * Returns <code>true</code> if the request type is a <code>DELETE</code>
117    * statement.
118    *
119    * @param requestType the request type
120    * @return true for a <code>DELETE</code> statement
121    */

122   static boolean isDelete(int requestType)
123   {
124     return RequestType.DELETE == requestType;
125   }
126
127   /**
128    * Returns <code>true</code> if the request type is an <code>INSERT</code>
129    * statement.
130    *
131    * @param requestType the request type
132    * @return true for a <code>INSERT</code> statement
133    */

134   static boolean isInsert(int requestType)
135   {
136     return RequestType.INSERT == requestType;
137   }
138
139   /**
140    * Returns <code>true</code> if the request type is an <code>UPDATE</code>
141    * statement.
142    *
143    * @param requestType the request type
144    * @return true for a <code>UPDATE</code> statement
145    */

146   static boolean isUpdate(int requestType)
147   {
148     return RequestType.UPDATE == requestType;
149   }
150
151   /**
152    * Returns <code>true</code> if the request type is a <code>DROP</code>
153    * statement.
154    *
155    * @param requestType the request type
156    * @return true for a <code>DROP</code> statement
157    */

158   static boolean isDrop(int requestType)
159   {
160     return RequestType.DROP == requestType;
161   }
162
163   /**
164    * Returns <code>true</code> if the request type is a <code>CREATE</code>
165    * statement.
166    *
167    * @param requestType the request type
168    * @return true for a <code>CREATE</code> statement
169    */

170   static boolean isCreate(int requestType)
171   {
172     return RequestType.CREATE == requestType;
173   }
174
175   /**
176    * Returns <code>true</code> if the request type is an <code>ALTER</code>
177    * statement.
178    *
179    * @param requestType the request type
180    * @return true for a <code>ALTER</code> statement
181    */

182   static boolean isAlter(int requestType)
183   {
184     return RequestType.ALTER == requestType;
185   }
186
187   /**
188    * Returns <code>true</code> if the request type is a <code>SELECT</code>
189    * statement.
190    *
191    * @param requestType the request type
192    * @return true for a <code>SELECT</code> statement
193    */

194   static boolean isSelect(int requestType)
195   {
196     return RequestType.SELECT == requestType;
197   }
198
199   /**
200    * Returns <code>true</code> if the request type is a
201    * <code>STORED_PROCEDURE</code> statement.
202    *
203    * @param requestType the request type
204    * @return true for a <code>STORED_PROCEDURE</code> statement
205    */

206   static boolean isStoredProcedure(int requestType)
207   {
208     return RequestType.STORED_PROCEDURE == requestType;
209   }
210
211   /**
212    * Returns the type of the request (internal implementation, subject to
213    * change).
214    *
215    * @param request the request to get the type from
216    * @return the request type
217    */

218   public static int getRequestType(AbstractRequest request)
219   {
220     return request.requestType;
221   }
222
223   /**
224    * Sets the requestType value. Used by constructors of AbstractRequest's
225    * subclasses.
226    */

227   static void setRequestType(AbstractRequest request, int type)
228   {
229     request.requestType = type;
230   }
231
232   /**
233    * Returns the request type in a <code>String</code> form.
234    *
235    * @param type the request type
236    * @return the <code>String</code> form of the request type
237    */

238   public static String JavaDoc getInformation(int type)
239   {
240     switch (type)
241     {
242       case RequestType.CACHEABLE :
243         return "CACHEABLE";
244       case RequestType.UNCACHEABLE :
245         return "UNCACHEABLE";
246       case RequestType.UNIQUE_CACHEABLE :
247         return "UNIQUE_CACHEABLE";
248       default :
249         return "Illegal request type";
250     }
251   }
252
253   /**
254    * Return a String representing the type of query. <strong>This method is
255    * intended to be used for debug and log only. Do not use in other cases.</strong>
256    * The returned String can be:
257    * <ul>
258    * <li>stored procedure</li>
259    * <li>read request</li>
260    * <li>write request</li>
261    * <li>unknown type request</li>
262    * <ul>
263    *
264    * @param request the request
265    * @return a String representing the type of request
266    */

267   static String JavaDoc getTypeAsString(AbstractRequest request)
268   {
269     if (request instanceof SelectRequest)
270     {
271       return "read request";
272     }
273     if (request instanceof AbstractWriteRequest)
274     {
275       return "write request";
276     }
277     if (request instanceof StoredProcedure)
278     {
279       return "stored procedure";
280     }
281     return "request of undefined type";
282   }
283
284   /**
285    * Returns a String representing the given type. The returned String can be:
286    * <ul>
287    * <li>DELETE</li>
288    * <li>INSERT</li>
289    * <li>UPDATE</li>
290    * <li>SELECT</li>
291    * <li>UNKNOWN_READ</li>
292    * <li>UNKNOWN_WRITE</li>
293    * <li>STORED_PROCEDURE</li>
294    * <li>CREATE</li>
295    * <li>ALTER</li>
296    * <li>DROP</li>
297    * <li>UNDEFINED</li>
298    * <ul>
299    *
300    * @param type the request type
301    * @return a String representing the type of request
302    */

303   static String JavaDoc getTypeAsString(int type)
304   {
305     switch (type)
306     {
307       case DELETE :
308         return "DELETE";
309       case INSERT :
310         return "INSERT";
311       case UPDATE :
312         return "UPDATE";
313       case SELECT :
314         return "SELECT";
315       case UNKNOWN_READ :
316         return "UNKNOWN_READ";
317       case UNKNOWN_WRITE :
318         return "UNKNOWN_WRITE";
319       case STORED_PROCEDURE :
320         return "STORED_PROCEDURE";
321       case CREATE :
322         return "CREATE";
323       case ALTER :
324         return "ALTER";
325       case DROP :
326         return "DROP";
327       default : // case UNDEFINED :
328
return "UNDEFINED";
329     }
330   }
331 }
332
Popular Tags