Class GenericQueryManagerDelegate<T>
- All Implemented Interfaces:
GenericQueryManager<T>,ValidationContext
- Direct Known Subclasses:
ContentQueryManager
-
Constructor Summary
ConstructorsConstructorDescriptionGenericQueryManagerDelegate(Datasource datasource, Class<T> klass) GenericQueryManagerDelegate(Datasource datasource, Class<T> klass, String table) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(GenericQueryManagerListener listener) Add the listener to the manager to get notifications when actions were successful.intcount()Count the number of beans persisted.intcount(CountQuery query) Count the number of beans persisted with a customCountQuery.<OtherBeanType>
GenericQueryManager<OtherBeanType>createNewManager(Class<OtherBeanType> type) Create a new generic query manager of the same kind but for another bean class.booleandelete(int objectId) Delete a single identified beanbooleandelete(DeleteQuery query) Delete beans selected by the passed inDeleteQueryGet the handled classGet the baseCountQueryused to count the number of beans persisted under this managerReturn the baseDeleteQuerythat would be used to delete beansgetDeleteQuery(int objectId) Return the baseDeleteQuerythat would be used to delete a single beanGet the name of the property defined as the identifier.intgetIdentifierValue(T bean) Get the value of the property defined as the identifier.Get the query that would be used to install the table.Get the base query used to restore beans.getRestoreQuery(int objectId) Get the base query used to restore a single identified bean.getTable()Get the managed database table nameintInsert a bean in the database.voidinstall()Install the database structure into the database.voidinstall(CreateTable query) Install the database structure into the database using a custom query.voidremove()Remove the database structurevoidRemove all the listeners that are registered to the manager.restore()Restore all the beans persisted under this manager.restore(int objectId) Restore a single bean using the identifier.booleanrestore(DbRowProcessor rowProcessor) Restore all beans using the row processor provided.booleanrestore(BeanFetcher<T> beanFetcher) Restore all beans using the bean fetcher provided.restore(RestoreQuery query) Restore a list of beans that match the providedRestoreQuery.booleanrestore(RestoreQuery query, DbRowProcessor rowProcessor) Restore a list of beans that match the providedRestoreQueryand process with theDbRowProcessor.booleanrestore(RestoreQuery query, BeanFetcher<T> beanFetcher) Restore a list of beans that match the providedRestoreQueryand process with theBeanFetcher.restoreFirst(RestoreQuery query) Restore the first bean that matches theRestoreQuery.intPersist a bean.intUpdate an existing bean in the database.voidValidates aValidatedin this context.
-
Constructor Details
-
GenericQueryManagerDelegate
-
GenericQueryManagerDelegate
-
-
Method Details
-
getDatasource
-
getDelegate
-
getBaseClass
Description copied from interface:GenericQueryManagerGet the handled class- Specified by:
getBaseClassin interfaceGenericQueryManager<T>- Returns:
- the handled class
-
getIdentifierName
Description copied from interface:GenericQueryManagerGet the name of the property defined as the identifier.Defaults to "id".
- Specified by:
getIdentifierNamein interfaceGenericQueryManager<T>- Returns:
- the name of the property defined as the identifier
- Throws:
DatabaseException
-
getIdentifierValue
Description copied from interface:GenericQueryManagerGet the value of the property defined as the identifier.The property defaults to "id".
- Specified by:
getIdentifierValuein interfaceGenericQueryManager<T>- Parameters:
bean- the bean to retrieve the identifier value for- Returns:
- the value of the property defined as the identifier
- Throws:
DatabaseException
-
validate
Description copied from interface:ValidationContextValidates aValidatedin this context.This method is not supposed 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:
validatein interfaceValidationContext- Parameters:
validated- theValidatedinstance that will be validated
-
getTable
Description copied from interface:GenericQueryManagerGet the managed database table name- Specified by:
getTablein interfaceGenericQueryManager<T>- Returns:
- the table name
-
install
Description copied from interface:GenericQueryManagerInstall 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
DatabaseExceptionand assume that the database is already installed.- Specified by:
installin interfaceGenericQueryManager<T>- Throws:
DatabaseException- See Also:
-
install
Description copied from interface:GenericQueryManagerInstall 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 theDatabaseExceptionand assume that the database is already installed.- Specified by:
installin interfaceGenericQueryManager<T>- Parameters:
query- theCreateTablequery to use to create the table- Throws:
DatabaseException- See Also:
-
remove
Description copied from interface:GenericQueryManagerRemove the database structureThis 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:
removein interfaceGenericQueryManager<T>- Throws:
DatabaseException- See Also:
-
save
Description copied from interface:GenericQueryManagerPersist 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:
savein interfaceGenericQueryManager<T>- Parameters:
bean- the bean to be saved- Returns:
- the identifier assigned to the new/updated bean
- Throws:
DatabaseException
-
insert
Description copied from interface:GenericQueryManagerInsert 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 mirrorGenericQueryManager.save(Object bean).- Specified by:
insertin interfaceGenericQueryManager<T>- Parameters:
bean- the bean to be inserted- Returns:
- the identifier assigned to the new bean
- Throws:
DatabaseException- See Also:
-
update
Description copied from interface:GenericQueryManagerUpdate 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 mirrorGenericQueryManager.save(Object bean).- Specified by:
updatein interfaceGenericQueryManager<T>- Parameters:
bean- the bean to be updated- Returns:
- the identifier assigned to the new bean
- Throws:
DatabaseException- See Also:
-
restore
Description copied from interface:GenericQueryManagerRestore all the beans persisted under this manager.This method will return a
Listof all the beans persisted under this manager.- Specified by:
restorein interfaceGenericQueryManager<T>- Returns:
- a
Listof all the persisted beans - Throws:
DatabaseException
-
restore
Description copied from interface:GenericQueryManagerRestore 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:
restorein interfaceGenericQueryManager<T>- Parameters:
objectId- the identifier to identify the bean to restore- Returns:
- the bean that matches the identifier provided
- Throws:
DatabaseException
-
restore
Description copied from interface:GenericQueryManagerRestore a list of beans that match the providedRestoreQuery.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:
restorein interfaceGenericQueryManager<T>- Parameters:
query- the query the beans should be restored from- Returns:
- a list containing all the restored beans
- Throws:
DatabaseException- See Also:
-
restore
Description copied from interface:GenericQueryManagerRestore all beans using the row processor provided.This method will return all beans using a
DbRowProcessorfor reduced memory requirements as opposed to the fullListversion ofGenericQueryManager.restore().- Specified by:
restorein interfaceGenericQueryManager<T>- Parameters:
rowProcessor- the DbRowProcessor each row should be passed to- Returns:
- true if beans were restored, false if not
- Throws:
DatabaseException- See Also:
-
restore
Description copied from interface:GenericQueryManagerRestore all beans using the bean fetcher provided.This method will return all beans using a
BeanFetcherfor reduced memory requirements as opposed to the fullListversion ofGenericQueryManager.restore().- Specified by:
restorein interfaceGenericQueryManager<T>- Parameters:
beanFetcher- the RowProcessor each row should be passed to- Returns:
- true if beans were restored, false if not
- Throws:
DatabaseException- See Also:
-
restoreFirst
Description copied from interface:GenericQueryManagerRestore the first bean that matches theRestoreQuery.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:
restoreFirstin interfaceGenericQueryManager<T>- Parameters:
query- the query the bean should be restored from- Returns:
- the first bean that matches the
RestoreQuery - Throws:
DatabaseException- See Also:
-
restore
Description copied from interface:GenericQueryManagerRestore a list of beans that match the providedRestoreQueryand process with theDbRowProcessor.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:
restorein interfaceGenericQueryManager<T>- Parameters:
query- the query the beans should be restored fromrowProcessor- the row processor that should be used to process each matched bean row- Returns:
- true if beans were processed, false if not
- Throws:
DatabaseException
-
restore
Description copied from interface:GenericQueryManagerRestore a list of beans that match the providedRestoreQueryand process with theBeanFetcher.This method will return a list of beans that match the provided RestoreQuery and process these matches with the provided
BeanFetcher. 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:
restorein interfaceGenericQueryManager<T>- Parameters:
query- the query the beans should be restored frombeanFetcher- the bean fetch that should be used to process each matched bean row- Returns:
- true if beans were processed, false if not
- Throws:
DatabaseException
-
getInstallTableQuery
Description copied from interface:GenericQueryManagerGet 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:
getInstallTableQueryin interfaceGenericQueryManager<T>- Returns:
- the query that would be used to install the database structure
- Throws:
DatabaseException
-
getRestoreQuery
Description copied from interface:GenericQueryManagerGet 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:
getRestoreQueryin interfaceGenericQueryManager<T>- Returns:
- the query that would be used to restore a number of beans
-
getRestoreQuery
Description copied from interface:GenericQueryManagerGet the base query used to restore a single identified 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:
getRestoreQueryin interfaceGenericQueryManager<T>- Returns:
- the query that would be used to restore a single identified bean
-
count
Description copied from interface:GenericQueryManagerCount the number of beans persisted.This method will count the total number of beans persisted under this manager.
- Specified by:
countin interfaceGenericQueryManager<T>- Returns:
- the number of beans persisted under this manager
- Throws:
DatabaseException
-
count
Description copied from interface:GenericQueryManagerCount the number of beans persisted with a customCountQuery.This method will count the total number of beans persisted under this manager that match the provided
CountQuery.- Specified by:
countin interfaceGenericQueryManager<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
Description copied from interface:GenericQueryManagerGet the baseCountQueryused to count the number of beans persisted under this manager- Specified by:
getCountQueryin interfaceGenericQueryManager<T>- Returns:
- the query that would be used to count the total number of beans persisted under this managerù
-
delete
Description copied from interface:GenericQueryManagerDelete a single identified beanThis method will delete the bean identifed by the passed in identifier.
- Specified by:
deletein interfaceGenericQueryManager<T>- Parameters:
objectId- the identifier of the bean- Returns:
- true if the deletion suceeded, false if it did not
- Throws:
DatabaseException
-
delete
Description copied from interface:GenericQueryManagerDelete beans selected by the passed inDeleteQueryThis method will delete all beans identified by the passed in
DeleteQuery.- Specified by:
deletein interfaceGenericQueryManager<T>- Parameters:
query- the query to select the beans- Returns:
- true if the deletion suceeded, false if it did not
- Throws:
DatabaseException
-
getDeleteQuery
Description copied from interface:GenericQueryManagerReturn the baseDeleteQuerythat would be used to delete beans- Specified by:
getDeleteQueryin interfaceGenericQueryManager<T>- Returns:
- the base
DeleteQuery
-
getDeleteQuery
Description copied from interface:GenericQueryManagerReturn the baseDeleteQuerythat would be used to delete a single bean- Specified by:
getDeleteQueryin interfaceGenericQueryManager<T>- Parameters:
objectId- the identifier to fill into the baseDeleteQuery- Returns:
- the base
DeleteQuery
-
addListener
Description copied from interface:GenericQueryManagerAdd the listener to the manager to get notifications when actions were successful.- Specified by:
addListenerin interfaceGenericQueryManager<T>- Parameters:
listener- the listener that has to be added
-
removeListeners
public void removeListeners()Description copied from interface:GenericQueryManagerRemove all the listeners that are registered to the manager.- Specified by:
removeListenersin interfaceGenericQueryManager<T>
-
createNewManager
public <OtherBeanType> GenericQueryManager<OtherBeanType> createNewManager(Class<OtherBeanType> type) Description copied from interface:GenericQueryManagerCreate a new generic query manager of the same kind but for another bean class.- Specified by:
createNewManagerin interfaceGenericQueryManager<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
-