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): ______________________.
022: */package org.continuent.sequoia.controller.virtualdatabase.protocol;
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.controller.requestmanager.distributed.DistributedRequestManager;
029: import org.continuent.sequoia.controller.requests.SelectRequest;
030:
031: /**
032: * Execute a remote read request. This should only happen in case of a request
033: * arriving at a controller without backend enabled (or having no backend
034: * capable of executing the request). In that case, the request is forwarded to
035: * a remote controller using this message for a remote execution.
036: *
037: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
038: * @version 1.0
039: */
040: public class ExecRemoteStatementExecuteQuery extends DistributedRequest {
041: private static final long serialVersionUID = -7183844510032678987L;
042:
043: /**
044: * Creates a new <code>ExecRemoteStatementExecuteQuery</code> object.
045: *
046: * @param request select request to execute
047: */
048: public ExecRemoteStatementExecuteQuery(SelectRequest request) {
049: super (request);
050: }
051:
052: /**
053: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedRequest#scheduleRequest(org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager)
054: */
055: public Object scheduleRequest(DistributedRequestManager drm)
056: throws SQLException {
057: return null;
058: }
059:
060: /**
061: * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedRequest#executeScheduledRequest(org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager)
062: */
063: public Serializable executeScheduledRequest(
064: DistributedRequestManager drm) throws SQLException {
065: // Check if the transaction has been started
066: if (!request.isAutoCommit()) {
067: long tid = request.getTransactionId();
068: try {
069: drm.getTransactionMetaData(new Long(tid));
070: } catch (SQLException e) { // Transaction not started. If we start a new transaction now, it will
071: // never be commited if this is a read-only transaction since the commit
072: // will never get distributed and reach us (read-only transactions are
073: // only commited locally). Therefore, we decide to execute this read in
074: // autoCommit mode which should not be a real big issue (TODO: check
075: // impact on transaction isolation).
076: // Note that further write queries on that transaction will really start
077: // a transaction and subsequent reads would then execute in the proper
078: // transaction.
079: request.setIsAutoCommit(true);
080: }
081: }
082:
083: try {
084: return drm
085: .execLocalStatementExecuteQuery((SelectRequest) request);
086: } catch (SQLException e) {
087: drm
088: .getLogger()
089: .warn(
090: Translate
091: .get(
092: "virtualdatabase.distributed.read.sqlexception",
093: e.getMessage()), e);
094: return e;
095: } catch (RuntimeException re) {
096: drm
097: .getLogger()
098: .warn(
099: Translate
100: .get(
101: "virtualdatabase.distributed.read.exception",
102: re.getMessage()), re);
103: return new SQLException(re.getMessage());
104: }
105: }
106:
107: /**
108: * @see java.lang.Object#toString()
109: */
110: public String toString() {
111: return "S " + request.getId() + " "
112: + request.getTransactionId() + " "
113: + request.getUniqueKey();
114: }
115:
116: }
|