KickJava   Java API By Example, From Geeks To Geeks.

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


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.LoggerThread;
31
32 /**
33  * This class defines a GetCheckpointLogIdEvent.
34  * <p>
35  * This event is used to retrieve a log ID associated to a checkpoint. <br>
36  * Once this event has been execute, the log ID is available through the
37  * <code>getCheckpointRequestId()</code> method
38  */

39 public class GetCheckpointLogIdEvent implements LogEvent
40 {
41
42   private Connection JavaDoc connection;
43   private String JavaDoc checkpointTableName;
44   private String JavaDoc checkpointName;
45   private long logId = -1;
46   private SQLException JavaDoc catchedException = null;
47
48   /**
49    * Creates a new <code>GetCheckpointLogIdEvent</code> object
50    *
51    * @param connection the connection used to access the checkpoint table
52    * @param checkpointTableName the name of the checkpoint table
53    * @param checkpointName the name of the checkpoint
54    */

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

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

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

131   public final SQLException JavaDoc getCatchedException()
132   {
133     return catchedException;
134   }
135
136   /**
137    * Gets the log identifier corresponding to the checkpoint
138    *
139    * @return long the request identifier corresponding to the checkpoint.
140    * @throws SQLException if an error occurs
141    */

142   public long getCheckpointLogId() throws SQLException JavaDoc
143   {
144     if (logId == -1)
145     {
146       throw catchedException;
147     }
148     return logId;
149   }
150
151   /**
152    * @see java.lang.Object#toString()
153    */

154   public String JavaDoc toString()
155   {
156     return "GetCheckpointLogIdEvent for checkpoint " + checkpointName;
157   }
158 }
159
Popular Tags