Package javax.jdo

Examples of javax.jdo.PersistenceManager


        BatchTestRunner.run(UnmodifiedSubqueryInstance.class);
    }

    /** */
    public void testPositive() throws Exception {
        PersistenceManager pm = getPM();
        runTestUnmodifiedSubquery(pm);
        runTestDifferentPM(pm);
    }
View Full Code Here


        String singleStringJDOQL =
            "SELECT FROM " + Employee.class.getName() + " WHERE this.weeklyhours > " +
            "(SELECT AVG(e.weeklyhours) FROM " + Employee.class.getName() + " e)";

        // create subquery instance using different pm
        PersistenceManager newPM =
            pm.getPersistenceManagerFactory().getPersistenceManager();
        Query sub = newPM.newQuery(Employee.class);
        sub.setResult("avg(this.weeklyhours)");

        Query apiQuery = pm.newQuery(Employee.class);
        apiQuery.setFilter("this.weeklyhours> averageWeeklyhours");
        apiQuery.addSubquery(sub, "double averageWeeklyhours", null);
View Full Code Here

      // First get the expired contracts that have not been archived yet
      // Get the prices and archive them
      query = "SELECT FROM " + Contract.class.getName() + " WHERE expiryDate>0 && archived==false ORDER BY expiryDate";
      print(query);
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Query q = pm.newQuery(query);
      Queue queue = QueueFactory.getDefaultQueue();
      @SuppressWarnings("unchecked")
      List<Contract> results = (List<Contract>) q.execute();
      print("Putting in queue for processing " + results.size() + " contracts.");
      for (Contract c : results) {
        String contractid = c.getId();
        // print("Adding contract "+contractid+
        // " in the queue. Will not archive.");
        queue.add(Builder.withUrl("/processContractClosingPrices").param("contract", contractid).param("archive", "y")
            .param("time_threshold_minutes", threshold.toString()).method(TaskOptions.Method.GET));
        queue.add(Builder.withUrl("/processContractTrades").param("contract", contractid)
            .param("time_threshold_minutes", "1").method(TaskOptions.Method.GET));
      }
      pm.close();

      // Now get the remaining active contracts (that have not been
      // archived yet)
      // Do no archive yet.

      long now = (new Date()).getTime();
      query = "SELECT FROM " + Contract.class.getName() + " WHERE laststoredCSV<" + (now - Contract.time_threshold())
          + " && expiryDate==0 && archived==false  ORDER BY laststoredCSV";
      print(query);
      pm = PMF.get().getPersistenceManager();
      q = pm.newQuery(query);

      @SuppressWarnings("unchecked")
      List<Contract> results_remaining = (List<Contract>) q.execute();

      print("Putting in queue for processing " + results_remaining.size() + " contracts.");
      for (Contract c : results_remaining) {
        String contractid = c.getId();
        // print("Adding contract "+contractid+
        // " in the queue. Will not archive.");
        queue.add(Builder.withUrl("/processContractClosingPrices").param("contract", contractid).param("archive", "n")
            .param("time_threshold_minutes", threshold.toString()).method(TaskOptions.Method.GET));
        queue.add(Builder.withUrl("/processContractTrades").param("contract", contractid)
            .param("time_threshold_minutes", "1").method(TaskOptions.Method.GET));
      }
      pm.close();

      print("Done!");

    } catch (com.google.apphosting.api.DeadlineExceededException e) {
      print("Reached execution time limit. Press refresh to continue.");
View Full Code Here

    doGet(req, resp);
  }

  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    PersistenceManager pm = null;
    try {
      this.r = resp;

      resp.setContentType("text/plain");

      String t = req.getParameter("time_threshold_minutes");
      if (t != null) {
        try {
          int i = Integer.parseInt(t);
          ProcessEventClass.time_threshold_minutes = i;
        } catch (Exception e) {
          ;
        }
      }

      String eventclass = req.getParameter("eventclass");
      if (eventclass != null) {
        resp.getWriter().println("Processing event class " + eventclass);
      } else {
        resp.getWriter().println("No class specified");
        return;
      }
      String u = req.getParameter("url");
      if (u != null) {
        try {
          URL param = new URL(u);
          url = param.toString();
        } catch (Exception e) {

        }
      }

      pm = PMF.get().getPersistenceManager();

      MarketXML m = null;
      try {
        m = pm.getObjectById(MarketXML.class, MarketXML.generateKeyFromID(url));
      } catch (Exception e) {
        m = null;
      }
      if (m != null) {
        //System.out.println(m.getURL());
        Document d = m.getXML();
        NodeList n = d.getElementsByTagName("EventClass");
        for (int i = 0; i < n.getLength(); i++) {
          Node nd = n.item(i);
          String event_id = nd.getAttributes().getNamedItem("id").getNodeValue();

          if (!event_id.equals(eventclass)) {
            continue;
          }
          storeEventClass(nd);
        }
      } else {
        // ... no results ...
      }

      pm.close();

    } catch (com.google.apphosting.api.DeadlineExceededException e) {
      print("Reached execution time limit. Press refresh to continue.");

    } finally {
      if (pm != null && !pm.isClosed()) {
        pm.close();
      }
    }

  }
