Example #1
0
  /**
   * 获取对象的RowMapper <功能详细描述>
   *
   * @return [参数说明]
   * @return RowMapper [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public RowMapper<T> getSelectRowMapper() {
    AssertUtils.notNull(this.type, "type is null");
    AssertUtils.notNull(this.classReflector, "classReflector is null");

    final Class<T> finalType = this.type;
    final ClassReflector<T> finalClassReflector = this.classReflector;
    RowMapper<T> rowMapper =
        new RowMapper<T>() {
          @Override
          public T mapRow(ResultSet rs, int rowNum) throws SQLException {
            T newObjInstance = ObjectUtils.newInstance(finalType);
            MetaObject metaObject = MetaObjectUtils.forObject(newObjInstance);

            for (Entry<String, String> entryTemp : getter2columnNameMapping.entrySet()) {
              String propertyName = entryTemp.getKey();
              String columnName = entryTemp.getValue();
              if (finalClassReflector.getSetterNames().contains(propertyName)) {
                Class<?> type = getter2JavaTypeMapping.get(propertyName);
                Object value = JdbcUtils.getResultSetValueForSimpleType(rs, columnName, type);
                metaObject.setValue(propertyName, value);
              }
            }
            return newObjInstance;
          }
        };
    return rowMapper;
  }
Example #2
0
  /** <默认构造函数> */
  public SqlSource(Class<T> type, Dialect dialect) {
    super();

    AssertUtils.notNull(type, "type is empty.");
    AssertUtils.notNull(dialect, "dialect is empty.");

    this.type = type;
    this.classReflector = ClassReflector.forClass(type);
    this.dialect = dialect;
  }
  /**
   * @param sourceTableDef
   * @param ddlDialect
   * @return
   */
  @Override
  public AlterTableDDLBuilder newInstance(TableDef sourceTable, DDLDialect ddlDialect) {
    AssertUtils.notNull(ddlDialect, "ddlDialect is null.");
    AssertUtils.notNull(sourceTable, "sourceTable is null.");
    AssertUtils.notEmpty(sourceTable.getTableName(), "sourceTable.tableName is empty.");
    AssertUtils.notEmpty(sourceTable.getColumns(), "sourceTable.columns is empty.");

    MysqlAlterTableDDLBuilder builder = new MysqlAlterTableDDLBuilder(sourceTable, ddlDialect);
    return builder;
  }
Example #4
0
  /** <默认构造函数> */
  public SqlSource(Class<T> type, String tableName, String pkName, Dialect dialect) {
    super();

    AssertUtils.notNull(type, "type is empty.");
    AssertUtils.notEmpty(pkName, "pkName is empty.");
    AssertUtils.notEmpty(tableName, "tableName is empty.");
    AssertUtils.notNull(dialect, "dialect is empty.");

    this.type = type;
    this.classReflector = ClassReflector.forClass(type);
    this.pkName = pkName.trim();
    this.tableName = tableName.trim().toUpperCase();
    this.dialect = dialect;
  }
  /**
   * @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;
  }
  /**
   * 根据id更新对象 <功能详细描述>
   *
   * @param templateTable
   * @return [参数说明]
   * @return boolean [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  @Transactional
  public boolean updateById(TemplateTable templateTable) {
    // TODO:验证参数是否合法,必填字段是否填写,
    AssertUtils.notNull(templateTable, "templateTable is null.");
    AssertUtils.notEmpty(templateTable.getId(), "templateTable.id is empty.");

    // TODO:生成需要更新字段的hashMap
    Map<String, Object> updateRowMap = new HashMap<String, Object>();
    updateRowMap.put("id", templateTable.getId());

    // TODO:需要更新的字段
    updateRowMap.put("createOperatorId", templateTable.getCreateOperatorId());
    updateRowMap.put("tableStatus", templateTable.getTableStatus());
    updateRowMap.put("remark", templateTable.getRemark());
    updateRowMap.put("tableName", templateTable.getTableName());
    updateRowMap.put("name", templateTable.getName());
    // type:java.lang.String
    updateRowMap.put("tableType", templateTable.getTableType());
    updateRowMap.put("systemId", templateTable.getSystemId());
    updateRowMap.put("createDate", templateTable.getCreateDate());
    updateRowMap.put("lastUpdateDate", templateTable.getLastUpdateDate());

    int updateRowCount = this.templateTableDao.updateTemplateTable(updateRowMap);

    // TODO:如果需要大于1时,抛出异常并回滚,需要在这里修改
    return updateRowCount >= 1;
  }
  /**
   * @param params
   * @return
   */
  @Override
  public List<RuleItemByteParam> queryRuleItemByteParamList(final Map<String, Object> params) {
    AssertUtils.notNull(params, "params is null.");
    AssertUtils.notEmpty(params.get("ruleKey"), "params.ruleKey is null.");

    StringBuilder sb = new StringBuilder(TxConstants.INITIAL_STR_LENGTH);
    sb.append("SELECT ");
    sb.append("ruleKey,");
    sb.append("paramKey,");
    sb.append("paramOrder,");
    sb.append("paramValue,");
    sb.append(" FROM RULE_BYTE_PARAM ");
    sb.append(" WHERE ruleKey = ?");
    List<RuleItemByteParam> resList =
        this.jdbcTemplate.query(
            sb.toString(),
            new PreparedStatementSetter() {
              @Override
              public void setValues(PreparedStatement ps) throws SQLException {
                int parameterIndex = 0;
                ps.setString(++parameterIndex, (String) params.get("ruleKey"));
              }
            },
            ruleItemByteParamRowMapper);
    return resList;
  }
