Package com.google.appengine.api.datastore

Examples of com.google.appengine.api.datastore.Entity


  public boolean checkSubscriptionExists(String from, String to){
    Query q_from = new Query(ACCOUNT_KIND);
    q_from.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, from);
    q_from.setKeysOnly();
    PreparedQuery pq_from = datastore.prepare(q_from);
    Entity e_from = pq_from.asSingleEntity();
    Key from_key = e_from.getKey();
   
    Query q_to = new Query(ACCOUNT_KIND);
    q_to.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, to);
    q_to.setKeysOnly();
    PreparedQuery pq_to = datastore.prepare(q_to);
    Entity e_to = pq_to.asSingleEntity();
    Key to_key = e_to.getKey();
   
    Query sub_from = new Query(SUBSCRIPTION_KIND);
    sub_from.setAncestor(from_key);
    sub_from.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, to);
    sub_from.addFilter(SUBSCRIPTION_STATUS_PROPERTY, FilterOperator.EQUAL, SUBSCRIPTION_STATUS_ACTIVE);
View Full Code Here


  public boolean activateSubscription(String from, String to) {
    Query q_from = new Query(ACCOUNT_KIND);
    q_from.setKeysOnly();
    q_from.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, from);
    PreparedQuery from_key = datastore.prepare(q_from);
    Entity e_from = from_key.asSingleEntity();
    if(e_from == null)
      return false;
    Key key_from = e_from.getKey();
   
    Query q_to = new Query(ACCOUNT_KIND);
    q_to.setKeysOnly();
    q_to.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, to);
    PreparedQuery to_key = datastore.prepare(q_to);
    Entity e_to = to_key.asSingleEntity();
    if(e_to == null)
      return false;
    Key key_to = e_to.getKey();
   
   
    Query s_to = new Query(SUBSCRIPTION_KIND);
    s_to.setAncestor(key_to);
    s_to.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, from);
    PreparedQuery pq_to = datastore.prepare(s_to);
    Entity sub_to = pq_to.asSingleEntity();
    if(sub_to == null || !sub_to.getProperty(SUBSCRIPTION_STATUS_PROPERTY).equals(SUBSCRIPTION_STATUS_WAITING))
      return false;
    sub_to.setProperty(SUBSCRIPTION_STATUS_PROPERTY, SUBSCRIPTION_STATUS_ACTIVE);
   
    Query s_from = new Query(SUBSCRIPTION_KIND);
    s_from.setAncestor(key_from);
    s_from.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, to);
    PreparedQuery pq_from = datastore.prepare(s_from);
    Entity sub_from = pq_from.asSingleEntity();
    if(sub_from == null || !sub_from.getProperty(SUBSCRIPTION_STATUS_PROPERTY).equals(SUBSCRIPTION_STATUS_PENDING))
      return false;
    sub_from.setProperty(SUBSCRIPTION_STATUS_PROPERTY, SUBSCRIPTION_STATUS_ACTIVE);
    Transaction txn = datastore.beginTransaction();
    datastore.put(sub_to);
    datastore.put(sub_from);
    txn.commit();
    return true;
View Full Code Here

  public boolean declineSubscription(String from, String to){
    Query q_from = new Query(ACCOUNT_KIND);
    q_from.setKeysOnly();
    q_from.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, from);
    PreparedQuery from_key = datastore.prepare(q_from);
    Entity e_from = from_key.asSingleEntity();
    if(e_from == null)
      return false;
    Key key_from = e_from.getKey();
   
    Query q_to = new Query(ACCOUNT_KIND);
    q_to.setKeysOnly();
    q_to.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, to);
    PreparedQuery to_key = datastore.prepare(q_to);
    Entity e_to = to_key.asSingleEntity();
    if(e_to == null)
      return false;
    Key key_to = e_to.getKey();
   
   
    Query s_to = new Query(SUBSCRIPTION_KIND);
    s_to.setAncestor(key_to);
    s_to.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, from);
    s_to.setKeysOnly();
    PreparedQuery pq_to = datastore.prepare(s_to);
    Entity sub_to = pq_to.asSingleEntity();
    if(sub_to == null || !sub_to.getProperty(SUBSCRIPTION_STATUS_PROPERTY).equals(SUBSCRIPTION_STATUS_WAITING))
      return false;
   
    Query s_from = new Query(SUBSCRIPTION_KIND);
    s_from.setAncestor(key_from);
    s_from.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, to);
    s_from.setKeysOnly();
    PreparedQuery pq_from = datastore.prepare(s_from);
    Entity sub_from = pq_from.asSingleEntity();
    if(sub_from == null || !sub_from.getProperty(SUBSCRIPTION_STATUS_PROPERTY).equals(SUBSCRIPTION_STATUS_PENDING))
      return false;
    Transaction txn = datastore.beginTransaction();
    datastore.delete(sub_to.getKey());
    datastore.delete(sub_from.getKey());
    txn.commit();
    return true;
  }
