001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Emmanuel Cecchet.
021: * Contributor(s): Mathieu Peltier.
022: */package org.continuent.sequoia.controller.requests;
023:
024: import java.io.Serializable;
025: import java.sql.SQLException;
026:
027: import org.continuent.sequoia.common.i18n.Translate;
028: import org.continuent.sequoia.common.sql.schema.DatabaseSchema;
029:
030: /**
031: * An <code>UnknownWriteRequest</code> is an SQL request that does not match
032: * any SQL query known by this software.<br>
033: * Quite strangely, it extends AbstractWriteRequest but has a returnsResultSet()
034: * method.
035: *
036: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
037: * @author <a href="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
038: * @version 1.0
039: */
040: public class UnknownWriteRequest extends AbstractWriteRequest implements
041: Serializable {
042: private static final long serialVersionUID = 2620807724931159903L;
043:
044: private boolean needsMacroProcessing;
045:
046: // Be conservative, if we cannot parse the query, assumes it invalidates
047: // everything
048: protected boolean altersStoredProcedureList = true;
049: protected boolean altersUsers = true;
050: protected boolean altersSomething = true;
051: protected boolean altersDatabaseCatalog = false;
052: protected boolean altersDatabaseSchema = false;
053: protected boolean altersUserDefinedTypes = false;
054: protected boolean altersAggregateList = false;
055: protected boolean altersMetadataCache = false;
056: protected boolean altersQueryResultCache = false;
057:
058: /**
059: * Creates a new <code>UnknownWriteRequest</code> instance.
060: *
061: * @param sqlQuery the SQL query
062: * @param escapeProcessing should the driver to escape processing before
063: * sending to the database?
064: * @param timeout an <code>int</code> value
065: * @param lineSeparator the line separator used in the query
066: */
067: public UnknownWriteRequest(String sqlQuery,
068: boolean escapeProcessing, int timeout, String lineSeparator) {
069: super (sqlQuery, escapeProcessing, timeout, lineSeparator,
070: RequestType.UNKNOWN_WRITE);
071: }
072:
073: /**
074: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersAggregateList()
075: */
076: public boolean altersAggregateList() {
077: return this .altersAggregateList;
078: }
079:
080: /**
081: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersDatabaseCatalog()
082: */
083: public boolean altersDatabaseCatalog() {
084: return this .altersDatabaseCatalog;
085: }
086:
087: /**
088: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersDatabaseSchema()
089: */
090: public boolean altersDatabaseSchema() {
091: return this .altersDatabaseSchema;
092: }
093:
094: /**
095: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersMetadataCache()
096: */
097: public boolean altersMetadataCache() {
098: return this .altersMetadataCache;
099: }
100:
101: /**
102: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersQueryResultCache()
103: */
104: public boolean altersQueryResultCache() {
105: return this .altersQueryResultCache;
106: }
107:
108: /**
109: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersSomething()
110: */
111: public boolean altersSomething() {
112: return altersSomething;
113: }
114:
115: /**
116: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersStoredProcedureList()
117: */
118: public boolean altersStoredProcedureList() {
119: return this .altersStoredProcedureList;
120: }
121:
122: /**
123: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersUserDefinedTypes()
124: */
125: public boolean altersUserDefinedTypes() {
126: return this .altersUserDefinedTypes;
127: }
128:
129: /**
130: * @see org.continuent.sequoia.controller.requests.AbstractRequest#altersUsers()
131: */
132: public boolean altersUsers() {
133: return altersUsers;
134: }
135:
136: /**
137: * @return <code>false</code>
138: * @see org.continuent.sequoia.controller.requests.AbstractRequest#needsMacroProcessing()
139: */
140: public boolean needsMacroProcessing() {
141: return needsMacroProcessing;
142: }
143:
144: /**
145: * Request is not parsed (isParsed is just set to true).
146: *
147: * @see AbstractRequest#cloneParsing(AbstractRequest)
148: */
149: public void cloneParsing(AbstractRequest request) {
150: isParsed = true;
151: }
152:
153: /**
154: * Request is not parsed (isParsed is just set to true).
155: *
156: * @see org.continuent.sequoia.controller.requests.AbstractRequest#parse(org.continuent.sequoia.common.sql.schema.DatabaseSchema,
157: * int, boolean)
158: */
159: public void parse(DatabaseSchema schema, int granularity,
160: boolean isCaseSensitive) throws SQLException { // No parsing for unknown write request
161: // Just let database try to execute the request
162: isParsed = true;
163: }
164:
165: /**
166: * @see org.continuent.sequoia.controller.requests.AbstractRequest#getParsingResultsAsString()
167: */
168: public String getParsingResultsAsString() {
169: StringBuffer sb = new StringBuffer(super
170: .getParsingResultsAsString());
171: sb.append(Translate.get("request.alters", new String[] {
172: String.valueOf(altersAggregateList()),
173: String.valueOf(altersDatabaseCatalog()),
174: String.valueOf(altersDatabaseSchema()),
175: String.valueOf(altersMetadataCache()),
176: String.valueOf(altersQueryResultCache()),
177: String.valueOf(altersSomething()),
178: String.valueOf(altersStoredProcedureList()),
179: String.valueOf(altersUserDefinedTypes()),
180: String.valueOf(altersUsers()) }));
181: return sb.toString();
182: }
183:
184: /**
185: * {@inheritDoc} <br>
186: * We do not need to override hashCode() in this class because it's already
187: * done correctly upper in the hierarchy. For more details see
188: * http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object-p2.html
189: *
190: * @see AbstractRequest#hashCode()
191: * @see org.continuent.sequoia.controller.requests.AbstractRequest#equals(java.lang.Object)
192: */
193: public boolean equals(Object other) {
194: if (id != 0) // this is the regular, usual case
195: return super .equals(other);
196:
197: // Special case: id is not set. This is a fake query (commit, rollback,...)
198: // used for notification purposes. We have to perform a more "manual"
199: // comparison below.
200: if ((other == null) || !(other instanceof UnknownWriteRequest))
201: return false;
202:
203: UnknownWriteRequest r = (UnknownWriteRequest) other;
204: return transactionId == r.getTransactionId()
205: && sqlQueryOrTemplate.equals(r.getSqlOrTemplate());
206: }
207: }
|