Example #1
0
  @Override
  public ArrayList<ProductDTO> getProducts() throws NotLoggedInException {
    List<Product> products = new ArrayList<Product>();
    ArrayList<ProductDTO> productsDTO = new ArrayList<ProductDTO>();

    PersistenceManager pm = getPersistenceManager();
    try {
      Query q = pm.newQuery(Product.class);
      products = (List<Product>) q.execute();
      for (Product productItem : products) {

        CategoryDTO categoryDTO = getCategoryForCombo(productItem.getCategoryid());

        ProductDTO productDTO =
            new ProductDTO(
                productItem.getId(),
                productItem.getName(),
                productItem.getPrice(),
                productItem.getDescription(),
                productItem.getDetalle(),
                productItem.getImage(),
                productItem.getImageCarrito(),
                categoryDTO);
        productsDTO.add(productDTO);
      }
    } finally {
      pm.close();
    }
    return productsDTO;
  }
Example #2
0
  /**
   * Demonstrates how to use the cursor to be able to pass over an complete set of data
   *
   * @param pm Persistence manager instance to use - let open at the end to allow possible object
   *     updates later
   * @param cursorString Representation of a cursor, to be used to get the next set of data to
   *     process
   * @param range Number of data to process at this particular stage
   * @param defaultSource Value to apply to any Demand instance without a default value
   * @return New representation of the cursor, ready for a next process call
   */
  @SuppressWarnings("unchecked")
  public static String updateSource(
      PersistenceManager pm, String cursorString, int range, Source defaultSource) {

    Query query = null;
    try {
      query = pm.newQuery(Demand.class);
      if (cursorString != null) {
        Map<String, Object> extensionMap = new HashMap<String, Object>();
        extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, Cursor.fromWebSafeString(cursorString));
        query.setExtensions(extensionMap);
      }
      query.setRange(0, range);
      List<Demand> results = (List<Demand>) query.execute();
      if (results.iterator().hasNext()) {
        for (Demand demand : results) {
          // Initialize the new field if necessary. By checking first that the field is null, we
          // allow this migration to be safely run multiple times.
          if (demand.getSource() == null) {
            demand.setSource(defaultSource);
            pm.makePersistent(demand);
          }
        }
        cursorString = JDOCursorHelper.getCursor(results).toWebSafeString();
      } else {
        // no results
        cursorString = null;
      }
    } finally {
      query.closeAll();
    }
    return cursorString;
  }
 protected void HandleRequest(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   PersistenceManager pm = PMF.getManager();
   Query query = pm.newQuery(MediumData.class);
   query.deletePersistentAll();
   response.getWriter().format("table.medium deleteAll %s", new Object[] {ActionStatus.SUCCESS});
 }
  public void testMbrTouches() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
      return;
    }

    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
      tx.begin();
      Point point = (Point) wktReader.read("POINT(75 75)");
      Query query =
          pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrTouches(:point, geom)");
      List list = (List) query.execute(point);
      assertEquals(
          "Wrong number of geometries which are touched by a given point returned", 2, list.size());
      assertTrue(
          "Polygon 1 should be in the list of geometries which are touched by a given point",
          list.contains(getSamplePolygon(1)));
      assertTrue(
          "Polygon 2 should be in the list of geometries which are touched by a given point",
          list.contains(getSamplePolygon(2)));
    } finally {
      tx.commit();
    }
  }
