Package siena

Examples of siena.SienaException


    }
    if(ClassInfo.isModel(type)) {
      try {
        return objectFieldToString(val, ClassInfo.getIdField(type));
      } catch (Exception e) {
        throw new SienaException(e);
      }
    } else {
      if (type == Json.class) {
        return val.toString();
      } else if (type == byte[].class) {
View Full Code Here


    }
    if(ClassInfo.isModel(type) && !ClassInfo.isEmbedded(field)) {
      try {
        return objectFieldToString(val, ClassInfo.getIdField(type));
      } catch (Exception e) {
        throw new SienaException(e);
      }
    } else {
      if (type == Json.class) {
        return val.toString();
      } else if (type == byte[].class) {
        return Base64.encodeBytes((byte[]) val);
      }
      else if (ClassInfo.isEmbedded(field)) {
        Embedded embed = field.getAnnotation(Embedded.class);
        switch(embed.mode()){
        case SERIALIZE_JSON:
          return JsonSerializer.serialize(val).toString();
        case SERIALIZE_JAVA:
          // this embedding mode doesn't manage @EmbedIgnores
          try {
            return Base64.encodeBytes(JavaSerializer.serialize(val));                       
          }
          catch(IOException ex) {
            throw new SienaException(ex);
          }
        case NATIVE:
          // returns null because here we need to manage all fields of the embedded entity
          return null;
        }
View Full Code Here

        Field relIdField = ClassInfo.getIdField(fieldClass);
        setFromString(relObj, relIdField, val);
        Util.setField(obj, field, relObj);
        return;
      } catch (Exception e) {
        throw new SienaException(e);
      }
    } else {
      if (fieldClass == byte[].class) {
        try {
          Util.setField(obj, field, Base64.decode(val));
          return;
        }catch(Exception ex){
          throw new SienaException(ex);
        }
      }
      else if (ClassInfo.isEmbeddedNative(field)) {
        return;
      }
View Full Code Here

          first = false;
         
          String[] columns = ClassInfo.getColumnNames(f);
          if("IN".equals(op)) {
            if(!Collection.class.isAssignableFrom(value.getClass()))
              throw new SienaException("Collection needed when using IN operator in filter() query");
            StringBuilder s = new StringBuilder();
            Collection<?> col = (Collection<?>) value;
            for (Object object : col) {
              // TODO manages model collection
              // TO BE VERIFIED: SHOULD BE MANAGED by toString!!!
              if(object != null){
                s.append(","+SimpleDB.quote(toString(f, object)));
              }else{
                throw new SienaException("Can't use NULL in collection for IN operator");
              }
            }
           
            String column = null;
            if(ClassInfo.isId(f)) {
              column = ITEM_NAME;
            } else {
              column = ClassInfo.getColumnNames(f)[0];
            }

            q.append(column+" in("+s.toString().substring(1)+")");
          } else if(ClassInfo.isModel(f.getType())) {
            // TODO could manage other ops here
            if(!op.equals("=")) {
              throw new SienaException("Unsupported operator for relationship: "+op);
            }
            ClassInfo relInfo = ClassInfo.getClassInfo(f.getType());
            int i = 0;
            for (Field key : relInfo.keys) {
              if(value == null) {
                q.append(columns[i++] + IS_NULL);
              } else {
                q.append(columns[i++] + op + SimpleDB.quote(objectFieldToString(value, key)));
              }
            }
          } else {
            String column = null;
            if(ClassInfo.isId(f)) {
              column = "itemName()";
             
              if(value == null && op.equals("=")) {
                throw new SienaException("SDB filter on @Id field with 'IS NULL' is not possible");
              }
            } else {
              column = ClassInfo.getColumnNames(f)[0];
            }
           
            if(value == null && op.equals("=")) {
              q.append(column + IS_NULL);
            } else if(value == null && op.equals("!=")) {
              q.append(column + IS_NOT_NULL);
            } else {
              q.append(column + op + SimpleDB.quote(toString(f, value)));
            }
          }
        }else if(QueryFilterSearch.class.isAssignableFrom(filter.getClass())){
          Class<T> clazz = query.getQueriedClass();
          QueryFilterSearch qf = (QueryFilterSearch)filter;
          //if(qf.fields.length>1)
          //  throw new SienaException("Search not possible for several fields in SDB: only one field");
          try {
            //Field field = Util.getField(clazz, qf.fields[0]);
            //if(field.isAnnotationPresent(Unindexed.class)){
            //  throw new SienaException("Cannot search the @Unindexed field "+field.getName());
            //}
           
            // cuts match into words
            String[] words = qf.match.split("\\s");
           
            // if several words, then only OR operator represented by IN GAE
            Pattern pNormal = Pattern.compile("[\\%]*(\\w+)[\\%]*");
           
            if(!first) {
              q.append(AND);
            }
           
            // forces true
            first = true;
            q.append(" ( ");

            for(String f: qf.fields){
              Field field = Util.getField(clazz, f);
              if(!first) {
                q.append(OR);
              }
              first = false;
             
              q.append(" ( ");
             
              String column = null;
              if(ClassInfo.isId(field)) {
                column = "itemName()";
              } else {
                column = ClassInfo.getColumnNames(field)[0];
              }
             
              first = true;
              for(String word:words){
                if(!first) {
                  q.append(OR);               
                }
                first = false;
               
                if(!pNormal.matcher(word).matches()){
                  throw new SienaException("'"+word+"' doesn't match pattern [\\%]*(\\w+)[\\%]*");
                }
                if(word.contains("%")){
                  q.append(column + LIKE + SimpleDB.quote(word));
                }else {
                  q.append(column + EQ + SimpleDB.quote(word));
                }
              }
              q.append(" ) ");
            }
            q.append(" ) ");
           
          }catch(Exception e){
            throw new SienaException(e);
          }
        }
      }
    }
   
View Full Code Here

        // follows the real offset
        sdbCtx.realOffset += pag.pageSize;
      }
    }else {
      // throws exception because it's impossible to reuse nextPage when paginating has been interrupted, the cases are too many
      throw new SienaException("Can't use nextPage after pagination has been interrupted...");
    }
  }
View Full Code Here

          sdbCtx.noMoreDataBefore = true;
        }*/
      }
    } else {
      // throws exception because it's impossible to reuse nextPage when paginating has been interrupted, the cases are too many
      throw new SienaException("Can't use nextPage after pagination has been interrupted...");
    }
  }
View Full Code Here

      c.setAutoCommit(false);
      c.setTransactionIsolation(isolationLevel);
    } catch (SQLException e) {
     
      logger.severe(e, e);
      throw new SienaException(e);
    }
  }
View Full Code Here

      Connection c = getConnection();
      c.setAutoCommit(false);
    } catch (SQLException e) {
     
      logger.severe(e, e);
      throw new SienaException(e);
    }
  }
View Full Code Here

      Connection c = getConnection();
      c.commit();
    } catch (SQLException e) {
     
      logger.severe(e, e);
      throw new SienaException(e);
    }
  }
View Full Code Here

      Connection c = getConnection();
      c.rollback();
    } catch (SQLException e) {
     
      logger.severe(e, e);
      throw new SienaException(e);
    }
  }
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.