Package javax.jdo

Examples of javax.jdo.Transaction


    }

    /** */
    private void runTestRetrieveAllWithCollectionDFGfalse(PersistenceManager pm) {
        createObjects(pm);
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Collection coll = new ArrayList();
            coll.add(p1);
            coll.add(p3);
            coll.add(rect);
            pm.retrieveAll(coll, false);
            pm.makeTransientAll(coll);
            tx.commit();
            tx = null;
            checkP1();
            checkP3();
            checkRectP1();
            checkRectId();
        }
        finally {
            if ((tx != null) && tx.isActive())
                tx.rollback();
        }
    }
View Full Code Here


    }

    /** */
    private void runTestRetrieveAllWithArray(PersistenceManager pm) {
        createObjects(pm);
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Object[] objs = new Object[3];
            objs[0] = p1;
            objs[1] = p3;
            objs[2] = rect;
            pm.retrieveAll(objs);
            pm.makeTransientAll(objs);
            tx.commit();
            tx = null;
            checkP1();
            checkP3();
            checkRectP1();
            checkRectId();
        }
        finally {
            if ((tx != null) && tx.isActive())
                tx.rollback();
        }
    }
View Full Code Here

    }

    /** */
    private void runTestRetrieveAllWithArrayDFGtrue(PersistenceManager pm) {
        createObjects(pm);
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Object[] objs = new Object[3];
            objs[0] = p1;
            objs[1] = p3;
            objs[2] = rect;
            pm.retrieveAll(objs, true);
            pm.makeTransientAll(objs);
            tx.commit();
            tx = null;
            checkP1();
            checkP3();
            // checkRectP1(); p1 is not in the default fetch group by default
            checkRectId();
        }
        finally {
            if ((tx != null) && tx.isActive())
                tx.rollback();
        }
    }
View Full Code Here

    }

    /** */
    private void runTestRetrieveAllWithArrayDFGfalse(PersistenceManager pm) {
        createObjects(pm);
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Object[] objs = new Object[3];
            objs[0] = p1;
            objs[1] = p3;
            objs[2] = rect;
            pm.retrieveAll(objs, false);
            pm.makeTransientAll(objs);
            tx.commit();
            tx = null;
            checkP1();
            checkP3();
            checkRectP1();
            checkRectId();
        }
        finally {
            if ((tx != null) && tx.isActive())
                tx.rollback();
        }
    }
View Full Code Here

        }
    }

    /** */
    private void createObjects(PersistenceManager pm) {
        Transaction tx = pm.currentTransaction();
        try {
            tx.setRetainValues(false);
            tx.begin();
            p1   = new PCPoint(1,1);
            p1print = p1.toString();
            p2   = new PCPoint(2,2);
            p3   = new PCPoint2(3,3);
            rect = new PCRect(100, p1, p2);
            pm.makePersistent(p1);
            pm.makePersistent(p2);
            pm.makePersistent(p3);
            pm.makePersistent(rect);
            if (debug) {
                logger.debug("p1: " + p1.name());
                logger.debug("p2: " + p2.name());
                logger.debug("p3: " + p3.name());
                logger.debug("rect id: " + rect.getId() +
                             ", upperLeft: " + rect.getUpperLeft().name() +
                             ", lowerRight: " + rect.getLowerRight().name());
            }
            tx.commit();
            tx = null;
        }
        finally {
            if ((tx != null) && tx.isActive())
                tx.rollback();
        }
    }
View Full Code Here

     * Helper method retuning all Employee instances.
     * @param pm the PersistenceManager
     * @return a List including all persistent Employee instances
     */
    protected List getAllEmployees(PersistenceManager pm) {
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            List allEmployees = (List)pm.newQuery(Employee.class).execute();
            tx.commit();
            return allEmployees;
        } finally {
            if ((tx != null) && tx.isActive()) {
                tx.rollback();
            }
        }
    }
View Full Code Here

  private static final long serialVersionUID = 6120246852958797435L;

  public static SpadgerUser findSpadgerUser(String id) {
    SpadgerUser user = null;
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
      tx.begin();
      user = pm.getObjectById(SpadgerUser.class, id);
    } catch (JDOObjectNotFoundException e) {
      user = new SpadgerUser();
      user.id = id;
      user.email = id;
      user = pm.makePersistent(user);
      user = pm.detachCopy(user);
    } finally {
      tx.commit();
      pm.close();
    }
    return user;
  }
View Full Code Here

  public Count getCount(WorkoutContext con){
    PersistenceManagerFactory pmf = PMF.get();
    PersistenceManager pm = null;
    try{
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      Count c = null;
      try{
        tx.begin();
        try{
          c = pm.getObjectById(Count.class, ViewConstants.PRIMARYKEY_ID);
        }catch(Exception e){
          log.log(Level.INFO, "Count 取得中例外", e);
          c = new Count();
        }
        c.setTotal(c.getTotal() + 1);
        if(con.getKingOrSolderScore()>con.getScholarOrCraftsmanScore()){
          c.setKingOrSolder(c.getKingOrSolder() + 1);
          if(con.getKingScore()>con.getSolderScore()){
            c.setKing(c.getKing() + 1);
          }else if(con.getKingScore()<con.getSolderScore()){
            c.setSolder(c.getSolder() + 1);
          }
         
        }else if(con.getKingOrSolderScore()<con.getScholarOrCraftsmanScore()){
          c.setScholarOrCraftsman(c.getScholarOrCraftsman() + 1);
          if(con.getScholarScore()>con.getCraftsmanScore()){
            c.setScholar(c.getScholar() + 1);
          }else if(con.getScholarScore()<con.getCraftsmanScore()){
            c.setCraftsman(c.getCraftsman() + 1);
          }
        }
        pm.makePersistent(c);
       
        tx.commit();
        log.info("Count:" + c.toString());
        return c;
      }finally{
        if(tx.isActive()) tx.rollback();
      }
    }finally{
      if(pm!=null) pm.close();
    }
  }
View Full Code Here

 
  @SuppressWarnings("rawtypes")
  public static void deleteAll(Collection objectsToDelete)
  {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
      tx.begin();
      pm.deletePersistentAll(objectsToDelete);
      tx.commit();
     
      for(Object obj: objectsToDelete)
      {
        try{
        if (obj instanceof Keyed)
          CacheSupport.cacheDelete(((Keyed)obj).getKey());
        } catch(Exception e)
        {}
      }
    } catch(Exception e) {
      if (tx.isActive())
        tx.rollback();
      throw new RuntimeException(e);
    } finally {
      pm.close();
    }
    return;
View Full Code Here

  public Count getCount(){
    PersistenceManagerFactory pmf = PMF.get();
    PersistenceManager pm = null;
    try{
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      Count c = null;
      try{
        tx.begin();
        try{
          c = pm.getObjectById(Count.class, ViewConstants.PRIMARYKEY_ID);
        }catch(Exception e){
          log.log(Level.INFO, "Count 取得中例外", e);
          c = new Count();
        }
        tx.commit();
        log.info("Count:" + c.toString());
        return c;
      }finally{
        if(tx.isActive()) tx.rollback();
      }
    }finally{
      if(pm!=null) pm.close();
    }
  }
View Full Code Here

TOP

Related Classes of javax.jdo.Transaction

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.