public class

QueryAction

extends ActionAdapter
java.lang.Object
   ↳ javax.swing.AbstractAction
     ↳ org.mbari.awt.event.ActionAdapter
       ↳ vars.query.ui.db.sql.QueryAction

Class Overview

This action takes a SQL query (as a string) and an IQueryable object, executes the query in a seperate thread and returns the results as a QueryResults object. Here's an example of usage:

 // Create our IQueryable object to execute our query
 IQueryable q = new IQueryable() {
     public QueryResults executeQuery(String query) {
         // Get a JDBC connection
         Connection c = ConnectionFactory.getConnection("vars");
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery(query);
         QueryResults queryResults = new QueryResults(rs);
         s.close();
         c.close();
         return queryResults;
     }
 };

 // Initialize our QueryAction
 QueryAction a = new QueryAction("SELECT * from MyTable", q);

 // We'll add some exception handling just to notify us of an error. This is optional
 a.addExceptionHandler(new ExceptionHandler() {
     public void doAction(Exception e) {
         e.printStackTrace();
     }
 });

 // Since it's multithreaded we can't just call getQueryResults because the
 // query may not be finished (Calling getQueryResults would return null). So we
 // attach a PropertyChangeListener to handle post query work
 a.addPropertyChangeListener("queryResults", new PropertyChangeListener() {
     public void propertyChange(PropertyChangeEvent evt) {
         System.out.println("Query is done");
         // Normally you would put save or display code here.
     }
 });

 

Summary

[Expand]
Inherited Constants
From interface javax.swing.Action
[Expand]
Inherited Fields
From class javax.swing.AbstractAction
Public Constructors
QueryAction(String query, IQueryable queryable, KnowledgebaseDAOFactory knowledgebaseDAOFactory)
Constructor for the QueryAction object
QueryAction(String query, IQueryable queryable, KnowledgebaseDAOFactory knowledgebaseDAOFactory, boolean showHiearchy, boolean showBasicPhylogeny, boolean showFullPhylogeny)
Constructs ...
Public Methods
synchronized void addExceptionHandler(ExceptionHandler eh)
synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Adds a feature to the PropertyChangeListener attribute of the QueryAction object
synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
void cancel()

void doAction()
Description of the Method
String getQuery()
synchronized QueryResults getQueryResults()
synchronized boolean isFinished()
synchronized void removeExceptionHandler(ExceptionHandler eh)
synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Description of the Method
synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
[Expand]
Inherited Methods
From class org.mbari.awt.event.ActionAdapter
From class javax.swing.AbstractAction
From class java.lang.Object
From interface java.awt.event.ActionListener
From interface javax.swing.Action
From interface org.mbari.awt.event.IAction

Public Constructors

public QueryAction (String query, IQueryable queryable, KnowledgebaseDAOFactory knowledgebaseDAOFactory)

Constructor for the QueryAction object

Parameters
query Description of the Parameter
queryable Description of the Parameter

public QueryAction (String query, IQueryable queryable, KnowledgebaseDAOFactory knowledgebaseDAOFactory, boolean showHiearchy, boolean showBasicPhylogeny, boolean showFullPhylogeny)

Constructs ...

Public Methods

public synchronized void addExceptionHandler (ExceptionHandler eh)

public synchronized void addPropertyChangeListener (PropertyChangeListener listener)

Adds a feature to the PropertyChangeListener attribute of the QueryAction object

Parameters
listener The feature to be added to the PropertyChangeListener attribute

public synchronized void addPropertyChangeListener (String propertyName, PropertyChangeListener listener)

public void cancel ()

public void doAction ()

Description of the Method

public String getQuery ()

Returns
  • Returns the query.

public synchronized QueryResults getQueryResults ()

Returns
  • Returns the queryResults.

public synchronized boolean isFinished ()

Returns
  • Returns the finished.

public synchronized void removeExceptionHandler (ExceptionHandler eh)

public synchronized void removePropertyChangeListener (PropertyChangeListener listener)

Description of the Method

Parameters
listener Description of the Parameter

public synchronized void removePropertyChangeListener (String propertyName, PropertyChangeListener listener)