View Full Code Here

    List<SubscriptionInformationObject> subl = new ArrayList<SubscriptionInformationObject>();
    Query key_query = new Query(ACCOUNT_KIND);
    key_query.setKeysOnly();
    key_query.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, user);
    PreparedQuery pq_key = datastore.prepare(key_query);
    Entity e_user = pq_key.asSingleEntity();
    if(e_user == null)
      return subl;
    Key key = e_user.getKey();
    Query q_sub = new Query(SUBSCRIPTION_KIND);
    q_sub.setAncestor(key);
    if(type.equalsIgnoreCase(SUBSCRIPTION_STATUS_WAITING) || type.equalsIgnoreCase(SUBSCRIPTION_STATUS_PENDING)) {
      q_sub.addFilter(SUBSCRIPTION_STATUS_PROPERTY, FilterOperator.NOT_EQUAL, SUBSCRIPTION_STATUS_ACTIVE);
      q_sub.addSort(SUBSCRIPTION_STATUS_PROPERTY, SortDirection.DESCENDING);
    }
    else if (type.equalsIgnoreCase(SUBSCRIPTION_STATUS_ACTIVE))
      q_sub.addFilter(SUBSCRIPTION_STATUS_PROPERTY, FilterOperator.EQUAL, SUBSCRIPTION_STATUS_ACTIVE);
    PreparedQuery pq = datastore.prepare(q_sub);
    List<Entity> entityList = pq.asList(FetchOptions.Builder.withDefaults());
    for(Iterator<Entity> i = entityList.iterator(); i.hasNext();){
      Entity e = i.next();
      String email = (String) e.getProperty(SUBSCRIPTION_EMAIL_PROPERTY);
      String status = (String) e.getProperty(SUBSCRIPTION_STATUS_PROPERTY);
      subl.add(new SubscriptionInformationObject(email,status));
    }
    return subl;
  }
View Full Code Here

  public boolean publishFeed(String email, String message){
    Query key_query = new Query(ACCOUNT_KIND);
    key_query.setKeysOnly();
    key_query.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, email);
    PreparedQuery pq_key = datastore.prepare(key_query);
    Entity e_from = pq_key.asSingleEntity();
    if(e_from == null)
      return false;
    Key key = e_from.getKey();
    Query q_sub = new Query(SUBSCRIPTION_KIND);
    q_sub.setAncestor(key);
    PreparedQuery pq = datastore.prepare(q_sub);
    List<Entity> entityList = pq.asList(FetchOptions.Builder.withDefaults());
    for(Iterator<Entity> i = entityList.iterator(); i.hasNext();){
      Entity e = i.next();
      String to_email = (String) e.getProperty(SUBSCRIPTION_EMAIL_PROPERTY);
      addFeed(to_email,email,message);
    }
    return true;
  }
View Full Code Here

  private boolean addFeed(String subscriber, String sender, String message){
    Query key_query = new Query(ACCOUNT_KIND);
    key_query.setKeysOnly();
    key_query.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, subscriber);
    PreparedQuery pq_key = datastore.prepare(key_query);
    Entity e_subscriber = pq_key.asSingleEntity();
    if(e_subscriber == null)
      return false;
    Key sub_key = e_subscriber.getKey();
    Query q_sub_sender = new Query(SUBSCRIPTION_KIND);
    q_sub_sender.setAncestor(sub_key);
    q_sub_sender.setKeysOnly();
    q_sub_sender.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, sender);
    q_sub_sender.addFilter(SUBSCRIPTION_STATUS_PROPERTY, FilterOperator.EQUAL, "Active");
    PreparedQuery pq_sender = datastore.prepare(q_sub_sender);
    Entity sender_entity = pq_sender.asSingleEntity();
    if(sender_entity == null)
      return false;
    Key sender_key = sender_entity.getKey();
    Transaction txn = datastore.beginTransaction();
    Entity sender_feed = new Entity(FEED_KIND, sender_key);
    sender_feed.setProperty(FEED_READ_STATUS_PROPERTY, false);
    sender_feed.setProperty(FEED_MESSAGE_PROPERTY, new Text(message));
    sender_feed.setProperty(FEED_TIMESTAMP_PROPERTY, new Date());
    datastore.put(sender_feed);
    txn.commit();
    return true;
  }
