|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface StorageBean
Describes an implementation of standard Store, Retrieve, and Delete operations using the command pattern.
Developers or Database Administrators may define data access commands, such as SQL queries, in an external resource.
The Java code refers to these commands by name. Commands may be changed in the external resource without changing the Java source code. A named command may include a sequence of queries if needed [TODO].
The parameters required by each command may be specified in the external resource [TODO] or in the Java code (or both).
The columns referenced by a command are represented as JavaBean properties. The result of the command may be applied against the instant StorageBean, returned as a collection of bean, or returned as an arbitrary result object. If no data is returned, a result code may be set.
Each subclass may specify its own command prefix so that like-named commands can be stored in the same resource, or the prefix may represent separate resources.
[TODO] The external resources are defined as CommandStore objects, which may be maintained as Properties files, XML documents, or some other type of resource file.
StorageBean differs from other approaches to persistence in that it does presume that SQL will be generated dynamically. Rather than model the database in XML and the SQL as "criteria" objects, developers or DBAs can provide the appropriate data access commands (SQL). Since the commands are referenced using a logical name, and loaded from an external file, coupling between the Java code and data access code is minimized.
The SQL/JDBC implementations of StorageBean use reflection to populate a JavaBean from a ResultSet. This avoids defining the columns and properties by hand. All developers need to provide is the SQL that will obtain the desired properties (columns) as one or more SQL commands. TODO: Multiple queries in a command TODO: Parameters in command file TODO: CommandStore objects
Field Summary |
---|
Fields inherited from interface org.apache.commons.scaffold.util.ProcessBean |
---|
USER_PROFILE_KEY |
Method Summary | |
---|---|
int |
count(String command,
Object parameter)
Count of matching entries. |
Object |
createKey(String keyName)
Returns next sequential key for given set of keys. |
Object |
delete(Object parameters)
Permanently delete this object from data storage. |
void |
executeUpdate(String command)
Lookup command and execute "update" query to create a table, seed it with data, et cetera. |
void |
executeUpdateRoot(String command)
Lookup command (sans prefix) and execute "update" query to create a table, seed it with data, et cetera. |
Collection |
findByProperty(Object target,
String property,
String value)
Select entries from data storage by indexed property.. |
Collection |
findCollection(Object target,
String command,
Object[] parameters)
Retrieve a collection of beans from data storage. |
boolean |
findElement(Object target,
String command,
Object key)
Retrieve object from data storage. |
Object[] |
getParameters(String command)
[:TODO: Javadoc] |
List |
getParamList(String command)
[:TODO: Javadoc] |
String |
getPrefix()
[:TODO: Javadoc] |
boolean |
isNew()
Return whether this is a new record, or one that has already been stored. |
void |
populate(Map parameters)
Populate this bean from the entries on the provided map. |
Object |
recycle(Object parameters)
Mark this object for deletion. |
Object |
restore(Object parameters)
Unmake this object for deletion. |
Object |
retrieve(Object parameters)
Retrieve this object from storage. |
void |
setParameters(Object[] parameters)
[:TODO: Javadoc] |
void |
setParamList(List parameters)
[:TODO: Javadoc] |
void |
setPrefix(String prefix)
[:TODO: Javadoc] |
Object |
store(Object parameters)
Commit this object to storage. |
Methods inherited from interface org.apache.commons.scaffold.util.Storable |
---|
allocateKey, delete, getResult, getResultCode, getStorageKey, recycle, restore, retrieve, setResult, setResultCode, setStorageKey, store |
Methods inherited from interface org.apache.commons.scaffold.util.ProcessBean |
---|
execute, execute, getLocale, getParameter, getRemoteNode, getRemoteServer, setLocale, setParameter, setRemoteNode, setRemoteServer |
Method Detail |
---|
String getPrefix()
void setPrefix(String prefix)
Object[] getParameters(String command) throws ResourceException
ResourceException
void setParameters(Object[] parameters)
List getParamList(String command) throws ResourceException
ResourceException
void setParamList(List parameters)
void populate(Map parameters) throws Exception
populate
in interface Storable
Subclasses
- can throw any Exception
Exception
int count(String command, Object parameter) throws ResourceException
command
- Name of command to executeparameter
- A parameter to be used with command, if any
Resource
- exception if data access error occurs
ResourceException
void executeUpdate(String command) throws ResourceException
command
- Name of command to execute
Resource
- exception if data access error occurs
ResourceException
void executeUpdateRoot(String command) throws ResourceException
command
- Name of command to execute
Resource
- exception if data access error occurs
ResourceException
boolean findElement(Object target, String command, Object key) throws ResourceException
NOTE that the precursor to this inteface,
the AccessBase
class reversed the
command and key parameters.
This was inconsistent with how the parameters were
used elsewhere.
If you are converting from AccessBase, be sure to
submit the parameters in the correct order.
target
- Object to use as factory when populating
(e.g. this)key
- The primary key of the entrycommand
- The name of the data access command
collection
ResourceException
- if SQL error occursCollection findCollection(Object target, String command, Object[] parameters) throws ResourceException
target
- Object to use as factory when populating
(e.g. this)command
- Name of the data access command
collectionparameters
- An array of parameters to be used with command
throws
- ResourceException if data access error occurs
ResourceException
Collection findByProperty(Object target, String property, String value) throws ParameterException, PopulateException, ResourceException
target
- Object to use as factory when populating
collection (e.g. this)property
- Field to searchvalue
- Term to match
Throws
- ParameterException if value is not a search
term for property
Throws
- PopulateExeception if result cannot be set
to target
throws
- PropertiesException, ResourceException on
SQL, IO, or other data access error occurs.
ParameterException
PopulateException
ResourceException
boolean isNew()
Object createKey(String keyName) throws ResourceException
keyName
- The name of the key set to use to generate
the key
ResourceException
- if data access error occursObject store(Object parameters) throws Exception
This signature is designed for compatibilty with the Executable interface.
Exception
Object retrieve(Object parameters) throws Exception
This signature is designed for compatibilty with the Executable interface.
Exception
Object recycle(Object parameters) throws Exception
This signature is designed for compatibilty with the Executable interface.
Exception
Object restore(Object parameters) throws Exception
This signature is designed for compatibilty with the Executable interface.
Exception
Object delete(Object parameters) throws Exception
This signature is designed for compatibilty with the Executable interface.
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |