Package com.google.appengine.api.datastore

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


    return key == null;
  }
 
  @Override
  public void copy(BaseEntity entity) {
    Key myKey = getKey();
    Entity buf = new Entity("tmp");
    entity.save(buf);
    load(buf);
    setKey(myKey);
  }
View Full Code Here


        HttpSession session = request.getSession();
        String id = AC_BASE + session.getId();
        byte[] serializedAC = (byte[]) memcache.get(id);
        if (serializedAC == null) {
            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            Key key = KeyFactory.createKey(AC_BASE, id);
            Entity entity = null;
            try {
                entity = ds.get(key);
            } catch (EntityNotFoundException e) {
                // Ok, we were a bit optimistic; we'll create a new one later
View Full Code Here

  public SienaFuture<Void> delete(Object obj) {
    return new SienaFutureContainer<Void>(ds.delete(GaeMappingUtils.getKey(obj)));
  }
 
  public SienaFuture<Void> get(final Object obj) {
    final Key key = GaeMappingUtils.getKey(obj);
    Future<Entity> future = ds.get(key);
   
    Future<Void> wrapped = new SienaFutureWrapper<Entity, Void>(future) {
            @Override
            protected Void wrap(Entity entity) throws Exception
View Full Code Here

      // join queries
      Map<Field, ArrayList<Key>> fieldMap = GaeQueryUtils.buildJoinFieldKeysMap(query);
     
      // creates the list of joined entity keys to extract
      for(Field field: fieldMap.keySet()){
        Key key = GaeMappingUtils.getKey(field.get(model));
        List<Key> keys = fieldMap.get(field);
        if(!keys.contains(key))
          keys.add(key);
      }
     
      Map<Field, Map<Key, Entity>> entityMap =
        new HashMap<Field, Map<Key, Entity>>();

      try {
        // retrieves all joined entities per field
        for(Field field: fieldMap.keySet()){
          Future<Map<Key, Entity>> entities = ds.get(fieldMap.get(field));
          // gets the future here because we need it!
          entityMap.put(field, entities.get());
        }
      }catch(Exception ex){
        throw new SienaException(ex);
      }
      // associates linked models to their models
      // linkedModels is just a map to contain entities already mapped
      Map<Key, Object> linkedModels = new HashMap<Key, Object>();
      Object linkedObj;
      Entity entity;
     
      for(Field field: fieldMap.keySet()){
        Object objVal = field.get(model);
        Key key = GaeMappingUtils.getKey(objVal);
        linkedObj = linkedModels.get(key);
        if(linkedObj==null){
          entity = entityMap.get(field).get(key);
          linkedObj = objVal;
          GaeMappingUtils.fillModel(linkedObj, entity);
View Full Code Here

                    // our object is not linked to another object...so it doesn't have any key
                    if(objVal == null) {
                        continue;
                    }

                    Key key = GaeMappingUtils.getKey(objVal);
          List<Key> keys = fieldMap.get(field);
          if(!keys.contains(key))
            keys.add(key);
        }
      }
     
      Map<Field, Map<Key, Entity>> entityMap =
        new HashMap<Field, Map<Key, Entity>>();

      try {
        // retrieves all joined entities per field
        for(Field field: fieldMap.keySet()){
          Future<Map<Key, Entity>> entities = ds.get(fieldMap.get(field));
          // gets the future here because we need it so we wait for it
          entityMap.put(field, entities.get());
        }
      }catch(Exception ex){
        throw new SienaException(ex);
      }
      // associates linked models to their models
      // linkedModels is just a map to contain entities already mapped
      Map<Key, Object> linkedModels = new HashMap<Key, Object>();
      Object linkedObj;
      Entity entity;
     
      for (final T model : models) {
        for(Field field: fieldMap.keySet()){
          Object objVal = Util.readField(model, field);
                    // our object is not linked to another object...so it doesn't have any key
                    if(objVal == null) {
                        continue;
                    }
          Key key = GaeMappingUtils.getKey(objVal);
          linkedObj = linkedModels.get(key);
          if(linkedObj==null){
            entity = entityMap.get(field).get(key);
            linkedObj = objVal;
            GaeMappingUtils.fillModel(linkedObj, entity);
View Full Code Here

   
    return new SienaFutureContainer<Integer>(wrapped);
  }
 
  public <T> SienaFuture<T> getByKey(final Class<T> clazz, final Object key) {
    Key gkey = GaeMappingUtils.makeKeyFromId(clazz, key);
    try {
      Future<Entity> future = ds.get(gkey);
     
      Future<T> wrapped = new SienaFutureWrapper<Entity, T>(future) {
              @Override
View Full Code Here

   
    if(info.hasAggregator){
      Relation rel = (Relation)Util.readField(obj, info.aggregator);
      if(rel != null && rel.mode == RelationMode.AGGREGATION){
        ClassInfo parentInfo = ClassInfo.getClassInfo(rel.target.getClass());
        Key parentKey = GaeMappingUtils.makeKey(parentInfo, rel.target);
        _deleteSingle(obj, keys, parentKey, parentInfo, (Field)rel.discriminator);
      }else {
        _deleteSingle(obj, keys, null, null, null);
      }
    }else {
View Full Code Here

 
  private void _deleteSingle(Object obj, List<Key> keys, final Key parentKey, final ClassInfo parentInfo, final Field parentField) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
   
    Key key;   
    if(parentKey==null){
      key = GaeMappingUtils.getKey(obj);
    }else {
      key = GaeMappingUtils.getKeyFromParent(obj, parentKey, parentInfo, parentField);
    }
View Full Code Here

  private void _deleteMultiple(Iterable<?> objects, List<Key> keys, final Key parentKey, final ClassInfo parentInfo, final Field parentField) {
    for(Object obj: objects){
      Class<?> clazz = obj.getClass();
      ClassInfo info = ClassInfo.getClassInfo(clazz);
     
      Key key;   
      if(parentKey==null){
        key = GaeMappingUtils.getKey(obj);
      }else {
        key = GaeMappingUtils.getKeyFromParent(obj, parentKey, parentInfo, parentField);
      }
View Full Code Here

    }
   
  }
 
  public void get(Object obj) {
    Key key = GaeMappingUtils.getKey(obj);
    ClassInfo info = ClassInfo.getClassInfo(obj.getClass());
    try {
      Entity entity = ds.get(key);
      if(entity != null){
        GaeMappingUtils.fillModel(obj, entity);
View Full Code Here

TOP

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

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.