1 package org.apache.ojb.tutorial2; 2 3 17 18 import org.odmg.Implementation; 19 import org.odmg.Transaction; 20 import org.odmg.Database; 21 22 25 public class UCEnterNewProduct extends AbstractUseCase 26 { 27 32 public UCEnterNewProduct(Implementation odmg) 33 { 34 super(odmg); 35 } 36 37 42 public String getDescription() 43 { 44 return "Enter a new product"; 45 } 46 47 50 public void apply() 51 { 52 Product newProduct = new Product(); 54 55 System.out.println("please enter a new product"); 57 58 String in = readLineWithMessage("enter name:"); 59 60 newProduct.setName(in); 61 in = readLineWithMessage("enter price:"); 62 newProduct.setPrice(Double.parseDouble(in)); 63 in = readLineWithMessage("enter available stock:"); 64 newProduct.setStock(Integer.parseInt(in)); 65 66 68 Database db = odmg.getDatabase(null); Transaction tx = odmg.newTransaction(); 71 72 tx.begin(); 73 74 db.makePersistent(newProduct); 76 77 tx.commit(); 79 } 80 } 81 | Popular Tags |