Package org.springframework.jdbc.support

Examples of org.springframework.jdbc.support.KeyHolder


          secondaryIndex.getResource().getId(),
          secondaryIndex.getColumnInfo().getName(),
          JdbcTypeMapper.jdbcTypeToString(secondaryIndex.getColumnInfo().getColumnType()),
          secondaryIndex.getId()};
   
    KeyHolder generatedKey = new GeneratedKeyHolder();
    JdbcTemplate j = getJdbcTemplate();
    PreparedStatementCreatorFactory creatorFactory = new PreparedStatementCreatorFactory(
        "UPDATE secondary_index_metadata SET resource_id=?,column_name=?,db_type=? WHERE id=?",
        new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER });
    creatorFactory.setReturnGeneratedKeys(true);
View Full Code Here


    Object[] parameters;
    parameters = new Object[]{newObject.getName(),
      newObject.getIndexUri(),
      JdbcTypeMapper.jdbcTypeToString(newObject.getColumnType())};

    KeyHolder generatedKey = new GeneratedKeyHolder();
    JdbcTemplate j = getJdbcTemplate();
    PreparedStatementCreatorFactory creatorFactory = new PreparedStatementCreatorFactory(
      "INSERT INTO partition_dimension_metadata (name,index_uri,db_type) VALUES (?,?,?)",
      new int[]{Types.VARCHAR, Types.VARCHAR, Types.VARCHAR});
    creatorFactory.setReturnGeneratedKeys(true);
    int rows = j.update(creatorFactory
      .newPreparedStatementCreator(parameters), generatedKey);
    if (rows != 1)
      throw new HiveRuntimeException("Unable to create Partition Dimension: " + parameters);
    if (generatedKey.getKeyList().size() == 0)
      throw new HiveRuntimeException("Unable to retrieve generated primary key");
    newObject.updateId(generatedKey.getKey().intValue());

    // dependencies
    for (Resource r : newObject.getResources())
      new ResourceDao(getDataSource()).create(r);
View Full Code Here

  public NodeDao(DataSource ds) {
    this.setDataSource(ds);
  }

  public Node create(Node newObject) {
    KeyHolder generatedKey = new GeneratedKeyHolder();
    JdbcTemplate j = getJdbcTemplate();
   
    PreparedStatementCreatorFactory creatorFactory =
      new PreparedStatementCreatorFactory(insertSql(),getTypes());
    creatorFactory.setReturnGeneratedKeys(true);
   
    int rows = j.update(creatorFactory.newPreparedStatementCreator(getParameters(newObject)), generatedKey);
    if (rows != 1)
      throw new HiveRuntimeException("Unable to create Resource: "
          + getParameters(newObject));
    if (generatedKey.getKeyList().size() == 0)
      throw new HiveRuntimeException("Unable to retrieve generated primary key");
   
    newObject.updateId(generatedKey.getKey().intValue());
   
    return newObject; 
  }
