KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > virtualdatabase > protocol > ExecReadRequest


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.controller.virtualdatabase.protocol;
26
27 import java.sql.SQLException JavaDoc;
28
29 import org.objectweb.cjdbc.common.i18n.Translate;
30 import org.objectweb.cjdbc.common.sql.SelectRequest;
31 import org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager;
32
33 /**
34  * Execute a read request.
35  *
36  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
37  * @version 1.0
38  */

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

48   public ExecReadRequest(SelectRequest request)
49   {
50     super(request);
51   }
52
53   /**
54    * @see org.objectweb.cjdbc.controller.virtualdatabase.protocol.DistributedRequest#scheduleRequest(org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager)
55    */

56   public void scheduleRequest(DistributedRequestManager drm)
57       throws SQLException JavaDoc
58   {
59   }
60
61   /**
62    * @see org.objectweb.cjdbc.controller.virtualdatabase.protocol.DistributedRequest#executeScheduledRequest(org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager)
63    */

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