View Full Code Here

  }

  private long lastRetrieved_eventclass(String event_id) {

    EventClass eventclass = null;
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      eventclass = pm.getObjectById(EventClass.class, EventClass.generateKeyFromID(event_id));
    } catch (Exception e) {
      eventclass = null;
    }
    pm.close();
    return (eventclass == null) ? 0 : eventclass.getLastretrieved();
  }
View Full Code Here

    EventClass ec = new EventClass(eventclass_id, event_name, event_displayorder);
    ec.setLastretrieved(now);
    print("Storing:" + ec.toString());

    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistent(ec);
    pm.close();

    return;

  }
View Full Code Here

  private HttpServletResponse  r;

  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    PersistenceManager pm = null;
    try {
      this.r = resp;

      resp.setContentType("text/plain");

      String t = req.getParameter("time_threshold_minutes");
      if (t != null) {
        try {
          int i = Integer.parseInt(t);
          StoreContracts.time_threshold_minutes = i;
        } catch (Exception e) {
          ;
        }
      }

      String eventclass = req.getParameter("eventclass");

      if (eventclass != null) {
        resp.getWriter().println("Processing class " + eventclass);
      }

      String eventgroup = req.getParameter("eventgroup");
      if (eventgroup != null) {
        resp.getWriter().println("Processing group " + eventgroup);
      }
      // Do not process the financial contracts for Dow Jones. We do not need
      // prediction markets for financial events. They are too many in any case and add needless load
      if (eventgroup.equals("4409")) { // 4409 is the Dow Jones code on Intrade
        resp.getWriter().println("We skip the Dow Jones contracts.");
        return;
      }

      String u = req.getParameter("url");
      if (u != null) {
        try {
          URL param = new URL(u);
          url = param.toString();
        } catch (Exception e) {

        }
      }

      pm = PMF.get().getPersistenceManager();

      MarketXML m = null;
      try {
        m = pm.getObjectById(MarketXML.class, MarketXML.generateKeyFromID(url));
      } catch (Exception e) {
        m = null;
      }
      if (m != null) {
        System.out.println(m.getURL());
        Document d = m.getXML();
        NodeList n = d.getElementsByTagName("EventClass");
        for (int i = 0; i < n.getLength(); i++) {
          Node nd = n.item(i);
          storeEventClasses(nd, eventclass, eventgroup);
        }
      } else {
        // ... no results ...
      }

      pm.close();

    } catch (com.google.apphosting.api.DeadlineExceededException e) {
      print("Reached execution time limit. Press refresh to continue.");

    } finally {
      if (pm != null && !pm.isClosed()) {
        pm.close();
      }
    }

  }
View Full Code Here

    this.targetTotalTime = targetTotalTime;
  }

  @SuppressWarnings("unchecked")
  public static Config getConfig() throws IOException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      String query = "select from " + Config.class.getName();
      List<Config> configs = (List<Config>) pm.newQuery(query).execute();
      if (configs.size() > 0) {
        Config config = configs.get(0);
        return pm.detachCopy(config);
      }
    } catch (Exception e) {
      throw new IOException("Error loading config", e);
    } finally {
      try {
        pm.close();
      } catch (Exception e) {
        log.severe(e.toString());
      }
    }
View Full Code Here

    // fallback - no config ?
    return new Config();
  }

  public void save() throws IOException {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      // save this
      pm.makePersistent(this);
    } finally {
      try {
        pm.close();
      } catch (Exception e) {
        log.severe(e.toString());
      }
    }
  }
View Full Code Here

    String id = args.get("id");
    String link = args.get("link");
   
    BlogManager blogManager = BlogManager.getInstance();
    DataManager dataManager = DataManagerFactory.getInstance();
    PersistenceManager pm = dataManager.newPersistenceManager();
   
    //get user
    User user = dataManager.getUserFromId(pm , id);
   
    //check if blog exists
    Blog blog = blogManager.getOrCreateSource(link);
   
    if (blog == null){
      //blog not found or not avaiable
      TalkService.sendMessage(user.getId(),"blog not found ! :(");
      return;
    }
   
    //check subscription
    Subscription sub = dataManager.getSubscription(pm , user, blog);
   
    //create new subscription
    if (sub == null){
      sub = new Subscription();
      sub.setBlogKey(blog.getKey());
      sub.setPriority(0);
      sub.setUserKey(user.getKey());
      sub.setLastProcessDate(new Date());
      sub.setLatestEntryNotifiedDate(new Date());
     
      pm.currentTransaction().begin();
      pm.makePersistent(sub);
      pm.currentTransaction().commit();

      TalkService.sendMessage(user.getId(),"source added ! :)");
      //update cache
      SubscriptionCache.removeUserFromCache(user.getId());
    } else {
      TalkService.sendMessage(user.getId(),"already subscribed");
    }
   
    pm.close();
    pm = null;
   
  }
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.