1 package org.apache.ojb.tutorial1; 2 3 17 18 import org.apache.ojb.broker.PersistenceBroker; 19 import org.apache.ojb.broker.PersistenceBrokerException; 20 21 24 public class UCEnterNewProduct extends AbstractUseCase 25 { 26 31 public UCEnterNewProduct(PersistenceBroker broker) 32 { 33 super(broker); 34 } 35 36 41 public String getDescription() 42 { 43 return "Enter a new product"; 44 } 45 46 49 public void apply() 50 { 51 Product newProduct = new Product(); 53 54 System.out.println("please enter a new product"); 56 57 String in = readLineWithMessage("enter name:"); 58 59 newProduct.setName(in); 60 in = readLineWithMessage("enter price:"); 61 newProduct.setPrice(Double.parseDouble(in)); 62 in = readLineWithMessage("enter available stock:"); 63 newProduct.setStock(Integer.parseInt(in)); 64 65 try 67 { 68 broker.beginTransaction(); 70 71 broker.store(newProduct); 73 broker.commitTransaction(); 74 } 75 catch (PersistenceBrokerException ex) 76 { 77 broker.abortTransaction(); 79 System.out.println(ex.getMessage()); 80 ex.printStackTrace(); 81 } 82 } 83 } 84 | Popular Tags |