View Full Code Here

    List<SubscriptionFeedObject> feeds = new ArrayList<SubscriptionFeedObject>();
    Query q = new Query(ACCOUNT_KIND);
    q.setKeysOnly();
    q.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, email);
    PreparedQuery pq = datastore.prepare(q);
    Entity e = pq.asSingleEntity();
    if(e == null) {
      return feeds;
    }
    Key k = e.getKey();
    Query q_feed = new Query(FEED_KIND);
    q_feed.setAncestor(k);
    q_feed.addSort(FEED_TIMESTAMP_PROPERTY,SortDirection.DESCENDING);
    if(getUnreadOnly)
      q_feed.addFilter(FEED_READ_STATUS_PROPERTY, FilterOperator.EQUAL, false);
    PreparedQuery pq_feed = datastore.prepare(q_feed);
    List<Entity> entityList = pq_feed.asList(FetchOptions.Builder.withDefaults());
    for(Iterator<Entity> i = entityList.iterator(); i.hasNext();) {
      Entity e_feed = i.next();
      Text feed_message_t = (Text)e_feed.getProperty(FEED_MESSAGE_PROPERTY);
      String feed_message = feed_message_t.getValue();
      boolean feed_read = (Boolean)e_feed.getProperty(FEED_READ_STATUS_PROPERTY);
      Date feed_timestamp = (Date)e_feed.getProperty(FEED_TIMESTAMP_PROPERTY);
      feeds.add(new SubscriptionFeedObject(feed_read, feed_message, feed_timestamp));
      if(setRead) {
        e_feed.setProperty(FEED_READ_STATUS_PROPERTY, true);
        datastore.put(e_feed);
      }
       
    }
    return feeds;
View Full Code Here

    if (!checkWorklistItemExists(user, wio)) {
      Query q_user = new Query(ACCOUNT_KIND);
      q_user.setKeysOnly();
      q_user.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, user);
      PreparedQuery pq = datastore.prepare(q_user);
      Entity e_user = pq.asSingleEntity();
      if (e_user == null)
        return false;
      Key k = e_user.getKey();
      Transaction txn = datastore.beginTransaction();
      Entity e_wli = new Entity(WORKLIST_ITEM_KIND, k);
      e_wli.setProperty(WORKLIST_ITEM_DEPT_PROPERTY, wio.getDeptId());
      e_wli.setProperty(WORKLIST_ITEM_COURSE_PROPERTY, wio.getCourseId());
      e_wli.setProperty(WORKLIST_ITEM_SECTION_PROPERTY, wio.getSectionId());
      if(spiderDatastore.querySectionFromId( wio.getDeptId(), wio.getCourseId(),wio.getSectionId()) == null)
        return false;
      datastore.put(e_wli);
      txn.commit();
    } else
View Full Code Here

  public boolean checkWorklistItemExists(String user, WorklistItemObject wio){
    Query q_user = new Query(ACCOUNT_KIND);
    q_user.setKeysOnly();
    q_user.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, user);
    PreparedQuery pq = datastore.prepare(q_user);
    Entity e_user = pq.asSingleEntity();
    if(e_user == null)
      return false;
    Key k = e_user.getKey();
    Query q_wio = new Query(WORKLIST_ITEM_KIND);
    q_wio.setAncestor(k);
    q_wio.addFilter(WORKLIST_ITEM_DEPT_PROPERTY, FilterOperator.EQUAL, wio.getDeptId());
    q_wio.addFilter(WORKLIST_ITEM_COURSE_PROPERTY, FilterOperator.EQUAL, wio.getCourseId());
    q_wio.addFilter(WORKLIST_ITEM_SECTION_PROPERTY, FilterOperator.EQUAL, wio.getSectionId());
View Full Code Here

  public boolean deleteWorklistItem(String user, WorklistItemObject wio){
      Query q_user = new Query(ACCOUNT_KIND);
      q_user.setKeysOnly();
      q_user.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, user);
      PreparedQuery pq = datastore.prepare(q_user);
      Entity e_user = pq.asSingleEntity();
      if (e_user == null)
        return false;
      Key k = e_user.getKey();
      Query q_wio = new Query(WORKLIST_ITEM_KIND);
      q_wio.setAncestor(k);
      q_wio.setKeysOnly();
      q_wio.addFilter(WORKLIST_ITEM_DEPT_PROPERTY, FilterOperator.EQUAL, wio.getDeptId());
      q_wio.addFilter(WORKLIST_ITEM_COURSE_PROPERTY, FilterOperator.EQUAL, wio.getCourseId());
View Full Code Here

TOP

Related Classes of com.google.appengine.api.datastore.Entity

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.