com.binaryfantasy.murq.source
Class DBSource

java.lang.Object
  extended by com.binaryfantasy.murq.source.DBSource
All Implemented Interfaces:
ISource

public class DBSource
extends Object
implements ISource

An ISource implementation that utilizes an RDBMS for persistance. This ISource will store it's data in a single table. That table's structure should resemble the following:

CREATE TABLE table_name (key_col VARCHAR(255),val_col BLOB);

If BLOB is not supported, use a corresponding datatype.

Author:
Bill Weiss

Constructor Summary
DBSource(DataSource dataSource, String table, String keyColumn, String valueColumn)
          Constructs a new instance using the specified dataSource.
DBSource(String driverClass, String url, String username, String password, String table, String keyColumn, String valueColumn)
          Constructs a new instance using the specified driverClass, url, username and password.
 
Method Summary
 void close()
          Called when a source is no longer to be used and provides a chance for clean up and release of resources.
 InputStream getInputStream(String key)
          Returns a stream to read the content specified by the key, or null if no content is associated with the key.
 Set<String> getKeys()
          Returns a Set of all current keys in this source, or an empty Set if there are none.
 OutputStream getOutputStream(String key)
          Returns a stream to write the content associated with the key.
 boolean remove(String key)
          Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBSource

public DBSource(DataSource dataSource,
                String table,
                String keyColumn,
                String valueColumn)
Constructs a new instance using the specified dataSource. See class overview for details related to required table structure.

Parameters:
dataSource - the DataSource to provide connectivity to the RDBMS.
table - name of the table in the RDBMS to persist data in.
keyColumn - name of the column that holds the keys.
valueColumn - name of the column that holds the raw binary data.

DBSource

public DBSource(String driverClass,
                String url,
                String username,
                String password,
                String table,
                String keyColumn,
                String valueColumn)
Constructs a new instance using the specified driverClass, url, username and password. See class overview for details related to required table structure.

Parameters:
driverClass - name of the Driver implementation used to provide connectivity to the RDBMS.
url - the url used to connect to the RDBMS.
username - the username used to connect to the RDBMS.
password - the password used to connect to the RDBMS.
table - name of the table in the RDBMS to persist data in.
keyColumn - name of the column that holds the keys.
valueColumn - name of the column that holds the raw binary data.
Method Detail

close

public void close()
           throws IOException
Description copied from interface: ISource
Called when a source is no longer to be used and provides a chance for clean up and release of resources.

Specified by:
close in interface ISource
Throws:
IOException - if there is a problem during closing.

getKeys

public Set<String> getKeys()
                    throws IOException
Description copied from interface: ISource
Returns a Set of all current keys in this source, or an empty Set if there are none.

Specified by:
getKeys in interface ISource
Returns:
a Set of all current keys in this source, or an empty Set if there are none.
Throws:
IOException - if there is a problem reading the keys.

remove

public boolean remove(String key)
               throws IOException
Description copied from interface: ISource
Returns true if the content mapped to the provided key was removed, false if no content is associated with the key.

Specified by:
remove in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
true if the content mapped to the provided key was removed, false if no content is associated with the key.
Throws:
IOException - if an error occurred while trying to remove the content.

getInputStream

public InputStream getInputStream(String key)
                           throws IOException
Description copied from interface: ISource
Returns a stream to read the content specified by the key, or null if no content is associated with the key.

Specified by:
getInputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to read the content specified by the key, or null if no content is associated with the key.
Throws:
IOException - if there is an error while getting the content stream for reading.

getOutputStream

public OutputStream getOutputStream(String key)
                             throws IOException
Description copied from interface: ISource
Returns a stream to write the content associated with the key.

Specified by:
getOutputStream in interface ISource
Parameters:
key - unique value associated with the content.
Returns:
a stream to write the content associated with the key.
Throws:
IOException - if there is an error while getting the content stream for writing.


Copyright (c) 2000-2006, BinaryFantasy.com