1 package org.apache.ojb.broker.prevayler.demo; 2 3 17 18 import org.apache.ojb.broker.PersistenceBroker; 19 import org.apache.ojb.broker.PersistenceBrokerException; 20 import org.apache.ojb.tutorial1.Product; 21 22 27 public class UCEnterNewProduct extends AbstractUseCase 28 { 29 32 public UCEnterNewProduct(PersistenceBroker broker) 33 { 34 super(broker); 35 } 36 37 38 public void apply() 39 { 40 Product newProduct = new Product(); 42 43 newProduct.setId((int)System.currentTimeMillis()); 45 46 System.out.println("please enter a new product"); 48 String in = readLineWithMessage("enter name:"); 49 newProduct.setName(in); 50 in = readLineWithMessage("enter price:"); 51 newProduct.setPrice(Double.parseDouble(in)); 52 in = readLineWithMessage("enter available stock:"); 53 newProduct.setStock(Integer.parseInt(in)); 54 55 try 57 { 58 broker.beginTransaction(); 60 61 broker.store(newProduct); 63 broker.commitTransaction(); 64 } 65 catch (PersistenceBrokerException ex) 66 { 67 broker.abortTransaction(); 69 System.out.println(ex.getMessage()); 70 ex.printStackTrace(); 71 } 72 } 73 74 75 public String getDescription() 76 { 77 return "Enter a new product"; 78 } 79 } 80 | Popular Tags |