The commons logger is included in shared/lib by Sakai itself so you do not need to package it in your tool war file (hence there is no <war.bundle>true</war.bundle>)
Version 1.0.4 was the current version when this was written
Adding the logger to your code
Add the following line just below your class line:
Implementing saveTask This function is meant to insert an object into persistent storage and return a boolean value which indicates if the insertion suceeded or failed
Use the HibernateTemplate to access the save method
Enter getHibernateTemplate() in place of the TODO comment line
Enter a "." to see the list of available methods in Eclipse
Choose the save method with a single object argument
Enter the name of the Task object (should be t) as the argument
Close the statement with a semicolon ";"
Surround the statement with a try-catch block
This shows how to use Eclipse to insert a try-catch block around a statement which automatically includes possible exceptions
Select the statement to surround with a try-catch block
Right click on the selection and choose Source -> Surround with Try / Catch Block
You should now edit the Auto-generated catch block(s)
Note: don't forget to remove the e.printStackTrace(); if you do not want this exception to put a stackTrace in the logs
Replace the TODO comment line with a logging statement like this one:
log.error("Hibernate could not save: " + e.toString());
Add return false; after the e.printStackTrace(); line
Change the auto-generated return false; line at the end of the function with return true;
Implementing deleteTask This function is meant to remove an object from persistent storage and return a boolean value which indicates if the insertion suceeded or failed
Use the HibernateTemplate to access the delete method
Enter getHibernateTemplate() in place of the TODO comment line
Enter a "." to see the list of available methods in Eclipse
Choose the delete method with a single object argument
Enter the name of the Task object (should be t) as the argument
Close the statement with a semicolon ";"
Surround the statement with a try-catch block
This shows how to use Eclipse to insert a try-catch block around a statement which automatically includes possible exceptions
Select the statement to surround with a try-catch block
Right click on the selection and choose Source -> Surround with Try / Catch Block
You should now edit the Auto-generated catch block(s)
Note: don't forget to remove the e.printStackTrace(); if you do not want this exception to put a stackTrace in the logs
Replace the TODO comment line with a logging statement like this one:
log.error("Hibernate could not delete: " + e.toString());
Add return false; after the e.printStackTrace(); line
Change the auto-generated return false; line at the end of the function with return true;
Implementing findAllTasks This function is meant to retrieve a collection of all objects from persistent storage based on the passed siteId (or Context)
Use the HibernateTemplate to access the findByCriteria method
Enter getHibernateTemplate() in place of the auto-generate return value:
return getHibernateTemplate()
Enter a "." to see the list of available methods in Eclipse
Choose the findByCriteria method with a single object argument
Enter the name of the Criteria object we will create (should be d) as the argument
Close the statement with a semicolon ";"
Create the DetachedCriteria object (d) to do our find This allows us to restrict which objects are returned and sort them, it is sorta like the "where" and "order by" in an SQL statement
Insert the required imports for our use of criterion