KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > recoverylog > events > GetCheckpointLogEntryEvent


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Jeff Mesnil.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.controller.recoverylog.events;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import org.continuent.sequoia.common.i18n.Translate;
30 import org.continuent.sequoia.controller.recoverylog.CheckpointLogEntry;
31 import org.continuent.sequoia.controller.recoverylog.LoggerThread;
32 import org.continuent.sequoia.controller.recoverylog.RecoveryLog;
33
34 /**
35  * This class defines a GetCheckpointLogEntryEvent.
36  * <p>
37  * This event is used to retrieve a log entry associated to a checkpoint.
38  * <br/>Once this event has been execute, the log entry is available through the
39  * <code>getCheckpointLogEntry()</code> method
40  */

41 public class GetCheckpointLogEntryEvent implements LogEvent
42 {
43
44   private Connection JavaDoc connection;
45   private RecoveryLog recoveryLog;
46   private String JavaDoc checkpointName;
47   private CheckpointLogEntry logEntry = null;
48   private SQLException JavaDoc catchedException = null;
49
50   /**
51    * Creates a new <code>GetCheckpointLogEntryEvent</code> object
52    *
53    * @param connection the connection used to access the checkpoint table
54    * @param recoveryLog the recovery log we are attached to
55    * @param checkpointName name of the checkpoint to look for
56    */

57   public GetCheckpointLogEntryEvent(Connection JavaDoc connection,
58       RecoveryLog recoveryLog, String JavaDoc checkpointName)
59   {
60     this.connection = connection;
61     this.recoveryLog = recoveryLog;
62     this.checkpointName = checkpointName;
63   }
64
65   /**
66    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
67    */

68   public boolean belongToTransaction(long tid)
69   {
70     return false;
71   }
72
73   /**
74    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#execute(org.continuent.sequoia.controller.recoverylog.LoggerThread)
75    */

76   public void execute(LoggerThread loggerThread)
77   {
78     PreparedStatement JavaDoc stmt = null;
79     ResultSet JavaDoc rs = null;
80     try
81     {
82       stmt = connection.prepareStatement("SELECT "
83           + recoveryLog.getLogTableSqlColumnName()
84           + ",vlogin,auto_conn_tran,transaction_id,request_id FROM "
85           + recoveryLog.getLogTableName() + ","
86           + recoveryLog.getCheckpointTableName() + " WHERE name LIKE ? and "
87           + recoveryLog.getLogTableName() + ".log_id="
88           + recoveryLog.getCheckpointTableName() + ".log_id");
89       stmt.setString(1, checkpointName);
90       rs = stmt.executeQuery();
91
92       if (rs.next())
93       {
94         logEntry = new CheckpointLogEntry(rs.getString(1), rs.getString(2), rs
95             .getString(3), rs.getLong(4), rs.getLong(5));
96         return;
97       }
98
99       String JavaDoc msg = Translate.get("recovery.jdbc.checkpoint.not.found",
100           checkpointName);
101       throw new SQLException JavaDoc(msg);
102     }
103     catch (SQLException JavaDoc e)
104     {
105       catchedException = new SQLException JavaDoc(Translate.get(
106           "recovery.jdbc.checkpoint.not.found.error", new String JavaDoc[]{
107               checkpointName, e.getMessage()}));
108     }
109     finally
110     {
111       try
112       {
113         if (rs != null)
114           rs.close();
115       }
116       catch (Exception JavaDoc ignore)
117       {
118       }
119       try
120       {
121         if (stmt != null)
122           stmt.close();
123       }
124       catch (Exception JavaDoc ignore)
125       {
126       }
127       synchronized (this)
128       {
129         notify();
130       }
131     }
132   }
133
134   /**
135    * Returns the catched exception if an error occured during the execution.
136    * Returns null if no error occured or the query did not execute yet.
137    *
138    * @return Returns the catchedException.
139    */

140   public final SQLException JavaDoc getCatchedException()
141   {
142     return catchedException;
143   }
144
145   /**
146    * Gets the CheckpointLogEntry corresponding to the checkpoint
147    *
148    * @return the CheckpointLogEntry that has been found
149    * @throws SQLException if an error occurs
150    */

151   public CheckpointLogEntry getCheckpointLogEntry() throws SQLException JavaDoc
152   {
153     if (logEntry == null)
154     {
155       throw catchedException;
156     }
157     return logEntry;
158   }
159
160   /**
161    * @see java.lang.Object#toString()
162    */

163   public String JavaDoc toString()
164   {
165     return "GetCheckpointLogEntryEvent for checkpoint " + checkpointName;
166   }
167 }
168
Popular Tags