KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > sql > RequestType


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Mathieu Peltier.
23  */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

236   public static String JavaDoc getInformation(int type)
237   {
238     switch (type)
239     {
240       case RequestType.CACHEABLE :
241         return "CACHEABLE";
242       case RequestType.UNCACHEABLE :
243         return "UNCACHEABLE";
244       case RequestType.UNIQUE_CACHEABLE :
245         return "UNIQUE_CACHEABLE";
246       default :
247         return "Illegal request type";
248     }
249   }
250 }
251
Popular Tags