1 package org.apache.ojb.tutorial1; 2 3 17 18 import org.apache.ojb.broker.PersistenceBroker; 19 import org.apache.ojb.broker.query.Query; 20 import org.apache.ojb.broker.query.QueryByIdentity; 21 22 25 public class UCDeleteProduct extends AbstractUseCase 26 { 27 32 public UCDeleteProduct(PersistenceBroker broker) 33 { 34 super(broker); 35 } 36 37 42 public String getDescription() 43 { 44 return "Delete a product entry"; 45 } 46 47 50 public void apply() 51 { 52 String in = readLineWithMessage("Delete Product with id:"); 53 int id = Integer.parseInt(in); 54 55 59 Product example = new Product(); 61 62 example.setId(id); 63 64 Query query = new QueryByIdentity(example); 66 67 try 68 { 69 broker.beginTransaction(); 71 Product toBeDeleted = (Product) broker.getObjectByQuery(query); 73 broker.delete(toBeDeleted); 75 broker.commitTransaction(); 77 } 78 catch (Throwable t) 79 { 80 broker.abortTransaction(); 82 t.printStackTrace(); 83 } 84 } 85 } 86 | Popular Tags |