Package siena

Examples of siena.SienaException


      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");
      }
    }
    else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
   
    return entity;
  }
View Full Code Here


      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");
      }
    }
    else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
   
    return entity;
  }
View Full Code Here

        break;
      case UUID:
        Util.setField(obj, idField, key.getName());
        break;
      default:
        throw new SienaException("Id Generator "+id.value()+ " not supported");
      }
    }
    else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
  }
View Full Code Here

        case UUID:
          return KeyFactory.createKey(
            ClassInfo.getClassInfo(clazz).tableName,
            value.toString());
        default:
          throw new SienaException("Id Generator "+id.value()+ " not supported");
        }
      }
      else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
    } catch (Exception e) {
      throw new SienaException(e);
    }
  }
View Full Code Here

          return KeyFactory.createKey(
              parentKey,
              getKindWithAncestorField(info, parentInfo, parentField),
              value.toString());
        default:
          throw new SienaException("Id Generator "+id.value()+ " not supported");
        }
      }
      else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
    } catch (Exception e) {
      throw new SienaException(e);
    }
  }
View Full Code Here

    }
  }
 
  public static Key makeKeyFromId(Class<?> clazz, Object idVal) {
    if(idVal == null)
      throw new SienaException("makeKeyFromId with Id null");
   
    ClassInfo info = ClassInfo.getClassInfo(clazz);
   
    try {
      Field idField = info.getIdField();
     
      if(idField.isAnnotationPresent(Id.class)){
        Id id = idField.getAnnotation(Id.class);
        switch(id.value()) {
        case NONE:
          // long or string goes toString
          return KeyFactory.createKey(
              ClassInfo.getClassInfo(clazz).tableName,
              idVal.toString());
        case AUTO_INCREMENT:
          Class<?> type = idField.getType();
          // as a string with auto_increment can't exist, it is not cast into long
          if (Long.TYPE==type || Long.class.isAssignableFrom(type)){
            return KeyFactory.createKey(
              ClassInfo.getClassInfo(clazz).tableName,
              (Long)idVal);
          }
          return KeyFactory.createKey(
            ClassInfo.getClassInfo(clazz).tableName,
            idVal.toString());
        case UUID:
          return KeyFactory.createKey(
            ClassInfo.getClassInfo(clazz).tableName,
            idVal.toString());
        default:
          throw new SienaException("Id Generator "+id.value()+ " not supported");
        }
      }
      else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
    } catch (Exception e) {
      throw new SienaException(e);
    }
  }
View Full Code Here

  }
 
  public static void embed(PutAttributesRequest req, String embeddingColumnName, Object embeddedObj){
    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).updateFields) {
      String propValue = SdbMappingUtils.objectFieldToString(embeddedObj, f);
      if(propValue != null){
View Full Code Here

 
  public static Key makeKey(ClassInfo info, Object object) {
    Field idField = info.getIdField();
    Object idVal = Util.readField(object, idField);
    if(idVal == null)
      throw new SienaException("Id Field " + idField.getName() + " value null");

    return makeKeyFromId(object.getClass(), idVal);
  }
View Full Code Here

  public static Key makeKeyFromParent(ClassInfo info, Object object, Key parentKey, ClassInfo parentInfo, Field parentField) {
    try {
      Field idField = info.getIdField();
      Object idVal = Util.readField(object, idField);
      if(idVal == null)
        throw new SienaException("Id Field " + idField.getName() + " value null");
     
      if(idField.isAnnotationPresent(Id.class)){
        Id id = idField.getAnnotation(Id.class);
        switch(id.value()) {
        case NONE:
          // long or string goes toString
          return KeyFactory.createKey(
              parentKey,
              getKindWithAncestorField(info, parentInfo, parentField),
              idVal.toString());
        case AUTO_INCREMENT:
          Class<?> type = idField.getType();
          // as a string with auto_increment can't exist, it is not cast into long
          if (Long.TYPE==type || Long.class.isAssignableFrom(type)){
            return KeyFactory.createKey(
              parentKey,
              getKindWithAncestorField(info, parentInfo, parentField),
              (Long)idVal);
          }
          return KeyFactory.createKey(
              parentKey,
              getKindWithAncestorField(info, parentInfo, parentField),
              idVal.toString());
        case UUID:
          return KeyFactory.createKey(
              parentKey,
              getKindWithAncestorField(info, parentInfo, parentField),
              idVal.toString());
        default:
          throw new SienaException("Id Generator "+id.value()+ " not supported");
        }
      }
      else throw new SienaException("Field " + idField.getName() + " is not an @Id field");
    } catch (Exception e) {
      throw new SienaException(e);
    }
  }
View Full Code Here

                byte[] b = JavaSerializer.serialize(value);
                // if length is less than 1Mb, can store in a blob else???
                if(b.length <= 1000000){
                  value = 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, ClassInfo.getSingleColumnName(field), value, 0);
              // has set several new properties in entity so go to next field
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.