Package org.objectweb.speedo.pobjects.detach

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


   */
  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);
   
View Full Code Here


   */
  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);
   
View Full Code Here

   */
  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());
View Full Code Here

   */
  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);
   
View Full Code Here

   */
  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);
   
View Full Code Here

   */
  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());
          newPlayerFound = true;
        }
      }
      assertTrue("The new player should have been made persistent", newPlayerFound);
View Full Code Here

TOP

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

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.