Package org.springframework.jdbc.core

Examples of org.springframework.jdbc.core.PreparedStatementCreator


  private <S extends T> S createWithAutoGeneratedKey(S entity, Map<String, Object> columns) {
    removeIdColumns(columns);
    final String createQuery = sqlGenerator.create(table, columns);
    final Object[] queryParams = columns.values().toArray();
    final GeneratedKeyHolder key = new GeneratedKeyHolder();
    jdbcOperations.update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
        final String idColumnName = table.getIdColumns().get(0);
        final PreparedStatement ps = con.prepareStatement(createQuery, new String[]{idColumnName});
        for (int i = 0; i < queryParams.length; ++i) {
View Full Code Here


        // CAMEL-7313 - check whether to return generated keys
        final Boolean shouldRetrieveGeneratedKeys =
            exchange.getIn().getHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, false, Boolean.class);

        PreparedStatementCreator statementCreator = new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                if (!shouldRetrieveGeneratedKeys) {
                    return con.prepareStatement(preparedQuery);
                } else {
View Full Code Here

      else if (entity.getId() != null) {
        returnCode = executeStatementSet(stmtSet);
      }
      else {
        KeyHolder keyHolder = new GeneratedKeyHolder();
        returnCode = jdbcTemplate.update(new PreparedStatementCreator() {
 
          public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
           
            LOG.info("Model INFO :" + stmtSet.getSql() + " param : " + Arrays.toString(stmtSet.getParams()));
            PreparedStatement ps = connection.prepareStatement(stmtSet.getSql(), new String[] { "id" });
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);
          }
         
        };
        template.query(sql_, params, new RowCallbackHandler() {
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()) {
      getJdbcTemplate().update(
          new PreparedStatementCreator() {
            @Override
            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, 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, getInsertTypes());
              return ps;
            }
View Full Code Here

    final String createStatement = Dao.createStatements.get(type);

    KeyHolder holder = new GeneratedKeyHolder();
    try {
      // Create a prepared statement.
      insert.update(new PreparedStatementCreator() {

        @Override
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
View Full Code Here

      boxlets = customBoxlets.toArray(new String[customBoxlets.size()]);
    }

    final String[] finalBoxlets = boxlets;
    if (jdbcTemplate.update(
            new PreparedStatementCreator() {
              @Override
              public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                PreparedStatement st = con.prepareStatement("UPDATE user_settings SET settings=?, main=? WHERE id=?");

                st.setObject(1, profile.getSettings());

                if (finalBoxlets!=null) {
                  st.setArray(2, con.createArrayOf("text", finalBoxlets));
                } else {
                  st.setNull(2, Types.ARRAY);
                }

                st.setInt(3, user.getId());

                return st;
              }
            })==0) {
      jdbcTemplate.update(
              new PreparedStatementCreator() {
                @Override
                public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                  PreparedStatement st = con.prepareStatement("INSERT INTO user_settings (id, settings, main) VALUES (?,?,?)");

                  st.setInt(1, user.getId());
View Full Code Here

    try {
      final String name = alias.getAliasname();
      final int codeId = alias.getCodeId();

      this.getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(
              SQL_INSERT, new String[] {});
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.