org.liquidsite.core.data
Class DataSource

java.lang.Object
  extended byorg.liquidsite.core.data.DataSource

public class DataSource
extends java.lang.Object

A data source. This object encapsulates a database connection that is used during for a set of data operations.


Constructor Summary
DataSource(DatabaseConnection connection)
          Creates a new data source.
DataSource(DatabaseConnector database)
          Creates a new data source.
 
Method Summary
 void close()
          Closes the connection to the data source.
protected  void finalize()
          Calls the close() method to free resources.
protected  DatabaseConnection getConnection()
          Returns the database connection.
 boolean isOpen()
          Checks if this object has an open connection to its data source.
 void open()
          Opens a connection to the data source.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSource

public DataSource(DatabaseConnector database)
Creates a new data source. The specified database connector will be used to get and return a database connection.

Parameters:
database - the database connector to use

DataSource

public DataSource(DatabaseConnection connection)
Creates a new data source. The specified database connection will be used continously. The open and close operation will not have any effect for data sources created in this way.

Parameters:
connection - the database connection to use
Method Detail

isOpen

public boolean isOpen()
Checks if this object has an open connection to its data source.

Returns:
true if a connection is already open, or false otherwise

open

public void open()
          throws DataObjectException
Opens a connection to the data source. Normally this method only retrieves an already established connection from the database connection pool (for efficiency). This method is implicitly called when using the data source for retrieving or storing data. Note that the corresponding close() method should be called after finishing the data operations to free unneeded resources.

Throws:
DataObjectException - if no data source connection could be established
See Also:
close()

close

public void close()
Closes the connection to the data source. Normally this method doesn't really close the physical connection, but rather returns it to the database connection pool. This method can be called without adverse effects and should be called whenever the data operations have finished. The data source can be opened and closed any number of times.

See Also:
open()

getConnection

protected DatabaseConnection getConnection()
                                    throws DataObjectException
Returns the database connection. If no previous connection exists, a new one will be created.

Returns:
a database connection
Throws:
DataObjectException - if no database connection could be established

finalize

protected void finalize()
Calls the close() method to free resources.

See Also:
close()