Package com.google.appengine.api.datastore

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


 
  public static String addNotifier(String email, String pNum, String dept, String course, String section){
    String verifyKey = generateVerificationKey();
    Key k = KeyFactory.createKey(DATASTORE_ENTITY_SET_NAME, DATASTORE_ENTITY_KEY_NAME);
    Transaction txn = datastore.beginTransaction();                               
    Entity e = new Entity(ENTRY_KIND,k);                                      
    e.setProperty(EMAIL_PROPERTY, email);    
    e.setProperty(ACTIVATED_PROPERTY, false);
    e.setProperty(VERIFY_KEY_PROPERTY, verifyKey);
    e.setProperty(PHONE_NUMBER_PROPERTY, pNum);
    e.setProperty(DEPT_PROPERTY, dept);
    e.setProperty(COURSE_PROPERTY, course);
    e.setProperty(SECTION_PROPERTY, section);
    datastore.put(e);                                                             
    txn.commit();
    return verifyKey;
  }
View Full Code Here


    Query q = new Query(ENTRY_KIND);
    q.addFilter(VERIFY_KEY_PROPERTY, FilterOperator.EQUAL, key);
    q.addFilter(ACTIVATED_PROPERTY, FilterOperator.EQUAL, false);
    PreparedQuery pq = datastore.prepare(q);
      try {
        Entity e = pq.asSingleEntity();
        if(e != null ) {
          e.setProperty(ACTIVATED_PROPERTY, true);
          datastore.put(e);
          return true;
        }
      }
      catch (Exception e){
View Full Code Here

  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

    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

    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());
      datastore.delete(e.getKey());
    }
  }
View Full Code Here

  public boolean addAccount(AccountObject ao){
    if(!this.checkAccountExist(ao.getEmail())){
      //create and commit this entry
      Key k = KeyFactory.createKey(DATASTORE_ENTITY_SET_NAME, DATASTORE_ENTITY_KEY_NAME);
      Transaction txn = datastore.beginTransaction();                               
      Entity e = new Entity(ACCOUNT_KIND,k);                                      
      e.setProperty(ACCOUNT_ID_PROPERTY, ao.getEmail());    
      e.setProperty(PASSWORD_PROPERTY, ao.getPassword());
      e.setProperty(ACTIVATED_PROPERTY, ao.isActivated());
      e.setProperty(AUTHENTICATION_KEY_PROPERTY, ao.getAuthkey());
      e.setProperty(PREFERENCE_NOTIFY_CONFIG_PROPERTY, ao.getNotifyConfig());
      e.setProperty(PREFERENCE_PHONE_NUMBER_PROPERTY, ao.getPhoneNumber());
      e.setProperty(PREFERENCE_CARRIER_PROPERTY, ao.getCarrier().getGateway());
      datastore.put(e);                                                             
      txn.commit();                                                                 
      return true;
    }
    return false;
View Full Code Here

   
  }
 
  public boolean activateAccount(String email, String authKey){
    PreparedQuery pq = queryAccount(email);
    Entity e = pq.asSingleEntity();
    if (e == null)
      return false;
    if(!e.getProperty(AUTHENTICATION_KEY_PROPERTY).equals(authKey))
      return false;
    if(e.getProperty(ACTIVATED_PROPERTY).equals(true))
      return false;
    Transaction txn = datastore.beginTransaction();
    e.setProperty(ACTIVATED_PROPERTY, true);
    datastore.put(e);
    txn.commit();
    return true;
  }
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);
    String authKey=(String) qe.getProperty(AUTHENTICATION_KEY_PROPERTY);
    long notifyConfig = (Long)qe.getProperty(PREFERENCE_NOTIFY_CONFIG_PROPERTY);
    String phoneNumber = (String)qe.getProperty(PREFERENCE_PHONE_NUMBER_PROPERTY);
    CARRIER carrier = CARRIER.get((String)qe.getProperty(PREFERENCE_CARRIER_PROPERTY));
    return new AccountObject(accountId,password,active,authKey, notifyConfig, phoneNumber, carrier);
  }
View Full Code Here

  }
 
  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());
    qe.setProperty(AUTHENTICATION_KEY_PROPERTY, lao.getAuthkey());
    qe.setProperty(PREFERENCE_NOTIFY_CONFIG_PROPERTY, lao.getNotifyConfig());
    qe.setProperty(PREFERENCE_PHONE_NUMBER_PROPERTY, lao.getPhoneNumber());
    qe.setProperty(PREFERENCE_CARRIER_PROPERTY, lao.getCarrier().getGateway());
    datastore.put(qe);
    txn.commit();
    return true;
  }
View Full Code Here

  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;
    Key k_from = e_from.getKey();
    Key k_to = e_to.getKey();
    if(checkSubscriptionExists(k_from, from, k_to, to))
      return false;
    Transaction txn = datastore.beginTransaction();
    Entity sub_from = new Entity(SUBSCRIPTION_KIND, k_from);
    sub_from.setProperty(SUBSCRIPTION_EMAIL_PROPERTY, to);
    //When first add, set a pending request
    sub_from.setProperty(SUBSCRIPTION_STATUS_PROPERTY, "Waiting");
    datastore.put(sub_from);
    Entity sub_to = new Entity(SUBSCRIPTION_KIND, k_to);
    sub_to.setProperty(SUBSCRIPTION_EMAIL_PROPERTY, from);
    sub_to.setProperty(SUBSCRIPTION_STATUS_PROPERTY, "Pending");
    datastore.put(sub_to);
    txn.commit();
    return true;
  }
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.