net.sourceforge.fluxion.datapublisher.sql.impl
Class SQLQuery<T>

java.lang.Object
  extended by net.sourceforge.fluxion.datapublisher.sql.impl.SQLQuery<T>
All Implemented Interfaces:
Query<T>
Direct Known Subclasses:
MySQLQuery, ODBCQuery, PostgresqlQuery

public abstract class SQLQuery<T>
extends java.lang.Object
implements Query<T>

Models a query against a MySQL bean. Queries are typed with the type of bean the query acts against. A SQLQuery would usually be generated from a SQLQueryFactory.

Version:
0.2
Author:
Tony Burdett
See Also:
SQLQueryFactory

Field Summary
protected  java.sql.Connection connection
           
protected  java.lang.String dbUri
           
protected  java.lang.String password
           
protected  java.lang.String user
           
 
Constructor Summary
SQLQuery(java.lang.Class<T> beanClass, Filter filter, java.lang.String dbUrl, java.lang.String user, java.lang.String password)
           
 
Method Summary
 void addFromClause(java.lang.String table)
          Adds the "from" clause for this query
 void addSelectClause(java.lang.String selection)
          Adds the "select" clause for this query
 void addWhereClause(java.lang.String param)
          Adds the "where" clause for this query
protected abstract  void closeConnection()
          Close the connection to the datasource.
 java.lang.String execute()
          Execute this query.
 boolean hasMoreResults()
          True if there are more results, false otherwise
 T nextResult()
          Returns the next result in the sequence
protected abstract  void openConnection()
          Acquire a connection to the underlying datasource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbUri

protected java.lang.String dbUri

user

protected java.lang.String user

password

protected java.lang.String password

connection

protected java.sql.Connection connection
Constructor Detail

SQLQuery

public SQLQuery(java.lang.Class<T> beanClass,
                Filter filter,
                java.lang.String dbUrl,
                java.lang.String user,
                java.lang.String password)
Method Detail

execute

public java.lang.String execute()
                         throws QueryExecutionException
Description copied from interface: Query
Execute this query. Queries should know how to acquire a connection to the datasource. Once executed, results can be pulled from this query using nextResult(), which will return the next bean instance. This method returns a String that describes the query that has been executed. This is used for logging purposes, and will usually look something like "LANG: SQL; STATEMENT: SELECT * FROM foo WHERE bar"

Specified by:
execute in interface Query<T>
Returns:
a string that describes the query
Throws:
QueryExecutionException - if the query failed to execute

hasMoreResults

public boolean hasMoreResults()
                       throws QueryExecutionException
Description copied from interface: Query
True if there are more results, false otherwise

Specified by:
hasMoreResults in interface Query<T>
Returns:
true if there are more results, false otherwise
Throws:
QueryExecutionException - if there is some problem with retrieving the results of the query

nextResult

public T nextResult()
             throws QueryExecutionException
Description copied from interface: Query
Returns the next result in the sequence

Specified by:
nextResult in interface Query<T>
Returns:
the next result
Throws:
QueryExecutionException - if there is a problem retrieving the next result

addSelectClause

public void addSelectClause(java.lang.String selection)
Adds the "select" clause for this query

Parameters:
selection - the fields being selected

addFromClause

public void addFromClause(java.lang.String table)
Adds the "from" clause for this query

Parameters:
table - the table being queried

addWhereClause

public void addWhereClause(java.lang.String param)
Adds the "where" clause for this query

Parameters:
param - the parameters for this query

openConnection

protected abstract void openConnection()
                                throws QueryExecutionException
Acquire a connection to the underlying datasource. This will be called by execute() to first acquire a new connection to satisfy the query.

Throws:
QueryExecutionException - if the connection couldn't be opened

closeConnection

protected abstract void closeConnection()
                                 throws QueryExecutionException
Close the connection to the datasource. This will be called by execute() once the query is completed.

Throws:
QueryExecutionException - if the connection failed to close properly


Copyright © 2010. All Rights Reserved.