1 package org.apache.ojb.tutorial5; 2 3 17 18 import javax.jdo.PersistenceManager; 19 import javax.jdo.PersistenceManagerFactory; 20 import javax.jdo.Transaction; 21 22 25 public class UCEnterNewProduct extends AbstractUseCase 26 { 27 32 public UCEnterNewProduct(PersistenceManagerFactory factory) 33 { 34 super(factory); 35 } 36 37 38 43 public String getDescription() 44 { 45 return "Enter a new product"; 46 } 47 48 51 public void apply() 52 { 53 Product newProduct = new Product(); 55 56 System.out.println("please enter a new product"); 58 59 String in = readLineWithMessage("enter name:"); 60 61 newProduct.setName(in); 62 in = readLineWithMessage("enter price:"); 63 newProduct.setPrice(Double.parseDouble(in)); 64 in = readLineWithMessage("enter available stock:"); 65 newProduct.setStock(Integer.parseInt(in)); 66 67 PersistenceManager manager = factory.getPersistenceManager(); 69 Transaction tx = manager.currentTransaction(); 70 71 tx.begin(); 72 manager.makePersistent(newProduct); 73 74 tx.commit(); 76 manager.close(); 77 } 78 } 79 | Popular Tags |