Esempio n. 1
0
 /**
  * This method persists an existing Task instance
  *
  * @param task
  */
 public void update(Task task) {
   cache.replace(task.getId(), task);
 }
Esempio n. 2
0
 /**
  * This method deletes an Task from the persistence store
  *
  * @param task
  */
 public void delete(Task task) {
   // Note object may be detached so we need to tell it to remove based on reference
   cache.remove(task.getId());
 }
Esempio n. 3
0
 /**
  * This method persists a new Task instance
  *
  * <p>NOTE: We use System.nanoTime() to create unique ids for the tasks, but please be aware that
  * using System.nanoTime() is not recommended and it does NOT guarantee unique id's. Why we use it
  * here is because we have a very simplified domain model and normally we would probably connect
  * tasks to a User object in which case generatign unique id's us much better.
  *
  * @param task
  */
 public void insert(Task task) {
   if (task.getCreatedOn() == null) task.setCreatedOn(new Date());
   task.setId(new Long(System.nanoTime())); // Not recommended!!!!
   cache.put(task.getId(), task);
 }