Package org.springframework.jdbc.core.namedparam

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


          params.addValue("identificationBarcode", barcode);

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != pool.getId()) {
            log.error("Expected Pool ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(POOL_DELETE, new MapSqlParameterSource().addValue("poolId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Pool ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Pool - issue with naming scheme", e);
      }
      /*
      String name = AbstractPool.lookupPrefix(pool.getPlatformType())+ DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      params.addValue("identificationBarcode", name + "::" + pool.getPlatformType().getKey());
      Number newId = insert.executeAndReturnKey(params);
      pool.setPoolId(newId.longValue());
      pool.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", pool.getName())) {
          params.addValue("poolId", pool.getId())
              .addValue("name", pool.getName())
              .addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(POOL_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Pool - issue with naming scheme", e);
      }
      /*
      params.addValue("poolId", pool.getPoolId())
              .addValue("name", pool.getName())
              .addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(POOL_UPDATE, params);
      */
    }

    //log.info("Unlinking elements from pool " + pool.getId());
    MapSqlParameterSource delparams = new MapSqlParameterSource();
    delparams.addValue("pool_poolId", pool.getId());
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    namedTemplate.update(POOL_ELEMENT_DELETE_BY_POOL_ID, delparams);

    if (pool.getPoolableElements() != null && !pool.getPoolableElements().isEmpty()) {
      String type = pool.getPoolableElements().iterator().next().getClass().getSimpleName();

      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template).withTableName("Pool_Elements");
      String lc = type.substring(0, 1).toLowerCase() + type.substring(1);

      Cache dc = cacheManager.getCache(lc + "Cache");
      Cache ldc = cacheManager.getCache("lazy" + type + "Cache");

      for (Poolable d : pool.getPoolableElements()) {
        //log.debug("Linking "+d.getName() + " to " + pool.getName());
        MapSqlParameterSource esParams = new MapSqlParameterSource();
        esParams.addValue("elementId", d.getId())
            .addValue("pool_poolId", pool.getId())
            .addValue("elementType", d.getClass().getName());

        eInsert.execute(esParams);

        if (this.cascadeType != null) {
          if (this.cascadeType.equals(CascadeType.PERSIST)) {
            Store<? super Poolable> dao = daoLookup.lookup(d.getClass());
            if (dao != null) {
              dao.save(d);
            }
          }
          else if (this.cascadeType.equals(CascadeType.REMOVE)) {
            if (d instanceof Plate) {
              dc = cacheManager.getCache("plateCache");
              ldc = cacheManager.getCache("lazyPlateCache");
            }
            //if (dc != null) dc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            //if (ldc != null) ldc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            if (dc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
            if (ldc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
          }
        }
      }
    }

    MapSqlParameterSource poolparams = new MapSqlParameterSource();
    poolparams.addValue("pool_poolId", pool.getId());
    NamedParameterJdbcTemplate poolNamedTemplate = new NamedParameterJdbcTemplate(template);
    poolNamedTemplate.update(POOL_EXPERIMENT_DELETE_BY_POOL_ID, poolparams);

    if (pool.getExperiments() != null && !pool.getExperiments().isEmpty()) {
      //Cache ec = cacheManager.getCache("experimentCache");

      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
View Full Code Here


  )
  public boolean remove(Pool<? extends Poolable> pool) throws IOException {
    MapSqlParameterSource poolparams = new MapSqlParameterSource();
    poolparams.addValue("pool_poolId", pool.getId());
    poolparams.addValue("poolId", pool.getId());
    NamedParameterJdbcTemplate poolNamedTemplate = new NamedParameterJdbcTemplate(template);

    boolean ok = true;
    if (pool.isDeletable() && poolNamedTemplate.update(POOL_DELETE, poolparams) == 1) {
      if (!pool.getDilutions().isEmpty()) {
        Poolable d = pool.getPoolableElements().iterator().next();
        ok = (poolNamedTemplate.update(POOL_ELEMENT_DELETE_BY_POOL_ID, poolparams) == 1);
        String type = d.getClass().getSimpleName();
        String lc = type.substring(0, 1).toLowerCase() + type.substring(1);
        Cache dc = cacheManager.getCache(lc + "Cache");
        Cache ldc = cacheManager.getCache("lazy" + type + "Cache");

        if (this.cascadeType != null) {
          if (this.cascadeType.equals(CascadeType.PERSIST)) {
            Store<? super Poolable> dao = daoLookup.lookup(d.getClass());
            if (dao != null) {
              dao.save(d);
            }
          }
          else if (this.cascadeType.equals(CascadeType.REMOVE)) {
            if (d instanceof Plate) {
              dc = cacheManager.getCache("plateCache");
              ldc = cacheManager.getCache("lazyPlateCache");
            }

            //if (dc != null) dc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            //if (ldc != null) ldc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            if (dc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
            if (ldc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
          }
        }
      }

      if (!pool.getExperiments().isEmpty()) {
        ok = (poolNamedTemplate.update(POOL_EXPERIMENT_DELETE_BY_POOL_ID, poolparams) == 1);
        //Cache ec = cacheManager.getCache("experimentCache");
        Collection<Experiment> exps = pool.getExperiments();
        for (Experiment e : exps) {
          if (this.cascadeType != null) {
            if (this.cascadeType.equals(CascadeType.PERSIST)) {
View Full Code Here

  public NamedParameterJdbcTemplate getNameParameterJdbcTemplate() {
    if (debug) {
      logger.info("dataSource:" + ds);
    }
    return new NamedParameterJdbcTemplate(ds);
  }
View Full Code Here

    new CallTemplate<List<T>>() {
      @Override
      List<T> doCall(String sql, MapSqlParameterSource params) {
        final RowMapper<T> mapper = new BeanPropertyRowMapper<T>(resultSetClass_);
       
        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() {
          int rowNum=0;
          @Override
          public void processRow(ResultSet rs) throws SQLException {
            handler.handleRow(mapper.mapRow(rs, rowNum++));
          }
View Full Code Here

    return maxRowsResultSetExtractor;
  }

  private NamedParameterJdbcOperations getJdbcTemplate() {
    if (_namedParameterJdbcTemplate == null)
      _namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
          _dataSource);

    return _namedParameterJdbcTemplate;
  }
View Full Code Here

   * Create a new SimpleJdbcTemplate for the given DataSource.
   * <p>Creates a classic Spring JdbcTemplate and wraps it.
   * @param dataSource the JDBC DataSource to access
   */
  public SimpleJdbcTemplate(DataSource dataSource) {
    this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
  }
View Full Code Here

  /**
   * Create a new SimpleJdbcTemplate for the given classic Spring JdbcTemplate.
   * @param classicJdbcTemplate the classic Spring JdbcTemplate to wrap
   */
  public SimpleJdbcTemplate(JdbcOperations classicJdbcTemplate) {
    this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(classicJdbcTemplate);
  }
View Full Code Here

   * Create a new SimpleJdbcTemplate for the given DataSource.
   * <p>Creates a classic Spring JdbcTemplate and wraps it.
   * @param dataSource the JDBC DataSource to access
   */
  public SimpleJdbcTemplate(DataSource dataSource) {
    this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
  }
View Full Code Here

  /**
   * Create a new SimpleJdbcTemplate for the given classic Spring JdbcTemplate.
   * @param classicJdbcTemplate the classic Spring JdbcTemplate to wrap
   */
  public SimpleJdbcTemplate(JdbcOperations classicJdbcTemplate) {
    this.namedParameterJdbcOperations = new NamedParameterJdbcTemplate(classicJdbcTemplate);
  }
View Full Code Here

    /* (non-Javadoc)
   * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
   */
  @Override
  public void afterPropertiesSet() throws Exception {
    this.jdbcOperations = new NamedParameterJdbcTemplate(this.dataSource);
  }
View Full Code Here

TOP

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

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.