com.uwyn.rife.database.querymanagers.generic
Class GenericQueryManagerDelegate<T>

java.lang.Object
  extended by com.uwyn.rife.database.querymanagers.generic.GenericQueryManagerDelegate<T>
All Implemented Interfaces:
GenericQueryManager<T>, ValidationContext
Direct Known Subclasses:
ContentQueryManager

public class GenericQueryManagerDelegate<T>
extends Object
implements GenericQueryManager<T>


Constructor Summary
GenericQueryManagerDelegate(Datasource datasource, Class<T> klass)
           
GenericQueryManagerDelegate(Datasource datasource, Class<T> klass, String table)
           
 
Method Summary
 void addListener(GenericQueryManagerListener listener)
          Add the listener to the manager to get notifications when actions were successful.
 int count()
          Count the number of beans persisted.
 int count(CountQuery query)
          Count the number of beans persisted with a custom CountQuery.
<OtherBeanType>
GenericQueryManager<OtherBeanType>
createNewManager(Class<OtherBeanType> type)
          Create a new generic query manager of the same kind but for another bean class.
 boolean delete(DeleteQuery query)
          Delete beans selected by the passed in DeleteQuery
 boolean delete(int objectId)
          Delete a single identified bean
 Class getBaseClass()
          Get the handled class
 CountQuery getCountQuery()
          Get the base CountQuery used to count the number of beans persisted under this manager
 Datasource getDatasource()
           
 GenericQueryManager<T> getDelegate()
           
 DeleteQuery getDeleteQuery()
          Return the base DeleteQuery that would be used to delete beans
 DeleteQuery getDeleteQuery(int objectId)
          Return the base DeleteQuery that would be used to delete a single bean
 String getIdentifierName()
          Get the name of the property defined as the identifier.
 int getIdentifierValue(T bean)
          Get the value of the property defined as the identifier.
 CreateTable getInstallTableQuery()
          Get the query that would be used to install the table.
 RestoreQuery getRestoreQuery()
          Get the base query used to restore beans.
 RestoreQuery getRestoreQuery(int objectId)
          Get the base query used to restore a single identifed bean.
 String getTable()
          Get the managed database table name
 int insert(T bean)
          Insert a bean in the database.
 void install()
          Install the database structure into the database.
 void install(CreateTable query)
          Install the database structure into the database using a custom query.
 void remove()
          Remove the database structure
 void removeListeners()
          Remove all the listeners that are registered to the manager.
 List<T> restore()
          Restore all the beans persisted under this manager.
 boolean restore(DbRowProcessor rowProcessor)
          Restore all beans using the row processor provided.
 T restore(int objectId)
          Restore a single bean using the identifier.
 List<T> restore(RestoreQuery query)
          Restore a list of beans that match the provided RestoreQuery.
 boolean restore(RestoreQuery query, DbRowProcessor rowProcessor)
          Restore a list of beans that match the provided RestoreQuery and process with the DbRowProcessor.
 T restoreFirst(RestoreQuery query)
          Restore the first bean that matches the RestoreQuery.
 int save(T bean)
          Persist a bean.
 int update(T bean)
          Update an existing bean in the database.
 void validate(Validated validated)
          Validates a Validated in this context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericQueryManagerDelegate

public GenericQueryManagerDelegate(Datasource datasource,
                                   Class<T> klass,
                                   String table)

GenericQueryManagerDelegate

public GenericQueryManagerDelegate(Datasource datasource,
                                   Class<T> klass)
Method Detail

getDatasource

public Datasource getDatasource()

getDelegate

public GenericQueryManager<T> getDelegate()

getBaseClass

public Class getBaseClass()
Description copied from interface: GenericQueryManager
Get the handled class

Specified by:
getBaseClass in interface GenericQueryManager<T>
Returns:
the handled class

getIdentifierName

public String getIdentifierName()
                         throws DatabaseException
Description copied from interface: GenericQueryManager
Get the name of the property defined as the identifier.

Defaults to "id".

Specified by:
getIdentifierName in interface GenericQueryManager<T>
Returns:
the name of the property defined as the identifier
Throws:
DatabaseException

