husted 2002/11/23 11:06:11
Modified: scaffold/src/java/org/apache/commons/scaffold/sql
StorageBeanBase.java
Log:
+ StorageBeanBase: Add generic access methods, update, element, collection.
Revision Changes Path
1.16 +128 -10
jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StorageBeanBase.java
Index: StorageBeanBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/sql/StorageBeanBase.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- StorageBeanBase.java 23 Nov 2002 02:45:55 -0000 1.15
+++ StorageBeanBase.java 23 Nov 2002 19:06:11 -0000 1.16
@@ -88,17 +88,17 @@
* resultset if you like
* </UL>
*
- * TODO: Refactor recycle,restore,delete to use common util method
- * TODO: Javadocs for new classes
- * TODO: Use reflection to read parameter key and make array from
+ * @todo Refactor recycle,restore,delete to use common util method
+ * @todo Javadocs for new classes
+ * @todo Use reflection to read parameter key and make array from
* that.
- * TODO: Check for key.paramlist then paramlist.
- * TODO: Permit each subclass to have its own properties (collection
+ * @todo Check for key.paramlist then paramlist.
+ * @todo Permit each subclass to have its own properties (collection
* of properties, like Struts Actions).
- * TODO: Switch to CommandStore (or eliminate that object if not
+ * @todo Switch to CommandStore (or eliminate that object if not
* needed).
- * TODO: Add properties to manage optimistic locking
- * TODO: Change from BeanUtil.populate to copyProperties in 1.1
+ * @todo Add properties to manage optimistic locking
+ * @todo Change from BeanUtil.populate to copyProperties in 1.1
* version.
* @author Ted Husted
* @author OK State DEQ
@@ -714,7 +714,7 @@
* Check to see if another modified timetamp
* matches the one for this instance.
* Returns true if the timestamps match.
- * @return true if the timestamps match.
+ * @returns true if the timestamps match.
* @param edited The new edited timestamp.
*/
public boolean isCurrent(Timestamp modified) {
@@ -760,6 +760,124 @@
// --------------------------------------------------------------------- store
+
+ public void fixModified() {
+ Timestamp modified = getModified();
+ if ((null==modified) || (ConvertUtils.NULL_TIMESTAMP==modified)) {
+ setModified(new Timestamp(System.currentTimeMillis()));
+ }
+ }
+
+
+ public int updateResultCode(String command) throws ResourceException {
+
+ int result = 0;
+ try {
+
+ result = StatementUtils.executeUpdate(
+ null,lookup(command),getParameters(command));
+
+ }
+ catch (SQLException e) {
+ throw new ResourceException(e);
+ }
+
+ return result;
+ }
+
+ // see interface for Javadoc
+ public Object update(Object parameters) throws Exception {
+
+ populate((Map) parameters);
+
+ String command = getParameter();
+
+ fixModified();
+ setResultCode(updateResultCode(command));
+
+ String message = null;
+ if (isNew()) message = Tokens.DATA_RECORD_INSERTED;
+ else message = Tokens.DATA_RECORD_UPDATED;
+
+ ProcessResult result = new ProcessResultBase(getResult());
+ result.addMessage(message);
+ result.addMessage(getStorageKey());
+ result.setSingleForm(true);
+ return result;
+ }
+
+
+ public Object elementResult(String command) throws Exception {
+
+ boolean found = false;
+ try {
+
+ found = StatementUtils.getElement(null,this,
+ lookup(command),getParameters(command));
+
+ }
+ catch (SQLException e) {
+ throw new ResourceException(e);
+ }
+
+ if (found) {
+
+ setResult(this);
+ setResultCode(1);
+
+ }
+ else {
+ setResultCode(0);
+ }
+
+ ProcessResult result = new ProcessResultBase(this);
+ result.setSingleForm(true);
+ return result;
+ }
+
+
+ // see interface for Javadoc
+ public Object element(Object command) throws Exception {
+
+ populate((Map) command);
+
+ return elementResult(getParameter());
+
+ }
+
+
+ public Object collectionResult(String command) throws Exception {
+
+ Collection result = null;
+
+ try {
+
+ result = StatementUtils.getCollection(null,
+ this,lookup(command),getParameters(command));
+
+ }
+ catch (SQLException e) {
+ throw new ResourceException(e);
+ }
+
+ setResult(result);
+
+ return new ProcessResultBase(result);
+
+ }
+
+
+ // see interface for Javadoc
+ public Object collection(Object parameters) throws Exception {
+
+ populate((Map) parameters);
+
+ return collectionResult(getParameter());
+
+ }
+
+// --------------------------------------------------------------------- store
+
/**
* [:TODO: Javadoc]
*/
@@ -859,7 +977,7 @@
* Otherwise, an existing object is updated.
* @return ProcessResult with messages and this object as data
* @exception ResourceException if data access error occurs
- * @param parameters The properties to use with operation
+ @ @parameters The properties to use with operation
*
*/
public Object store(Object parameters) throws Exception {
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>