source: src/main/java/weka/gui/sql/event/QueryExecuteEvent.java @ 26

Last change on this file since 26 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.0 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 * QueryExecuteEvent.java
19 * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.sql.event;
24
25import weka.gui.sql.DbUtils;
26
27import java.sql.ResultSet;
28import java.util.EventObject;
29
30/**
31 * An event that is generated when a query is executed.
32 *
33 * @see         QueryExecuteListener
34 * @author      FracPete (fracpete at waikato dot ac dot nz)
35 * @version     $Revision: 1.2 $
36 */
37public class QueryExecuteEvent
38  extends EventObject {
39
40  /** for serialization */
41  private static final long serialVersionUID = -5556385019954730740L;
42 
43  /** the Db utils instance for the current DB connection  */
44  protected DbUtils m_DbUtils;
45 
46  /** the query that was executed */
47  protected String m_Query;
48
49  /** the produced ResultSet, if any */
50  protected ResultSet m_ResultSet;
51
52  /** a possible exception, if the query failed */
53  protected Exception m_Exception;
54
55  /** the maximum number of rows to retrieve */
56  protected int m_MaxRows;
57 
58  /**
59   * constructs the event
60   * @param source        the source that generated this event
61   * @param utils         the DbUtils instance that connected to the DB
62   * @param query         the query that is the basis for the resultset
63   * @param rows          the maximum number of rows to retrieve (0 for all)
64   * @param rs            the ResultSet that was produced (depending on the
65   *                      type of SQL query it can also be NULL)
66   * @param ex            in case an exception occurred
67   */
68  public QueryExecuteEvent( Object source, 
69                            DbUtils utils,
70                            String query, 
71                            int rows,
72                            ResultSet rs, 
73                            Exception ex ) {
74    super(source);
75
76    m_DbUtils   = utils;
77    m_Query     = query;
78    m_MaxRows   = rows;
79    m_ResultSet = rs;
80    m_Exception = ex;
81  }
82
83  /**
84   * returns the DbUtils instance that was executed the query
85   */
86  public DbUtils getDbUtils() {
87    return m_DbUtils;
88  }
89
90  /**
91   * returns the query that was executed
92   */
93  public String getQuery() {
94    return m_Query;
95  }
96
97  /**
98   * returns the maximum number of rows to retrieve. 0 means all.
99   */
100  public int getMaxRows() {
101    return m_MaxRows;
102  }
103
104  /**
105   * is TRUE in case the exception is not NULL, i.e. the query failed
106   */
107  public boolean failed() {
108    return (m_Exception != null);
109  }
110
111  /**
112   * whether a ResultSet was produced, e.g. DDL commands like delete, drop
113   * or update do not produce one.
114   */
115  public boolean hasResult() {
116    return (m_ResultSet != null);
117  }
118
119  /**
120   * returns the resultset that was produced, can be null in case the query
121   * failed
122   */
123  public ResultSet getResultSet() {
124    return m_ResultSet;
125  }
126
127  /**
128   * returns the exception, if one happened, otherwise NULL
129   */
130  public Exception getException() {
131    return m_Exception;
132  }
133
134  /**
135   * returns the event in a string representation
136   * @return        the event in a string representation
137   */
138  public String toString() {
139    String        result;
140
141    result  = super.toString();
142    result  = result.substring(0, result.length() - 1);  // remove "]"
143    result +=   ",query=" + getQuery() 
144              + ",maxrows=" + getMaxRows()
145              + ",failed=" + failed()
146              + ",exception=" + getException() + "]";
147
148    return result;
149  }
150}
Note: See TracBrowser for help on using the repository browser.