Package javax.jdo

Examples of javax.jdo.PersistenceManager


            pm.close();
        }
    }
   
    public Photo readPhoto(Key key) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            return pm.getObjectById(Photo.class, key);
        } finally {
            pm.close();
        }
    }
View Full Code Here


        photo.setUserId(getUserId());
        photo.setModificationDate(new Date());
        if (photo.getAdditionDate() == null) {
            photo.setAdditionDate(new Date());
        }
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            return pm.makePersistent(photo);
        } catch (RuntimeException re) {
            throw re;
        } finally {
            pm.close();
        }
    }
View Full Code Here

            pm.close();
        }
    }
   
    public void deletePhoto(Photo photo) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.deletePersistent(photo);
        } finally {
            pm.close();
        }
    }
View Full Code Here

      if (userService.isUserAdmin()) {
      String user = userService.getCurrentUser().getEmail();
      if (req.getParameter("action") != null) {
        String action = req.getParameter("action");
        if (action.equalsIgnoreCase("flushTokens")) {
          PersistenceManager pm = PMF.get().getPersistenceManager();
          try {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.HOUR, -6);
            Query query = pm.newQuery(AuthenticationToken.class);
            query.setFilter("activity < activityParam");
            query.setRange(0, 1000);
            query.declareImports("import java.util.Date");
            query.declareParameters("Date activityParam");
            List<AuthenticationToken> objs = (List<AuthenticationToken>) query.execute(cal.getTime());
              long c = objs.size();
              for (AuthenticationToken obj : objs) {
              pm.deletePersistent(obj);
              }
              String msg = user + " - Flushed " + c + " tokens.";
              log.log(Level.INFO, msg);
              resp.getWriter().write(msg);
          } finally {
            pm.close();
          }
        } else if (action.equalsIgnoreCase("countTokens")) {
          PersistenceManager pm = PMF.get().getPersistenceManager();
          try {
            Query query = pm.newQuery(AuthenticationToken.class);
              List<AuthenticationToken> objs = (List<AuthenticationToken>) query.execute();
              int c = objs.size();
              String msg = user + " - There are " + c + " tokens.";
              log.log(Level.INFO, msg);
              resp.getWriter().write(msg);
          } finally {
            pm.close();
          }
        } else if (action.equalsIgnoreCase("countFlushTokens")) {
          PersistenceManager pm = PMF.get().getPersistenceManager();
          try {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.HOUR, -6);
            Query query = pm.newQuery(AuthenticationToken.class);
            query.setFilter("activity < activityParam");
            query.declareImports("import java.util.Date");
            query.declareParameters("Date activityParam");
            List<AuthenticationToken> objs = (List<AuthenticationToken>) query.execute(cal.getTime());
            int c = objs.size();
            String msg = user + " - There are " + c + " tokens to flush.";
          log.log(Level.INFO, msg);
            resp.getWriter().write(msg);
          } finally {
            pm.close();
          }
        }
      }
      }
    }
View Full Code Here

     *
     * @param purpose the certificate's purpose
     * @return the certificate associated with the specified purpose
     */
    public static Certificate getCertificate(String purpose) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Certificate cert = null;
      try {
        cert = pm.getObjectById(Certificate.class, purpose);
      }
      catch (JDOObjectNotFoundException e) { }
      finally {
        pm.close();
      }
      return cert;
    }
View Full Code Here

     * @param purpose the certificate's purpose
     * @param key the private key
     */
  public static void putCertificate(String purpose, String key) {
    try {
      PersistenceManager pm = PMF.get().getPersistenceManager();
        Certificate cert = new Certificate(purpose, key);
        pm.makePersistent(cert);
    } catch(Exception x) {
    }
  }
View Full Code Here

     *
     * @param activity the token's last activity
     */
    public void setActivity(Date activity) {
      this.activity = activity;
      PersistenceManager pm = PMF.get().getPersistenceManager();
      try {
      pm.makePersistent(this);
      } catch (JDOObjectNotFoundException e) {
      } finally {
        pm.close();
      }
    }
View Full Code Here

     *
     * @param email the user's email address
     * @return the Authentication Token, if any
     */
    public static AuthenticationToken getUserToken(String email) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      AuthenticationToken token = null;
      try {
        token = pm.getObjectById(AuthenticationToken.class, email);
      } catch (JDOObjectNotFoundException e) { }
      finally {
        pm.close();
      }
      return token;
    }
View Full Code Here

     * @param email the user's email address
     * @param token the AuthSub token
     * @return the new or updated Authentication Token
     */
    public static AuthenticationToken storeUserToken(String email, String token) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      AuthenticationToken at = null;
      try {
        try {
          at = pm.getObjectById(AuthenticationToken.class, email);
          at.setToken(token);
        }
        catch (JDOObjectNotFoundException e) {
          Cryptoid enc;
          String publicToken = token;
        try {
          enc = new Cryptoid();
            publicToken = enc.hash(email).replace("+", "_").replace("/", "-").replace("=", "_");
        } catch (Exception x) {
          Logger.getLogger(AuthenticationToken.class.getName()).log(Level.SEVERE, "Token encryption error: "  + x.getMessage(), x);
          x.printStackTrace();
        }
          at = new AuthenticationToken(email, token, publicToken, new Date(), new Date());
          pm.makePersistent(at);
        }
      } finally {
        pm.close();
      }
      return at;
    }
View Full Code Here

     * Clears a user token from the data store.
     *
     * @param email the user's email address
     */
    public static void clearUserToken(String email) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      AuthenticationToken token = null;
      try {
        token = pm.getObjectById(AuthenticationToken.class, email);
        pm.deletePersistent(token);
      }
      catch (JDOObjectNotFoundException e) { }
      finally {
        pm.close();
      }
    }
View Full Code Here

TOP

Related Classes of javax.jdo.PersistenceManager

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.