KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * 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  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): Mathieu Peltier.
22  */

23
24 package org.continuent.sequoia.controller.requests;
25
26 import java.io.Serializable JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import org.continuent.sequoia.common.i18n.Translate;
30 import org.continuent.sequoia.controller.semantic.SemanticBehavior;
31 import org.continuent.sequoia.controller.sql.schema.DatabaseSchema;
32
33 /**
34  * An <code>UnknownWriteRequest</code> is an SQL request that does not match
35  * any SQL query known by this software.<br>
36  * Quite strangely, it extends AbstractWriteRequest but has a returnsResultSet()
37  * method.
38  *
39  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
40  * @author <a HREF="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
41  * @version 1.0
42  */

43 public class UnknownWriteRequest extends AbstractWriteRequest
44     implements
45       Serializable JavaDoc
46 {
47   private static final long serialVersionUID = 2620807724931159903L;
48
49   private boolean needsMacroProcessing;
50
51   // Be conservative, if we cannot parse the query, assumes it invalidates
52
// everything
53
protected boolean altersStoredProcedureList = true;
54   protected boolean altersUsers = true;
55   protected boolean altersSomething = true;
56   protected boolean altersDatabaseCatalog = false;
57   protected boolean altersDatabaseSchema = false;
58   protected boolean altersUserDefinedTypes = false;
59   protected boolean altersAggregateList = false;
60   protected boolean altersMetadataCache = false;
61   protected boolean altersQueryResultCache = false;
62
63   /**
64    * Creates a new <code>UnknownWriteRequest</code> instance.
65    *
66    * @param sqlQuery the SQL query
67    * @param escapeProcessing should the driver to escape processing before
68    * sending to the database?
69    * @param timeout an <code>int</code> value
70    * @param lineSeparator the line separator used in the query
71    */

72   public UnknownWriteRequest(String JavaDoc sqlQuery, boolean escapeProcessing,
73       int timeout, String JavaDoc lineSeparator)
74   {
75     super(sqlQuery, escapeProcessing, timeout, lineSeparator,
76         RequestType.UNKNOWN_WRITE);
77   }
78
79   /**
80    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersAggregateList()
81    */

82   public boolean altersAggregateList()
83   {
84     return this.altersAggregateList;
85   }
86
87   /**
88    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersDatabaseCatalog()
89    */

90   public boolean altersDatabaseCatalog()
91   {
92     return this.altersDatabaseCatalog;
93   }
94
95   /**
96    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersDatabaseSchema()
97    */

98   public boolean altersDatabaseSchema()
99   {
100     return this.altersDatabaseSchema;
101   }
102
103   /**
104    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersMetadataCache()
105    */

106   public boolean altersMetadataCache()
107   {
108     return this.altersMetadataCache;
109   }
110
111   /**
112    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersQueryResultCache()
113    */

114   public boolean altersQueryResultCache()
115   {
116     return this.altersQueryResultCache;
117   }
118
119   /**
120    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersSomething()
121    */

122   public boolean altersSomething()
123   {
124     return altersSomething;
125   }
126
127   /**
128    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersStoredProcedureList()
129    */

130   public boolean altersStoredProcedureList()
131   {
132     return this.altersStoredProcedureList;
133   }
134
135   /**
136    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersUserDefinedTypes()
137    */

138   public boolean altersUserDefinedTypes()
139   {
140     return this.altersUserDefinedTypes;
141   }
142
143   /**
144    * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersUsers()
145    */

146   public boolean altersUsers()
147   {
148     return altersUsers;
149   }
150
151   /**
152    * @return <code>false</code>
153    * @see org.continuent.sequoia.controller.requests.AbstractRequest#needsMacroProcessing()
154    */

155   public boolean needsMacroProcessing()
156   {
157     return needsMacroProcessing;
158   }
159
160   /**
161    * Request is not parsed but a default semantic information is applied.
162    *
163    * @see org.continuent.sequoia.controller.requests.AbstractRequest#parse(org.continuent.sequoia.controller.sql.schema.DatabaseSchema,
164    * int, boolean)
165    */

166   public void parse(DatabaseSchema schema, int granularity,
167       boolean isCaseSensitive) throws SQLException JavaDoc
168   {
169     // No parsing for unknown write request
170
// Just let database try to execute the request
171
isParsed = true;
172     setSemantic(new SemanticBehavior(null, writeLockedTables, null,
173         altersDatabaseSchema(), altersMetadataCache(),
174         altersQueryResultCache(), altersUsers(), isReadOnly,
175         needsMacroProcessing(), SemanticBehavior.SERIALIZABLE_ORDER,
176         requiresConnectionPoolFlush
177             ? SemanticBehavior.FLUSH_ALL_USERS
178             : SemanticBehavior.FLUSH_NONE));
179   }
180
181   /**
182    * Clone the default semantic information.
183    *
184    * @see AbstractRequest#cloneParsing(AbstractRequest)
185    */

186   public void cloneParsing(AbstractRequest request)
187   {
188     super.cloneParsingCommons(request);
189     isParsed = true;
190   }
191
192   /**
193    * @see org.continuent.sequoia.controller.requests.AbstractRequest#getParsingResultsAsString()
194    */

195   public String JavaDoc getParsingResultsAsString()
196   {
197     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(super.getParsingResultsAsString());
198     sb.append(Translate.get("request.alters",
199         new String JavaDoc[]{String.valueOf(altersAggregateList()),
200             String.valueOf(altersDatabaseCatalog()),
201             String.valueOf(altersDatabaseSchema()),
202             String.valueOf(altersMetadataCache()),
203             String.valueOf(altersQueryResultCache()),
204             String.valueOf(altersSomething()),
205             String.valueOf(altersStoredProcedureList()),
206             String.valueOf(altersUserDefinedTypes()),
207             String.valueOf(altersUsers())}));
208     return sb.toString();
209   }
210
211   /**
212    * {@inheritDoc} <br>
213    * We do not need to override hashCode() in this class because it's already
214    * done correctly upper in the hierarchy. For more details see
215    * http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object-p2.html
216    *
217    * @see AbstractRequest#hashCode()
218    * @see org.continuent.sequoia.controller.requests.AbstractRequest#equals(java.lang.Object)
219    */

220   public boolean equals(Object JavaDoc other)
221   {
222     if (id != 0) // this is the regular, usual case
223
return super.equals(other);
224
225     // Special case: id is not set. This is a fake query (commit, rollback,...)
226
// used for notification purposes. We have to perform a more "manual"
227
// comparison below.
228
if ((other == null) || !(other instanceof UnknownWriteRequest))
229       return false;
230
231     UnknownWriteRequest r = (UnknownWriteRequest) other;
232     return transactionId == r.getTransactionId()
233         && sqlQueryOrTemplate.equals(r.getSqlOrTemplate());
234   }
235 }
Popular Tags