Package com.google.appengine.api.datastore

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


      datastore.delete(it.next().getKey());
   
  }
 
  public static QueryResultIterator<Entity> getAll(){
    Query q = new Query(ENTRY_KIND);
    PreparedQuery pq = datastore.prepare(q);
    return pq.asQueryResultIterator();
  }
View Full Code Here


    datastore=DatastoreServiceFactory.getDatastoreService();
    initSchema();
  }

  public void initSchema(){
    Query q = new Query(DATASTORE_ENTITY_SET_NAME);
    q.setKeysOnly();
    if(datastore.prepare(q).asSingleEntity() == null) {
      Transaction txn = datastore.beginTransaction();   
      Entity e = new Entity(DATASTORE_ENTITY_SET_NAME, DATASTORE_ENTITY_KEY_NAME);
      datastore.put(e);
      txn.commit();
View Full Code Here

    }
  }

 
  public void traceSchema() {
    Query q = new Query();
    Key k = KeyFactory.createKey(DATASTORE_ENTITY_SET_NAME, DATASTORE_ENTITY_KEY_NAME);
    q.setAncestor(k);
    q.setKeysOnly();
    List<Entity> l = datastore.prepare(q).asList(
        FetchOptions.Builder.withDefaults());
    for (Iterator i = l.iterator(); i.hasNext();) {
      Entity e = (Entity) i.next();
      System.out.println(e.getKey().toString());
View Full Code Here

      System.out.println(e.getKey().toString());
    }
  }
 
  public void dropSchema() {
    Query q = new Query();
    Key k = KeyFactory.createKey(DATASTORE_ENTITY_SET_NAME, DATASTORE_ENTITY_KEY_NAME);
    q.setAncestor(k);
    q.setKeysOnly();
    List<Entity> l = datastore.prepare(q).asList(
        FetchOptions.Builder.withDefaults());
    for (Iterator i = l.iterator(); i.hasNext();) {
      Entity e = (Entity) i.next();
      System.out.println("deleting " + e.getKey());
View Full Code Here

    txn.commit();
    return true;
  }
 
  private PreparedQuery queryAccount(String email){
    Query q = new Query(ACCOUNT_KIND);
    q.addFilter(ACCOUNT_ID_PROPERTY, FilterOperator.EQUAL, email);
    return datastore.prepare(q);
  }
View Full Code Here

  }
 
  public AccountObject getAccountObject(String accountId) {
    if(accountId == null)
      return null;
    Query q = new Query(ACCOUNT_KIND);
    q.addFilter(ACCOUNT_ID_PROPERTY, Query.FilterOperator.EQUAL, accountId);
    Entity qe = datastore.prepare(q).asSingleEntity();
    if(qe == null)
      return null;
    String password = (String) qe.getProperty(PASSWORD_PROPERTY);
    boolean active = (Boolean) qe.getProperty(ACTIVATED_PROPERTY);
View Full Code Here

    CARRIER carrier = CARRIER.get((String)qe.getProperty(PREFERENCE_CARRIER_PROPERTY));
    return new AccountObject(accountId,password,active,authKey, notifyConfig, phoneNumber, carrier);
  }
 
  public boolean updateAccountObject(AccountObject lao){
    Query q = new Query(ACCOUNT_KIND);
    q.addFilter(ACCOUNT_ID_PROPERTY, Query.FilterOperator.EQUAL, lao.getEmail());
    Entity qe = datastore.prepare(q).asSingleEntity();
    if(qe == null)
      return false;
    Transaction txn = datastore.beginTransaction();  
    qe.setProperty(PASSWORD_PROPERTY, lao.getPassword());
View Full Code Here

    return true;
  }
 
  //Bi-directional subscription adding
  public boolean addSubscription(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();
   
    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();
   
    if(e_from == null || e_to == null)
      return false;
View Full Code Here

    return true;
  }
 
  //Bidirectional email check
  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);
    sub_from.setKeysOnly();
    PreparedQuery sub_pq_from = datastore.prepare(sub_from);
   
    Query sub_to = new Query(SUBSCRIPTION_KIND);
    sub_to.setAncestor(to_key);
    sub_to.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, from);
    sub_from.addFilter(SUBSCRIPTION_STATUS_PROPERTY, FilterOperator.EQUAL, SUBSCRIPTION_STATUS_ACTIVE);
    sub_to.setKeysOnly();
    PreparedQuery sub_pq_to = datastore.prepare(sub_to);
   
    if(sub_pq_from.asSingleEntity() != null || sub_pq_to.asSingleEntity() != null )
      return true;
    return false;
View Full Code Here

   
  }
 
  //Bidirectional check
  private boolean checkSubscriptionExists(Key from_key, String from, Key to_key, String to){
    Query q_from = new Query(SUBSCRIPTION_KIND);
    q_from.setAncestor(from_key);
    q_from.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, to);
    q_from.setKeysOnly();
    PreparedQuery pq_from = datastore.prepare(q_from);
   
    Query q_to = new Query(SUBSCRIPTION_KIND);
    q_to.setAncestor(to_key);
    q_to.addFilter(SUBSCRIPTION_EMAIL_PROPERTY, FilterOperator.EQUAL, from);
    q_to.setKeysOnly();
    PreparedQuery pq_to = datastore.prepare(q_to);
    if(pq_from.asSingleEntity() != null || pq_to.asSingleEntity() != null )
      return true;
    return false;
  }
View Full Code Here

TOP

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

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.