I've attached a patch which fixes up the Task insert so that when you assign a task to a user you can capture the TaskID for the task.

It also avoids the hacky try/catch solution to try update first and only insert if that fails.

Index: TaskServiceImpl.java
===================================================================
--- TaskServiceImpl.java        (revision 56926)
+++ TaskServiceImpl.java        (working copy)
@@ -16,17 +16,15 @@
 
 package org.apache.agila.impl.jdbc;
 
-import org.apache.agila.services.user.UserID;
-import org.apache.agila.services.task.TaskID;
-import org.apache.agila.services.task.Task;
 import org.apache.agila.services.task.AbstractTaskService;
-
+import org.apache.agila.services.task.Task;
+import org.apache.agila.services.task.TaskID;
+import org.apache.agila.services.user.UserID;
 import org.apache.agila.util.JDBCUtil;
 
 import java.util.List;
 
 /**
- *
  * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  * @version $Id: $
  */
@@ -37,29 +35,26 @@
     /**
      * Add or update a task.
      */
-    protected void internalSave(Task ti) {
+    protected void internalSave(Task task) {
 
         // Add or update task
-
-        // TODO fast hack to determine whether to insert or update.
-        // need to modify this
-        try {
-            jdbcUtil.updateTask( ti );
-        } catch( Exception e ) {
-            // Can't update so insert
-            jdbcUtil.insertTask( ti );
+        if (task.getTaskID() != null && task.getTaskID().getID() > 0) {
+            jdbcUtil.updateTask(task);
         }
+        else {
+            task.setTaskID(jdbcUtil.insertTask(task));
+        }
     }
 
-    protected  List internalGetTasksByUserID(UserID userID, int type) {
+    protected List internalGetTasksByUserID(UserID userID, int type) {
 
-        return jdbcUtil.getTasksForUser( userID, type );
+        return jdbcUtil.getTasksForUser(userID, type);
 
     }
 
     protected Task internalGetTask(TaskID taskID) {
 
-        return jdbcUtil.getTaskByID( taskID );
+        return jdbcUtil.getTaskByID(taskID);
 
     }
 



James ------- http://radio.weblogs.com/0112098/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to