Package org.objectweb.speedo.pobjects.detach

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


  /**
   * Test the detach method with inheritance.
   */
  public void testDetachInherited() {
    logger.log(BasicLevel.DEBUG, "***************testDetachInherited*****************");
    Car c = new Car("r5", 4, "red");
    FormulaOne f = new FormulaOne("williams", 4, "green", 262);
 
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the car " + c.toString() +
      " and the formula one " + f.toString());
    pm.makePersistent(c);
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    try {
      //detach the car c
      Car copyOfC = (Car) pm.detachCopy(c);
      assertNotNull(copyOfC);
      assertEquals(c.getName(), copyOfC.getName());
      assertEquals(c.getColor(), copyOfC.getColor());
      assertEquals(c.getNbOfWheels(), copyOfC.getNbOfWheels());
      assertEquals(c.getType(), copyOfC.getType());
      //  print the car out
      logger.log(BasicLevel.DEBUG, copyOfC.toString());
      //detach the formula one f
      FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
      assertNotNull(copyOfF);
      assertEquals(f.getName(), copyOfF.getName());
      assertEquals(f.getColor(), copyOfF.getColor());
View Full Code Here


  /**
   * Test the attach method: make an inherited object persistent, detach it then attach it.
   */
  public void testAttachInherited() {
    logger.log(BasicLevel.DEBUG, "***************testAttachInherited*****************");
    Car c = new Car("r5", 4, "red");
    FormulaOne f = new FormulaOne("williams", 4, "green", 262);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the car " + c.toString() );
    logger.log(BasicLevel.DEBUG, "make persistent the formula one " + f.toString());
    pm.makePersistent(c);
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    //detach the car c
    Car copyOfC = (Car) pm.detachCopy(c);
    //print the car out
    logger.log(BasicLevel.DEBUG, copyOfC.toString());
    //detach the formula one f
    FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
    //print the formula one out
    logger.log(BasicLevel.DEBUG, copyOfF.toString());
    pm.currentTransaction().begin();
    //attach the copied car
    Car attachedCar = (Car) pm.makePersistent(copyOfC);
    //attach the copied formula one
    FormulaOne attachedF = (FormulaOne) pm.makePersistent(copyOfF);
    pm.currentTransaction().commit();
    try {
      assertNotNull(attachedCar);
      assertEquals(copyOfC.getColor(), attachedCar.getColor());
      assertEquals(copyOfC.getName(), attachedCar.getName());
      assertEquals(copyOfC.getNbOfWheels(), attachedCar.getNbOfWheels());
      assertEquals(copyOfC.getType(), attachedCar.getType());
   
      assertNotNull(attachedF);
      assertEquals(copyOfF.getColor(), attachedF.getColor());
      assertEquals(copyOfF.getName(), attachedF.getName());
      assertEquals(copyOfF.getNbOfWheels(), attachedF.getNbOfWheels());
      assertEquals(copyOfF.getType(), attachedF.getType());
      assertEquals(copyOfF.getSpeedMax(), attachedF.getSpeedMax());
   
      logger.log(BasicLevel.DEBUG,"The attached version of the car is as follows:\n " + attachedCar.toString());
      logger.log(BasicLevel.DEBUG,"The attached version of the formula one is as follows:\n " + attachedF.toString());
    } catch (Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
View Full Code Here

TOP

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

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.