Package org.objectweb.speedo.pobjects.detach

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


   * 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());
      assertEquals(f.getNbOfWheels(), copyOfF.getNbOfWheels());
      assertEquals(f.getType(), copyOfF.getType());
      assertEquals(f.getSpeedMax(), copyOfF.getSpeedMax());
      //print the formula one out
      logger.log(BasicLevel.DEBUG, copyOfF.toString());
    } catch(Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
View Full Code Here


  /**
    * Test the detach method with a non persistent object which is inherited from a super class: the object is made persistent before being detached.
    */
  public void testDetachNonPersistentInherited() {
    logger.log(BasicLevel.DEBUG, "*************testDetachNonPersistentInherited*****************");
    FormulaOne f = new FormulaOne("sauber", 4, "blue", 274);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    //    detach the formula one f while it is not persistent
    FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
    assertTrue(((JDOPersistentObjectItf) f).jdoIsPersistent());
    pm.currentTransaction().commit();
    try {
      assertNotNull(copyOfF);
      assertEquals(f.getName(), copyOfF.getName());
      assertEquals(f.getColor(), copyOfF.getColor());
      assertEquals(f.getNbOfWheels(), copyOfF.getNbOfWheels());
      assertEquals(f.getType(), copyOfF.getType());
      assertEquals(f.getSpeedMax(), copyOfF.getSpeedMax());
      //print the team out
      logger.log(BasicLevel.DEBUG, copyOfF.toString());
    } catch(Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
View Full Code Here

  /**
    * Test the detach method with a persistent-deleted inherited object: an exception must be thrown.
    */
  public void testDetachPersistentDeletedInherited() {
    logger.log(BasicLevel.DEBUG, "******************testDetachPersistentDeletedInherited****************");
    FormulaOne f = new FormulaOne("honda", 4, "yellow", 240);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    //make persistent
    pm.currentTransaction().begin();
    pm.makePersistent(f);
View Full Code Here

  /**
    * Test the detach method with a persistent-dirty inherited object: the object is flushed before being detached.
    */
  public void testDetachPersistentDirtyInherited() {
    logger.log(BasicLevel.DEBUG, "******************testDetachPersistentDirtyInherited****************");
    FormulaOne f = new FormulaOne("ferrari", 4, "yellow", 240);
    PersistenceManager pm = pmf.getPersistenceManager();
    //make persistent
    pm.currentTransaction().begin();
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    //update and detach
    pm.currentTransaction().begin();
    f.setNbOfWheels(3);
    f.setSpeedMax(300);
    pm.currentTransaction().commit();
    try {
      //detach the formula one while it is persistent-dirty: the object must be flushed before being detached
      FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
      assertEquals(f.getName(), copyOfF.getName());
      assertEquals(f.getColor(), copyOfF.getColor());
      assertEquals(3, copyOfF.getNbOfWheels());
      assertEquals(f.getType(), copyOfF.getType());
      assertEquals(300, copyOfF.getSpeedMax());
      //print the formula one out
      logger.log(BasicLevel.DEBUG, copyOfF.toString());
    } catch(Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
View Full Code Here

  /**
    * Test the detach method with a persistent-new inherited object: the object is flushed before being detached.
    */
  public void testDetachPersistentNewInherited() {
    logger.log(BasicLevel.DEBUG, "******************testDetachPersistentNewInherited****************");
    FormulaOne f = new FormulaOne("renault", 4, "yellow", 260);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    try {
      //detach the formula one while it is persistent-new: the object must be flushed before being detached
      FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
      assertEquals(f.getName(), copyOfF.getName());
      assertEquals(f.getColor(), copyOfF.getColor());
      assertEquals(f.getNbOfWheels(), copyOfF.getNbOfWheels());
      assertEquals(f.getType(), copyOfF.getType());
      assertEquals(f.getSpeedMax(), copyOfF.getSpeedMax());
      //  print the formula one out
      logger.log(BasicLevel.DEBUG, copyOfF.toString());
    } catch(Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
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())
        pm.currentTransaction().rollback();
View Full Code Here

  /**
   * Test the attach method with update: make an inherited object persistent, detach it , modify it and then attach it.
   */
  public void testAttachModifiedInherited() {
    logger.log(BasicLevel.DEBUG, "***************testAttachModifiedInherited*****************");
    FormulaOne f = new FormulaOne("renault", 4, "yellow", 262);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the formula one " + f.toString());
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    //detach
    FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
    //modify
    copyOfF.setNbOfWheels(2);
    copyOfF.setSpeedMax(320);
    //print out
    logger.log(BasicLevel.DEBUG, "Copy of formula one " + copyOfF.toString());
    pm.currentTransaction().begin();
    //attach
    FormulaOne attachedF = (FormulaOne) pm.makePersistent(copyOfF);
    try {
      assertEquals(2, attachedF.getNbOfWheels());
      assertEquals(320, attachedF.getSpeedMax());
      pm.currentTransaction().commit();
      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())
        pm.currentTransaction().rollback();
View Full Code Here

  /**
   * Test the attach method with a new inherited object: the object is made persistent.
   */
  public void testAttachNewInherited() {
    logger.log(BasicLevel.DEBUG, "***************testAttachNewInherited*****************");
    FormulaOne f = new FormulaOne("sauber", 4, "red", 262);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "attach the f1 " + f.toString());
    FormulaOne attachedF = (FormulaOne) pm.makePersistent(f);
    try {
      assertTrue(((JDOPersistentObjectItf)attachedF).jdoIsPersistent());
      pm.currentTransaction().commit();
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedF.toString());
    } catch (Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
        pm.currentTransaction().rollback();
View Full Code Here

  /**
   * Test the attach method with an invalid copy: make an inherited object persistent, modify it, detach it , rollback the transaction and then attach it.
   */
  public void testAttachInvalidInherited() {
    logger.log(BasicLevel.DEBUG, "***************testAttachInvalidInherited*****************");
    FormulaOne f = new FormulaOne("ferrari", 4, "red", 262);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the f1 " + f.toString());
    pm.makePersistent(f);
    pm.currentTransaction().commit();
    pm.currentTransaction().begin();
    //modify
     f.setNbOfWheels(1);
     //detach the team t
    FormulaOne copyOfF = (FormulaOne) pm.detachCopy(f);
    //rollback the tx : it invalids the copy
    pm.currentTransaction().rollback();
    //  print out
    logger.log(BasicLevel.DEBUG, "Copy of f1 " + copyOfF.toString());
    logger.log(BasicLevel.DEBUG, "rollback of the tx: the attach shouldn't work.");
    try
      //attach the "invalid" f1
      pm.currentTransaction().begin();
        FormulaOne attachedF = (FormulaOne) pm.makePersistent(copyOfF);
        pm.currentTransaction().commit();
        logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedF.toString());
    } catch(Exception e){
        assertEquals("Wrong exception thrown: " + e.getMessage(), JDOException.class, e.getClass());
    } finally {
      if (pm.currentTransaction().isActive()) {
            pm.currentTransaction().rollback();
View Full Code Here

TOP

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

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.