Package siena

Examples of siena.Model


          throw new SienaException("Invalid time");
        }
      }
      String action = root.getName();
      if("insert".equals(action)) {
        Model obj = parseEntity(root, classLoader);
        obj.insert();
        return simpleResponse(obj, true);
      } else if("update".equals(action)) {
        parseEntity(root, classLoader).update();
      } else if("delete".equals(action)) {
        parseEntity(root, classLoader).delete();
      } else if("get".equals(action)) {
        Model obj = parseEntity(root, classLoader);
        obj.get();
        return simpleResponse(obj, false);
      } else if("query".equals(action)) {
        // TODO: convert document to QueryBase
       
        String clazzName = root.attributeValue("class");
View Full Code Here


    }
  }
 
  public static Model parseEntity(Element element, ClassLoader classLoader) {
    String clazzName = element.attributeValue("class");
    Model obj = null;
    try {
      Class<?> clazz = classForName(clazzName, classLoader);
      obj = (Model) clazz.newInstance();
    } catch(Exception e) {
      throw new SienaException("Error while trying to create an instance of "+clazzName+". "+e.getMessage());
View Full Code Here

      // return true in case we want to field to be nullable
      return true;
    }
   
    if(validatedObject instanceof Model) {
      Model ss = (Model) validatedObject;
     
      try {
              if (context != null) {
                  if (context instanceof FieldContext) {
                      FieldContext ctx = (FieldContext) context;
                      String fieldName = ctx.getField().getName();
                     
                      Query<? extends Object> all = Model.all(validatedObject.getClass());
                List<? extends Object> fetched = all.filter(fieldName, value).fetch();
                if(fetched.size() == 0) return true;
                Object sskey = SienaUtils.findKey(ss);
                if(sskey == null) {
                  // new object => value already in database
                  return false;
                } else {
                  // existing object
                  // check if we can find the id inside the fetched objects
                  for(Object o : fetched) {
                    Model s = (Model) o;
                    Object skey = SienaUtils.findKey(s);
                    if(skey!=null && skey.equals(sskey)) return true;
                  }
                  return false;
                }
View Full Code Here

      // return true in case we want to field to be nullable
      return true;
    }
   
    if(validatedObject instanceof Model) {
      Model ss = (Model) validatedObject;
     
      try {
              if (context != null) {
                  if (context instanceof FieldContext) {
                      FieldContext ctx = (FieldContext) context;
                      String fieldName = ctx.getField().getName();
                     
                      Query<? extends Object> all = Model.all(validatedObject.getClass());
                List<? extends Object> fetched = all.filter(fieldName, value).fetch();
                if(fetched.size() == 0) return true;
                Object sskey = SienaModelUtils.keyValue(ss);
                if(sskey == null) {
                  // new object => value already in database
                  return false;
                } else {
                  // existing object
                  // check if we can find the id inside the fetched objects
                  for(Object o : fetched) {
                    Model s = (Model) o;
                    Object skey = SienaModelUtils.keyValue(ss);
                    if(skey!=null && skey.equals(sskey)) return true;
                  }
                  return false;
                }
View Full Code Here

TOP

Related Classes of siena.Model

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.