001: package net.sourceforge.squirrel_sql.client.session;
002:
003: /*
004: * Copyright (C) 2002-2004 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * Modifications Copyright (C) 2003-2004 Jason Height
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: import java.util.Calendar;
024: import java.util.Date;
025:
026: /**
027: * Information about an executed query.
028: *
029: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
030: */
031: public class SQLExecutionInfo {
032: /** Query index. */
033: private int _idx;
034:
035: /** Execution start time. */
036: private Date _sqlExecutionStart;
037:
038: /** Results processing start time. */
039: private Date _resultsProcessingStart;
040:
041: /** Results processing end time. */
042: private Date _resultsProcessingEnd;
043:
044: /** SQL script executed. */
045: private String _sql;
046:
047: /** Number of rows query limited to. */
048: private final int _maxRows;
049:
050: /**
051: * Default ctor. Defaults SQL execution start time to the current time.
052: */
053: // public SQLExecutionInfo()
054: // {
055: // this(1, "");
056: // }
057: /**
058: * ctor specifying the query index. Defaults SQL execution start time to
059: * the current time.
060: *
061: * @param idx Query index.
062: */
063: // public SQLExecutionInfo(int idx)
064: // {
065: // this(idx, "");
066: // }
067: /**
068: * ctor specifying the SQL being executed. Defaults SQL execution start time
069: * to the current time.
070: *
071: * @param sql SQL being executed.
072: *
073: * @throws IllegalArgumentException
074: * Thrown if <TT>null</TT> sql passed.
075: */
076: // public SQLExecutionInfo(String sql)
077: // {
078: // super();
079: // if (sql == null)
080: // {
081: // throw new IllegalArgumentException("SQL script == null");
082: // }
083: // _sql = sql;
084: // _sqlExecutionStart = Calendar.getInstance().getTime();
085: // }
086: /**
087: * ctor specifying the SQL being executed and the query index. Defaults SQL
088: * execution start time to the current time.
089: *
090: * @param idx Query index.
091: * @param sql SQL being executed.
092: * @param maxRows Number of rows query is limited to.
093: *
094: * @throws IllegalArgumentException
095: * Thrown if <TT>null</TT> sql passed.
096: */
097: public SQLExecutionInfo(int idx, String sql, int maxRows) {
098: super ();
099: if (sql == null) {
100: throw new IllegalArgumentException("SQL script == null");
101: }
102: _idx = idx;
103: _sql = sql;
104: _maxRows = maxRows;
105: _sqlExecutionStart = Calendar.getInstance().getTime();
106: }
107:
108: /**
109: * Flag that the SQL execution is complete.
110: */
111: public void sqlExecutionComplete() {
112: _resultsProcessingStart = Calendar.getInstance().getTime();
113: }
114:
115: /**
116: * Flag that the results processing is complete.
117: */
118: public void resultsProcessingComplete() {
119: _resultsProcessingEnd = Calendar.getInstance().getTime();
120: }
121:
122: /**
123: * Retrieve the query index.
124: *
125: * @return Query index.
126: */
127: public int getQueryIndex() {
128: return _idx;
129: }
130:
131: /**
132: * Retrieve the SQL script executed.
133: *
134: * @return SQL script executed.
135: */
136: public String getSQL() {
137: return _sql;
138: }
139:
140: /**
141: * Retrieve the SQL Execution start time.
142: *
143: * @return SQL execution start time.
144: */
145: public Date getSQLExecutionStartTime() {
146: return _sqlExecutionStart;
147: }
148:
149: /**
150: * Set the SQL Execution start time.
151: *
152: * @param value SQL execution start time.
153: *
154: * @throws IllegalArgumentException
155: * Thrown if <TT>null</TT> <TT>Date</TT> passed.
156: */
157: public void setSQLExecutionStartTime(Date value) {
158: if (value == null) {
159: throw new IllegalArgumentException(
160: "SQL Execution start time == null");
161: }
162: _sqlExecutionStart = value;
163: }
164:
165: /**
166: * Retrieve the elapsed time time in milliseconds for the SQL execution.
167: *
168: * @return SQL execution elapsed time in millis.
169: */
170: public long getSQLExecutionElapsedMillis() {
171: long results = 0;
172: if (_resultsProcessingStart != null) {
173: results = _resultsProcessingStart.getTime()
174: - _sqlExecutionStart.getTime();
175: }
176: return results;
177: }
178:
179: /**
180: * Retrieve the elapsed time time in milliseconds for the results processing.
181: *
182: * @return Results processing elapsed time in millis.
183: */
184: public long getResultsProcessingElapsedMillis() {
185: long results = 0;
186: if (_resultsProcessingEnd != null
187: && _resultsProcessingStart != null) {
188: results = (_resultsProcessingEnd.getTime() - _resultsProcessingStart
189: .getTime());
190: }
191: return results;
192: }
193:
194: /**
195: * Retrieve the total elapsed time time in milliseconds.
196: *
197: * @return Total elapsed time in millis.
198: */
199: public long getTotalElapsedMillis() {
200: return getSQLExecutionElapsedMillis()
201: + getResultsProcessingElapsedMillis();
202: }
203:
204: /**
205: * Retrieve number of rows query limited to. Zero means unlimited.
206: *
207: * @return number of rows query limited to.
208: */
209: public int getMaxRows() {
210: return _maxRows;
211: }
212: }
|