net.sf.jameleon.data
Class SqlDataDriver

java.lang.Object
  extended by net.sf.jameleon.data.SqlDataDriver
All Implemented Interfaces:
DataDriver

public class SqlDataDriver
extends Object
implements DataDriver

Am implementation of @{link DataDriver} for SQL.


Field Summary
protected  Connection conn
           
protected  String jdbcDriver
           
protected  List keys
           
protected  String password
           
protected  String query
           
protected  ResultSet rs
           
protected  Statement stmt
           
protected  String url
           
protected  String username
           
 
Constructor Summary
SqlDataDriver()
          Default construtor.
SqlDataDriver(String url, String jdbcDriver, String username, String password)
          Sets up all required fields.
 
Method Summary
 void close()
          Closes the handle to the data source
 void executeQuery()
          Executes a query against the database once a valid connection has been established.
 Map getNextRow()
          Gets the next row from the data source
 boolean hasMoreRows()
          Tells whether the data source has another row
 void open()
          Opens the handle to the data source
protected  void readRecord()
           
protected  void registerJDBCDriver()
           
 void setJDBCDriver(String jdbcDriver)
          Sets the JDBC Driver.
 void setJDBCPassword(String password)
          Sets the JDBC password.
 void setJDBCUrl(String url)
          Sets the JDBC url.
 void setJDBCUsername(String username)
          Sets the JDBC username.
protected  void setKeys()
          Gets MetaData from the result set and builds an ArrayList of the Column headers
 void setQuery(String query)
          Sets the SQL Query.
protected  void validate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

protected String url

jdbcDriver

protected String jdbcDriver

username

protected String username

password

protected String password

query

protected String query

conn

protected Connection conn

keys

protected List keys

stmt

protected Statement stmt

rs

protected ResultSet rs
Constructor Detail

SqlDataDriver

public SqlDataDriver()
Default construtor. After calling this constructor, The Following will Need to be set. setJDBCDriver(java.lang.String) setJDBCUrl(java.lang.String)


SqlDataDriver

public SqlDataDriver(String url,
                     String jdbcDriver,
                     String username,
                     String password)
Sets up all required fields.

Parameters:
url - - the jdbc url used to connect to the database
jdbcDriver - - the jdbc driver used to connect to the database
username - - the username used to connect to the database
password - - the password used to connect to the database
Method Detail

close

public void close()
Closes the handle to the data source

Specified by:
close in interface DataDriver

open

public void open()
          throws IOException
Opens the handle to the data source

Specified by:
open in interface DataDriver
Throws:
IOException - when the data source can not be found.

validate

protected void validate()

registerJDBCDriver

protected void registerJDBCDriver()
                           throws IOException
Throws:
IOException

readRecord

protected void readRecord()
                   throws SQLException
Throws:
SQLException

executeQuery

public void executeQuery()
                  throws SQLException
Executes a query against the database once a valid connection has been established.

Throws:
SQLException - if there is no query defined.

setKeys

protected void setKeys()
Gets MetaData from the result set and builds an ArrayList of the Column headers


getNextRow

public Map getNextRow()
Gets the next row from the data source

Specified by:
getNextRow in interface DataDriver
Returns:
a key-value HashMap representing the data row or null if no data row is available

hasMoreRows

public boolean hasMoreRows()
Tells whether the data source has another row

Specified by:
hasMoreRows in interface DataDriver
Returns:
true if the data source still has more rows

setJDBCDriver

public void setJDBCDriver(String jdbcDriver)
Sets the JDBC Driver.


setJDBCUrl

public void setJDBCUrl(String url)
Sets the JDBC url.


setJDBCUsername

public void setJDBCUsername(String username)
Sets the JDBC username.


setJDBCPassword

public void setJDBCPassword(String password)
Sets the JDBC password.


setQuery

public void setQuery(String query)
Sets the SQL Query.



Copyright © 2003-2008 Christian Hargraves. All Rights Reserved.