Package org.springframework.jdbc.core.namedparam

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


     * {@inheritDoc}
     */
    @Override
    public NamedParameterJdbcTemplate apply(DataSource input) {
        checkNotNull(input, "Provided data source is null");
        return new NamedParameterJdbcTemplate(input);
    }
View Full Code Here


  protected void checkDaoConfig() {
    super.checkDaoConfig();
    if(dialect == null) throw new IllegalStateException("'dialect' property must be not null");
    log.info("use jdbc dialect:"+dialect);
    simpleJdbcTemplate = new SimpleJdbcTemplate(getJdbcTemplate());
    namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate());
  }
View Full Code Here

      Number newId = insert.executeAndReturnKey(params);
      printJob.setJobId(newId.longValue());
    }
    else {
      params.addValue("jobId", printJob.getJobId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(PRINT_JOB_UPDATE, params);
    }
    return printJob.getJobId();
  }
View Full Code Here

          params.addValue("name", name);

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != run.getId()) {
            log.error("Expected Run ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(RUN_DELETE, new MapSqlParameterSource().addValue("runId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Run ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Run - invalid field:" + run.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Run - issue with naming scheme", e);
      }
      /*
      String name = "RUN" + DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      Number newId = insert.executeAndReturnKey(params);
      run.setRunId(newId.longValue());
      run.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", run.getName())) {
          params.addValue("runId", run.getId())
                .addValue("name", run.getName());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(RUN_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save Run - invalid field:" + run.toString());
        }
      }
View Full Code Here

    return run.getId();
  }

  public synchronized int[] saveAll(Collection<Run> runs) throws IOException {
    log.debug(">>> Entering saveAll with " + runs.size() + " runs");
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    List<SqlParameterSource> batch = new ArrayList<SqlParameterSource>();
    long autoIncrement = DbUtils.getAutoIncrement(template, TABLE_NAME);

    for (Run run : runs) {
      Long securityProfileId = run.getSecurityProfile().getProfileId();
      if (securityProfileId == null || (this.cascadeType != null)) {// && this.cascadeType.equals(CascadeType.PERSIST))) {
        securityProfileId = securityProfileDAO.save(run.getSecurityProfile());
      }

      Long statusId = null;
      if (run.getStatus() != null) {
        Status s = run.getStatus();
        statusId = s.getStatusId();
        //if no status has ever been saved to the database for this run
        //we want to create one, cascading or not
        if (statusId == StatusImpl.UNSAVED_ID || (this.cascadeType != null && this.cascadeType.equals(CascadeType.PERSIST))) {
          if (s.getRunName() == null) {
            s.setRunName(run.getAlias());
          }

          if (s.getInstrumentName() == null && run.getSequencerReference() != null) {
            s.setInstrumentName(run.getSequencerReference().getName());
          }
        }
        statusId = statusDAO.save(s);
        run.setStatus(s);
      }
      else {
        log.warn("No status available to save for run: " + run.getAlias());
      }

      try {
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue("accession", run.getAccession())
                .addValue("alias", run.getAlias())
                .addValue("description", run.getDescription())
                .addValue("platformRunId", run.getPlatformRunId())
                .addValue("pairedEnd", run.getPairedEnd())
                .addValue("cycles", run.getCycles())
                .addValue("filePath", run.getFilePath())
                .addValue("platformType", run.getPlatformType().getKey())
                .addValue("securityProfile_profileId", securityProfileId)
                .addValue("status_statusId", statusId)
                .addValue("sequencerReference_sequencerReferenceId", run.getSequencerReference().getId());

        if (run.getId() == AbstractRun.UNSAVED_ID) {
          SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                  .withTableName(TABLE_NAME)
                  .usingGeneratedKeyColumns("runId");
          try {
            run.setId(autoIncrement);

            String name = namingScheme.generateNameFor("name", run);
            run.setName(name);

            if (namingScheme.validateField("name", run.getName())) {
              params.addValue("name", name);

              Number newId = insert.executeAndReturnKey(params);
              if (newId.longValue() != run.getId()) {
                log.error("Expected Run ID doesn't match returned value from database insert: rolling back...");
                new NamedParameterJdbcTemplate(template).update(RUN_DELETE, new MapSqlParameterSource().addValue("runId", newId.longValue()));
                throw new IOException("Something bad happened. Expected Run ID doesn't match returned value from DB insert");
              }
              autoIncrement = newId.longValue() + 1;
              log.debug(run.getName() + ":: Inserted as ID " + run.getId());
            }
            else {
              throw new IOException("Cannot save Run - invalid field:" + run.toString());
            }
          }
          catch (MisoNamingException e) {
            throw new IOException("Cannot save Run - issue with naming scheme", e);
          }

          /*
          String name = "RUN" + autoIncrement;
          params.addValue("name", name);
          Number newId = insert.executeAndReturnKey(params);
          run.setRunId(newId.longValue());
          run.setName(name);
          autoIncrement = newId.longValue() + 1;
          log.debug(run.getName() + ":: Inserted as ID " + run.getRunId());
          */
        }
        else {
          try {
            if (namingScheme.validateField("name", run.getName())) {
              params.addValue("runId", run.getId())
                    .addValue("name", run.getName());
              log.debug(run.getName() + ":: Updating as ID " + run.getId());
              batch.add(params);
            }
            else {
              throw new IOException("Cannot save Run - invalid field:" + run.toString());
            }
          }
          catch (MisoNamingException e) {
            throw new IOException("Cannot save Run - issue with naming scheme", e);
          }
          /*
          params.addValue("runId", run.getRunId())
                .addValue("name", run.getName());
          log.debug(run.getName() + ":: Updating as ID " + run.getRunId());
          batch.add(params);
          */
        }

        if (this.cascadeType != null) {
          if (this.cascadeType.equals(CascadeType.PERSIST)) {
            for (SequencerPartitionContainer<SequencerPoolPartition> l : ((RunImpl)run).getSequencerPartitionContainers()) {
              l.setSecurityProfile(run.getSecurityProfile());
              if (l.getPlatformType() == null) {
                l.setPlatformType(run.getPlatformType());
              }
              long containerId = sequencerPartitionContainerDAO.save(l);

              SimpleJdbcInsert fInsert = new SimpleJdbcInsert(template).withTableName("Run_SequencerPartitionContainer");
              MapSqlParameterSource fcParams = new MapSqlParameterSource();
              fcParams.addValue("Run_runId", run.getId())
                      .addValue("containers_containerId", containerId);

              try {
                fInsert.execute(fcParams);
              }
              catch(DuplicateKeyException dke) {
                log.debug("This Run/SequencerPartitionContainer combination already exists - not inserting: " + dke.getMessage());
              }
            }
          }

          if (!run.getNotes().isEmpty()) {
            for (Note n : run.getNotes()) {
              noteDAO.saveRunNote(run, n);
            }
          }

          //if this is saved by a user, and not automatically saved by the notification system
          User user = securityManager.getUserByLoginName(SecurityContextHolder.getContext().getAuthentication().getName());
          watcherDAO.removeWatchedEntityByUser(run, user);

          for (User u : run.getWatchers()) {
            watcherDAO.saveWatchedEntityUser(run, u);
          }
        }
      }
      catch (IOException e) {
        log.error("Cannot batch save run: " + run.getName());
        e.printStackTrace();
      }
    }

    int[] rows = namedTemplate.batchUpdate(RUN_UPDATE, batch.toArray(new SqlParameterSource[batch.size()]));

    //flush caches
    purgeCaches(runs);

    log.debug("<<< Exiting saveAll");
