示例#1
0
  /**
   * 获取查询sql <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String updateSql(Object obj) {
    AssertUtils.notEmpty(obj, "update obj must not empty.");

    // 获取当前对象中有哪些属性
    MetaObject metaObject = MetaObjectUtils.forObject(obj);
    Set<String> keySet = new HashSet<String>();
    for (String getterName : metaObject.getGetterNames()) {
      keySet.add(getterName);
    }
    AssertUtils.isTrue(
        keySet.contains(this.pkName),
        "obj:{} must contains pk{}.",
        new Object[] {obj, this.pkName});

    // 构建query语句
    SqlBuilder.BEGIN();
    SqlBuilder.UPDATE(this.tableName);

    for (String propertyName : updateAblePropertyNames) {
      if (!keySet.contains(propertyName)) {
        continue;
      }
      // Object value = metaObject.getValue(propertyName);
      String columnName = getter2columnNameMapping.get(propertyName);
      SqlBuilder.SET(columnName + " = ?");
    }
    SqlBuilder.WHERE(this.getter2columnNameMapping.get(this.pkName) + " = ? ");
    String updateSql = SqlBuilder.SQL();
    SqlBuilder.RESET();
    return updateSql;
  }
示例#2
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;
  }
示例#3
0
  /**
   * 获取删除语句<br>
   * <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String deleteSql() {
    AssertUtils.notEmpty(this.pkName, "pkName is empty.");
    AssertUtils.isTrue(
        this.getter2columnNameMapping.containsKey(this.pkName),
        "property2columnNameMapping not contains pkName:{}.",
        this.pkName);

    // 开始构建sql
    SqlBuilder.BEGIN();
    SqlBuilder.DELETE_FROM(this.tableName);
    SqlBuilder.WHERE(this.getter2columnNameMapping.get(this.pkName) + " = ? ");
    String deleteSql = SqlBuilder.SQL();
    SqlBuilder.RESET();

    return deleteSql;
  }
示例#4
0
  /**
   * 获取插入语句 <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String insertSql() {
    // 开始构建sql
    SqlBuilder.BEGIN();
    SqlBuilder.INSERT_INTO(this.tableName);
    for (Entry<String, String> entryTemp : getter2columnNameMapping.entrySet()) {
      SqlBuilder.VALUES(entryTemp.getValue(), "?");
    }
    for (Entry<String, String> entryTemp : otherColumn2expressionMapping.entrySet()) {
      SqlBuilder.VALUES(entryTemp.getKey(), entryTemp.getValue());
    }

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

    return insertSql;
  }
示例#5
0
  /**
   * 获取查询单条数据的sql <功能详细描述>
   *
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String findSql() {
    AssertUtils.notEmpty(this.pkName, "pkName is empty.");
    AssertUtils.isTrue(
        this.getter2columnNameMapping.containsKey(this.pkName),
        "property2columnNameMapping not contains pkName:{}.",
        this.pkName);

    SqlBuilder.BEGIN();
    for (Entry<String, String> entryTemp : getter2columnNameMapping.entrySet()) {
      SqlBuilder.SELECT(entryTemp.getValue());
    }
    SqlBuilder.FROM(this.tableName);
    SqlBuilder.WHERE(this.getter2columnNameMapping.get(this.pkName) + " = ? ");
    String findSql = SqlBuilder.SQL();
    SqlBuilder.RESET();
    return findSql;
  }
示例#6
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;
  }