Package org.objectweb.speedo.pobjects.detach

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


   *   tx.commit
   *    attach => OK
   */
  public void testVersion2() {
    logger.log(BasicLevel.DEBUG, "***************testVersion2*****************");
    Team t = new Team("T2",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p3", t, 20);
    players.add(p1);
    Player p2 = new Player("p4", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c2", 10, t);
    t.setCoach(c);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //modify the coach
    t.getCoach().setExperience(99);
    Iterator it  = t.getPlayers().iterator();
    //modify the players
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //commit
    pm.currentTransaction().commit();
    pm.currentTransaction().begin();
    try
      //attach the team
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
        pm.currentTransaction().commit();
    }catch(Exception e){
      fail("The attached is supposed to be ok");
    } finally {
      if (pm.currentTransaction().isActive()) {
View Full Code Here


  /**
   * Test the attach method: make an object persistent, detach it then attach it.
   */
  public void testAttachCopy() {
    logger.log(BasicLevel.DEBUG, "***************testAttachCopy*****************");
    Team t = new Team("Bordeaux",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p1", t, 25);
    players.add(p1);
    Player p2 = new Player("p2", t, 32);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c1", 5, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    try {
      //detach the team t
      Team copyOfT = (Team) pm.detachCopy(t);
      assertNotNull(copyOfT);
      //print the team out
      logger.log(BasicLevel.DEBUG, copyOfT.toString());
      pm.currentTransaction().begin();
      //attach the team t
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
      assertEquals(copyOfT.getTown(), attachedTeam.getTown());
      assertEquals(copyOfT.getCoach().getExperience(), attachedTeam.getCoach().getExperience());
      assertEquals(copyOfT.getCoach().getName(), attachedTeam.getCoach().getName());
      pm.currentTransaction().commit();
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.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 object persistent, detach it , modify it and then attach it.
   */
  public void testAttachModifiedCopy() {
    logger.log(BasicLevel.DEBUG, "***************testAttachModifiedCopy*****************");
    Team t = new Team("Paris",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p3", t, 20);
    players.add(p1);
    Player p2 = new Player("p4", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c2", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //modify the team
    copyOfT.getCoach().setExperience(99);
    //print the team out
    logger.log(BasicLevel.DEBUG, "Copy of team " + copyOfT.toString());
    pm.currentTransaction().begin();
    //attach the team t
    Team attachedTeam = (Team) pm.makePersistent(copyOfT);
    try {
      assertNotNull(attachedTeam);
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.toString());
      assertEquals(99, attachedTeam.getCoach().getExperience());
      pm.currentTransaction().commit();
    } catch (Exception e) {
      fail(e.getMessage());
    } finally {
      if (pm.currentTransaction().isActive())
View Full Code Here

  /**
   * Test the attach method with an update on a reference: make an object persistent, detach it , modify it and then attach it.
   */
  public void testAttachModifiedReference() {
    logger.log(BasicLevel.DEBUG, "***************testAttachModifiedReference*****************");
    Team t = new Team("Lens",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p21", t, 20);
    players.add(p1);
    Player p2 = new Player("p22", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c23", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    try {
      //detach the team t
      Team copyOfT = (Team) pm.detachCopy(t);
      Coach newCoach = new Coach("c33", 15, new Team("DummyTeam",null,null));
      //  update the reference while detached
      copyOfT.setCoach(newCoach);
      //print the team out
      logger.log(BasicLevel.DEBUG, "Copy of team " + copyOfT.toString());
      pm.currentTransaction().begin();
      //  attach the team t
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
      assertNotNull("attachedTeam should not be null", attachedTeam);
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.toString());
      assertEquals("Coach of the attached team is not the good one", newCoach, attachedTeam.getCoach());
      pm.currentTransaction().commit();
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    } finally {
View Full Code Here

  /**
   * Test the attach method with update on a collection: make an object persistent, detach it , modify it and then attach it.
   */
  public void testAttachModifiedCollectionCopy() {
    logger.log(BasicLevel.DEBUG, "***************testAttachModifiedCollectionCopy*****************");
    Team t = new Team("Nantes",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p5", t, 20);
    players.add(p1);
    Player p2 = new Player("p6", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c3", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    pm.close();
    //modify the coach
    copyOfT.getCoach().setExperience(99);
    //and modify the collection
    Iterator it = copyOfT.getPlayers().iterator();
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
    //    print the team out
    logger.log(BasicLevel.DEBUG, "Copy of team " + copyOfT.toString());
    PersistenceManager pm2 = pmf.getPersistenceManager();
    try {
      pm2.currentTransaction().begin();
      //attach the team t
      Team attachedTeam = (Team) pm2.makePersistent(copyOfT);
   
      Iterator itP = attachedTeam.getPlayers().iterator();
      while(itP.hasNext()){
        Player p = (Player) itP.next();
        assertEquals(99, p.getAge());
      }
      pm2.currentTransaction().commit();
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.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 object: the object is made persistent.
   */
  public void testAttachNewObject() {
    logger.log(BasicLevel.DEBUG, "***************testAttachNewObject*****************");
    Team t = new Team("Bastia",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p7", t, 20);
    players.add(p1);
    Player p2 = new Player("p8", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c4", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "attach the team " + t.toString());
    Team attachedTeam = (Team) pm.makePersistent(t);
    pm.currentTransaction().commit();
    try {
      assertTrue( ((JDOPersistentObjectItf) attachedTeam).jdoIsPersistent());
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.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 object having a null reference.
   */
  public void testAttachNullRef() {
    logger.log(BasicLevel.DEBUG, "***************testAttachNullRef*****************");
    Team t = new Team("Istres",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p9", t, 20);
    players.add(p1);
    Player p2 = new Player("p10", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c5", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    try {
      //detach the team t
      Team copyOfT = (Team) pm.detachCopy(t);
      assertNotNull(copyOfT);
      assertNotNull("Coach of detached team should not be null.", copyOfT.getCoach());
      //set null for the coach
      copyOfT.setCoach(null);
      assertNull(copyOfT.getCoach());
      //print the team out
      logger.log(BasicLevel.DEBUG, copyOfT.toString());
      pm.currentTransaction().begin();
      //attach the team t
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
      assertEquals(copyOfT.getTown(), attachedTeam.getTown());
      assertNull("Coach of attached team should be null", attachedTeam.getCoach());
      pm.currentTransaction().commit();
      logger.log(BasicLevel.DEBUG,"The attached version of the team is as follows:\n " + attachedTeam.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 object in a Collection : the object is made persistent.
   */
  public void testAttachNewObjectInCollection() {
    logger.log(BasicLevel.DEBUG, "***************testAttachNewObjectInCollection*****************");
    Team t = new Team("Le Mans",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p11", t, 20);
    players.add(p1);
    Player p2 = new Player("p12", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c6", 10, t);
    t.setCoach(c);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "Make the team persistent " + t.toString());
    pm.makePersistent(t);
    pm.currentTransaction().commit();
   
    try {
      //detach the team
      Team copyOfT = (Team) pm.detachCopy(t);
      t = null;
      //create a new player
      String newPlayerName = "pXX";
      Player newPlayer = new Player(newPlayerName, copyOfT, 35);
      copyOfT.addPlayer(newPlayer);
      //attach the team
      pm.currentTransaction().begin();
      Team attachedTeam =  (Team) pm.makePersistent(copyOfT);
      pm.currentTransaction().commit();
      Iterator it = attachedTeam.getPlayers().iterator();
      boolean newPlayerFound = false;
      while(!newPlayerFound && it.hasNext()) {
        Player p = (Player) it.next();
        if (p.getName().equals(newPlayerName)) {
          assertTrue("The new player is not a persistent object", ((JDOPersistentObjectItf) p).jdoIsPersistent());
View Full Code Here

TOP

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

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.