Package siena

Examples of siena.Id


    return keyVal;
  }
 
  public static String getItemNameFromKey(Class<?> clazz, Object key){
    Field idField = ClassInfo.getIdField(clazz);
    Id id = idField.getAnnotation(Id.class);

    String keyVal = null;
    if(id != null){
      switch(id.value()) {
      case NONE:
      {
        keyVal = toString(idField, key);       
        break;
      }
      case AUTO_INCREMENT:
        // manages String ID as not long!!!
        throw new SienaRestrictedApiException("DB", "getItemName", "@Id AUTO_INCREMENT not supported by SDB");
      case UUID:
      {
        keyVal = toString(idField, key);       
        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


    JdbcClassInfo classInfo = JdbcClassInfo.getClassInfo(obj.getClass());

    PreparedStatement ps = null;
    try {
      for (Field field : classInfo.keys) {
        Id id = field.getAnnotation(Id.class);
        if (id.value() == Generator.UUID) {
          field.set(obj, UUID.randomUUID().toString());
        }
      }
      // TODO: implement primary key generation: SEQUENCE
View Full Code Here

      Field idField = classInfo.info.getIdField();
      Object idVal = Util.readField(obj, idField);

      if(idVal == null) {
        for (Field field : classInfo.keys) {
          Id id = field.getAnnotation(Id.class);
          if (id.value() == Generator.UUID) {
            field.set(obj, UUID.randomUUID().toString());
          }
        }
      }
      // TODO: implement primary key generation: SEQUENCE
View Full Code Here

    ps = getConnection().prepareStatement(classInfo.insertSQL,
        Statement.RETURN_GENERATED_KEYS);
   
    for(Object obj: objMap.get(classInfo)){
      for (Field field : classInfo.keys) {
        Id id = field.getAnnotation(Id.class);
        if (id.value() == Generator.UUID) {
          field.set(obj, UUID.randomUUID().toString());
        }
      }
      // TODO: implement primary key generation: SEQUENCE
      addParameters(obj, classInfo.insertFields, ps, 1);
View Full Code Here

        if(classInfo.generatedKeys.isEmpty()){
          ps = getConnection().prepareStatement(classInfo.insertSQL);
         
          for(Object obj: objMap.get(classInfo)){
            for (Field field : classInfo.keys) {
              Id id = field.getAnnotation(Id.class);
              if (id.value() == Generator.UUID) {
                field.set(obj, UUID.randomUUID().toString());
              }
            }
            // TODO: implement primary key generation: SEQUENCE
            addParameters(obj, classInfo.insertFields, ps, 1);
View Full Code Here

          Object idVal = Util.readField(obj, idField);
         
          // only generates a UUID if the idVal is null
          if(idVal == null){
            for (Field field : classInfo.keys) {
              Id id = field.getAnnotation(Id.class);
              if (id.value() == Generator.UUID) {
                field.set(obj, UUID.randomUUID().toString());
              }
            }
          }
          // TODO: implement primary key generation: SEQUENCE
View Full Code Here

              column.setDefaultValue("0");
            }
          }
        }
       
        Id id = field.getAnnotation(Id.class);
        if(id != null) {
          column.setPrimaryKey(true);
          column.setRequired(true);
         
          // auto_increments managed ONLY for long
          if(id.value() == Generator.AUTO_INCREMENT
              && (Long.TYPE == type || Long.class.isAssignableFrom(type)))
            column.setAutoIncrement(true);
         
          // adds index on primary key
          /*UniqueIndex i = uniques.get(columns[0]);
View Full Code Here

        Statement.RETURN_GENERATED_KEYS);
   
    int res = 0;
    for(Object obj: objMap.get(classInfo)){
      for (Field field : classInfo.keys) {
        Id id = field.getAnnotation(Id.class);
        if (id.value() == Generator.UUID) {
          field.set(obj, UUID.randomUUID().toString());
        }
      }
      // TODO: implement primary key generation: SEQUENCE
      addParameters(obj, classInfo.insertFields, ps, 1);
View Full Code Here

      ps = getConnection().prepareStatement(
          classInfo.insertSQL + " RETURNING " + Util.join(keyNames, ","));
     
      for(Object obj: objMap.get(classInfo)){
        for (Field field : classInfo.keys) {
          Id id = field.getAnnotation(Id.class);
          if (id.value() == Generator.UUID) {
            field.set(obj, UUID.randomUUID().toString());
          }
        }
        // TODO: implement primary key generation: SEQUENCE
        addParameters(obj, classInfo.insertFields, ps, 1);
View Full Code Here

TOP

Related Classes of siena.Id

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.