com.uwyn.rife.resources
Class DatabaseResources

java.lang.Object
  extended by com.uwyn.rife.database.DbQueryManager
      extended by com.uwyn.rife.resources.DatabaseResources
All Implemented Interfaces:
ResourceFinder, ResourceWriter, Cloneable

public abstract class DatabaseResources
extends DbQueryManager
implements ResourceFinder, ResourceWriter

This class offers ResourceFinder and ResourceWriter capabilities for resources that are stored in a database. The relevant database is specified through a Datasource/code> instance at construction.

While the table can be configured through the TABLE_RESOURCES configuration setting, the structure of the table is fixed. It can be installed with the install() method and removed with the remove() method. The latter will implicitely erase all the resources that have been stored in the database table.

Since:
1.0
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)
See Also:
ResourceFinder

Field Summary
protected static String COLUMN_CONTENT
           
protected static String COLUMN_MODIFIED
           
protected static String COLUMN_NAME
           
protected static String PROTOCOL
           
 
Constructor Summary
protected DatabaseResources(Datasource datasource)
          Creates a new instance according to the provided datasource.
 
Method Summary
protected  void _addResource(Insert addResource, String name, String content)
           
protected  String _getContent(Select getResourceContent, URL resource, String encoding)
           
protected  long _getModificationTime(Select getResourceModified, URL resource)
           
protected  URL _getResource(Select hasResource, String name)
           
protected  boolean _install(CreateTable createTable)
           
protected  boolean _remove(DropTable dropTable)
           
protected  boolean _removeResource(Delete removeResource, String name)
           
protected  boolean _updateResource(Update updateResource, String name, String content)
           
protected
<ResultType>
ResultType
_useStream(Select getResourceContent, URL resource, InputStreamUser user)
           
 String getContent(String name)
          Retrieves the complete content of the resource that corresponds to the provided name.
 String getContent(String name, String encoding)
          Retrieves the complete content of the resource that corresponds to the provided name.
 String getContent(URL resource)
          Retrieves the complete content of the provided resource.
 long getModificationTime(String name)
          Retrieves the modification time of the resource that corresponds to the provided name.
abstract  boolean install()
          Installs the database structure that's needed to store and retrieve resources in and from a database.
abstract  boolean remove()
          Removes the database structure that's needed to store and retrieve resources in and from a database.
<ResultType>
ResultType
useStream(String name, InputStreamUser user)
          Returns a stream that can be used to read the contents of the resource that corresponds to the provided name.
 
Methods inherited from class com.uwyn.rife.database.DbQueryManager
clone, executeFetchAll, executeFetchAll, executeFetchAllBeans, executeFetchAllBeans, executeFetchFirst, executeFetchFirst, executeFetchFirstBean, executeFetchFirstBean, executeGetFirstBoolean, executeGetFirstBoolean, executeGetFirstByte, executeGetFirstByte, executeGetFirstBytes, executeGetFirstBytes, executeGetFirstDate, executeGetFirstDate, executeGetFirstDate, executeGetFirstDate, executeGetFirstDouble, executeGetFirstDouble, executeGetFirstFloat, executeGetFirstFloat, executeGetFirstInt, executeGetFirstInt, executeGetFirstLong, executeGetFirstLong, executeGetFirstShort, executeGetFirstShort, executeGetFirstString, executeGetFirstString, executeGetFirstTime, executeGetFirstTime, executeGetFirstTime, executeGetFirstTime, executeGetFirstTimestamp, executeGetFirstTimestamp, executeGetFirstTimestamp, executeGetFirstTimestamp, executeHasResultRows, executeHasResultRows, executeQuery, executeQuery, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUseFirstAsciiStream, executeUseFirstAsciiStream, executeUseFirstBinaryStream, executeUseFirstBinaryStream, executeUseFirstCharacterStream, executeUseFirstCharacterStream, fetch, fetch, fetchAll, getConnection, getDatasource, inTransaction, reserveConnection
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.uwyn.rife.resources.ResourceFinder
getContent, getModificationTime, getResource, useStream
 
Methods inherited from interface com.uwyn.rife.resources.ResourceWriter
addResource, removeResource, updateResource
 

Field Detail

PROTOCOL

protected static final String PROTOCOL
See Also:
Constant Field Values

COLUMN_NAME

protected static final String COLUMN_NAME
See Also:
Constant Field Values

COLUMN_CONTENT

protected static final String COLUMN_CONTENT
See Also:
Constant Field Values

COLUMN_MODIFIED

protected static final String COLUMN_MODIFIED
See Also:
Constant Field Values
Constructor Detail

DatabaseResources

protected DatabaseResources(Datasource datasource)
Creates a new instance according to the provided datasource.