Example #5
0
  public static Admin getByUserId(String aUserId, long surveyId) {
    PersistenceManager pm = null;
    Admin result = null;
    List<Admin> results = null;
    try {
      pm = PMF.get().getPersistenceManager();
      Query query = null;
      try {
        query = pm.newQuery(Admin.class);
        query.setFilter("userIdLowerCase==userIdLowerCaseParam && surveyId==surveyIdParam");
        query.declareParameters("String userIdLowerCaseParam, Long surveyIdParam");

        results = (List<Admin>) query.execute(aUserId.toLowerCase(), surveyId);

        // Touch object to get data.  Size method triggers the underlying database call.
        results.size();
      } finally {
        if (query != null) {
          query.closeAll();
        }
      }
    } finally {
      if (pm != null) {
        pm.close();
      }
    }

    if (results != null && !results.isEmpty()) {
      result = results.get(0);
    }

    return result;
  }
  public void testMbrEqual() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
      return;
    }

    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
      tx.begin();
      Polygon polygon =
          (Polygon)
              wktReader.read(
                  "POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
      Query query =
          pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrEqual(geom, :polygon)");
      List list = (List) query.execute(polygon);
      assertEquals(
          "Wrong number of geometries which are equal to a given polygon returned", 1, list.size());
      assertTrue(
          "Polygon 1 should be in the list of geometries which are equal to a given polygon",
          list.contains(getSamplePolygon(1)));
    } finally {
      tx.commit();
    }
  }
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String email = req.getParameter("email");
    String name = req.getParameter("name");
    String pwd = req.getParameter("pwd");
    String repwd = req.getParameter("repwd");
    PersistenceManager p = PMF.get().getPersistenceManager();
    Query q = p.newQuery(Users.class);
    q.setFilter("email == '" + email + "'");
    //	q.setFilter("email == '"+uname+"' && password == '"+passwd+"'");

    List<Users> exists = (List<Users>) q.execute();
    if (exists.isEmpty()) {
      try {
        System.out.println("inside try");

        /*req.getRequestDispatcher("/signup").forward(req, resp);*/
        resp.getWriter().write("sucess");
      } catch (Exception e) {
        System.out.println(e);
      }
    } else {
      System.out.println("inside else");
      System.out.println(email);
      resp.getWriter().write(email);
    }
  }
Example #8
0
  /**
   * searches for users that match the non-null params
   *
   * @return
   */
  @SuppressWarnings("unchecked")
  public List<User> searchUser(
      String username,
      String emailAddress,
      String orderByField,
      String orderByDir,
      String cursorString) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(User.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();

    appendNonNullParam("userName", filterString, paramString, "String", username, paramMap);
    appendNonNullParam("emailAddress", filterString, paramString, "String", emailAddress, paramMap);

    if (orderByField != null) {
      String ordering = orderByDir;
      if (ordering == null) {
        ordering = "asc";
      }
      query.setOrdering(orderByField + " " + ordering);
    }
    if (filterString.length() > 0) {
      query.setFilter(filterString.toString());
      query.declareParameters(paramString.toString());
    }

    prepareCursor(cursorString, query);
    List<User> results = (List<User>) query.executeWithMap(paramMap);
    return results;
  }
  private Query createQuery(boolean forCount) {
    Expression<?> source = getSource();

    // serialize
    JDOQLSerializer serializer = new JDOQLSerializer(getTemplates(), source);
    serializer.serialize(queryMixin.getMetadata(), forCount, false);

    logQuery(serializer.toString());

    // create Query
    Query query = persistenceManager.newQuery(serializer.toString());
    orderedConstants = serializer.getConstants();
    queries.add(query);

    if (!forCount) {
      List<? extends Expression<?>> projection = queryMixin.getMetadata().getProjection();
      Class<?> exprType = projection.get(0).getClass();
      if (exprType.equals(QTuple.class)) {
        query.setResultClass(JDOTuple.class);
      } else if (FactoryExpression.class.isAssignableFrom(exprType)) {
        query.setResultClass(projection.get(0).getType());
      }

      if (!fetchGroups.isEmpty()) {
        query.getFetchPlan().setGroups(fetchGroups);
      }
      if (maxFetchDepth != null) {
        query.getFetchPlan().setMaxFetchDepth(maxFetchDepth);
      }
    }

    return query;
  }
Example #10
0
  /**
   * Get a User {@link Key} for a facebook id
   *
   * @param facebookId
   * @return the user {@link Key} or null
   */
  @SuppressWarnings("unchecked")
  public static Key getUserForFacebookId(String facebookId) {

    // check if APIKey -> TDUser Key found in cache
    if (MemcacheServiceFactory.getMemcacheService().contains(facebookId)) {
      // if so, return from cache
      return (Key) MemcacheServiceFactory.getMemcacheService().get(facebookId);
    } else {
      // query for matching user
      final String queryString = "SELECT key FROM " + TDUser.class.getName();
      final Query q = PMF.get().getPersistenceManager().newQuery(queryString);
      q.setFilter("facebookId == :p");
      q.setRange("0,1");

      final List<Key> keys = (List<Key>) q.execute(facebookId);

      final Key result = (keys.size() > 0 ? keys.get(0) : null);

      if (null != result) {
        // put ApiKey -> TDUser Key map in cache
        MemcacheServiceFactory.getMemcacheService().put(facebookId, result);
      }

      // return the found key
      return result;
    }
  }
