Package siena

Examples of siena.SienaException


      Relation rel =
        new Relation(RelationMode.AGGREGATION, aggreg.aggregator, aggreg.field);
      Util.setField(obj, info.aggregator, rel);
    }
    else if(aggregs.size() > 1){
      throw new SienaException("Only one aggregation per query allowed");
    }
   
    if(ownees.size() == 1){
      // owners
      QueryOwned ownee = ownees.get(0);       
      Util.setField(obj, ownee.field, ownee.owner);
       
    }
    else if(ownees.size() > 1){
      throw new SienaException("Only one owner per query allowed");
    }
   
    return obj;
  }
View Full Code Here


      for(T obj: objs){
        Util.setField(obj, info.aggregator, rel);
      }     
    }
    else if(aggregs.size() > 1){
      throw new SienaException("Only one aggregation per query allowed");
    }
   
    if(ownees.size() == 1){
      // owners
      QueryOwned ownee = ownees.get(0);
      for(T obj: objs){
        Util.setField(obj, ownee.field, ownee.owner);
      }
    }
    else if(ownees.size() > 1){
      throw new SienaException("Only one owner per query allowed");
    }
    return objs;
  }
View Full Code Here

        return results;
      } catch(SienaException e) {
        throw e;
      } catch(Exception e) {
        throw new SienaException(e);
      } finally {
        scanner.close();
      }
    }
View Full Code Here

        String name = hTableDescriptor.getNameAsString();
        admin.disableTable(name);
        admin.deleteTable(name);
      }
    } catch(IOException e) {
      throw new SienaException(e);
    }
  }
View Full Code Here

    // the level prevents from stackoverflow in case of a circular ref
    if(level > 2) return;
   
    Class<?> clazz = embeddedObj.getClass();
    if(clazz.isArray() || Collection.class.isAssignableFrom(clazz)){
      throw new SienaException("can't serializer Array/Collection in native mode");
    }
   
    for (Field f : ClassInfo.getClassInfo(clazz).allFields) {
      // doesn't try to analyze fields, just try to store it
      Class<?> fieldClass = f.getType();
      String propName = embeddingColumnName + "." + ClassInfo.getSingleColumnName(f);
      Object propValue = Util.readField(embeddedObj, f);     
     
      if (propValue != null) {
        if (fieldClass == Json.class) {
          propValue = propValue.toString();
        } else if (propValue instanceof String) {
          String s = (String) propValue;
          if (s.length() > 500)
            propValue = new Text(s);
        } else if (propValue instanceof byte[]) {
          byte[] arr = (byte[]) propValue;
          // GAE Blob doesn't accept more than 1MB
          if (arr.length < 1000000)
            propValue = new Blob(arr);
          else
            propValue = new Blob(Arrays.copyOf(arr, 1000000));
        }
        else if (ClassInfo.isEmbedded(f)) {
          Embedded embed = f.getAnnotation(Embedded.class);
          switch(embed.mode()){
          case SERIALIZE_JSON:
            propValue = JsonSerializer.serialize(propValue).toString();
            String s = (String) propValue;
            if (s.length() > 500)
              propValue = new Text(s);
            break;
          case SERIALIZE_JAVA:
            // this embedding mode doesn't manage @EmbedIgnores
            try {
              byte[] b = JavaSerializer.serialize(propValue);
              // if length is less than 1Mb, can store in a blob else???
              if(b.length <= 1000000){
                propValue = new Blob(b);
              }else{
                throw new SienaException("object can be java serialized because it's too large >1mb");
              }               
            }
            catch(IOException ex) {
              throw new SienaException(ex);
            }
            break;
          case NATIVE:
            GaeNativeSerializer.embed(entity, embeddingColumnName + "." + ClassInfo.getSingleColumnName(f), propValue, level+1);
            // has set several new properties in entity so go to next field
View Full Code Here

      switch(id.value()) {
      case NONE:
      {
        Object idVal = Util.readField(obj, idField);
        if(idVal == null)
          throw new SienaException("Id Field " + idField.getName() + " value null");
        keyVal = toString(idField, idVal);       
        break;
      }
      case AUTO_INCREMENT:
        // manages String ID as not long!!!
        throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
      case UUID:
      {
        Object idVal = Util.readField(obj, idField);
        if(idVal == null){
          UUID uuid = UUID.randomUUID();
          keyVal = uuid.toString();
         
          if(idField.getType() == UUID.class){
            Util.setField(obj, idField, uuid);
          }
          else if(idField.getType() == String.class){
            Util.setField(obj, idField, uuid.toString());
          }
          else {
            throw new SienaRestrictedApiException("DB", "getItemName", "@Id UUID must be of type String or UUID");
          }
        }else {
          keyVal = toString(idField, idVal);
        }
        break;
      }
      default:
        throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator "+id.value()+ " not supported");
      }
    }
    else throw new SienaException("Field " + idField.getName() + " is not an @Id field");

    return keyVal;
  }
View Full Code Here

      }
      default:
        throw new SienaRestrictedApiException("DB", "createEntityInstance", "Id Generator "+id.value()+ " not supported");
      }
    }
    else throw new SienaException("Field " + idField.getName() + " is not an @Id field");

    return keyVal;
 
View Full Code Here

  public static <T> T unembed(Class<T> clazz, String embeddingFieldName, Entity entity, int level){
    // the level prevents from stackoverflow in case of a circular ref
    if(level > 2) return null;
   
    if(clazz.isArray() || Collection.class.isAssignableFrom(clazz)){
      throw new SienaException("can't serializer Array/Collection in native mode");
    }

    T obj = Util.createObjectInstance(clazz);

    try {
      for (Field f : ClassInfo.getClassInfo(clazz).allFields) {
        // doesn't try to analyze fields, just try to store it
        String propName = embeddingFieldName + "." + ClassInfo.getSingleColumnName(f);     
        Object propValue = entity.getProperty(propName);
       
        if(ClassInfo.isEmbedded(f) && f.getAnnotation(Embedded.class).mode() == Embedded.Mode.NATIVE){
          Object value = GaeNativeSerializer.unembed(
              f.getType(), embeddingFieldName + "." + ClassInfo.getSingleColumnName(f), entity, level+1);
          Util.setField(obj, f, value);
        }
        else if(ClassInfo.isModel(f.getType())){
          // here we create a model with only the key as we don't embed anything else because there is no join by default
          Class<?> fieldClass = f.getType();
          Object value = Util.createObjectInstance(fieldClass);
          Util.setField(value, ClassInfo.getIdField(fieldClass), propValue);
         
          Util.setField(obj, f, value);
        }
        else {
          GaeMappingUtils.setFromObject(obj, f, propValue);
        }
      }
     
      return obj;
    }catch(Exception e){
      throw new SienaException(e);
    }
  }
View Full Code Here

          if (ClassInfo.isEmbeddedNative(field)){
            SdbNativeSerializer.embed(req, ClassInfo.getSingleColumnName(field), value);           
          }
        }
      } catch (Exception e) {
        throw new SienaException(e);
      }
    }
    return req;
  }
View Full Code Here

          if (ClassInfo.isEmbeddedNative(field)){
            SdbNativeSerializer.embed(item, ClassInfo.getSingleColumnName(field), value);           
          }
        }
      } catch (Exception e) {
        throw new SienaException(e);
      }
    }

    return item;
  }
View Full Code Here

TOP

Related Classes of siena.SienaException

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.