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 UCEditProduct extends AbstractUseCase 28 { 29 32 public UCEditProduct(org.apache.ojb.broker.PersistenceBroker b) 33 { 34 super(b); 35 } 36 37 38 public void apply() 39 { 40 String in = readLineWithMessage("Edit Product with id:"); 41 int id = Integer.parseInt(in); 42 43 Product example = new Product(); 48 example.setId(id); 49 50 Query query = new QueryByIdentity(example); 52 try 53 { 54 broker.beginTransaction(); 56 57 Product toBeEdited = (Product) broker.getObjectByQuery(query); 59 60 System.out.println("please edit the product entry"); 62 in = readLineWithMessage("enter name (was " + toBeEdited.getName() + "):"); 63 toBeEdited.setName(in); 64 in = readLineWithMessage("enter price (was " + toBeEdited.getPrice() + "):"); 65 toBeEdited.setPrice(Double.parseDouble(in)); 66 in = readLineWithMessage("enter available stock (was " + toBeEdited.getStock() + "):"); 67 toBeEdited.setStock(Integer.parseInt(in)); 68 69 70 71 broker.store(toBeEdited); 73 broker.commitTransaction(); 75 } 76 catch (Throwable t) 77 { 78 broker.abortTransaction(); 80 t.printStackTrace(); 81 } 82 } 83 84 85 public String getDescription() 86 { 87 return "Edit a product entry"; 88 } 89 } 90 | Popular Tags |