Example #11
0
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    Long orderId = Long.parseLong(req.getParameter("orderid"));
    Status status = Status.valueOf(req.getParameter("status"));

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (AdminAuthenticator.isAdmin(user)) {

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

      String select_query = "select from " + Order.class.getName();
      Query query = pm.newQuery(select_query);
      query.setFilter("id == paramId");
      query.declareParameters("java.lang.Long paramId");
      // execute
      List<Order> orders = (List<Order>) query.execute(orderId);

      if (!orders.isEmpty()) {
        // should be only one - safety check here
        Order order = orders.get(0);
        order.setStatus(status);
        pm.close();
        res.sendRedirect("/home.html");
      }
    }
  }
 @RequestMapping(value = "/resetforgotpassword", method = RequestMethod.POST)
 public String resetforgotPassword(HttpServletRequest request, ModelMap model) {
   String email = HtmlUtils.htmlEscape(request.getParameter("email"));
   if (email != null) {
     String userid = email;
     String password = HtmlUtils.htmlEscape(request.getParameter("password"));
     PersistenceManager pm = PMF.get().getPersistenceManager();
     Query q = pm.newQuery(User.class);
     q.setFilter("email==userid");
     q.declareParameters("String userid");
     List<User> result = (List<User>) q.execute(userid);
     try {
       User c = pm.getObjectById(User.class, result.get(0).getUserId());
       c.setPassword(password);
       model.addAttribute("registered", "Password reset successfully, Login now !!");
       model.addAttribute("subCategoryList", categoryDao.getSubCategoryList());
     } finally {
       pm.close();
     }
     return "login";
   } else {
     model.addAttribute("subCategoryList", categoryDao.getSubCategoryList());
     return "login";
   }
 }
Example #13
0
  public OGRFeature findByCountryTypeAndSub(
      String countryCode, String name, FeatureType featureType, ArrayList<String> subArray) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(OGRFeature.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();

    appendNonNullParam(
        "featureType", filterString, paramString, "String", featureType, paramMap, EQ_OP);
    appendNonNullParam("name", filterString, paramString, "String", name, paramMap, EQ_OP);
    appendNonNullParam(
        "countryCode", filterString, paramString, "String", countryCode, paramMap, EQ_OP);
    for (int i = 1; i < subArray.size() + 1; i++) {
      appendNonNullParam(
          "sub" + i, filterString, paramString, "String", subArray.get(i - 1), paramMap, EQ_OP);
    }

    query.setFilter(filterString.toString());
    query.declareParameters(paramString.toString());

    @SuppressWarnings("unchecked")
    List<OGRFeature> results = (List<OGRFeature>) query.executeWithMap(paramMap);
    if (results != null && results.size() > 0) return results.get(0);
    else return null;
  }
Example #14
0
  @SuppressWarnings("unchecked")
  public List<OGRFeature> listByCountryAndType(
      String countryCode, FeatureType featureType, String cursorString) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(OGRFeature.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();

    appendNonNullParam(
        "featureType", filterString, paramString, "String", featureType, paramMap, EQ_OP);
    appendNonNullParam(
        "countryCode", filterString, paramString, "String", countryCode, paramMap, EQ_OP);

    query.setFilter(filterString.toString());
    query.declareParameters(paramString.toString());

    prepareCursor(cursorString, query);
    List<OGRFeature> results = (List<OGRFeature>) query.executeWithMap(paramMap);

    if (results != null && results.size() > 0) {
      return results;
    } else {
      return null;
    }
  }