Example #8
0
  /** @param 对property2columnNameMapping进行赋值 */
  public void addGetter2columnMapping(String getterName, String columnName, Class<?> type) {
    AssertUtils.notEmpty(getterName, "getterName is empty.");
    AssertUtils.notEmpty(columnName, "columnName is empty.");
    AssertUtils.notNull(type, "type is empty.");

    this.getter2columnNameMapping.put(getterName.trim(), columnName.trim().toUpperCase());
    this.getter2JavaTypeMapping.put(getterName, type);
  }
  /**
   * 将templateTable实例插入数据库中保存 1、如果templateTable为空时抛出参数为空异常 2、如果templateTable中部分必要参数为非法值时抛出参数不合法异常
   * <功能详细描述>
   *
   * @param district [参数说明]
   * @return void [返回类型说明]
   * @exception throws
   * @see [类、类#方法、类#成员]
   */
  @Transactional
  public void insertTemplateTable(TemplateTable templateTable) {
    // TODO:验证参数是否合法,必填字段是否填写,
    AssertUtils.notNull(templateTable, "templateTable is null.");
    AssertUtils.notEmpty(templateTable.getId(), "templateTable.id is empty.");

    this.templateTableDao.insertTemplateTable(templateTable);
  }
Example #10
0
  /** <默认构造函数> */
  public SqlSource(Dialect dialect) {
    super();

    AssertUtils.notEmpty(pkName, "pkName is empty.");
    AssertUtils.notEmpty(tableName, "tableName is empty.");
    AssertUtils.notNull(dialect, "dialect is empty.");

    this.dialect = dialect;
  }
Example #11
0
  /**
   * 解析类型为表定义详细实例<br>
   * :实例中将含有对应的索引以及字段和索引<br>
   * <功能详细描述>
   *
   * @param type
   * @return [参数说明]
   * @return TableDef [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public static TableDef analyzeToTableDefDetail(Class<?> type) {
    AssertUtils.notNull(type, "type is null.");

    if (TYPE_2_TABLEDEF_MAP.containsKey(type)) {
      return TYPE_2_TABLEDEF_MAP.get(type);
    }
    JPAEntityTableDef tableDef = doAnalyzeToTableDefDetail(type);
    TYPE_2_TABLEDEF_MAP.put(type, tableDef);
    return tableDef;
  }
  /**
   * @param newTableDef
   * @param sourceTableDef
   * @param ddlDialect
   * @return
   */
  @Override
  public AlterTableDDLBuilder newInstance(
      TableDef newTable, TableDef sourceTable, DDLDialect ddlDialect) {
    AssertUtils.notNull(ddlDialect, "ddlDialect is null.");
    AssertUtils.notNull(newTable, "newTable is null.");
    AssertUtils.notEmpty(newTable.getTableName(), "newTable.tableName is empty.");
    AssertUtils.notNull(sourceTable, "sourceTable is null.");
    AssertUtils.notEmpty(sourceTable.getTableName(), "sourceTable.tableName is empty.");
    AssertUtils.isTrue(
        newTable.getTableName().equalsIgnoreCase(sourceTable.getTableName()),
        "newTable.tableName:{} should equalsIgnoreCase sourceTable.tableName:{}",
        new Object[] {newTable.getTableName(), sourceTable.getTableName()});

    MysqlAlterTableDDLBuilder builder =
        new MysqlAlterTableDDLBuilder(newTable, sourceTable, ddlDialect);
    this.columns.addAll(newTable.getColumns());
    this.indexes.addAll(newTable.getIndexes());
    return builder;
  }
