KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2006 Continuent, Inc.
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): Emmanuel Cecchet.
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 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.continuent.sequoia.controller.recoverylog.LoggerThread;
32
33 /**
34  * This class defines a GetAllBeginLoggedAfterIdEvent.
35  * <p>
36  * This event is used to retrieve a log ID associated to a checkpoint. <br>
37  * Once this event has been execute, the log ID is available through the
38  * <code>getCheckpointRequestId()</code> method
39  */

40 public class GetAllBeginLoggedAfterIdEvent implements LogEvent
41 {
42
43   private Connection JavaDoc connection;
44   private String JavaDoc logTableName;
45   private long checkpointId;
46   private List JavaDoc beginList = null;
47   private SQLException JavaDoc catchedException = null;
48   private String JavaDoc logTableSqlColumnName;
49
50   /**
51    * Creates a new <code>GetAllBeginLoggedAfterIdEvent</code> object
52    *
53    * @param connection the connection used to access the checkpoint table
54    * @param logTableName the name of the checkpoint table
55    * @param logTableSqlColumnName name of the recovery log table sql column
56    * @param checkpointId the name of the checkpoint
57    */

58   public GetAllBeginLoggedAfterIdEvent(Connection JavaDoc connection,
59       String JavaDoc logTableName, String JavaDoc logTableSqlColumnName, long checkpointId)
60   {
61     this.connection = connection;
62     this.logTableName = logTableName;
63     this.checkpointId = checkpointId;
64     this.logTableSqlColumnName = logTableSqlColumnName;
65   }
66
67   /**
68    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
69    */

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

78   public void execute(LoggerThread loggerThread)
79   {
80     PreparedStatement JavaDoc stmt = null;
81     ResultSet JavaDoc rs = null;
82     try
83     {
84       stmt = connection.prepareStatement("SELECT transaction_id FROM "
85           + logTableName + " WHERE log_id>? AND " + logTableSqlColumnName
86           + " LIKE ?");
87       stmt.setLong(1, checkpointId);
88       stmt.setString(2, "begin");
89       rs = stmt.executeQuery();
90       beginList = new ArrayList JavaDoc();
91       while (rs.next())
92         beginList.add(new Long JavaDoc(rs.getLong(1)));
93     }
94     catch (SQLException JavaDoc e)
95     {
96       catchedException = e;
97     }
98     finally
99     {
100       try
101       {
102         if (rs != null)
103           rs.close();
104       }
105       catch (Exception JavaDoc ignore)
106       {
107       }
108       try
109       {
110         if (stmt != null)
111           stmt.close();
112       }
113       catch (Exception JavaDoc ignore)
114       {
115       }
116       synchronized (this)
117       {
118         notify();
119       }
120     }
121   }
122
123   /**
124    * Returns the catched exception if an error occured during the execution.
125    * Returns null if no error occured or the query did not execute yet.
126    *
127    * @return Returns the catchedException.
128    */

129   public final SQLException JavaDoc getCatchedException()
130   {
131     return catchedException;
132   }
133
134   /**
135    * Return the list of transactions started after the given id
136    *
137    * @return begin list
138    * @throws SQLException if an error occured
139    */

140   public List JavaDoc getBeginList() throws SQLException JavaDoc
141   {
142     if (beginList == null)
143       throw catchedException;
144     return beginList;
145   }
146
147   /**
148    * @see java.lang.Object#toString()
149    */

150   public String JavaDoc toString()
151   {
152     return "GetCheckpointLogIdEvent for checkpoint " + checkpointId;
153   }
154
155 }
156
Popular Tags