Package org.objectweb.speedo.pobjects.detach

Examples of org.objectweb.speedo.pobjects.detach.Share


   * Test the detach method on a Big Decimal : bug fixed to update a big decimal object when detaching it.
   */
  public void testDetachModifyAttachCollection() {
    logger.log(BasicLevel.DEBUG, "*****************testDetachModifyAttachCollection************");
    //1st create 2 shares and prices
    Share share1 = new Share(1);
    Share share2 = new Share(2);
   
    SharePrice sp11 = new SharePrice(11, 2004, 11, new BigDecimal(11000));
    SharePrice sp12 = new SharePrice(12, 2004, 11, new BigDecimal(12000));
    SharePrice sp13 = new SharePrice(13, 2004, 11, new BigDecimal(13000));
   
    share1.addPrice(sp11);
    share1.addPrice(sp12);
    share1.addPrice(sp13);
   
    SharePrice sp21 = new SharePrice(21, 2005, 11, new BigDecimal(21000));
    SharePrice sp22 = new SharePrice(22, 2005, 11, new BigDecimal(22000));
    SharePrice sp23 = new SharePrice(23, 2005, 11, new BigDecimal(23000));
   
    share1.addPrice(sp21);
    share1.addPrice(sp22);
    share1.addPrice(sp23);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(share1);
    pm.makePersistent(share2);
    pm.currentTransaction().commit();
   
    Share copyOfShare = (Share) pm.detachCopy((Object)share1);
    logger.log(BasicLevel.DEBUG, "share detached");
    SharePrice price = copyOfShare.getPrice(12,2004,11);
    if (price != null) {
        price.setPrice(new BigDecimal(99000));
    }
    SharePrice newSp = new SharePrice(31, 2006, 11, new BigDecimal(31000));
    copyOfShare.addPrice(newSp);
    try {
      logger.log(BasicLevel.DEBUG, "share price updated");
      pm.currentTransaction().begin();
      Share attachedShare = (Share) pm.makePersistent((Object)copyOfShare);
      pm.currentTransaction().commit();
      assertEquals(copyOfShare.getId(), attachedShare.getId());
      assertEquals("Collection of prices for the detached share and its attached copy is not the same.", copyOfShare.getPrices().size(), attachedShare.getPrices().size());
      logger.log(BasicLevel.DEBUG, "share attached");
    } catch (Exception e) {
      fail(e.getMessage());
    } finally {
      pm.close();
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.detach.Share

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.