Example #13
0
  /** <默认构造函数> */
  public SqlSource(String tableName, String pkName, Dialect dialect) {
    super();

    AssertUtils.notEmpty(pkName, "pkName is empty.");
    AssertUtils.notEmpty(tableName, "tableName is empty.");
    AssertUtils.notNull(dialect, "dialect is empty.");

    this.pkName = pkName.trim();
    this.tableName = tableName.trim().toUpperCase();
    this.dialect = dialect;
  }
  /** <默认构造函数> */
  public RuleItemByteParamDaoImpl(JdbcTemplate jdbcTemplate, LobHandler lobHandler) {
    super();
    AssertUtils.notNull(jdbcTemplate == null, "jdbcTemplate is null.");
    AssertUtils.notNull(lobHandler == null, "lobHandler is null.");
    this.jdbcTemplate = jdbcTemplate;
    this.lobHandler = lobHandler;

    final LobHandler finalLobHandler = this.lobHandler;
    this.ruleItemByteParamRowMapper =
        new RowMapper<RuleItemByteParam>() {
          @Override
          public RuleItemByteParam mapRow(ResultSet rs, int rowNum) throws SQLException {
            RuleItemByteParam ruleItemByteParam = new RuleItemByteParam();
            ruleItemByteParam.setParamKey(rs.getString("paramKey"));
            ruleItemByteParam.setParamOrder(rs.getInt("paramOrder"));
            byte[] attach = finalLobHandler.getBlobAsBytes(rs, "paramValue");
            ruleItemByteParam.setParamValue(attach);
            ruleItemByteParam.setRuleKey(rs.getString("ruleKey"));

            return ruleItemByteParam;
          }
        };
  }
Example #15
0
  /**
   * 添加属性值与条件的映射关系<br>
   * <功能详细描述>
   *
   * @param propertyName
   * @param conditionExpression [参数说明]
   * @return void [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public void addQueryConditionKey2SqlMapping(
      QueryConditionTypeEnum queryConditionType,
      String key,
      String conditionExpression,
      JdbcType jdbcType,
      Class<?> javaType) {
    AssertUtils.notEmpty(key, "key is empty.");
    AssertUtils.notEmpty(conditionExpression, "conditionExpression is empty.");
    AssertUtils.notNull(jdbcType, "jdbcType is empty.");

    this.queryConditionKey2SqlMapping.put(key, conditionExpression);
    this.queryConditionKey2JdbcTypeMapping.put(key, jdbcType);
    this.queryConditionKey2JavaTypeMapping.put(key, javaType);

    if (queryConditionType != null) {
      this.queryConditionKey2ConditionInfoMapping.put(
          key, new QueryConditionInfo(queryConditionType, key, javaType, jdbcType));
    }
  }
Example #16
0
  /**
   * 获取一个设置的callbackHandler实现 <功能详细描述>
   *
   * @param newObjInstance
   * @return [参数说明]
   * @return RowCallbackHandler [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public RowCallbackHandler getSelectRowCallbackHandler(Object newObjInstance) {
    AssertUtils.notNull(this.classReflector, "classReflector is null");

    final MetaObject metaObject = MetaObjectUtils.forObject(newObjInstance);
    final ClassReflector<T> finalClassReflector = this.classReflector;
    RowCallbackHandler res =
        new RowCallbackHandler() {
          @Override
          public void processRow(ResultSet rs) throws SQLException {
            for (Entry<String, String> entryTemp : getter2columnNameMapping.entrySet()) {

              String propertyName = entryTemp.getKey();
              String columnName = entryTemp.getValue();

              if (finalClassReflector.getSetterNames().contains(propertyName)) {
                Class<?> type = getter2JavaTypeMapping.get(propertyName);
                Object value = JdbcUtils.getResultSetValueForSimpleType(rs, columnName, type);
                metaObject.setValue(propertyName, value);
              }
            }
          }
        };
    return res;
  }
Example #17
0
 /**
  * 获取对象的主键值
  *
  * @param 对pkName进行赋值
  */
 public Object getValue(Object obj) {
   AssertUtils.notNull(obj, "obj is null.");
   MetaObject metaObject = MetaObjectUtils.forObject(obj);
   return metaObject.getValue(this.pkName);
 }
Example #18
0
  /**
   * 添加getter2ColumnInfo的映射 <功能详细描述>
   *
   * @param jpaMetaClass
   * @param getterName [参数说明]
   * @return void [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public void addGetter2GetterColumnInfoMapping(JpaMetaClass<?> jpaMetaClass, String getterName) {
    AssertUtils.notEmpty(getterName, "getterName is empty.");
    AssertUtils.notNull(jpaMetaClass, "jpaMetaClass is empty.");

    this.getter2getterColumnInfo.put(getterName, new Getter2ColumnInfo(jpaMetaClass, getterName));
  }
Example #19
0
  /** @param 对type进行赋值 */
  public void setType(Class<T> type) {
    AssertUtils.notNull(type, "type is empty.");

    this.type = type;
    this.classReflector = ClassReflector.forClass(type);
  }
Example #20
0
  /**
   * 获取规则关键字 <功能详细描述>
   *
   * @param rule
   * @return [参数说明]
   * @return String [返回类型说明]
   * @exception throws [异常类型] [异常说明]
   * @see [类、类#方法、类#成员]
   */
  public String getRuleKey(Rule rule) {
    AssertUtils.notNull(rule, "rule is emtpy.");

    return getRuleCacheKey(rule);
  }