Package rife.resources
Class DatabaseResources
java.lang.Object
rife.database.DbQueryManager
rife.resources.DatabaseResources
- All Implemented Interfaces:
Cloneable,ResourceFinder,ResourceWriter
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 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 implicitly erase all the
resources that have been stored in the database table.
- Since:
- 1.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDatabaseResources(Datasource datasource) Creates a new instance according to the provided datasource. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 booleanprotected boolean_removeResource(Delete removeResource, String name) protected boolean_updateResource(Update updateResource, String name, String content) protected <ResultType>
ResultType_useStream(Select getResourceContent, URL resource, InputStreamUser<ResultType, ?> user) getContent(String name) Retrieves the complete content of the resource that corresponds to the provided name.getContent(String name, String encoding) Retrieves the complete content of the resource that corresponds to the provided name.getContent(URL resource) Retrieves the complete content of the provided resource.longgetModificationTime(String name) Retrieves the modification time of the resource that corresponds to the provided name.abstract booleaninstall()Installs the database structure that's needed to store and retrieve resources in and from a database.abstract booleanremove()Removes the database structure that's needed to store and retrieve resources in and from a database.<ResultType>
ResultTypeuseStream(String name, InputStreamUser<ResultType, ?> 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 rife.database.DbQueryManager
clone, executeFetchAll, executeFetchAll, executeFetchAll, executeFetchAll, executeFetchAllBeans, executeFetchAllBeans, executeFetchFirst, executeFetchFirst, 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, executeResultQuery, executeUpdate, executeUpdate, executeUpdate, executeUseFirstAsciiStream, executeUseFirstAsciiStream, executeUseFirstBinaryStream, executeUseFirstBinaryStream, executeUseFirstCharacterStream, executeUseFirstCharacterStream, fetch, fetch, fetch, fetchAll, fetchAll, getConnection, getDatasource, inTransaction, inTransaction, reserveConnectionMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface rife.resources.ResourceFinder
getContent, getModificationTime, getResource, useStreamMethods inherited from interface rife.resources.ResourceWriter
addResource, removeResource, updateResource
-
Field Details
-
PROTOCOL
- See Also:
-
COLUMN_NAME
- See Also:
-
COLUMN_CONTENT
- See Also:
-
COLUMN_MODIFIED
- See Also:
-
-
Constructor Details
-
DatabaseResources
Creates a new instance according to the provided datasource.- Parameters:
datasource- theDatasourceinstance that defines the database that will be used as resources storage.- Since:
- 1.0
-
-
Method Details
-
install
Installs the database structure that's needed to store and retrieve resources in and from a database.- Throws:
ResourceWriterErrorException- when an error occurred during the installation
-
remove
Removes the database structure that's needed to store and retrieve resources in and from a database.- Throws:
ResourceWriterErrorException- when an error occurred during the removal
-
_install
- Throws:
ResourceWriterErrorException
-
_remove
- 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
-
_useStream
protected <ResultType> ResultType _useStream(Select getResourceContent, URL resource, InputStreamUser<ResultType, ?> user) throws ResourceFinderErrorException, InnerClassException -
_getContent
protected String _getContent(Select getResourceContent, URL resource, String encoding) throws ResourceFinderErrorException - Throws:
ResourceFinderErrorException
-
_getModificationTime
-
useStream
public <ResultType> ResultType useStream(String name, InputStreamUser<ResultType, ?> user) throws ResourceFinderErrorException, InnerClassExceptionDescription copied from interface:ResourceFinderReturns a stream that can be used to read the contents of the resource that corresponds to the provided name.- Specified by:
useStreamin interfaceResourceFinder- Parameters:
name- the name of the resource to retrieveuser- an instance ofInputStreamUserthat contains the logic that will be executed with this stream- Returns:
- the return value from the
useInputStreammethod of the providedInputStreamUserinstance - Throws:
ResourceFinderErrorException- when an error occurred during the creation or opening of the stream.InnerClassException- when errors occurs inside theInputStreamUser- See Also:
-
getContent
Description copied from interface:ResourceFinderRetrieves 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:
getContentin interfaceResourceFinder- Parameters:
name- the name of the resource to retrieve- Returns:
- a
Stringobject that contains the complete content of the resource with the provided name; ornullif the resource couldn't be found. - Throws:
ResourceFinderErrorException- when an error occurred during the retrieval of the content.- See Also:
-
getContent
Description copied from interface:ResourceFinderRetrieves the complete content of the resource that corresponds to the provided name.- Specified by:
getContentin interfaceResourceFinder- Parameters:
name- the name of the resource to retrieve the content fromencoding- the encoding that should be used to read the content- Returns:
- a
Stringobject that contains the complete content of the resource with the provided name; ornullif 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:
-
getContent
Description copied from interface:ResourceFinderRetrieves the complete content of the provided resource. The content will be read into a string by using the platform's default encoding.- Specified by:
getContentin interfaceResourceFinder- Parameters:
resource- the resource to retrieve the content from- Returns:
- a
Stringobject that contains the complete content of the resource with the provided name; ornullif 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:
-
getModificationTime
Description copied from interface:ResourceFinderRetrieves the modification time of the resource that corresponds to the provided name.- Specified by:
getModificationTimein interfaceResourceFinder- Parameters:
name- the name of the resource to retrieve- Returns:
- a positive
longwith the modification time in milliseconds; or-1if the resource couldn't be found. - Throws:
ResourceFinderErrorException- when an error occurred during the retrieval of the modification time.- See Also:
-