Package org.springframework.jdbc.core.namedparam

Examples of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource


  @Transactional
  public void storeOwner(Owner owner) throws DataAccessException {
    if (owner.isNew()) {
      Number newKey = this.insertOwner.executeAndReturnKey(
          new BeanPropertySqlParameterSource(owner));
      owner.setId(newKey.intValue());
    }
    else {
      this.simpleJdbcTemplate.update(
          "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
          "city=:city, telephone=:telephone WHERE id=:id",
          new BeanPropertySqlParameterSource(owner));
    }
  }
View Full Code Here


      if (arg instanceof MapSqlParameterSource) {
        msp.addValues(((MapSqlParameterSource) arg).getValues());
        continue;
      }

      BeanPropertySqlParameterSource sps = new BeanPropertySqlParameterSource(arg);
      List<Field> fields = new ArrayList<Field>();
      for (Class<?> c = arg.getClass(); c != null; c = c.getSuperclass()) {
        if (c.equals(Object.class))
          continue;
        fields.addAll(Arrays.asList(c.getDeclaredFields()));
      }
      for (Field f : fields) {
        try {
          String fn = f.getName();
          if (msp.hasValue(fn)) {
            if (warnParamOverride) {
              warnParamOverride = false;
              logger.warn(String.format("Field with name=%s has "
                  + "been already mapped by another arg bean. Overriding! Next time will warn if DEBUG is enabled.", fn));
            } else {
              if (logger.isDebugEnabled()) {
                logger.warn(String.format("Field with name=%s has "
                  + "been already mapped by another arg bean. Overriding!", fn));
              }
            }
          }
          if (Enum.class.isAssignableFrom(f.getType())) {
            sps.registerSqlType(f.getName(), Types.VARCHAR);
          }

          msp.addValue(fn, sps.getValue(fn), sps.getSqlType(fn), sps.getTypeName(fn));
          logger.debug(String.format("prepared sql arg: name=%s, value=%s, type=%s", fn, sps.getValue(fn),
              sps.getTypeName(fn)));
        } catch (Exception e) {
          Throwables.propagate(e);
        }
      }
    }
View Full Code Here

        }
    }

    @Override
    public void save(Owner owner) throws DataAccessException {
        BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
        if (owner.isNew()) {
            Number newKey = this.insertOwner.executeAndReturnKey(parameterSource);
            owner.setId(newKey.intValue());
        } else {
            this.namedParameterJdbcTemplate.update(
View Full Code Here

    @Override
    public int addFileHistory(FileHistory fileHistory) {
        String sql = "insert into config_file_history(app_name, file_name, version, xml, comment, creator, create_time, is_published, publisher, publish_time) " +
                "values(:appName, :fileName, :version, :xml, :comment, :creator, :createTime, :published, :publisher, :publishTime)";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(fileHistory);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

    @Override
    public int addApp(App app) {
        String sql = "insert into config_app(app_name, description, creator, create_time) " +
                "values(:appName, :description, :creator, :createTime)";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(app);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

    @Override
    public int addFilePublished(FilePublished filePublished) {
        String sql = "insert into config_file_published(app_name, file_name, version, xml, md5) " +
                "values(:appName, :fileName, :version, :xml, :md5)";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(filePublished);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

    @Override
    public int updateFilePublished(FilePublished filePublished) {
        String sql = "update config_file_published set version=:version, xml=:xml, md5=:md5 " +
                "where app_name=:appName and file_name=:fileName";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(filePublished);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

    @Override
    public int addFileCurrent(FileCurrent fileCurrent) {
        String sql = "insert into config_file_current(app_name, file_name, version, xml, comment, creator, create_time, last_publish_version, last_publisher, last_publish_time) " +
                "values(:appName, :fileName, :version, :xml, :comment, :creator, :createTime, :lastPublishVersion, :lastPublisher, :lastPublishTime)";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(fileCurrent);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

    public int updateFileCurrent(FileCurrent fileCurrent) {
        String sql = "update config_file_current " +
                "set version=:version, xml=:xml, comment=:comment, creator=:creator, create_time=:createTime, " +
                "last_publish_version=:lastPublishVersion, last_publisher=:lastPublisher, last_publish_time=:lastPublishTime" +
                " where app_name=:appName and file_name=:fileName";
        SqlParameterSource bpsp = new BeanPropertySqlParameterSource(fileCurrent);
        return getNamedParameterJdbcTemplate().update(sql, bpsp);
    }
View Full Code Here

  }

  private int queryTotalCount(String countQuery,Object filtersObject) {
    XsqlFilterResult countQueryXsqlResult = getXsqlBuilder().generateHql(countQuery,filtersObject);
    String removedOrderByQuery = SqlRemoveUtils.removeOrders(countQueryXsqlResult.getXsql());
    final int totalCount = getNamedParameterJdbcTemplate().queryForInt(removedOrderByQuery,new BeanPropertySqlParameterSource(filtersObject));
    return totalCount;
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource

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.