001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Emic Networks.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Checchet.
019: * Contributor(s): Olivier Fambon.
020: */package org.continuent.sequoia.controller.recoverylog.events;
021:
022: import java.io.Serializable;
023:
024: /**
025: * This class defines a recovery log entry that needs to be stored in the
026: * recovery database. This is also sent over the wire between controllers, when
027: * copying recovery log entries to a remote controller (copyLogFromCheckpoint).
028: *
029: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
030: * </a>
031: * @version 1.0
032: */
033: public class LogEntry implements Serializable {
034: private static final long serialVersionUID = 1363084035201225164L;
035:
036: private String autoConnTrans;
037: private String executionStatus;
038: private long tid;
039: private String query;
040: private String queryParams;
041: private String login;
042: private long logId;
043: private boolean escapeProcessing = false;
044: private long requestId = 0;
045: private long executionTimeInMs = 0;
046: private int updateCountResult = -1;
047:
048: /**
049: * auto_conn_trans value for a request in autoCommit mode (no persistent
050: * connection)
051: */
052: public static final String AUTOCOMMIT = "A";
053: /** auto_conn_trans value for a persistent connection */
054: public static final String PERSISTENT_CONNECTION = "C";
055: /** auto_conn_trans value for a transaction */
056: public static final String TRANSACTION = "T";
057:
058: /** Execution status value to executing */
059: public static final String EXECUTING = "E";
060: /** Execution status value to success */
061: public static final String SUCCESS = "S";
062: /** Execution status value to failed */
063: public static final String FAILED = "F";
064: /** Execution status value to unknown */
065: public static final String UNKNOWN = "U";
066: /** Status that will be used if the statement is not found in the recovery log */
067: public static final String MISSING = "M";
068:
069: /**
070: * Create a log entry with a default execution status set to EXECUTING.
071: *
072: * @param logId the recovery log unique id
073: * @param login login used for this request
074: * @param query query to log
075: * @param queryParams query parameters if this is a PreparedStatement
076: * @param autoConnTrans AUTOCOMMIT, PERSISTENT_CONNECTION or TRANSACTION
077: * @param tid transaction id of this request
078: */
079: public LogEntry(long logId, String login, String query,
080: String queryParams, String autoConnTrans, long tid) {
081: if (query == null)
082: throw new NullPointerException(
083: "Invalid null query in log entry");
084: if (login == null)
085: throw new NullPointerException(
086: "Invalid null login in log entry");
087:
088: this .logId = logId;
089: this .login = login;
090: this .query = query;
091: this .queryParams = queryParams;
092: this .autoConnTrans = autoConnTrans;
093: this .tid = tid;
094: this .executionStatus = EXECUTING;
095: }
096:
097: /**
098: * Create a log object.
099: *
100: * @param logId the recovery log unique id
101: * @param login login used for this request
102: * @param query query to log
103: * @param queryParams query parameters if this is a PreparedStatement
104: * @param autoConnTrans 'A' if autoCommit, 'C' if persistent connection, 'T'
105: * if transaction
106: * @param tid transaction id of this request
107: * @param escapeProcessing true if escape processing must be done
108: * @param requestId the unique request id
109: * @param executionTime the estimated execution time of the request in
110: * milliseconds
111: * @param updateCountResult the result of this query if it returned an update
112: * count
113: */
114: public LogEntry(long logId, String login, String query,
115: String queryParams, String autoConnTrans, long tid,
116: boolean escapeProcessing, long requestId,
117: long executionTime, int updateCountResult) {
118: this (logId, login, query, queryParams, autoConnTrans, tid,
119: escapeProcessing, requestId, executionTime);
120: this .updateCountResult = updateCountResult;
121: }
122:
123: /**
124: * Create a log object.
125: *
126: * @param logId the recovery log unique id
127: * @param login login used for this request
128: * @param query query to log
129: * @param queryParams query parameters if this is a PreparedStatement
130: * @param autoConnTrans 'A' if autoCommit, 'C' if persistent connection, 'T'
131: * if transaction
132: * @param tid transaction id of this request
133: * @param escapeProcessing true if escape processing must be done
134: * @param requestId the unique request id
135: * @param executionTime the estimated execution time of the request in
136: * milliseconds
137: * @param updateCountResult the result of this query if it returned an update
138: * count
139: * @param status execution status as defined in LogEntry constants
140: */
141: public LogEntry(long logId, String login, String query,
142: String queryParams, String autoConnTrans, long tid,
143: boolean escapeProcessing, long requestId,
144: long executionTime, int updateCountResult, String status) {
145: this (logId, login, query, queryParams, autoConnTrans, tid,
146: escapeProcessing, requestId, executionTime,
147: updateCountResult);
148: this .executionStatus = status;
149: }
150:
151: /**
152: * Create a log object.
153: *
154: * @param logId the recovery log unique id
155: * @param login login used for this request
156: * @param query query to log
157: * @param queryParams query parameters if this is a PreparedStatement
158: * @param autoConnTrans 'A' if autoCommit, 'C' if persistent connection, 'T'
159: * if transaction
160: * @param tid transaction id of this request
161: * @param escapeProcessing true if escape processing must be done
162: * @param requestId the unique request id
163: * @param executionTime the estimated execution time of the request in
164: * milliseconds
165: */
166: public LogEntry(long logId, String login, String query,
167: String queryParams, String autoConnTrans, long tid,
168: boolean escapeProcessing, long requestId, long executionTime) {
169: this (logId, login, query, queryParams, autoConnTrans, tid);
170: this .escapeProcessing = escapeProcessing;
171: this .requestId = requestId;
172: this .executionTimeInMs = executionTime;
173: }
174:
175: /**
176: * Returns the autoConnTrans value.
177: *
178: * @return Returns the autoConnTrans.
179: */
180: public String getAutoConnTrans() {
181: return autoConnTrans;
182: }
183:
184: /**
185: * @return true if escape processing is needed
186: */
187: public boolean getEscapeProcessing() {
188: return escapeProcessing;
189: }
190:
191: /**
192: * Returns the executionStatus value.
193: *
194: * @return Returns the executionStatus.
195: */
196: public final String getExecutionStatus() {
197: return executionStatus;
198: }
199:
200: /**
201: * Sets the executionStatus value.
202: *
203: * @param executionStatus The executionStatus to set.
204: */
205: public final void setExecutionStatus(String executionStatus) {
206: this .executionStatus = executionStatus;
207: }
208:
209: /**
210: * Returns the executionTime value.
211: *
212: * @return Returns the executionTime.
213: */
214: public long getExecutionTimeInMs() {
215: return executionTimeInMs;
216: }
217:
218: /**
219: * @return the request id
220: */
221: public long getLogId() {
222: return logId;
223: }
224:
225: /**
226: * @return the login used for this request
227: */
228: public String getLogin() {
229: return login;
230: }
231:
232: /**
233: * @return the request itself
234: */
235: public String getQuery() {
236: return query;
237: }
238:
239: /**
240: * Returns the queryParams value.
241: *
242: * @return Returns the queryParams.
243: */
244: public final String getQueryParams() {
245: return queryParams;
246: }
247:
248: /**
249: * Returns the requestId value.
250: *
251: * @return Returns the requestId.
252: */
253: public long getRequestId() {
254: return requestId;
255: }
256:
257: /**
258: * @return the transaction id
259: */
260: public long getTid() {
261: return tid;
262: }
263:
264: /**
265: * Returns the result value.
266: *
267: * @return Returns the result.
268: */
269: public int getUpdateCountResult() {
270: return updateCountResult;
271: }
272:
273: /**
274: * Sets the logId value.
275: *
276: * @param logId The logId to set.
277: */
278: public final void setLogId(long logId) {
279: this .logId = logId;
280: }
281:
282: /**
283: * @see java.lang.Object#toString()
284: */
285: public String toString() {
286: return "Log entry: log id" + logId + " (" + autoConnTrans
287: + ") transactionId:" + tid + " requestId:" + requestId
288: + " vlogin:" + login + " status: " + executionStatus
289: + " sql:" + query + " params:" + queryParams;
290: }
291:
292: }
|