Package org.objectweb.speedo.pobjects.detach

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


        } finally {
            pm.close();
        }
    }
  private void createPlayers(){
    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);
   
    Team t2 = new Team("Nantes", null, null);
    Collection players2 = new ArrayList();
    Player p3 = new Player("p3", t2, 25);
    players2.add(p3);
    Player p4 = new Player("p4", t2, 32);
    players2.add(p4);
    t2.setPlayers(players2);
    Coach c2 = new Coach("c2", 5, t2);
    t2.setCoach(c2);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the team " + t.toString());
    pm.makePersistent(t);
View Full Code Here


      Query query = pm.newQuery(Team.class);
      Collection results = (Collection)query.execute();
      logger.log(BasicLevel.DEBUG, "Teams:");
      Iterator it = results.iterator();
      while(it.hasNext()){
        Team t = (Team) it.next();
        logger.log(BasicLevel.DEBUG, t.toString());
      }
      Collection detachedTeams = (Collection) pm.detachCopyAll(results);
      query.closeAll();
      return detachedTeams;
    }
View Full Code Here

   *   tx.commit
   *    attach => FAIL
   */
  public void testVersion3() {
    logger.log(BasicLevel.DEBUG, "***************testVersion3*****************");
    Team t = new Team("T3",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();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //detach the team t
    Team copyOfT = null;
    try {
      copyOfT = (Team) pm.detachCopy(t);
      //  modify the coach
      t.setCoach(new Coach("c31", 10, t));
      Iterator it  = t.getPlayers().iterator();
      //modify the players
      while(it.hasNext()){
        Player p = (Player) it.next();
        p.setAge(99);
      }
      //commit
      pm.currentTransaction().commit();
    } catch (Exception e) {
      fail("Detach error: " + e.getMessage());
      pm.currentTransaction().rollback();
      pm.close();
      return;
    }
    pm.currentTransaction().begin();
    try
      //attach the team
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
        pm.currentTransaction().commit();
        fail("The attached is supposed to fail");
    }catch(Exception e){
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
    } finally {
View Full Code Here

   *   tx.rollback
   *    attach => OK
   */
  public void testVersion4() {
    logger.log(BasicLevel.DEBUG, "***************testVersion4*****************");
    Team t = new Team("T4",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();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    pm.currentTransaction().begin();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //rollback the tx
    pm.currentTransaction().rollback();
    pm.currentTransaction().begin();
    try
      //attach the "invalid" 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

   *  tx.rollback
   *   attach => FAIL
   */
  public void testVersion5() {
    logger.log(BasicLevel.DEBUG, "***************testVersion5*****************");
    Team t = new Team("T5",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();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //modify the coach
    t.setCoach(new Coach("c51", 10, t));
    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);
    //rollback
    pm.currentTransaction().rollback();
    pm.currentTransaction().begin();
    try
      //attach the team
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
        pm.currentTransaction().commit();
        fail("The attached is supposed to fail.");
    }catch(Exception e){
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
    } finally {
View Full Code Here

   *   tx.rollback
   *    attach => OK
   */
  public void testVersion6() {
    logger.log(BasicLevel.DEBUG, "***************testVersion6*****************");
    Team t = new Team("T6",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();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //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);
    }
    //rollback
    pm.currentTransaction().rollback();
    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

   *      attach(d2) => FAIL
   *   tx.commit  
   */
  public void testVersion7() {
    logger.log(BasicLevel.DEBUG, "***************testVersion7*****************");
    Team t = new Team("T7",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p13", t, 20);
    players.add(p1);
    Player p2 = new Player("p14", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c7", 10, t);
    t.setCoach(c);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //detach the team t
    Team copyOfT1 = (Team) pm.detachCopy(t);
    //detach the team t
    Team copyOfT2 = (Team) pm.detachCopy(t);
    //commit
    pm.currentTransaction().commit();
   
    //modify the copy1
    copyOfT1.getCoach().setExperience(99);
    Iterator it  = copyOfT1.getPlayers().iterator();
    //modify the players
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
    //modify the copy2
    copyOfT2.getCoach().setExperience(99);
    it  = copyOfT2.getPlayers().iterator();
    //modify the players
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
   
    boolean attach1OK = false;
    try{
      pm.currentTransaction().begin();
      //attach the copy1
      Team attachedTeam1 = (Team) pm.makePersistent(copyOfT1);
        pm.currentTransaction().commit();
        attach1OK = true;
        pm.currentTransaction().begin();
      //attach the copy2
      Team attachedTeam2 = (Team) pm.makePersistent(copyOfT2);
        pm.currentTransaction().commit();
        fail("The second attach is supposed to fail");
    }catch(Exception e){
      assertTrue("The first attach is supposed to be ok.", attach1OK);
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
View Full Code Here

   *      attach(d1) => FAIL
   *   tx.commit  
   */
  public void testVersion8() {
    logger.log(BasicLevel.DEBUG, "***************testVersion8*****************");
    Team t = new Team("T8",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p15", t, 20);
    players.add(p1);
    Player p2 = new Player("p16", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c8", 10, t);
    t.setCoach(c);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    //detach the team t
    Team copyOfT1 = (Team) pm.detachCopy(t);
    //detach the team t
    Team copyOfT2 = (Team) pm.detachCopy(t);
    //commit
    pm.currentTransaction().commit();
   
    //modify the copy1
    copyOfT1.getCoach().setExperience(99);
    Iterator it  = copyOfT1.getPlayers().iterator();
    //modify the players
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
    //modify the copy2
    copyOfT2.getCoach().setExperience(99);
    it  = copyOfT2.getPlayers().iterator();
    //modify the players
    while(it.hasNext()){
      Player p = (Player) it.next();
      p.setAge(99);
    }
   
    boolean attach2OK = false;
    try{
      pm.currentTransaction().begin();
      //attach the copy2
      Team attachedTeam2 = (Team) pm.makePersistent(copyOfT2);
        pm.currentTransaction().commit();
        attach2OK = true;
        pm.currentTransaction().begin();
      //attach the copy1
      Team attachedTeam1 = (Team) pm.makePersistent(copyOfT1);
        pm.currentTransaction().commit();
        fail("The attach of copy1 is supposed to fail");
    }catch(Exception e){
      assertTrue("The attach of copy2 is supposed to be ok.", attach2OK);
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
View Full Code Here

   *     attach => FAIL
   *   tx.commit
   */
  public void testVersion9() {
    logger.log(BasicLevel.DEBUG, "***************testVersion9*****************");
    Team t = new Team("T9",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p17", t, 20);
    players.add(p1);
    Player p2 = new Player("p18", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c9", 10, t);
    t.setCoach(c);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //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);
    }
    try
      //attach the team
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
        pm.currentTransaction().commit();
        fail("The attached is supposed to fail.");
    }catch(Exception e){
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
    } finally {
View Full Code Here

   *     attach => FAIL
   *   tx.commit
   */
  public void testVersion10() {
    logger.log(BasicLevel.DEBUG, "***************testVersion10*****************");
    Team t = new Team("T10",null,null);
    Collection players = new ArrayList();
    Player p1 = new Player("p19", t, 20);
    players.add(p1);
    Player p2 = new Player("p20", t, 30);
    players.add(p2);
    t.setPlayers(players);
    Coach c = new Coach("c10", 10, t);
    t.setCoach(c);
    PersistenceManager pm = pmf.getPersistenceManager();
    pm.currentTransaction().begin();
    pm.makePersistent(t);
    pm.currentTransaction().commit();
    //detach the team t
    Team copyOfT = (Team) pm.detachCopy(t);
    //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);
    }
    //commit
    pm.currentTransaction().commit();
    //begin
    pm.currentTransaction().begin();
    try
      //attach the team
      Team attachedTeam = (Team) pm.makePersistent(copyOfT);
        pm.currentTransaction().commit();
        fail("The attached is supposed to fail.");
    }catch(Exception e){
      assertEquals("Wrong exception thrown: " + e.getClass(), JDOException.class, e.getClass());
    } finally {
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.