Package org.beangle.model.query.builder

Examples of org.beangle.model.query.builder.Condition


     */
    public static void bindValues(final Query query, final List<Condition> conditions) {
      int position = 0;
      boolean hasInterrogation = false; // 含有问号
      for (final Iterator<Condition> iter = conditions.iterator(); iter.hasNext();) {
        final Condition condition = (Condition) iter.next();
        if (StringUtils.contains(condition.getContent(), "?")) {
          hasInterrogation = true;
        }
        if (hasInterrogation) {
          for (final Iterator<?> iterator = condition.getParams().iterator(); iterator.hasNext();) {
            query.setParameter(position++, iterator.next());
          }
        } else {
          final List<String> paramNames = condition.getParamNames();
          for (int i = 0; i < paramNames.size(); i++) {
            final String name = paramNames.get(i);
            final Object value = condition.getParams().get(i);

            if (value.getClass().isArray()) {
              query.setParameterList(name, (Object[]) value);
            } else if (value instanceof Collection<?>) {
              query.setParameterList(name, (Collection<?>) value);
View Full Code Here


      params.add("%" + groupName + "%");
      queryGroup = true;
    }
    if (queryGroup) {
      sb.append(')');
      Condition groupCondition = new Condition(sb.toString());
      groupCondition.params(params);
      userQuery.where(groupCondition);
    }

    Long categoryId = getLong("categoryId");
    if (null != categoryId) {
View Full Code Here

      String[] contents = StringUtils.split(StringUtils.replace(patternContent, " and ", "$"), "$");

      StringBuilder singleConBuf = new StringBuilder("(");
      for (int i = 0; i < contents.length; i++) {
        String content = contents[i];
        Condition c = new Condition(content);
        List<String> params = c.getParamNames();
        for (final String paramName : params) {
          RestrictField param = pattern.getEntity().getField(paramName);
          String value = restriction.getItem(param);
          if (StringUtils.isNotEmpty(value)) {
            if (value.equals(Restriction.ALL)) {
              content = "";
            } else {
              content = StringUtils.replace(content, ":" + param.getName(),
                  ":" + param.getName() + index);
              paramValues.add(getFieldValue(param, restriction));
            }
          } else {
            throw new RuntimeException(paramName + " had not been initialized");
          }
        }
        if (singleConBuf.length() > 1 && content.length() > 0) {
          singleConBuf.append(" and ");
        }
        singleConBuf.append(content);
      }

      if (singleConBuf.length() > 1) {
        singleConBuf.append(')');
        if (conBuffer.length() > 0) {
          conBuffer.append(" or ");
        }
        conBuffer.append(singleConBuf.toString());
      }
      index++;
    }
    if (conBuffer.length() > 0) {
      Condition con = new Condition(conBuffer.toString());
      con.params(paramValues);
      query.where(con);
    }
  }
View Full Code Here

      String strValue = entry.getValue().toString().trim();
      // 过滤空属性
      if (StringUtils.isNotEmpty(strValue)) {
        try {
          if (RESERVED_NULL && "null".equals(strValue)) {
            conditions.add(new Condition(prefix + "." + attr + " is null"));
          } else {
            Model.getPopulator().populateValue(entity, attr, strValue);
            Object settedValue = PropertyUtils.getProperty(entity, attr);
            if (null == settedValue) continue;
            if (settedValue instanceof String) {
              conditions.add(new Condition(prefix + "." + attr + " like :"
                  + attr.replace('.', '_'), "%" + (String) settedValue + "%"));
            } else {
              conditions.add(new Condition(prefix + "." + attr + "=:" + attr.replace('.', '_'),
                  settedValue));
            }
          }
        } catch (Exception e) {
          logger.debug("[populateFromParams]:error in populate entity " + prefix + "'s attribute "
View Full Code Here

    return entityDao.get(getEntityClass(), id);
  }

  public List<T> get(ID[] ids) {
    OqlBuilder<T> query = OqlBuilder.from(getEntityClass(), "entity").where(
        new Condition("entity.id in(:gids)", ids));
    return entityDao.search(query);
  }
View Full Code Here

     */
    public static void bindValues(final Query query, final List<Condition> conditions) {
      int position = 0;
      boolean hasInterrogation = false; // 含有问号
      for (final Iterator<Condition> iter = conditions.iterator(); iter.hasNext();) {
        final Condition condition = (Condition) iter.next();
        if (StringUtils.contains(condition.getContent(), "?")) {
          hasInterrogation = true;
        }
        if (hasInterrogation) {
          for (final Iterator<?> iterator = condition.getParams().iterator(); iterator
              .hasNext();) {
            query.setParameter(position++, iterator.next());
          }
        } else {
          final List<String> paramNames = condition.getParamNames();
          for (int i = 0; i < paramNames.size(); i++) {
            final String name = paramNames.get(i);
            final Object value = condition.getParams().get(i);

            if (value.getClass().isArray()) {
              query.setParameterList(name, (Object[]) value);
            } else if (value instanceof Collection<?>) {
              query.setParameterList(name, (Collection<?>) value);
View Full Code Here

      params.add("%" + groupName + "%");
      queryGroup = true;
    }
    if (queryGroup) {
      sb.append(')');
      Condition groupCondition = new Condition(sb.toString());
      groupCondition.params(params);
      userQuery.where(groupCondition);
    }

    Long categoryId = getLong("categoryId");
    if (null != categoryId) {
View Full Code Here

          StringUtils.replace(patternContent, " and ", "$"), "$");

      StringBuilder singleConBuf = new StringBuilder(prefix);
      for (int i = 0; i < contents.length; i++) {
        String content = contents[i];
        Condition c = new Condition(content);
        List<String> params = c.getParamNames();
        for (final String paramName : params) {
          RestrictField param = pattern.getObject().getField(paramName);
          String value = restriction.getItem(param);
          if (StringUtils.isNotEmpty(value)) {
            if (value.equals(Restriction.ALL)) {
              content = "";
            } else {
              content = StringUtils.replace(content, ":" + param.getName(), ":"
                  + param.getName() + index);
              paramValues.add(getValue(restriction,param));
            }
          } else {
            throw new RuntimeException(paramName + " had not been initialized");
          }
        }
        if (singleConBuf.length() > 1 && content.length() > 0) {
          singleConBuf.append(" and ");
        }
        singleConBuf.append(content);
      }

      if (singleConBuf.length() > 1) {
        singleConBuf.append(')');
        if (conBuffer.length() > 0) {
          conBuffer.append(" or ");
        }
        conBuffer.append(singleConBuf.toString());
      }
      index++;
    }
    if (conBuffer.length() > 0) {
      Condition con = new Condition(conBuffer.toString());
      con.params(paramValues);
      query.where(con);
    }
  }
View Full Code Here

      String strValue = entry.getValue().toString().trim();
      // 过滤空属性
      if (StringUtils.isNotEmpty(strValue)) {
        try {
          if (RESERVED_NULL && "null".equals(strValue)) {
            conditions.add(new Condition(prefix + "." + attr + " is null"));
          } else {
            Model.getPopulator().populateValue(entity, attr, strValue);
            Object settedValue = PropertyUtils.getProperty(entity, attr);
            if (null == settedValue) continue;
            if (settedValue instanceof String) {
              conditions.add(new Condition(prefix + "." + attr + " like :"
                  + attr.replace('.', '_'), "%" + (String) settedValue + "%"));
            } else {
              conditions.add(new Condition(prefix + "." + attr + "=:"
                  + attr.replace('.', '_'), settedValue));
            }
          }
        } catch (Exception e) {
          logger.debug("[populateFromParams]:error in populate entity " + prefix
View Full Code Here

  }

  public Class getCodeClass(String codeName) {
    try {
      EntityQuery query = new EntityQuery(CodeMeta.class, "CodeMeta");
      query.add(new Condition("CodeMeta.engName=:name", codeName));
      List rs = (List) entityDao.search(query);
      if (1 != rs.size()) {
        throw new RuntimeException("ClassNotFoundException:" + codeName + " is not defined!");
      } else {
        return Class.forName(codeName);
View Full Code Here

TOP

Related Classes of org.beangle.model.query.builder.Condition

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.