Example #15
0
 public static List<?> getList(
     Class<?> cls, String ordering, int start, int stop, PersistenceManager pm) {
   Query query = pm.newQuery(cls);
   query.setOrdering(ordering);
   query.setRange(start, stop);
   return (List<?>) query.execute();
 }
  public void testUnencodedLongPk_BatchGet() throws EntityNotFoundException {
    switchDatasource(PersistenceManagerFactoryName.nontransactional);
    HasLongPkJDO pojo = new HasLongPkJDO();
    beginTxn();
    pojo.setId(1L);
    pm.makePersistent(pojo);
    commitTxn();

    HasLongPkJDO pojo2 = new HasLongPkJDO();
    beginTxn();
    pojo2.setId(2L);
    pm.makePersistent(pojo2);
    commitTxn();

    assertNotNull(pojo.getId());
    assertNotNull(pojo2.getId());

    beginTxn();
    Query q = pm.newQuery("select from " + HasLongPkJDO.class.getName() + " where id == :ids");
    List<HasLongPkJDO> pojos =
        (List<HasLongPkJDO>) q.execute(Utils.newArrayList(pojo.getId(), pojo2.getId()));
    assertEquals(2, pojos.size());
    // we should preserve order but right now we don't
    Set<Long> pks = Utils.newHashSet(pojos.get(0).getId(), pojos.get(1).getId());
    assertEquals(pks, Utils.newHashSet(1L, 2L));
    commitTxn();
  }
Example #17
0
  @SuppressWarnings("unchecked")
  public List<OGRFeature> listBySubLevelCountry(
      String countryCode, Integer subLevel, String cursorString) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(OGRFeature.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();
    appendNonNullParam(
        "countryCode", filterString, paramString, "String", countryCode, paramMap, EQ_OP);
    appendNonNullParam(
        "featureType",
        filterString,
        paramString,
        "String",
        FeatureType.SUB_COUNTRY_OTHER,
        paramMap,
        EQ_OP);
    appendNonNullParam(
        "sub" + (subLevel), filterString, paramString, "String", "null", paramMap, NOT_EQ_OP);
    appendNonNullParam(
        "sub" + (subLevel + 1), filterString, paramString, "String", "null", paramMap, EQ_OP);
    query.setFilter(filterString.toString());
    query.declareParameters(paramString.toString());

    prepareCursor(cursorString, query);

    List<OGRFeature> resultsGTE = (List<OGRFeature>) query.executeWithMap(paramMap);

    return resultsGTE;
  }
Example #18
0
  /**
   * gets all translations for a given id and parentType combination. The map returned is keyed on
   * language code.
   *
   * @param parentType
   * @param parentId
   * @return
   */
  @SuppressWarnings("unchecked")
  public HashMap<String, Translation> findTranslations(
      Translation.ParentType parentType, Long parentId) {
    PersistenceManager pm = PersistenceFilter.getManager();
    javax.jdo.Query query = pm.newQuery(Translation.class);
    StringBuilder filterString = new StringBuilder();
    StringBuilder paramString = new StringBuilder();
    Map<String, Object> paramMap = null;
    paramMap = new HashMap<String, Object>();

    appendNonNullParam("parentType", filterString, paramString, "String", parentType, paramMap);
    appendNonNullParam("parentId", filterString, paramString, "Long", parentId, paramMap);

    query.setFilter(filterString.toString());
    query.declareParameters(paramString.toString());

    HashMap<String, Translation> translations = new HashMap<String, Translation>();
    List<Translation> translationList = (List<Translation>) query.executeWithMap(paramMap);
    if (translationList != null) {
      for (Translation t : translationList) {
        translations.put(t.getLanguageCode(), t);
      }
    }
    return translations;
  }
Example #19
0
 private User getUser(String login, String password) {
   PersistenceManager manager = null;
   Transaction transaction = null;
   List<User> users = null;
   try {
     manager = PMF.newInstance().getPersistenceManager();
     transaction = manager.currentTransaction();
     transaction.begin();
     Query query = manager.newQuery(User.class);
     users = (List<User>) query.execute();
     transaction.commit();
   } catch (Exception e) {
     if (transaction != null) {
       transaction.rollback();
     }
   } finally {
     manager.close();
   }
   if (users != null && !users.isEmpty()) {
     for (User u : users) {
       System.out.println(u.getLogin() + " : " + u.getPassword());
       if (login.equals(u.getLogin()) && password.equals(u.getPassword())) {
         System.out.println(u.getLogin() + " : " + u.getPassword());
         return u;
       }
     }
   }
   return null;
 }
