Package org.springframework.jdbc.support

Examples of org.springframework.jdbc.support.GeneratedKeyHolder


 
  @Transactional
  @Override
  public void create(final BannerForm banner) {
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("banner")+ " SET name = ?, status = ?";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, banner.getName());
        ps.setInt(2, banner.getStatus());
        return ps;
      }
    }, keyHolder);
   
    int bannerId = keyHolder.getKey().intValue();
   
    banner.setId(bannerId);
    addBannerImages(banner);
  }
View Full Code Here


 
  private void addBannerImages(final BannerForm banner){
    if(banner.getImages().size()>0){
      for(final BannerImage image: banner.getImages()){
       
        KeyHolder keyHolder = new GeneratedKeyHolder();
        getJdbcOperations().update(new PreparedStatementCreator() {
          @Override
          public PreparedStatement createPreparedStatement(Connection con)
              throws SQLException {
            String sql = "INSERT INTO " +quoteTable("banner_image")+ " SET banner_id = ?, link = ?, image = ?";
            PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setInt(1, banner.getId());
            ps.setString(2, image.getLink());
            ps.setString(3, image.getImage());
            return ps;
          }
        }, keyHolder);
       
        int imageId = keyHolder.getKey().intValue();
       
        if(image.getDescs().size()>0){
          String sql = "INSERT INTO " +quoteTable("banner_image_description")
              + " SET banner_image_id = ?, language_id = ?, banner_id = ?, title = ?";
          for(BannerImageDesc desc: image.getDescs()){
View Full Code Here

 
  @Transactional
  @Override
  public void create(final LayoutForm layoutForm) {
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("layout") + "(name) VALUES(?)";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, layoutForm.getName());
        return ps;
      }
    }, keyHolder);
   
    int layoutId = keyHolder.getKey().intValue();
   
    layoutForm.setId(layoutId);
    addLayoutRoutes(layoutForm);
  }
View Full Code Here

 
 
  @Transactional
  @Override
  public void create(final CategoryForm catForm) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO " +quoteTable("category")+ "(image, parent_id, top,"
          +quoteName("column")+",sort_order, status, date_added, date_modified) VALUES(?,?,?,?,?,?,?,?) ";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, HtmlUtils.htmlEscape(catForm.getImage()));
        ps.setInt(2, catForm.getParentId());
        ps.setBoolean(3, catForm.isTop());
        ps.setInt(4, catForm.getColumn());
        ps.setInt(5, catForm.getSortOrder());
        ps.setShort(6, catForm.getStatus());
        Timestamp currentTime = new Timestamp(new Date().getTime());
        ps.setTimestamp(7, currentTime);
        ps.setTimestamp(8, currentTime);
        return ps;
      }
    }, keyHolder);
    Integer catId = keyHolder.getKey().intValue();
    catForm.setId(catId);
    setAdditionalFormValues(catForm);
  }
View Full Code Here

 
  @Transactional
  @Override
  public void create(final GeoZoneForm geoZone) {
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO "+quoteTable("geo_zone")+"(name, description, date_added) VALUES(?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, geoZone.getName());
        ps.setString(2, geoZone.getDescription());
        ps.setTimestamp(3, new Timestamp(new Date().getTime()));
        return ps;
      }
    }, keyHolder);
   
    int geoZoneId = keyHolder.getKey().intValue();
   
    addZoneToGeoZones(geoZoneId, geoZone.getZoneToGeoZones());
   
  }
View Full Code Here

      if(orderStatusId!=null){
        String sql = "INSERT INTO "+quoteTable("order_status")+"(order_status_id, language_id, name) VALUES(?, ?, ?)";
        getJdbcOperations().update(sql, orderStatusId,
            desc.getLanguageId(), desc.getName());
      }else{
        KeyHolder keyHolder = new GeneratedKeyHolder();
        getJdbcOperations().update(new PreparedStatementCreator() {
          @Override
          public PreparedStatement createPreparedStatement(Connection con)
              throws SQLException {
            String sql = "INSERT INTO "+quoteTable("order_status")+"(language_id, name) VALUES(?, ?)";
            PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setInt(1, desc.getLanguageId());
            ps.setString(2, desc.getName());
            return ps;
          }
        }, keyHolder);
        orderStatusId = keyHolder.getKey().intValue();
      }
    }
  }
View Full Code Here

 
  @Transactional
  @Override
  public void create(final TaxClass taxClass) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO "+quoteTable("tax_class")+"(title, description, date_added) VALUES(?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, taxClass.getTitle());
        ps.setString(2, taxClass.getDescription());
        ps.setTimestamp(3, new Timestamp(new Date().getTime()));
        return ps;
      }
    }, keyHolder);
   
    int taxClassId = keyHolder.getKey().intValue();
   
    addTaxRules(taxClassId, taxClass.getTaxRules());
  }
View Full Code Here

 
  @Transactional
  @Override
  public void create(final LanguageForm lang) {
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO "+quoteTable("language")+"(name, code, locale, " +
            "directory, filename, image, sort_order, status) VALUES(?,?,?,?,?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, lang.getName());
        ps.setString(2, lang.getCode());
        ps.setString(3, lang.getLocaleAsString());
        ps.setString(4, lang.getDirectory());
        ps.setString(5, lang.getFilename());
        ps.setString(6, lang.getImage());
        ps.setInt(7, lang.getSortOrder());
        ps.setInt(8, lang.getStatus());
        return ps;
      }
    }, keyHolder);
   
    int langId = keyHolder.getKey().intValue();
   
    //find default language. We're going to copy text from default language to the new one.
    String langCode = getJdbcOperations().queryForObject("SELECT value FROM "+quoteTable("setting")
        +" WHERE "+quoteName("group")+" = 'config' AND "+quoteName("key")
        +" = 'config_language' AND store_id=0", String.class);
View Full Code Here

 
  @Transactional
  @Override
  public void create(final VoucherThemeForm vtForm) {
   
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO "+quoteTable("voucher_theme")+" SET image = ?";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, vtForm.getImage());
        return ps;
      }
    }, keyHolder);
    Integer attrId = keyHolder.getKey().intValue();
    vtForm.setId(attrId);
    setAdditionalFormValues(vtForm);
  }
View Full Code Here

 
  @Transactional
  @Override
  public void create(final TaxRate taxRate) {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcOperations().update(new PreparedStatementCreator() {
      @Override
      public PreparedStatement createPreparedStatement(Connection con)
          throws SQLException {
        String sql = "INSERT INTO "+quoteTable("tax_rate")+"(name, rate, type, geo_zone_id, date_added, date_modified) VALUES(?,?,?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, taxRate.getName());
        ps.setBigDecimal(2, taxRate.getRate());
        ps.setString(3, taxRate.getType());
        ps.setInt(4, taxRate.getGeoZoneId());
        Timestamp timestamp = new Timestamp(new Date().getTime());
        ps.setTimestamp(5, timestamp);
        ps.setTimestamp(6, timestamp);
        return ps;
      }
    }, keyHolder);
   
    int taxRateId = keyHolder.getKey().intValue();
   
    addCustomerGroupIds(taxRateId, taxRate.getCustomerGroupIds());
   
  }
View Full Code Here

TOP

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

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.