de.hpi.fgis.dude.database
Class DatabaseSource

java.lang.Object
  extended by de.hpi.fgis.dude.util.AbstractCleanable
      extended by de.hpi.fgis.dude.datasource.AbstractDataSource<DatabaseSource>
          extended by de.hpi.fgis.dude.database.DatabaseSource
All Implemented Interfaces:
DataSource, Cleanable, AutoJsonable, JsonableReader<DuDeObject>, Closeable, Iterable<DuDeObject>

public class DatabaseSource
extends AbstractDataSource<DatabaseSource>

DatabaseSource represents databases.

Author:
Matthias Pohl
See Also:
Database, DBConnector

Nested Class Summary
protected  class DatabaseSource.DatabaseSourceIterator
          DatabaseSourceIterator is used for generating DuDeObjects out of DatabaseSources.
 
Nested classes/interfaces inherited from class de.hpi.fgis.dude.datasource.AbstractDataSource
AbstractDataSource.AbstractDataSourceIterator<T extends AbstractDataSource<?>>
 
Constructor Summary
protected DatabaseSource()
          Internal constructor for Jsonable deserialization.
  DatabaseSource(String identifier, Database db, String tbName)
          Initializes DatabaseSource for the passed Database and table.
 
Method Summary
 void cleanUp()
          Closes all registered Closeable and Cleanable instances.
protected  Database getDatabase()
          Returns the underlying Database.
protected  String getJDBCString()
          Returns the JDBC String of the underlying database.
protected  String getQuery()
          Returns the complete query that is used for querying the result.
protected  String getTableName()
          Returns the table name.
 Iterator<DuDeObject> iterator()
           
protected  void registerStatement(Statement stmt)
          Registers a Statement.
 void setWhereFilter(String whereExt)
          Enables the where clause with the passed query extension.
 DatabaseSource withWhereFilter(String whereExt)
          Sets the where clause for the data extraction.
 
Methods inherited from class de.hpi.fgis.dude.datasource.AbstractDataSource
addIdAttributes, autoGeneratedIds, close, equals, getExtractedRecordCount, getIdAttributes, getIdentifier, hashCode, setExtractedRecordCount, toString, withIdAttributes
 
Methods inherited from class de.hpi.fgis.dude.util.AbstractCleanable
registerCleanable, registerCloseable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.hpi.fgis.dude.util.Cleanable
registerCleanable, registerCloseable
 

Constructor Detail

DatabaseSource

protected DatabaseSource()
Internal constructor for Jsonable deserialization.


DatabaseSource

public DatabaseSource(String identifier,
                      Database db,
                      String tbName)
Initializes DatabaseSource for the passed Database and table.

Parameters:
identifier - The identifier of this DataSource.
db - The underlying Database.
tbName - The table name.
Method Detail

getDatabase

protected Database getDatabase()
Returns the underlying Database.

Returns:
The underlying Database.

getTableName

protected String getTableName()
Returns the table name.

Returns:
The table name.

setWhereFilter

public void setWhereFilter(String whereExt)
Enables the where clause with the passed query extension. This method can be used for extracting only specified records. CAUTION: No query validation is done.

Parameters:
whereExt - The where clause.

withWhereFilter

public DatabaseSource withWhereFilter(String whereExt)
Sets the where clause for the data extraction.

Parameters:
whereExt - The where clause.
Returns:
The current instance.
See Also:
setWhereFilter(String)

getQuery

protected String getQuery()
Returns the complete query that is used for querying the result.

Returns:
The SQL query.

getJDBCString

protected String getJDBCString()
Returns the JDBC String of the underlying database.

Returns:
The JDBC String of the underlying database.

registerStatement

protected void registerStatement(Statement stmt)
Registers a Statement. This statement will be closed during the next call of cleanUp().

Parameters:
stmt - The statement that shall be closed later on.

cleanUp

public void cleanUp()
Description copied from interface: Cleanable
Closes all registered Closeable and Cleanable instances.

Specified by:
cleanUp in interface Cleanable
Overrides:
cleanUp in class AbstractCleanable

iterator

public Iterator<DuDeObject> iterator()
Specified by:
iterator in interface Iterable<DuDeObject>
Specified by:
iterator in class AbstractDataSource<DatabaseSource>


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.