KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > virtualdatabase > protocol > ExecRemoteStatementExecuteQuery


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): ______________________.
22  */

23
24 package org.continuent.sequoia.controller.virtualdatabase.protocol;
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.requestmanager.distributed.DistributedRequestManager;
31 import org.continuent.sequoia.controller.requests.SelectRequest;
32
33 /**
34  * Execute a remote read request. This should only happen in case of a request
35  * arriving at a controller without backend enabled (or having no backend
36  * capable of executing the request). In that case, the request is forwarded to
37  * a remote controller using this message for a remote execution.
38  *
39  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
40  * @version 1.0
41  */

42 public class ExecRemoteStatementExecuteQuery extends DistributedRequest
43 {
44   private static final long serialVersionUID = -7183844510032678987L;
45
46   /**
47    * Creates a new <code>ExecRemoteStatementExecuteQuery</code> object.
48    *
49    * @param request select request to execute
50    */

51   public ExecRemoteStatementExecuteQuery(SelectRequest request)
52   {
53     super(request);
54   }
55
56   /**
57    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedRequest#scheduleRequest(org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager)
58    */

59   public Object JavaDoc scheduleRequest(DistributedRequestManager drm)
60       throws SQLException JavaDoc
61   {
62     return null;
63   }
64
65   /**
66    * @see org.continuent.sequoia.controller.virtualdatabase.protocol.DistributedRequest#executeScheduledRequest(org.continuent.sequoia.controller.requestmanager.distributed.DistributedRequestManager)
67    */

68   public Serializable JavaDoc executeScheduledRequest(DistributedRequestManager drm)
69       throws SQLException JavaDoc
70   {
71     // Check if the transaction has been started
72
if (!request.isAutoCommit())
73     {
74       long tid = request.getTransactionId();
75       try
76       {
77         drm.getTransactionMetaData(new Long JavaDoc(tid));
78       }
79       catch (SQLException JavaDoc e)
80       { // Transaction not started. If we start a new transaction now, it will
81
// never be commited if this is a read-only transaction since the commit
82
// will never get distributed and reach us (read-only transactions are
83
// only commited locally). Therefore, we decide to execute this read in
84
// autoCommit mode which should not be a real big issue (TODO: check
85
// impact on transaction isolation).
86
// Note that further write queries on that transaction will really start
87
// a transaction and subsequent reads would then execute in the proper
88
// transaction.
89
request.setIsAutoCommit(true);
90       }
91     }
92
93     try
94     {
95       return drm.execLocalStatementExecuteQuery((SelectRequest) request);
96     }
97     catch (SQLException JavaDoc e)
98     {
99       drm.getLogger().warn(
100           Translate.get("virtualdatabase.distributed.read.sqlexception", e
101               .getMessage()), e);
102       return e;
103     }
104     catch (RuntimeException JavaDoc re)
105     {
106       drm.getLogger().warn(
107           Translate.get("virtualdatabase.distributed.read.exception", re
108               .getMessage()), re);
109       return new SQLException JavaDoc(re.getMessage());
110     }
111   }
112
113   /**
114    * @see java.lang.Object#toString()
115    */

116   public String JavaDoc toString()
117   {
118     return "S " + request.getId() + " " + request.getTransactionId() + " "
119         + request.getUniqueKey();
120   }
121
122 }
Popular Tags