Example #20
0
 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
   HttpSession session = req.getSession();
   PersistenceManager p = PMF.get().getPersistenceManager();
   String date = req.getParameter("Value");
   Query q1 = p.newQuery(Schedule.class);
   q1.setFilter("email == '" + session.getAttribute("emailid") + "' &&date == '" + date + "'");
   q1.setOrdering("listName asc");
   // System.out.println(session.getAttribute("emailid"));
   List<Schedule> schedule = (List<Schedule>) q1.execute();
   /*String json = new Gson().toJson(contents);*/
   ObjectMapper n = new ObjectMapper();
   String json = n.writeValueAsString(schedule);
   System.out.println(json);
   resp.setContentType("application/json");
   resp.setCharacterEncoding("UTF-8");
   resp.getWriter().write(json.toString());
   /*resp.getWriter().write(contents.toString());*/
   /*if (!contents.isEmpty()) {
       for (Content cont : contents) {
   	    String listname = cont.getListname();
   	    String listcontent = cont.getContent();
   	    String listdate = cont.getDate();
   	    resp.getWriter().write(listname);
   	    resp.getWriter().write(listcontent);
       }
   }*/
 }
Example #21
0
  @SuppressWarnings("unchecked")
  @ApiMethod(name = "userinfos.phone.test", path = "user_info_phone_test", httpMethod = "post")
  public UserInfo phoneTest(UserInfo userInfo) {
    // check if there is another user using same phone number
    PersistenceManager pm = PMF.getPersistenceManagerSQL();
    Query query = pm.newQuery(UserInfo.class);
    query.setFilter("phone == thePhone");
    query.declareParameters("String thePhone");
    List<UserInfo> userInfos = (List<UserInfo>) pm.newQuery(query).execute(userInfo.getPhone());

    // phone number already taken
    if (!userInfos.isEmpty()) return userInfo;

    try {
      String verNumber = getVerNumberString();
      sendVerNumber(userInfo.getPhone(), verNumber);

      // save verification code and phone number in verCode field together
      userInfo.setVerificationCode(verNumber + userInfo.getPhone());
      userInfo.setPhone("");
      update(userInfo);

      // erase verCode field before send back to the user
      userInfo.setVerificationCode("");
    } catch (TwilioRestException e) { // failed to send code message
    }

    return userInfo;
  }
Example #22
0
  private void persistNewsData(NodeList titles, NodeList links, NodeList descriptions) {
    // Persists news data feed.
    // Also clears out previously persisted news feed data

    PersistenceManager pm = PMF.get().getPersistenceManager();
    javax.jdo.Query query = pm.newQuery(NewsItem.class);
    Long res = query.deletePersistentAll();

    System.out.println("Datastore deleted  " + res + "records");

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

    try {
      for (int i = 1; i < titles.getLength(); i++) {
        NewsItem ni = new NewsItem();
        ni.setTitle(titles.item(i).getTextContent());
        ni.setLink(links.item(i).getTextContent());
        if (descriptions.item(i) != null) {
          ni.setDescription(new Text(descriptions.item(i).getTextContent()));
        }
        pm.makePersistent(ni);
      }
    } finally {
      pm.close();
    }
  }
Example #23
0
  /**
   * Gives friend (friendid) permission to given target to user's (uid) data
   *
   * @param pm
   * @param uid
   * @param friendid
   * @param target
   * @return
   */
  @SuppressWarnings("unchecked")
  public static boolean addUserToCircle(
      PersistenceManager pm, String uid, String friendid, int target) {

    if (logger.isLoggable(Level.FINER)) {
      logger.log(
          Level.FINER,
          "Adding user to circle: uid=" + uid + ", friendid=" + friendid + ", target=" + target);
    }

    boolean ok = true;

    // check if permission already found
    Query q = pm.newQuery(Circle.class);
    q.setFilter("openId == openIdParam && friendId == friendIdParam && target == targetParam");
    q.declareParameters(
        "java.lang.String openIdParam, java.lang.String friendIdParam, java.lang.Integer targetParam");
    q.setRange(0, 1);
    List<Circle> list = (List<Circle>) q.execute(uid, friendid, target);

    // if no previous permissions found
    if (list.size() != 0) {
      pm.deletePersistent(list.get(0));
      ok = true;
    }

    // remove users from cache
    // TODO needs improving
    WeekCache cache = new WeekCache();
    cache.removeUsers();

    return ok;
  }