View Full Code Here

                      @Property(name="includeParameterTypes", value="false")
              }
          )
  )
  public boolean remove(Run r) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (r.isDeletable() &&
           (namedTemplate.update(RUN_DELETE,
                            new MapSqlParameterSource().addValue("runId", r.getId())) == 1)) {
      purgeListCache(r, false);
      return true;
    }
    return false;
View Full Code Here

          params.addValue("name", name);

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != pcr.getId()) {
            log.error("Expected emPCR ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(EMPCR_DELETE, new MapSqlParameterSource().addValue("pcrId", newId.longValue()));
            throw new IOException("Something bad happened. Expected emPCR ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save emPCR - invalid field:" + pcr.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save emPCR - issue with naming scheme", e);
      }
      /*
      String name = "EMP"+ DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      Number newId = insert.executeAndReturnKey(params);
      pcr.setPcrId(newId.longValue());
      pcr.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", pcr.getName())) {
          params.addValue("pcrId", pcr.getId())
                .addValue("name", pcr.getName());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(EMPCR_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save emPCR - invalid field:" + pcr.toString());
        }
      }
View Full Code Here

                      @Property(name="includeParameterTypes", value="false")
              }
          )
  )
  public boolean remove(emPCR e) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (e.isDeletable() &&
           (namedTemplate.update(EMPCR_DELETE,
                            new MapSqlParameterSource().addValue("pcrId", e.getId())) == 1)) {
      LibraryDilution ld = e.getLibraryDilution();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (ld != null) libraryDilutionDAO.save(ld);
      }
View Full Code Here

      Number newId = insert.executeAndReturnKey(params);
      alert.setAlertId(newId.longValue());
    }
    else {
      params.addValue("alertId", alert.getAlertId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(ALERT_UPDATE, params);
    }

    return alert.getAlertId();
  }
View Full Code Here

          params.addValue("name", name);

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != experiment.getId()) {
            log.error("Expected Experiment ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(EXPERIMENT_DELETE, new MapSqlParameterSource().addValue("experimentId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Experiment ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Experiment - invalid field:" + experiment.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Experiment - issue with naming scheme", e);
      }
      /*
      String name = Experiment.PREFIX + DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      Number newId = insert.executeAndReturnKey(params);
      experiment.setExperimentId(newId.longValue());
      experiment.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", experiment.getName())) {
          params.addValue("experimentId", experiment.getId())
                .addValue("name", experiment.getName());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(EXPERIMENT_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save Experiment - invalid field:" + experiment.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Experiment - issue with naming scheme", e);
      }
      /*
      params.addValue("experimentId", experiment.getExperimentId())
              .addValue("name", experiment.getName());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(EXPERIMENT_UPDATE, params);
      */
    }

    if (this.cascadeType != null) {
      MapSqlParameterSource eParams = new MapSqlParameterSource();
      eParams.addValue("experiments_experimentId", experiment.getId());
      NamedParameterJdbcTemplate eNamedTemplate = new NamedParameterJdbcTemplate(template);
      eNamedTemplate.update(POOL_EXPERIMENT_DELETE_BY_EXPERIMENT_ID, eParams);

      if (experiment.getPool() != null) {
        SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
                .withTableName("Pool_Experiment");

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.