Package siena

Examples of siena.ClassInfo


  public SienaFuture<Integer> save(final Iterable<?> objects) {
    List<Entity> entities = new ArrayList<Entity>();
    for(Object obj:objects){
      Class<?> clazz = obj.getClass();
      ClassInfo info = ClassInfo.getClassInfo(clazz);
      Field idField = info.getIdField();
     
      Entity entity;
      Object idVal = Util.readField(obj, idField);
      // id with null value means insert
      if(idVal == null){
        entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
      }
      // id with not null value means update
      else{
        entity = GaeMappingUtils.createEntityInstanceForUpdate(info, obj);     
      }
     
      GaeMappingUtils.fillEntity(obj, entity);
      entities.add(entity);     
    }
   
    Future<List<Key>> future = ds.put(entities);
   
    Future<Integer> wrapped = new SienaFutureWrapper<List<Key>, Integer>(future) {
            @Override
            protected Integer wrap(List<Key> keys) throws Exception
            {
              int i=0;
            for(Object obj:objects){
              Class<?> clazz = obj.getClass();
              ClassInfo info = ClassInfo.getClassInfo(clazz);
              Field idField = info.getIdField();
              Object idVal = Util.readField(obj, idField);
              if(idVal == null){
                GaeMappingUtils.setIdFromKey(idField, obj, keys.get(i++));
              }
            }
View Full Code Here


 
  public void delete(Object obj){
    List<Key> keys = new ArrayList<Key>();
   
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
   
    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);
      }
View Full Code Here

    ds.delete(keys);
  }
 
  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 {
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 {
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

    }
  }

  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){
        obj = Util.createObjectInstance(clazz);
View Full Code Here

    _insertSingle(obj);
  }
   
  private <T> void _insertSingle(T obj) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
   
    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);
      }
View Full Code Here

  }
 
  private <T> void _insertSingle(T obj, final Key parentEntityKey, final Object parentObj,
      final ClassInfo parentInfo, final Field field) {
    Class<?> clazz = obj.getClass();
    ClassInfo info = ClassInfo.getClassInfo(clazz);
    Field idField = info.getIdField();
    final Entity entity;
   
    // first put the entity to have its ID at least!
    if(parentEntityKey==null){
      entity = GaeMappingUtils.createEntityInstance(idField, info, obj);
View Full Code Here

  private <T> int _insertMultiple(Iterable<T> objects){
    List<Entity> entities = new ArrayList<Entity>();

    for(Object obj:objects){
      Class<?> clazz = obj.getClass();
      ClassInfo info = ClassInfo.getClassInfo(clazz);
     
      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);
        }
View Full Code Here

    List<Object> relObjects = new ArrayList<Object>();

    for(Object obj:objects){
      Class<?> clazz = obj.getClass();
      ClassInfo info = ClassInfo.getClassInfo(clazz);
      Field idField = info.getIdField();
      GaeMappingUtils.setIdFromKey(idField, obj, generatedKeys.get(i));
     
      // creates the aggregation relation
      //Relation rel = new Relation(RelationMode.AGGREGATION, parentObj, field);
      //Util.setField(obj, info.aggregator, rel);
View Full Code Here

TOP

Related Classes of siena.ClassInfo

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.