getIdentifierValue

public int getIdentifierValue(T bean)
                       throws DatabaseException
Description copied from interface: GenericQueryManager
Get the value of the property defined as the identifier.

The property defaults to "id".

Specified by:
getIdentifierValue in interface GenericQueryManager<T>
Parameters:
bean - the bean to retrieve the identifier value for
Returns:
the value of the property defined as the identifier
Throws:
DatabaseException

validate

public void validate(Validated validated)
Description copied from interface: ValidationContext
Validates a Validated in this context.

This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

Specified by:
validate in interface ValidationContext
Parameters:
validated - the Validated instance that will be validated

getTable

public String getTable()
Description copied from interface: GenericQueryManager
Get the managed database table name

Specified by:
getTable in interface GenericQueryManager<T>
Returns:
the table name

install

public void install()
             throws DatabaseException
Description copied from interface: GenericQueryManager
Install the database structure into the database.

This method will cause the structure needed to persist the bean to be installed into the database. This includes any validatity checks that the database supports and that have already been defined. Including (but not limited to): length, notNull, notEmpty, etc. etc. This method will fail semi-gracefully if the installation fails. Generally it's best to catch the DatabaseException and assume that the database is already installed.

Specified by:
install in interface GenericQueryManager<T>
Throws:
DatabaseException
See Also:
GenericQueryManager.remove()

install

public void install(CreateTable query)
             throws DatabaseException
Description copied from interface: GenericQueryManager
Install the database structure into the database using a custom query.

This method will cause the structure needed to persist the bean to be installed into the database using the provided custom query. The custom query is usually obtained by using GenericQueryManager.getInstallTableQuery(). This includes any validatity checks that the database supports and that have already been defined. Including (but not limited to): length, notNull, notEmpty, etc. etc. This method will fail semi-gracefully if the installation fails. Generally it's best to catch the DatabaseException and assume that the database is already installed.

Specified by:
install in interface GenericQueryManager<T>
Parameters:
query - the CreateTable query to use to create the table
Throws:
DatabaseException
See Also:
GenericQueryManager.install(), GenericQueryManager.remove()

remove

public void remove()
            throws DatabaseException
Description copied from interface: GenericQueryManager
Remove the database structure

This method will cause the database structure to be removed from the database deleting all saved beans in the process. No new beans of this type can be persisted until the database structure is reinstalled.

Specified by:
remove in interface GenericQueryManager<T>
Throws:
DatabaseException
See Also:
GenericQueryManager.install()

save

public int save(T bean)
         throws DatabaseException
Description copied from interface: GenericQueryManager
Persist a bean.

This method allows a person to persist a bean to a DB to be later restored. A bean to be persisted must have at least one integer identifier and one bean property both with accessors. If the identifier value is greater than or equal to 0, the bean is attempted to be updated first, if this fails (or the identifier is -1) the bean is assumed to be a new bean and a new sequential identifier is generated by the database.

Specified by:
save in interface GenericQueryManager<T>
Parameters:
bean - the bean to be saved
Returns:
the identifier assigned to the new/updated bean
Throws:
DatabaseException

insert

public int insert(T bean)
           throws DatabaseException
Description copied from interface: GenericQueryManager
Insert a bean in the database.

This method specifically forces insertion of the bean into the database. This method is only recommended for use when you know what you are doing. The GenericQueryManager.save(Object bean) method is safer because it can detect whether to insert or update the bean in that database, leading to safer, simpler code. Bean restrictions mirror GenericQueryManager.save(Object bean).

Specified by:
insert in interface GenericQueryManager<T>
Parameters:
bean - the bean to be inserted
Returns:
the indentier assigned to the new bean
Throws:
DatabaseException
See Also:
GenericQueryManager.save(Object bean)

update

public int update(T bean)
           throws DatabaseException
Description copied from interface: GenericQueryManager
Update an existing bean in the database.

This method specifically forces the updating of the bean into the database. This method is only recommended for use when you know what you are doing. The GenericQueryManager.save(Object bean) method is safer because it can detect whether to insert or update the bean in that database, leading to safer, simpler code. Bean restrictions mirror GenericQueryManager.save(Object bean).

