|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.database.querymanagers.generic.GenericQueryManagerDelegate<T>
public class GenericQueryManagerDelegate<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. |
|
|
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 |
|---|
public GenericQueryManagerDelegate(Datasource datasource,
Class<T> klass,
String table)
public GenericQueryManagerDelegate(Datasource datasource,
Class<T> klass)
| Method Detail |
|---|
public Datasource getDatasource()
public GenericQueryManager<T> getDelegate()
public Class getBaseClass()
GenericQueryManager
getBaseClass in interface GenericQueryManager<T>
public String getIdentifierName()
throws DatabaseException
GenericQueryManagerDefaults to "id".
getIdentifierName in interface GenericQueryManager<T>DatabaseException
public int getIdentifierValue(T bean)
throws DatabaseException
GenericQueryManagerThe property defaults to "id".
getIdentifierValue in interface GenericQueryManager<T>bean - the bean to retrieve the identifier value for
DatabaseExceptionpublic void validate(Validated validated)
ValidationContextValidated 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.
validate in interface ValidationContextvalidated - the Validated instance that will be validatedpublic String getTable()
GenericQueryManager
getTable in interface GenericQueryManager<T>
public void install()
throws DatabaseException
GenericQueryManagerThis 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.
install in interface GenericQueryManager<T>DatabaseExceptionGenericQueryManager.remove()
public void install(CreateTable query)
throws DatabaseException
GenericQueryManagerThis 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.
install in interface GenericQueryManager<T>query - the CreateTable query to use to create the table
DatabaseExceptionGenericQueryManager.install(),
GenericQueryManager.remove()
public void remove()
throws DatabaseException
GenericQueryManagerThis 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.
remove in interface GenericQueryManager<T>DatabaseExceptionGenericQueryManager.install()
public int save(T bean)
throws DatabaseException
GenericQueryManagerThis 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.
save in interface GenericQueryManager<T>bean - the bean to be saved
DatabaseException
public int insert(T bean)
throws DatabaseException
GenericQueryManagerThis 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).
insert in interface GenericQueryManager<T>bean - the bean to be inserted
DatabaseExceptionGenericQueryManager.save(Object bean)
public int update(T bean)
throws DatabaseException
GenericQueryManagerThis 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).
update in interface GenericQueryManager<T>bean - the bean to be updated
DatabaseExceptionGenericQueryManager.save(Object bean)
public List<T> restore()
throws DatabaseException
GenericQueryManagerThis method will return a List of all the beans persisted
under this manager.
restore in interface GenericQueryManager<T>List of all the persisted beans
DatabaseException
public T restore(int objectId)
throws DatabaseException
GenericQueryManagerThis 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.
restore in interface GenericQueryManager<T>objectId - the identifier to identify the bean to restore
DatabaseException
public List<T> restore(RestoreQuery query)
throws DatabaseException
GenericQueryManagerRestoreQuery.
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.
restore in interface GenericQueryManager<T>query - the query the beans should be restored from
DatabaseExceptionGenericQueryManager.restore()
public boolean restore(DbRowProcessor rowProcessor)
throws DatabaseException
GenericQueryManagerThis method will return all beans using a DbRowProcessor for
reduced memory requirements as opposed to the full List version
of GenericQueryManager.restore().
restore in interface GenericQueryManager<T>rowProcessor - the DbRowProcessor each row should be passed to
DatabaseExceptionGenericQueryManager.restore()
public T restoreFirst(RestoreQuery query)
throws DatabaseException
GenericQueryManagerRestoreQuery.
This method will return the first bean that matches the RestoreQuery. Especially useful for selecting the first returned bean
from a complex query.
restoreFirst in interface GenericQueryManager<T>query - the query the bean should be restored from
RestoreQuery
DatabaseExceptionGenericQueryManager.restore(RestoreQuery)
public boolean restore(RestoreQuery query,
DbRowProcessor rowProcessor)
throws DatabaseException
GenericQueryManagerRestoreQuery
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.
restore in interface GenericQueryManager<T>query - the query the beans should be restored fromrowProcessor - the row processor that should be used to process
each matched bean row
DatabaseException
public CreateTable getInstallTableQuery()
throws DatabaseException
GenericQueryManagerThis 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)
getInstallTableQuery in interface GenericQueryManager<T>DatabaseExceptionpublic RestoreQuery getRestoreQuery()
GenericQueryManagerThis 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.
getRestoreQuery in interface GenericQueryManager<T>public RestoreQuery getRestoreQuery(int objectId)
GenericQueryManagerThis 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.
getRestoreQuery in interface GenericQueryManager<T>
public int count()
throws DatabaseException
GenericQueryManagerThis method will count the total number of beans persisted under this manager.
count in interface GenericQueryManager<T>DatabaseException
public int count(CountQuery query)
throws DatabaseException
GenericQueryManagerCountQuery.
This method will count the total number of beans persisted under
this manager that match the provided CountQuery.
count in interface GenericQueryManager<T>query - the query that will be used to determine which beans to
count
DatabaseExceptionpublic CountQuery getCountQuery()
GenericQueryManagerCountQuery used to count the number of beans
persisted under this manager
getCountQuery in interface GenericQueryManager<T>
public boolean delete(int objectId)
throws DatabaseException
GenericQueryManagerThis method will delete the bean identifed by the passed in identifier.
delete in interface GenericQueryManager<T>objectId - the identifier of the bean
DatabaseException
public boolean delete(DeleteQuery query)
throws DatabaseException
GenericQueryManagerDeleteQuery
This method will delete all beans identified by the passed in DeleteQuery.
delete in interface GenericQueryManager<T>query - the query to select the beans
DatabaseExceptionpublic DeleteQuery getDeleteQuery()
GenericQueryManagerDeleteQuery that would be used to delete beans
getDeleteQuery in interface GenericQueryManager<T>DeleteQuerypublic DeleteQuery getDeleteQuery(int objectId)
GenericQueryManagerDeleteQuery that would be used to delete a
single bean
getDeleteQuery in interface GenericQueryManager<T>objectId - the identifier to fill into the base DeleteQuery
DeleteQuerypublic void addListener(GenericQueryManagerListener listener)
GenericQueryManager
addListener in interface GenericQueryManager<T>listener - the listener that has to be addedpublic void removeListeners()
GenericQueryManager
removeListeners in interface GenericQueryManager<T>public <OtherBeanType> GenericQueryManager<OtherBeanType> createNewManager(Class<OtherBeanType> type)
GenericQueryManager
createNewManager in interface GenericQueryManager<T>type - the class of the bean for which the new generic query
manager has to be created
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||