KickJava   Java API By Example, From Geeks To Geeks.

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


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): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.controller.recoverylog.events;
23
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.continuent.sequoia.common.i18n.Translate;
28 import org.continuent.sequoia.common.log.Trace;
29 import org.continuent.sequoia.controller.recoverylog.LoggerThread;
30 import org.continuent.sequoia.controller.recoverylog.RecoveryLog;
31
32 /**
33  * This class defines a LogRequestEvent to log a request log entry.
34  *
35  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
36  * @version 1.0
37  */

38 public class LogRequestEvent implements LogEvent
39 {
40   protected LogEntry logEntry;
41
42   /**
43    * Creates a new <code>LogRequestEvent</code> object
44    *
45    * @param entry the log entry to use (not null)
46    */

47   public LogRequestEvent(LogEntry entry)
48   {
49     if (entry == null)
50       throw new RuntimeException JavaDoc(
51           "Invalid null entry in LogRequestEvent constructor");
52     this.logEntry = entry;
53   }
54
55   /**
56    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
57    */

58   public boolean belongToTransaction(long tid)
59   {
60     return logEntry.getTid() == tid;
61   }
62
63   /**
64    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#execute(org.continuent.sequoia.controller.recoverylog.LoggerThread)
65    */

66   public void execute(LoggerThread loggerThread)
67   {
68     Trace logger = loggerThread.getLogger();
69     try
70     {
71       if (logger.isDebugEnabled())
72         logger.debug(Translate.get("recovery.jdbc.loggerthread.log.info",
73             logEntry.getLogId()));
74
75       PreparedStatement JavaDoc pstmt = loggerThread.getLogPreparedStatement();
76       pstmt.setLong(RecoveryLog.COLUMN_INDEX_LOG_ID, logEntry.getLogId());
77       pstmt.setString(RecoveryLog.COLUMN_INDEX_VLOGIN, logEntry.getLogin());
78       pstmt.setString(RecoveryLog.COLUMN_INDEX_SQL, logEntry.getQuery());
79       pstmt.setString(RecoveryLog.COLUMN_INDEX_SQL_PARAMS, logEntry
80           .getQueryParams());
81       pstmt.setString(RecoveryLog.COLUMN_INDEX_AUTO_CONN_TRAN, logEntry
82           .getAutoConnTrans());
83       pstmt.setLong(RecoveryLog.COLUMN_INDEX_TRANSACTION_ID, logEntry.getTid());
84       pstmt.setLong(RecoveryLog.COLUMN_INDEX_REQUEST_ID, logEntry
85           .getRequestId());
86       pstmt.setString(RecoveryLog.COLUMN_INDEX_EXEC_STATUS, logEntry
87           .getExecutionStatus());
88       pstmt.setLong(RecoveryLog.COLUMN_INDEX_EXEC_TIME, logEntry
89           .getExecutionTimeInMs());
90       pstmt.setLong(RecoveryLog.COLUMN_INDEX_UPDATE_COUNT, logEntry
91           .getUpdateCountResult());
92       pstmt.setLong(RecoveryLog.COLUMN_INDEX_COMPLETION_LOG_ID, logEntry
93           .getCompletionLogId());
94       if (logger.isDebugEnabled())
95         logger.debug(pstmt.toString());
96       try
97       {
98         pstmt.setEscapeProcessing(logEntry.getEscapeProcessing());
99       }
100       catch (Exception JavaDoc ignore)
101       {
102       }
103       int updatedRows = pstmt.executeUpdate();
104       if ((updatedRows != 1) && logger.isWarnEnabled())
105         logger
106             .warn("Recovery log did not update a single entry while executing: "
107                 + pstmt.toString());
108     }
109     catch (SQLException JavaDoc e)
110     {
111       loggerThread.invalidateLogStatements();
112       if ("T".equals(logEntry.getAutoConnTrans()))
113         logger.error(Translate.get(
114             "recovery.jdbc.loggerthread.log.failed.transaction", new String JavaDoc[]{
115                 logEntry.getQuery(), String.valueOf(logEntry.getTid())}), e);
116       else
117         logger.error(Translate.get("recovery.jdbc.loggerthread.log.failed",
118             logEntry.getQuery()), e);
119       // Push object back in the queue, it needs to be logged again
120
loggerThread.putBackAtHeadOfQueue(this, e);
121     }
122   }
123
124   /**
125    * @see java.lang.Object#toString()
126    */

127   public String JavaDoc toString()
128   {
129     return "LogRequestEvent: " + logEntry;
130   }
131
132 }
133
Popular Tags