|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface GenericQueryManager<BeanType>
A GenericQueryManager provides features that make it easy to
persist and retrieve beans in a database with single method calls. An
instance of the manager can by obtained by using the GenericQueryManagerFactory class.
Callbacks are also supported to make it possible to interact with the
persistence actions in a bean-centric way. More information can be found in
the Callbacks interface.
GenericQueryManagerFactory,
Callbacks| 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> beanClass)
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 |
|
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(BeanType 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(BeanType 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<BeanType> |
restore()
Restore all the beans persisted under this manager. |
|
boolean |
restore(DbRowProcessor rowProcessor)
Restore all beans using the row processor provided. |
|
BeanType |
restore(int objectId)
Restore a single bean using the identifier. |
|
List<BeanType> |
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. |
|
BeanType |
restoreFirst(RestoreQuery query)
Restore the first bean that matches the RestoreQuery. |
|
int |
save(BeanType bean)
Persist a bean. |
|
int |
update(BeanType bean)
Update an existing bean in the database. |
|
| Methods inherited from interface com.uwyn.rife.site.ValidationContext |
|---|
validate |
| Method Detail |
|---|
Class getBaseClass()
String getTable()
String getIdentifierName()
Defaults to "id".
int getIdentifierValue(BeanType bean)
throws DatabaseException
The property defaults to "id".
bean - the bean to retrieve the identifier value for
DatabaseException
void install()
throws DatabaseException
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.
DatabaseExceptionremove()
void install(CreateTable query)
throws DatabaseException
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 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.
query - the CreateTable query to use to create the table
DatabaseExceptioninstall(),
remove()
void remove()
throws DatabaseException
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.
DatabaseExceptioninstall()
int save(BeanType bean)
throws DatabaseException
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.
bean - the bean to be saved
DatabaseException
int insert(BeanType bean)
throws DatabaseException
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 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 save(Object bean).
bean - the bean to be inserted
DatabaseExceptionsave(Object bean)
int update(BeanType bean)
throws DatabaseException
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 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 save(Object bean).
bean - the bean to be updated
DatabaseExceptionsave(Object bean)
List<BeanType> restore()
throws DatabaseException
This method will return a List of all the beans persisted
under this manager.
List of all the persisted beans
DatabaseException
BeanType restore(int objectId)
throws DatabaseException
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.
objectId - the identifier to identify the bean to restore
DatabaseException
boolean restore(DbRowProcessor rowProcessor)
throws DatabaseException
This method will return all beans using a DbRowProcessor for
reduced memory requirements as opposed to the full List version
of restore().
rowProcessor - the DbRowProcessor each row should be passed to
DatabaseExceptionrestore()
BeanType restoreFirst(RestoreQuery query)
throws DatabaseException
RestoreQuery.
This method will return the first bean that matches the RestoreQuery. Especially useful for selecting the first returned bean
from a complex query.
query - the query the bean should be restored from
RestoreQuery
DatabaseExceptionrestore(RestoreQuery)
List<BeanType> restore(RestoreQuery query)
throws DatabaseException
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.
query - the query the beans should be restored from
DatabaseExceptionrestore()
boolean restore(RestoreQuery query,
DbRowProcessor rowProcessor)
throws DatabaseException
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.
query - the query the beans should be restored fromrowProcessor - the row processor that should be used to process
each matched bean row
DatabaseException
CreateTable getInstallTableQuery()
throws DatabaseException
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 install(CreateTable)
DatabaseExceptionRestoreQuery getRestoreQuery()
This method will return the base query that would be used to restore
beans with restore(). This can be used to restrict the query
so that less beans are returned or certain beans are returned.
RestoreQuery getRestoreQuery(int objectId)
This method will return the base query that would be used to restore
a single bean with restore(int). This can be used to restrict
the query so that a bean not matching the query will not be returned.
int count()
throws DatabaseException
This method will count the total number of beans persisted under this manager.
DatabaseException
int count(CountQuery query)
throws DatabaseException
CountQuery.
This method will count the total number of beans persisted under
this manager that match the provided CountQuery.
query - the query that will be used to determine which beans to
count
DatabaseExceptionCountQuery getCountQuery()
CountQuery used to count the number of beans
persisted under this manager
boolean delete(int objectId)
throws DatabaseException
This method will delete the bean identifed by the passed in identifier.
objectId - the identifier of the bean
DatabaseException
boolean delete(DeleteQuery query)
throws DatabaseException
DeleteQuery
This method will delete all beans identified by the passed in DeleteQuery.
query - the query to select the beans
DatabaseExceptionDeleteQuery getDeleteQuery()
DeleteQuery that would be used to delete beans
DeleteQueryDeleteQuery getDeleteQuery(int objectId)
DeleteQuery that would be used to delete a
single bean
objectId - the identifier to fill into the base DeleteQuery
DeleteQueryvoid addListener(GenericQueryManagerListener listener)
listener - the listener that has to be addedvoid removeListeners()
<OtherBeanType> GenericQueryManager<OtherBeanType> createNewManager(Class<OtherBeanType> beanClass)
beanClass - 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 | |||||||||