Exemplo n.º 1
0
  /**
   * 获取查询sql <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String countSql(Object obj) {
    // 构建query语句
    SqlBuilder.BEGIN();
    SqlBuilder.SELECT("COUNT(1)");
    SqlBuilder.FROM(this.tableName);

    if (!ObjectUtils.isEmpty(obj)) {
      MetaObject metaObject = MetaObjectUtils.forObject(obj);
      for (Entry<String, String> entryTemp : queryConditionKey2SqlMapping.entrySet()) {
        String queryKeyName = entryTemp.getKey();
        Object valueObj = metaObject.getValue(queryKeyName);
        if (ObjectUtils.isEmpty(valueObj)) {
          continue;
        }
        SqlBuilder.WHERE(entryTemp.getValue());
      }
    }
    for (String conditionExpressionTemp : otherCondition) {
      SqlBuilder.WHERE(conditionExpressionTemp);
    }
    String querySql = SqlBuilder.SQL();
    SqlBuilder.RESET();

    return querySql;
  }
Exemplo n.º 2
0
  /**
   * 获取查询条件的Setter对象 <功能详细描述>
   *
   * @param obj
   * @return [参数说明]
   * @return PreparedStatementSetter [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public PreparedStatementSetter getQueryCondtionSetter(Object obj) {
    PreparedStatementSetter res = null;
    if (!ObjectUtils.isEmpty(obj)) {
      final MetaObject metaObject = MetaObjectUtils.forObject(obj);
      res =
          new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps) throws SQLException {
              int i = 1;
              for (Entry<String, String> entryTemp : queryConditionKey2SqlMapping.entrySet()) {
                String queryKeyName = entryTemp.getKey();
                Object valueObj = metaObject.getValue(queryKeyName);
                if (ObjectUtils.isEmpty(valueObj)) {
                  continue;
                }
                JdbcType jdbcType = queryConditionKey2JdbcTypeMapping.get(queryKeyName);
                JdbcUtils.setPreparedStatementValueForSimpleType(ps, i, valueObj, jdbcType);
                i++;
              }
            }
          };
    } else {
      res =
          new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps) throws SQLException {}
          };
    }

    return res;
  }
  /**
   * @param condition
   * @return
   */
  @Override
  public int deleteRuleItemByteParam(final RuleItemByteParam condition) {
    AssertUtils.notNull(condition, "ruleItemByteParam is null.");
    AssertUtils.notEmpty(condition.getRuleKey(), "ruleItemValueParam.ruleKey is null.");

    StringBuilder sb = new StringBuilder(TxConstants.INITIAL_STR_LENGTH);
    sb.append("DELETE FROM RULE_BYTE_PARAM ");
    sb.append(" WHERE ruleKey = ? ");
    if (!ObjectUtils.isEmpty(condition.getParamKey())) {
      sb.append(" AND paramKey = ? ");
    }
    int resInt =
        this.jdbcTemplate.update(
            sb.toString(),
            new PreparedStatementSetter() {
              @Override
              public void setValues(PreparedStatement ps) throws SQLException {
                int parameterIndex = 0;
                ps.setString(++parameterIndex, condition.getRuleKey());
                if (!ObjectUtils.isEmpty(condition.getParamKey())) {
                  ps.setString(++parameterIndex, condition.getParamKey());
                }
              }
            });
    return resInt;
  }
Exemplo n.º 4
0
  /**
   * 获取查询sql <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String querySql(Object obj) {
    AssertUtils.notEmpty(this.pkName, "pkName is empty.");
    AssertUtils.isTrue(
        this.getter2columnNameMapping.containsKey(this.pkName),
        "property2columnNameMapping not contains pkName:{}.",
        this.pkName);

    // 构建query语句
    SqlBuilder.BEGIN();
    for (Entry<String, String> entryTemp : getter2columnNameMapping.entrySet()) {
      SqlBuilder.SELECT(entryTemp.getValue());
    }
    SqlBuilder.FROM(this.tableName);

    if (!ObjectUtils.isEmpty(obj)) {
      MetaObject metaObject = MetaObjectUtils.forObject(obj);
      for (Entry<String, String> entryTemp : queryConditionKey2SqlMapping.entrySet()) {
        String queryKeyName = entryTemp.getKey();
        Object valueObj = metaObject.getValue(queryKeyName);
        if (ObjectUtils.isEmpty(valueObj)) {
          continue;
        }
        SqlBuilder.WHERE(entryTemp.getValue());
      }
    }
    for (String conditionExpressionTemp : otherCondition) {
      SqlBuilder.WHERE(conditionExpressionTemp);
    }

    // 在不存在排序字段时默认使用主键对应字段作为排序字段<br/>
    if (CollectionUtils.isEmpty(orderList)) {
      SqlBuilder.ORDER_BY(this.getter2columnNameMapping.get(this.pkName));
    } else {
      for (String order : orderList) {
        SqlBuilder.ORDER_BY(order);
      }
    }

    String querySql = SqlBuilder.SQL();
    SqlBuilder.RESET();

    return querySql;
  }
Exemplo n.º 5
0
 /**
  * 获取动态查询条件的参数映射关系<br>
  * <功能详细描述>
  *
  * @param obj
  * @return [参数说明]
  * @return LinkedHashMap<String,Object> [返回类型说明]
  * @exception throws [异常类型] [异常说明]
  * @see [类、类#方法、类#成员]
  */
 public LinkedHashMap<String, Object> getQueryCondtionParamMaps(Object obj) {
   final MetaObject metaObject = MetaObjectUtils.forObject(obj);
   final LinkedHashMap<String, Object> resMap = new LinkedHashMap<String, Object>();
   for (Entry<String, String> entryTemp : queryConditionKey2SqlMapping.entrySet()) {
     String queryKeyName = entryTemp.getKey();
     Object valueObj = metaObject.getValue(queryKeyName);
     if (ObjectUtils.isEmpty(valueObj)) {
       continue;
     }
     resMap.put(queryKeyName, valueObj);
   }
   return resMap;
 }