Example #24
0
  /**
   * Searches for {@link Dish}es belonging to a {@link Restauarnt} using the supplied search terms
   *
   * @param queryWords terms to search with
   * @param restKey {@link Key} to the {@link Restaurant} to search within
   * @param maxResults maximum number of results to return
   * @return {@link Collection} of {@link Dish}es
   */
  @SuppressWarnings("unchecked")
  public static Set<Dish> searchDishesByRestaurant(
      String[] queryWords, Key restKey, int maxResults) {
    List<Object> paramList = null;
    String paramS = "";
    String queryS = "";
    final String queryString = "SELECT key FROM " + Dish.class.getName();
    final Query q = PMF.get().getPersistenceManager().newQuery(queryString);

    if (queryWords.length > 0) {
      paramList = new ArrayList<Object>();
      queryS += "restaurant == restParam";
      paramS = Key.class.getName() + " restParam";
      paramList.add(restKey);

      for (int i = 0; i < queryWords.length; i++) {
        queryS += " && searchTerms.contains(s" + i + ")";
        paramS += ", String s" + i;
        paramList.add(queryWords[i]);
      }

      q.setFilter(queryS);
      q.declareParameters(paramS);

      return Datastore.get(new HashSet<Key>((List<Key>) q.executeWithArray(paramList.toArray())));
    }

    return new HashSet<Dish>();
  }
Example #25
0
 @Override
 @Transactional(readOnly = true)
 public Collection<Pin> getPins(PnfsId pnfsId) {
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class, "_pnfsId == :pnfsId");
   Collection<Pin> pins = (Collection<Pin>) query.execute(pnfsId.toString());
   return pm.detachCopyAll(pins);
 }
Example #26
0
 @SuppressWarnings("unchecked")
 public static Opinion loadOpinion(Long user_id, Long restaurant_id, PersistenceManager pm) {
   Query query = pm.newQuery(Opinion.class, "user_id == :uu && restaurant_id == :oo");
   List<Opinion> tmp = (List<Opinion>) query.execute(user_id, restaurant_id);
   Opinion rv = tmp != null && tmp.size() > 0 ? tmp.get(0) : null;
   query.closeAll();
   return rv;
 }
Example #27
0
 @SuppressWarnings("unchecked")
 public static boolean opinionExists(Long user_id, Long restaurant_id, PersistenceManager pm) {
   Query query = pm.newQuery(User.class, "user_id == :uu && restaurant_id == :oo");
   List<User> tmp = (List<User>) query.execute(user_id, restaurant_id);
   boolean rv = tmp != null && tmp.size() > 0;
   query.closeAll();
   return rv;
 }
Example #28
0
  /**
   * Gets {@link Key}s of all the {@link Dish}es at a {@link Restaurant}
   *
   * @param restKey {@link Key} of the {@link Restaurant}
   * @return {@link Collection} of {@link Key} objects
   */
  @SuppressWarnings("unchecked")
  public static Collection<Key> getDishKeysByRestaurant(Key restKey) {
    String query = "SELECT key FROM " + Dish.class.getName();
    Query q = PMF.get().getPersistenceManager().newQuery(query);
    q.setFilter("restaurant == :param");

    return (Collection<Key>) q.execute(restKey);
  }
Example #29
0
  private List<FeedbackSession> getFeedbackSessionEntitiesForCourses(List<String> courseIds) {
    Query q = getPM().newQuery(FeedbackSession.class);
    q.setFilter(":p.contains(courseId)");

    @SuppressWarnings("unchecked")
    List<FeedbackSession> feedbackSessionList = (List<FeedbackSession>) q.execute(courseIds);
    return feedbackSessionList;
  }
Example #30
0
 @Override
 @Transactional(readOnly = true)
 public Collection<Pin> getPins() {
   PersistenceManager pm = _pmf.getPersistenceManager();
   Query query = pm.newQuery(Pin.class);
   Collection<Pin> pins = (Collection<Pin>) query.execute();
   return pm.detachCopyAll(pins);
 }