Package com.google.appengine.api.datastore

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


      throw new SienaException(e);
    }
  }

  public <T> T getByKey(Class<T> clazz, Object key) {
    Key gKey = GaeMappingUtils.makeKeyFromId(clazz, key);
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    try {
      Entity entity = ds.get(gKey);
      T obj = null;
      if(entity != null){
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);
        _insertSingle(obj, parentKey, rel.target, parentInfo, (Field)rel.discriminator);
      }else {
        _insertSingle(obj, null, null, null, null);
      }
    }else {
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);
          _insertAddEntity(entities, obj, info, parentKey, parentInfo, (Field)rel.discriminator);
        }else {
          _insertAddEntity(entities, obj, info, null, null, null);
        }
      }else {
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);
        if(!info.hasAggregatedFields && !info.hasOwnedFields){
          _updateSimple(obj, info, parentKey, parentInfo, (Field)rel.discriminator);
        }
        else {
          _updateComplex(obj, parentKey, parentInfo, (Field)rel.discriminator);
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);
          _updateBuildMaps(entitiesMap, objectsMap, keysMap,
              obj, parentKey, parentInfo, (Field)rel.discriminator);
        }else {
          _updateBuildMaps(entitiesMap, objectsMap, keysMap,
              obj, null, null, null);
View Full Code Here

          Object prevObj =one.getPrev();
          if(prevObj != null){
            Class<?> delClazz = prevObj.getClass();
            ClassInfo delInfo = ClassInfo.getClassInfo(delClazz);

            Key delKey = GaeMappingUtils.makeKeyFromParent(
                  delInfo, prevObj, entity.getKey(), info, f);
           
            List<Key> key2Remove = keysMap.get(PersistenceType.DELETE);
            if(key2Remove == null){
              key2Remove = new ArrayList<Key>();
              keysMap.put(PersistenceType.DELETE, key2Remove);
            }
            key2Remove.add(delKey);
          }
          // resets modified flag
          one.setModified(false);
         
          Object oneObj = one.get();
          if(oneObj != null){
            _updateBuildMaps(entitiesMap, objectsMap, keysMap, oneObj, entity.getKey(), info, f);
          }
        }
       
      }
      else if(ClassInfo.isMany(f)){
        Many4PM<?> lq = (Many4PM<?>)Util.readField(obj, f);
        // do not update all objects, would be crazy :)
        // UPDATE IS THE RESPONSABILITY OF THE CODER
        /*if(!lq.asList().isEmpty()){
          for(Object elt : lq.asList()){
            _buildUpdateList(entities, entities2Remove, objects2Save, elt, entity.getKey(), info, f);
          }         
        }*/
       
        // add to entities2remove child entities that have been removed
        if(!lq.asList2Remove().isEmpty()){
          Key delKey;
          for(Object elt : lq.asList2Remove()){
            Class<?> delClazz = elt.getClass();
            ClassInfo delInfo = ClassInfo.getClassInfo(delClazz);

            delKey = GaeMappingUtils.makeKeyFromParent(
View Full Code Here

      q = new com.google.appengine.api.datastore.Query(info.tableName);
      return ds.prepare(GaeQueryUtils.addFiltersOrders(query, q));
    }
    else if(aggregs.size() == 1){
      QueryAggregated aggreg = aggregs.get(0);
      Key ancestorKey = GaeMappingUtils.getKey(aggreg.aggregator);
      q = new com.google.appengine.api.datastore.Query(
          GaeMappingUtils.getKindWithAncestorField(info,
              ClassInfo.getClassInfo(aggreg.aggregator.getClass()), aggreg.field));
      q.setAncestor(ancestorKey);
     
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()){
          Map<Key, Entity> entities = ds.get(fieldMap.get(field));
          entityMap.put(field, entities);
        }
      }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

      // join queries
      Map<Field, ArrayList<Key>> fieldMap = GaeQueryUtils.buildJoinFieldKeysMap(model);
     
      // 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()){
          Map<Key, Entity> entities = ds.get(fieldMap.get(field));
          entityMap.put(field, entities);
        }
      }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()){
          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);
        }
      }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

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.