1 package org.apache.ojb.broker.prevayler.demo; 2 3 17 18 import org.apache.ojb.broker.query.Query; 19 import org.apache.ojb.broker.query.QueryByIdentity; 20 import org.apache.ojb.tutorial1.Product; 21 22 27 public class UCDeleteProduct extends AbstractUseCase 28 { 29 32 public UCDeleteProduct(org.apache.ojb.broker.PersistenceBroker b) 33 { 34 super(b); 35 } 36 37 38 public void apply() 39 { 40 String in = readLineWithMessage("Delete Product with id:"); 41 int id = Integer.parseInt(in); 42 43 Product example = new Product(); 48 example.setId(id); 49 Query query = new QueryByIdentity(example); 51 try 52 { 53 broker.beginTransaction(); 55 Product toBeDeleted = (Product) broker.getObjectByQuery(query); 57 broker.delete(toBeDeleted); 59 broker.commitTransaction(); 61 } 62 catch (Throwable t) 63 { 64 broker.abortTransaction(); 66 t.printStackTrace(); 67 } 68 } 69 70 71 public String getDescription() 72 { 73 return "Delete a product entry"; 74 } 75 } 76 | Popular Tags |