View Full Code Here

      final String shead = section.getShortHeading();
      final String heading = section.getHeading();
      final int sequence = section.getSectionSequence();
      final String headingText = section.getTextHeading();

      KeyHolder keyHolder = new GeneratedKeyHolder();
      this.getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(
              SQL_CREATE_SECTION, new String[] { "id" });

          if (parentId == null) {
            ps.setNull(1, java.sql.Types.INTEGER);
          } else {
            ps.setInt(1, parentId);
          }
          if (codeId == null) {
            ps.setNull(2, java.sql.Types.INTEGER);
          } else {
            ps.setInt(2, codeId);
          }
          ps.setString(3, heading);
          ps.setString(4, shead);
          ps.setString(5, ref);
          ps.setInt(6, sequence);
          ps.setString(7, leveltype);
          ps.setString(8, levelpos);
          ps.setString(9, headingText);
          return ps;
        }
      }, keyHolder);

      int newID = keyHolder.getKey().intValue();
      section.setId(newID);
      return newID;
    } catch (DataIntegrityViolationException e) {
      System.out.println("Could not create section: "
          + e.getLocalizedMessage());
View Full Code Here

      final String status = code.getStatus();
      final int colId = code.getCodeCollectionId();
      final int codeSeq = code.getCodeSequence();
      final String headTitle = code.getTitle();

      KeyHolder keyHolder = new GeneratedKeyHolder();
      this.getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(
              SQL_CREATE, new String[] { "id" });
          ps.setString(1, heading);
          ps.setString(2, shead);
          ps.setString(3, name);
          ps.setInt(4, codeSeq);
          ps.setString(5, status);
          ps.setInt(6, colId);
          ps.setString(7, headTitle);
          return ps;
        }
      }, keyHolder);

      int newID = keyHolder.getKey().intValue();
      code.setId(newID);
      return newID;
    } catch (DataIntegrityViolationException e) {
      System.out.println("Could not create code: "
          + e.getLocalizedMessage());
View Full Code Here

      final int sid = content.getSectionId();
      final String data = content.getContent();
      final String format = content.getFormatType();
      final boolean isNotes = content.isNotes();

      KeyHolder keyHolder = new GeneratedKeyHolder();
      this.getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(
              SQL_CREATE, new String[] { "id" });
          ps.setInt(1, sid);
          ps.setString(2, data);
          ps.setString(3, format);
          ps.setBoolean(4, isNotes);
          return ps;
        }
      }, keyHolder);

      int newID = keyHolder.getKey().intValue();
      content.setId(newID);
      return newID;
    } catch (DataIntegrityViolationException e) {
      System.out.println("Could not create content full: "
          + e.getLocalizedMessage());
View Full Code Here

      final boolean isNotes = content.isNotes();
      final String ctype = content.getContentType();
      final String ntype = content.getNotesType();
      final String ftype = content.getFormatType();

      KeyHolder keyHolder = new GeneratedKeyHolder();
      this.getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(
            Connection connection) throws SQLException {
          PreparedStatement ps = connection.prepareStatement(
              SQL_CREATE, new String[] { "id" });
          ps.setString(1, text);
          ps.setInt(2, sectionId);
          if (contentId == null) {
            ps.setNull(3, java.sql.Types.INTEGER);
          } else {
            ps.setInt(3, contentId);
          }
          ps.setInt(4, sortKey);
          ps.setBoolean(5, isHeader);
          ps.setBoolean(6, isNotes);
          ps.setString(7, ctype);
          ps.setString(8, ntype);
          ps.setString(9, ftype);
          return ps;
        }
      }, keyHolder);

      int newID = keyHolder.getKey().intValue();
      content.setId(newID);
      return newID;
    } catch (DataIntegrityViolationException e) {
      System.out.println("Could not create content part: "
          + e.getLocalizedMessage());
View Full Code Here

    final String name = codeCollection.getName();
    final String scode = codeCollection.getStateCode();
    final boolean isFed = codeCollection.isFederal();
    final int year = codeCollection.getYear();

    KeyHolder keyHolder = new GeneratedKeyHolder();
    this.getJdbcTemplate().update(new PreparedStatementCreator() {
      public PreparedStatement createPreparedStatement(
          Connection connection) throws SQLException {
        PreparedStatement ps = connection.prepareStatement(SQL_CREATE,
            new String[] { "id" });
        ps.setInt(1, year);
        ps.setString(2, heading);
        ps.setString(3, name);
        ps.setBoolean(4, isFed);
        ps.setString(5, scode);
        return ps;
      }
    }, keyHolder);

    int newID = keyHolder.getKey().intValue();
    codeCollection.setId(newID);
    return newID;

  }
View Full Code Here

        Number result;
        DataAccess dataAccess = dataAccessProvider.getDataAccess(//
                runtime.getMetaData(), runtime.getProperties());
        if (returnGeneratedKeys) {
            ArrayList<Number> keys = new ArrayList<Number>(1);
            KeyHolder generatedKeyHolder = new GeneratedKeyHolder(keys);
            dataAccess.update(runtime.getSQL(), runtime.getArgs(), generatedKeyHolder);
            if (keys.size() > 0) {
                result = generatedKeyHolder.getKey();
            } else {
                result = null;
            }
        } else {
            result = new Integer(dataAccess.update(runtime.getSQL(), runtime.getArgs(), null));
View Full Code Here

  private UpdateResult updateInternal(String procName, String sql, Object... args) throws DataAccessException {
    sql = checkAuthPlaceholder(sql);
    return new CallTemplate<UpdateResult>() {
      @Override
      UpdateResult doCall(String sql, MapSqlParameterSource params) {
        KeyHolder kh = new GeneratedKeyHolder();
        int rowsAffected = getJdbcTemplate().update(sql, params, kh);
        return new UpdateResult(kh, rowsAffected);
      }
    }.call(procName, sql, args);
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.support.KeyHolder

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.