Specified by:
update in interface GenericQueryManager<T>
Parameters:
bean - the bean to be updated
Returns:
the indentier assigned to the new bean
Throws:
DatabaseException
See Also:
GenericQueryManager.save(Object bean)

restore

public List<T> restore()
                throws DatabaseException
Description copied from interface: GenericQueryManager
Restore all the beans persisted under this manager.

This method will return a List of all the beans persisted under this manager.

Specified by:
restore in interface GenericQueryManager<T>
Returns:
a List of all the persisted beans
Throws:
DatabaseException

restore

public T restore(int objectId)
          throws DatabaseException
Description copied from interface: GenericQueryManager
Restore a single bean using the identifier.

This method will return a single bean having the provided identifier. Since the identifier is unique, you can be assured of a single bean with a persistent id. This id is never changed under normal circumstances.

Specified by:
restore in interface GenericQueryManager<T>
Parameters:
objectId - the identifier to identify the bean to restore
Returns:
the bean that matches the identifier provided
Throws:
DatabaseException

restore

public List<T> restore(RestoreQuery query)
                throws DatabaseException
Description copied from interface: GenericQueryManager
Restore a list of beans that match the provided RestoreQuery.

This method will return a list of beans that match the provided RestoreQuery. This can be used for more complex queries, or for exclusion of certain beans from the results.

Specified by:
restore in interface GenericQueryManager<T>
Parameters:
query - the query the beans should be restored from
Returns:
a list containing all the restored beans
Throws:
DatabaseException
See Also:
GenericQueryManager.restore()

restore

public boolean restore(DbRowProcessor rowProcessor)
                throws DatabaseException
Description copied from interface: GenericQueryManager
Restore all beans using the row processor provided.

This method will return all beans using a DbRowProcessor for reduced memory requirements as opposed to the full List version of GenericQueryManager.restore().

Specified by:
restore in interface GenericQueryManager<T>
Parameters:
rowProcessor - the DbRowProcessor each row should be passed to
Returns:
true if beans were restored, false if not
Throws:
DatabaseException
See Also:
GenericQueryManager.restore()

restoreFirst

public T restoreFirst(RestoreQuery query)
               throws DatabaseException
Description copied from interface: GenericQueryManager
Restore the first bean that matches the RestoreQuery.

This method will return the first bean that matches the RestoreQuery. Especially useful for selecting the first returned bean from a complex query.

Specified by:
restoreFirst in interface GenericQueryManager<T>
Parameters:
query - the query the bean should be restored from
Returns:
the first bean that matches the RestoreQuery
Throws:
DatabaseException
See Also:
GenericQueryManager.restore(RestoreQuery)

restore

public boolean restore(RestoreQuery query,
                       DbRowProcessor rowProcessor)
                throws DatabaseException
Description copied from interface: GenericQueryManager
Restore a list of beans that match the provided RestoreQuery and process with the DbRowProcessor.

This method will return a list of beans that match the provided RestoreQuery and process these matches with the provided DbRowProcessor. This can be used for more memory-intensive (or larger result sets) complex queries or for the exclusion of certain beans from the results.

Specified by:
restore in interface GenericQueryManager<T>
Parameters:
query - the query the beans should be restored from
rowProcessor - the row processor that should be used to process each matched bean row
Returns:
true if beans were processed, false if not
Throws:
DatabaseException

getInstallTableQuery

public CreateTable getInstallTableQuery()
                                 throws DatabaseException
Description copied from interface: GenericQueryManager
Get the query that would be used to install the table.

This method will return the query that would be used to install the database structure. Can be used to modify the structure if i custom structure is needed. Mostly likely to be passed into GenericQueryManager.install(CreateTable)

Specified by:
getInstallTableQuery in interface GenericQueryManager<T>
Returns:
the query that would be used to install the database structure
Throws:
DatabaseException

getRestoreQuery

public RestoreQuery getRestoreQuery()
Description copied from interface: GenericQueryManager
Get the base query used to restore beans.

