Package org.springframework.jdbc.core

Examples of org.springframework.jdbc.core.PreparedStatementCreator


        logger.debug("SQL for Save: " + sql);
        int updateCount = 0;
        if (isNewRow && persistentObject.isUsingGeneratedKeysStrategy()) {
            KeyHolder keyHolder = new GeneratedKeyHolder();
            final String prepSql = sql.toString();
            updateCount = getJdbcTemplate().update(new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(prepSql, Statement.RETURN_GENERATED_KEYS);
                    int cnt = 0;
                    for (Iterator iter = parameterValues.iterator(); iter.hasNext(); ) {
                        PersistentValue pv = (PersistentValue)iter.next();
                        StatementCreatorUtils.setParameterValue(ps, cnt+1, pv.getSqlType(), null, pv.getValue());
                        cnt++;
                    }
                    return ps;
                }
            }, keyHolder);
            assignGeneratedKey(o, keyHolder);
        }
        else {
            final String prepSql = sql.toString();
            updateCount = getJdbcTemplate().update(new PreparedStatementCreator() {
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                    PreparedStatement ps = con.prepareStatement(prepSql);
                    int cnt = 0;
                    for (Iterator iter = parameterValues.iterator(); iter.hasNext(); ) {
                        PersistentValue pv = (PersistentValue)iter.next();
View Full Code Here


    public User createUser(final User user) {
        final String sql = "insert into sys_users(username, password, salt, locked) values(?,?,?, ?)";

        GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
        getJdbcTemplate().update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement psst = connection.prepareStatement(sql, new String[]{"id"});
                psst.setString(1, user.getUsername());
                psst.setString(2, user.getPassword());
View Full Code Here

   */
  public List getAll() {
    JdbcTemplate jt = new JdbcTemplate(getDataSource());
   
    return (List)jt.execute(
      new PreparedStatementCreator() {

        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
          return connection.prepareStatement("select t.*, td.* from Tests t inner join TestDetails td on t.TestId = td.Test");
        }
      
View Full Code Here

      return keyHolder;
    }
    else {
      //TODO Add support for SQL Type info
      int updateCount = jdbcTemplate.update(
          new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
              PreparedStatement ps = prepareStatementForGeneratedKeys(con);
              setParameterValues(ps, values, null);
              return ps;
            }
View Full Code Here

      logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values);
    }
    final KeyHolder keyHolder = new GeneratedKeyHolder();
    if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) {
      jdbcTemplate.update(
          new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
              PreparedStatement ps = prepareStatementForGeneratedKeys(con);
              setParameterValues(ps, values, getInsertTypes());
              return ps;
            }
View Full Code Here

      logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values);
    }
    final KeyHolder keyHolder = new GeneratedKeyHolder();
    if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) {
      jdbcTemplate.update(
          new PreparedStatementCreator() {
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
              PreparedStatement ps = prepareStatementForGeneratedKeys(con);
              setParameterValues(ps, values, null);
              return ps;
            }
View Full Code Here

        ParsedSql parsedSql = parseSqlStatement(sql);
        String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
        Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
        List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, paramSource);
        PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
        PreparedStatementCreator psc = pscf.newPreparedStatementCreator(params);
        PreparedStatement stmt = psc.createPreparedStatement(con);
        registry.put(registryKey, stmt);
        return stmt;
    }
View Full Code Here

        NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource) {
          @Override
          protected PreparedStatementCreator getPreparedStatementCreator(String sql,
              SqlParameterSource paramSource) {
            PreparedStatementCreator originalCreator = super.getPreparedStatementCreator(sql, paramSource);
            return new StreamingStatementCreator(originalCreator);
          }

        };
        final AtomicInteger rowNum = new AtomicInteger(0);
View Full Code Here

      final BagOfWordsData bagOfWordsData) {
    txNew.execute(new TransactionCallback<Object>() {

      @Override
      public Object doInTransaction(TransactionStatus txStatus) {
        jdbcTemplate.query(new PreparedStatementCreator() {

          @Override
          public PreparedStatement createPreparedStatement(
              Connection conn) throws SQLException {
            return conn.prepareStatement(sql,
View Full Code Here

      final BagOfWordsData bagOfWordsData) {
    txNew.execute(new TransactionCallback<Object>() {

      @Override
      public Object doInTransaction(TransactionStatus txStatus) {
        jdbcTemplate.query(new PreparedStatementCreator() {

          @Override
          public PreparedStatement createPreparedStatement(
              Connection conn) throws SQLException {
            return conn.prepareStatement(sql,
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.PreparedStatementCreator

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.