Parameters:
datasource - the Datasource instance that defines the database that will be used as resources storage.
Since:
1.0
Method Detail

install

public abstract boolean install()
                         throws ResourceWriterErrorException
Installs the database structure that's needed to store and retrieve resources in and from a database.

Throws:
ResourceFinderErrorException - when an error occurred during the installation
ResourceWriterErrorException

remove

public abstract boolean remove()
                        throws ResourceWriterErrorException
Removes the database structure that's needed to store and retrieve resources in and from a database.

Throws:
ResourceFinderErrorException - when an error occurred during the removal
ResourceWriterErrorException

_install

protected boolean _install(CreateTable createTable)
                    throws ResourceWriterErrorException
Throws:
ResourceWriterErrorException

_remove

protected boolean _remove(DropTable dropTable)
                   throws ResourceWriterErrorException
Throws:
ResourceWriterErrorException

_addResource

protected void _addResource(Insert addResource,
                            String name,
                            String content)
                     throws ResourceWriterErrorException
Throws:
ResourceWriterErrorException

_updateResource

protected boolean _updateResource(Update updateResource,
                                  String name,
                                  String content)
                           throws ResourceWriterErrorException
Throws:
ResourceWriterErrorException

_removeResource

protected boolean _removeResource(Delete removeResource,
                                  String name)
                           throws ResourceWriterErrorException
Throws:
ResourceWriterErrorException

_getResource

protected URL _getResource(Select hasResource,
                           String name)

_useStream

protected <ResultType> ResultType _useStream(Select getResourceContent,
                                             URL resource,
                                             InputStreamUser user)
                         throws ResourceFinderErrorException,
                                InnerClassException
Throws:
ResourceFinderErrorException
InnerClassException

_getContent

protected String _getContent(Select getResourceContent,
                             URL resource,
                             String encoding)
                      throws ResourceFinderErrorException
Throws:
ResourceFinderErrorException

_getModificationTime

protected long _getModificationTime(Select getResourceModified,
                                    URL resource)

useStream

public <ResultType> ResultType useStream(String name,
                                         InputStreamUser user)
                     throws ResourceFinderErrorException,
                            InnerClassException
Description copied from interface: ResourceFinder
Returns a stream that can be used to read the contents of the resource that corresponds to the provided name.

Specified by:
useStream in interface ResourceFinder
Parameters:
name - the name of the resource to retrieve
user - an instance of InputStreamUser that contains the logic that will be executed with this stream
Returns:
the return value from the useInputStream method of the provided InputStreamUser instance
Throws:
ResourceFinderErrorException - when an error occurred during the creation or opening of the stream.
InnerClassException - when errors occurs inside the InputStreamUser
See Also:
InputStreamUser, ResourceFinder.useStream(URL, InputStreamUser)

getContent

public String getContent(String name)
                  throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the complete content of the resource that corresponds to the provided name. The content will be read into a string by using the platform's default encoding.

Specified by:
getContent in interface ResourceFinder
Parameters:
name - the name of the resource to retrieve
Returns:
a String object that contains the complete content of the resource with the provided name; or

null if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the content.
See Also:
ResourceFinder.getContent(String, String), ResourceFinder.getContent(URL, String)

getContent

public String getContent(String name,
                         String encoding)
                  throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the complete content of the resource that corresponds to the provided name.

Specified by:
getContent in interface ResourceFinder
Parameters:
name - the name of the resource to retrieve the content from
encoding - the encoding that should be used to read the content
Returns:
a String object that contains the complete content of the resource with the provided name; or

null if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
See Also:
ResourceFinder.getContent(String), ResourceFinder.getContent(URL), ResourceFinder.getContent(URL, String)

getContent

public String getContent(URL resource)
                  throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the complete content of the provided resource. The content will be read into a string by using the platform's default encoding.

Specified by:
getContent in interface ResourceFinder
Parameters:
resource - the resource to retrieve the content from
Returns:
a String object that contains the complete content of the resource with the provided name; or

null if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the content or when the encoding is not supported.
See Also:
ResourceFinder.getContent(String), ResourceFinder.getContent(String, String), ResourceFinder.getContent(URL, String)

getModificationTime

public long getModificationTime(String name)
                         throws ResourceFinderErrorException
Description copied from interface: ResourceFinder
Retrieves the modification time of the resource that corresponds to the provided name.

Specified by:
getModificationTime in interface ResourceFinder
Parameters:
name - the name of the resource to retrieve
Returns:
a positive long with the modification time in milliseconds; or

-1 if the resource couldn't be found.

Throws:
ResourceFinderErrorException - when an error occurred during the retrieval of the modification time.
See Also:
ResourceFinder.getModificationTime(URL)


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.