Package com.google.appengine.api.datastore

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


      }
      // 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
View Full Code Here


      }
      // 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
View Full Code Here

        // creates a query for fieldname:child_tablename
        com.google.appengine.api.datastore.Query q =
          new com.google.appengine.api.datastore.Query(GaeMappingUtils.getKindWithAncestorField(cInfo, info, f));

        PreparedQuery pq = ds.prepare(q.setAncestor(ancestorKey));
        Entity cEntity = pq.asSingleEntity();
        Object cObj = Util.createObjectInstance(cClazz);
        GaeMappingUtils.fillModelAndKey(cObj, cEntity);
        Util.setField(ancestor, f, cObj);
      }
      // todo manage joined one2many listquery
View Full Code Here

    }
   
    Map<Key, Entity> entityMap = ds.get(keys);
   
    for(Object obj:objects){
      Entity e = entityMap.get(GaeMappingUtils.getKey(obj));
      if(e!=null){
        GaeMappingUtils.fillModel(obj, e);
      }
    }
   
View Full Code Here

    }
   
    Map<Key, Entity> entityMap = ds.get(gaeKeys);
    List<T> models = new ArrayList<T>(entityMap.size());
    for(Object key:keys){
      Entity entity = entityMap.get(GaeMappingUtils.makeKeyFromId(clazz, key));
      T obj = null;
      if(entity != null){
        obj = GaeMappingUtils.mapEntity(entity, clazz);
        if(obj != null){
          // related fields (Many<T> management mainly)
View Full Code Here

import com.google.appengine.api.datastore.Text;

public class GaeMappingUtils {
 
  public static Entity createEntityInstance(Field idField, ClassInfo info, Object obj){
    Entity entity = null;
    Id id = idField.getAnnotation(Id.class);
    Class<?> type = idField.getType();

    if(id != null){
      switch(id.value()) {
      case NONE:
        Object idVal = null;
        idVal = Util.readField(obj, idField);
        if(idVal == null)
          throw new SienaException("Id Field " + idField.getName() + " value null");
        String keyVal = Util.toString(idField, idVal);       
        entity = new Entity(info.tableName, keyVal);
        break;
      case AUTO_INCREMENT:
        // manages String ID as not long!!!
        if(Long.TYPE == type || Long.class.isAssignableFrom(type)){
          entity = new Entity(info.tableName);
        }else {
          Object idStringVal = null;
          idStringVal = Util.readField(obj, idField);
          if(idStringVal == null)
            throw new SienaException("Id Field " + idField.getName() + " value null");
          String keyStringVal = Util.toString(idField, idStringVal);       
          entity = new Entity(info.tableName, keyStringVal);
        }
        break;
      case UUID:
        entity = new Entity(info.tableName, UUID.randomUUID().toString());
        break;
      default:
        throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator "+id.value()+ " not supported");
      }
    }
View Full Code Here

    return entity;
  }
 
  public static Entity createEntityInstanceForUpdate(ClassInfo info, Object obj){
    Key key = makeKey(info, obj);
    Entity entity = new Entity(key);
   
    return entity;
  }
View Full Code Here

    return entity;
  }
 
  public static Entity createEntityInstanceForUpdateFromParent(ClassInfo info, Object obj, Key parentKey, ClassInfo parentInfo, Field parentField){
    Key key = makeKeyFromParent(info, obj, parentKey, parentInfo, parentField);
    Entity entity = new Entity(key);
   
    return entity;
  }
View Full Code Here

  }
 
  public static Entity createEntityInstanceFromParent(
      Field idField, ClassInfo info, Object obj,
      Key parentKey, ClassInfo parentInfo, Field parentField){
    Entity entity = null;
    Id id = idField.getAnnotation(Id.class);
    Class<?> type = idField.getType();

    if(id != null){
      switch(id.value()) {
      case NONE:
        Object idVal = null;
        idVal = Util.readField(obj, idField);
        if(idVal == null)
          throw new SienaException("Id Field " + idField.getName() + " value null");
        String keyVal = Util.toString(idField, idVal);       
        entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), keyVal, parentKey);
        break;
      case AUTO_INCREMENT:
        // manages String ID as not long!!!
        if(Long.TYPE == type || Long.class.isAssignableFrom(type)){
          entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), parentKey);
        }else {
          Object idStringVal = null;
          idStringVal = Util.readField(obj, idField);
          if(idStringVal == null)
            throw new SienaException("Id Field " + idField.getName() + " value null");
          String keyStringVal = Util.toString(idField, idStringVal);       
          entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), keyStringVal, parentKey);
        }
        break;
      case UUID:
        entity = new Entity(getKindWithAncestorField(info, parentInfo, parentField), UUID.randomUUID().toString(), parentKey);
        break;
      default:
        throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator "+id.value()+ " not supported");
      }
    }
View Full Code Here

    public boolean hasNext() {
      return gaeIterator.hasNext();
    }

    public T next() {
      Entity entity = gaeIterator.next();
      T obj = pm.map(query, entity);
      return obj;
    }
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.