Package org.apache.commons.beanutils

Examples of org.apache.commons.beanutils.BeanMap


    return getForeignerCriterions(entity, map.keySet());
  }

  public static List<Criterion> getForeignerCriterions(Object entity, Collection<String> properties) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    for (Iterator<String> iter = properties.iterator(); iter.hasNext();) {
      String propertyName = iter.next();
      Object foreigner = map.get(propertyName);
      if (foreigner instanceof Entity) {
        BeanMap foreignerMap = new BeanMap(foreigner);
        Object foreignKey = foreignerMap.get("id");
        // 该值不能为空,而且要么不是String类型,要么是不空String类型变量.
        if (ValidEntityKeyPredicate.getInstance().evaluate(foreignKey)) {
          // 在查询中添加该键值.
          criterions.add(Restrictions.eq(propertyName + ".id", foreignKey));
        }
View Full Code Here


   * @param mode
   * @return
   */
  public static List<Criterion> getLikeCriterions(Object entity, String[] properties, MatchMode mode) {
    List<Criterion> criterions = CollectUtils.newArrayList();
    BeanMap map = new BeanMap(entity);
    for (int i = 0; i < properties.length; i++) {
      Object value = map.get(properties[i]);
      if ((value instanceof String) && (StringUtils.isNotEmpty((String) value))) {
        criterions.add(Restrictions.like(properties[i], (String) value, mode));
      }
    }
    return criterions;
View Full Code Here

    if (value instanceof String) {
      if (StringUtils.isNotEmpty((String) value)) {
        criterions.add(likeCriterion(nestedName + path, (String) value, mode));
      }
    } else if (value instanceof Entity) {
      BeanMap foreignerMap = new BeanMap(value);
      Object foreignKey = foreignerMap.get("id");
      // 该值不能为空,而且要么不是String类型,要么是不空String类型变量.
      if (ValidEntityKeyPredicate.getInstance().evaluate(foreignKey)) {
        // 在查询中添加该键值.
        criterions.add(eqCriterion(nestedName + path + ".id", foreignKey));
      }
View Full Code Here

      component = (Component) PropertyUtils.getProperty(entity, property);
    } catch (Exception e) {
      return Collections.emptyList();
    }
    if (null == component) { return Collections.emptyList(); }
    BeanMap map = new BeanMap(component);
    Set<String> properties = map.keySet();
    Set<String> excludeSet = null;
    if (null == excludePropertes) {
      excludeSet = Collections.emptySet();
    } else {
      excludeSet = CollectUtils.newHashSet();
      excludeSet.addAll(Arrays.asList(excludePropertes));
    }
    for (Iterator<String> iter = properties.iterator(); iter.hasNext();) {
      String propertyName = iter.next();
      String cascadeName = property + "." + propertyName;
      if (excludeSet.contains(cascadeName) || "class".equals(propertyName)) {
        continue;
      }
      if (!PropertyUtils.isWriteable(component, propertyName)) {
        continue;
      }
      Object value = map.get(propertyName);

      addCriterion(nestedName, entity, excludePropertes, cascadeName, value, criterions, mode,
          ignoreZero);
    }
    return criterions;
View Full Code Here

    if (null == entity) { return; }
    boolean isEntity = false;
    if (entity instanceof Entity) {
      isEntity = true;
    }
    BeanMap map = new BeanMap(entity);
    List<String> attList = CollectUtils.newArrayList();
    attList.addAll(map.keySet());
    attList.remove("class");
    for (final String attr : attList) {
      if (!PropertyUtils.isWriteable(entity, attr)) {
        continue;
      }
      Object value = map.get(attr);
      if (null == value) {
        continue;
      } else {
        // evict invalid entity key
        if (isEntity && attr.equals("id")) {
          if (!ValidEntityKeyPredicate.getInstance().evaluate(value)) {
            map.put(attr, null);
          }
        }
        // evict invalid entity
        if (value instanceof Entity && !ValidEntityPredicate.getInstance().evaluate(value)) {
          map.put(attr, null);
        } else if (value instanceof Component) {
          // evict component recursively
          evictEmptyProperty(value);
        }
      }
View Full Code Here

   *            忽略数字和字符串的默认值
   * @return
   */
  @SuppressWarnings("unchecked")
  public static boolean isEmpty(Entity<?> entity, boolean ignoreDefault) {
    BeanMap map = new BeanMap(entity);
    List<String> attList = CollectUtils.newArrayList();
    attList.addAll(map.keySet());
    attList.remove("class");
    try {
      for (final String attr : attList) {
        if (!PropertyUtils.isWriteable(entity, attr)) {
          continue;
        }
        Object value = map.get(attr);
        if (null == value) {
          continue;
        }
        if (ignoreDefault) {
          if (value instanceof Number) {
View Full Code Here

  void displayResults(Object result) {
    if (null == result)
      return;

    BeanMap beanMap = new BeanMap(result);
    int i = 0;
    for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty.hasNext(); i++) {
      String propertyName = "" + itProperty.next();
      Object propertyValue = beanMap.get(propertyName);

      if ("class".equals(propertyName))
        continue;

      if (null == propertyValue)
        continue;

      Class<?> propertyClass = null;

      try {
        propertyClass = beanMap.getType(propertyName);
      } catch (Exception e) {
        getLog().warn("Failure on property " + propertyName, e);
      }

      if (null == propertyClass) {
View Full Code Here

  protected void displayResults(Object result) {
    if (null == result)
      return;

    BeanMap beanMap = new BeanMap(result);

    for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty.hasNext();) {
      String propertyName = "" + itProperty.next();
      Object propertyValue = beanMap.get(propertyName);

      if ("class".equals(propertyName))
        continue;

      if (null == propertyValue)
        continue;

      Class<?> propertyClass = null;

      try {
        propertyClass = beanMap.getType(propertyName);
      } catch (Exception e) {
        getLog().warn("Failure on property " + propertyName, e);
      }

      if (null == propertyClass) {
View Full Code Here

  protected void displayResults(Object result) {
    if (null == result)
      return;

    BeanMap beanMap = new BeanMap(result);

    for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty
        .hasNext();) {
      String propertyName = "" + itProperty.next();
      Object propertyValue = beanMap.get(propertyName);

      if ("class".equals(propertyName))
        continue;

      if (null == propertyValue)
        continue;

      Class<?> propertyClass = null;

      try {
        propertyClass = beanMap.getType(propertyName);
      } catch (Exception e) {
        getLog().warn("Failure on property " + propertyName, e);
      }

      if (null == propertyClass) {
View Full Code Here

  protected void displayResults(Object result) {
    if (null == result)
      return;

    BeanMap beanMap = new BeanMap(result);

    for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty
        .hasNext();) {
      String propertyName = "" + itProperty.next();
      Object propertyValue = beanMap.get(propertyName);

      if ("class".equals(propertyName))
        continue;

      if (null == propertyValue)
        continue;

      Class<?> propertyClass = null;

      try {
        propertyClass = beanMap.getType(propertyName);
      } catch (Exception e) {
        getLog().warn("Failure on property " + propertyName, e);
      }

      if (null == propertyClass) {
View Full Code Here

TOP

Related Classes of org.apache.commons.beanutils.BeanMap

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.