KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > recoverylog > events > UnlogRequestEvent


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

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

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

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

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

67   public void execute(LoggerThread loggerThread)
68   {
69     Trace logger = loggerThread.getLogger();
70     try
71     {
72       if (logger.isInfoEnabled())
73         logger.info(Translate.get("recovery.jdbc.loggerthread.unlog.info",
74             logEntry.getId()));
75
76       PreparedStatement JavaDoc pstmt = loggerThread.getUnlogPreparedStatement();
77       pstmt.setLong(1, logEntry.getId());
78       pstmt.setString(2, logEntry.getLogin());
79       pstmt.setString(3, logEntry.getQuery());
80       pstmt.setLong(4, logEntry.getTid());
81       if (logger.isDebugEnabled())
82         logger.debug(pstmt.toString());
83
84       try
85       {
86         pstmt.setEscapeProcessing(logEntry.getEscapeProcessing());
87       }
88       catch (Exception JavaDoc ignore)
89       {
90       }
91       int updatedRows = pstmt.executeUpdate();
92       if ((updatedRows != 1) && logger.isWarnEnabled())
93         logger
94             .warn("Recovery log did not update a single entry while executing: "
95                 + pstmt.toString());
96     }
97     catch (SQLException JavaDoc e)
98     {
99       loggerThread.invalidateLogStatements();
100       logger.error(
101           Translate.get("recovery.jdbc.loggerthread.log.failed", new String JavaDoc[]{
102               logEntry.getQuery(), String.valueOf(logEntry.getTid())}), e);
103       // Push object back in the queue, it needs to be logged again
104
loggerThread.putBackAtHeadOfQueue(this);
105     }
106   }
107
108 }
109
Popular Tags