001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Emmanuel Cecchet.
020: * Contributor(s): ______________________________________.
021: */package org.continuent.sequoia.controller.requests;
022:
023: import java.util.ArrayList;
024:
025: import org.continuent.sequoia.common.i18n.Translate;
026:
027: /**
028: * <code>AbstractWriteRequest</code> is the super-class of all requests which
029: * do NOT return any ResultSet. They do have side-effects (else what would they
030: * useful for?!)
031: *
032: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
033: * @version 1.0
034: */
035: public abstract class AbstractWriteRequest extends AbstractRequest {
036: /** Name of the table involved in this write query. */
037: protected transient String tableName;
038:
039: /**
040: * <code>ArrayList</code> of <code>TableColumn</code> involved in this
041: * write query.
042: */
043: protected transient ArrayList columns;
044:
045: /** <code>true</code> if this request might block. */
046: protected transient boolean blocking = true;
047:
048: /** Primary key value */
049: protected transient String pkValue = null;
050:
051: /**
052: * True if the request requires to take a global lock.
053: */
054: protected boolean requiresGlobalLock = false;
055:
056: /**
057: * Creates a new <code>AbstractWriteRequest</code> object
058: *
059: * @param sqlQuery the SQL query
060: * @param escapeProcessing should the driver to escape processing before
061: * sending to the database ?
062: * @param timeout an <code>int</code> value
063: * @param lineSeparator the line separator used in the query
064: * @param requestType the request type as defined in RequestType class
065: * @see RequestType
066: */
067: public AbstractWriteRequest(String sqlQuery,
068: boolean escapeProcessing, int timeout,
069: String lineSeparator, int requestType) {
070: super (sqlQuery, escapeProcessing, timeout, lineSeparator,
071: requestType);
072: }
073:
074: /**
075: * Clones table name and columns from an already parsed request.
076: *
077: * @param abstractWriteRequest the already parsed request
078: */
079: protected void cloneTableNameAndColumns(
080: AbstractWriteRequest abstractWriteRequest) {
081: tableName = abstractWriteRequest.getTableName();
082: columns = abstractWriteRequest.getColumns();
083: pkValue = abstractWriteRequest.getPk();
084: cacheable = abstractWriteRequest.getCacheAbility();
085: writeLockedTables = abstractWriteRequest
086: .getWriteLockedDatabaseTables();
087: }
088:
089: /**
090: * Returns an <code>ArrayList</code> of <code>TableColumn</code> objects
091: * representing the columns affected by this statement.
092: *
093: * @return an <code>ArrayList</code> value
094: */
095: public ArrayList getColumns() {
096: return columns;
097: }
098:
099: /**
100: * @return Returns the pk.
101: */
102: public String getPk() {
103: return pkValue;
104: }
105:
106: /**
107: * Returns the name of the table affected by this statement.
108: *
109: * @return a <code>String</code> value
110: */
111: public String getTableName() {
112: return tableName;
113: }
114:
115: /**
116: * Tests if this request might block.
117: *
118: * @return <code>true</code> if this request might block
119: */
120: public boolean mightBlock() {
121: return blocking;
122: }
123:
124: /**
125: * Sets if this request might block.
126: *
127: * @param blocking a <code>boolean</code> value
128: */
129: public void setBlocking(boolean blocking) {
130: this .blocking = blocking;
131: }
132:
133: /**
134: * @see org.continuent.sequoia.controller.requests.AbstractRequest#getParsingResultsAsString()
135: */
136: public String getParsingResultsAsString() {
137: StringBuffer sb = new StringBuffer(super
138: .getParsingResultsAsString());
139: sb.append(Translate.get("request.table.involved", tableName));
140: if (columns != null && columns.size() > 0) {
141: sb.append(Translate.get("request.table.column"));
142: for (int i = 0; i < columns.size(); i++) {
143: sb.append(Translate.get("request.table.column", columns
144: .get(i)));
145: }
146: }
147: sb.append(Translate.get("request.blocking", blocking));
148: sb.append(Translate.get("request.primary.key", pkValue));
149: return sb.toString();
150: }
151:
152: /**
153: * Return true if the query requires a global locking.
154: *
155: * @return the requiresGlobalLock value.
156: */
157: public boolean requiresGlobalLock() {
158: return requiresGlobalLock;
159: }
160: }
|