This method will return the base query that would be used to restore beans with GenericQueryManager.restore(). This can be used to restrict the query so that less beans are returned or certain beans are returned.

Specified by:
getRestoreQuery in interface GenericQueryManager<T>
Returns:
the query that would be used to restore a number of beans

getRestoreQuery

public RestoreQuery getRestoreQuery(int objectId)
Description copied from interface: GenericQueryManager
Get the base query used to restore a single identifed bean.

This method will return the base query that would be used to restore a single bean with GenericQueryManager.restore(int). This can be used to restrict the query so that a bean not matching the query will not be returned.

Specified by:
getRestoreQuery in interface GenericQueryManager<T>
Returns:
the query that would be used to restore a single identified bean

count

public int count()
          throws DatabaseException
Description copied from interface: GenericQueryManager
Count the number of beans persisted.

This method will count the total number of beans persisted under this manager.

Specified by:
count in interface GenericQueryManager<T>
Returns:
the number of beans persisted under this manager
Throws:
DatabaseException

count

public int count(CountQuery query)
          throws DatabaseException
Description copied from interface: GenericQueryManager
Count the number of beans persisted with a custom CountQuery.

This method will count the total number of beans persisted under this manager that match the provided CountQuery.

Specified by:
count in interface GenericQueryManager<T>
Parameters:
query - the query that will be used to determine which beans to count
Returns:
the number of beans persisted under this manager that match the provided query
Throws:
DatabaseException

getCountQuery

public CountQuery getCountQuery()
Description copied from interface: GenericQueryManager
Get the base CountQuery used to count the number of beans persisted under this manager

Specified by:
getCountQuery in interface GenericQueryManager<T>
Returns:
the query that would be used to count the total number of beans persisted under this manager├╣

delete

public boolean delete(int objectId)
               throws DatabaseException
Description copied from interface: GenericQueryManager
Delete a single identified bean

This method will delete the bean identifed by the passed in identifier.

Specified by:
delete in interface GenericQueryManager<T>
Parameters:
objectId - the identifier of the bean
Returns:
true if the deletion suceeded, false if it did not
Throws:
DatabaseException

delete

public boolean delete(DeleteQuery query)
               throws DatabaseException
Description copied from interface: GenericQueryManager
Delete beans selected by the passed in DeleteQuery

This method will delete all beans identified by the passed in DeleteQuery.

Specified by:
delete in interface GenericQueryManager<T>
Parameters:
query - the query to select the beans
Returns:
true if the deletion suceeded, false if it did not
Throws:
DatabaseException

getDeleteQuery

public DeleteQuery getDeleteQuery()
Description copied from interface: GenericQueryManager
Return the base DeleteQuery that would be used to delete beans

Specified by:
getDeleteQuery in interface GenericQueryManager<T>
Returns:
the base DeleteQuery

getDeleteQuery

public DeleteQuery getDeleteQuery(int objectId)
Description copied from interface: GenericQueryManager
Return the base DeleteQuery that would be used to delete a single bean

Specified by:
getDeleteQuery in interface GenericQueryManager<T>
Parameters:
objectId - the identifier to fill into the base DeleteQuery
Returns:
the base DeleteQuery

addListener

public void addListener(GenericQueryManagerListener listener)
Description copied from interface: GenericQueryManager
Add the listener to the manager to get notifications when actions were successful.

Specified by:
addListener in interface GenericQueryManager<T>
Parameters:
listener - the listener that has to be added

removeListeners

public void removeListeners()
Description copied from interface: GenericQueryManager
Remove all the listeners that are registered to the manager.

Specified by:
removeListeners in interface GenericQueryManager<T>

createNewManager

public <OtherBeanType> GenericQueryManager<OtherBeanType> createNewManager(Class<OtherBeanType> type)
Description copied from interface: GenericQueryManager
Create a new generic query manager of the same kind but for another bean class.

Specified by:
createNewManager in interface GenericQueryManager<T>
Parameters:
type - the class of the bean for which the new generic query manager has to be created
Returns:
a new generic query manager instance


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