Package org.springframework.jdbc.core.namedparam

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


    String squery = "%" + query + "%";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("search", squery);
          //.addValue("platformName", platformType.getKey());

    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    return namedTemplate.query(EMPCR_DILUTION_SELECT_BY_SEARCH, params, new LazyEmPCRDilutionMapper());
  }
View Full Code Here


          params.addValue("identificationBarcode", barcode);

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

      /*
      String name = "LDI"+ DbUtils.getAutoIncrement(template, "LibraryDilution");
      params.addValue("name", name);
      params.addValue("identificationBarcode", name + "::" + dilution.getLibrary().getAlias());     
      Number newId = insert.executeAndReturnKey(params);
      dilution.setDilutionId(newId.longValue());
      dilution.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", dilution.getName())) {
          params.addValue("dilutionId", dilution.getId())
                .addValue("name", dilution.getName())
                .addValue("identificationBarcode", dilution.getName() + "::" + dilution.getLibrary().getAlias());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(LIBRARY_DILUTION_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save LibraryDilution - invalid field:" + dilution.toString());
        }
      }
View Full Code Here

          params.addValue("identificationBarcode", barcode);

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

                      @Property(name="includeParameterTypes", value="false")
              }
          )
  )
  public boolean removeLibraryDilution(LibraryDilution d) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (d.isDeletable() &&
           (namedTemplate.update(LIBRARY_DILUTION_DELETE,
                                 new MapSqlParameterSource().addValue("dilutionId", d.getId())) == 1)) {
      Library l = d.getLibrary();
      if(this.cascadeType.equals(CascadeType.PERSIST)) {
        if (l != null) libraryDAO.save(l);
      }
View Full Code Here

                      @Property(name="includeParameterTypes", value="false")
              }
          )
  )
  public boolean removeEmPCRDilution(emPCRDilution d) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (d.isDeletable() &&
           (namedTemplate.update(EMPCR_DILUTION_DELETE,
                                 new MapSqlParameterSource().addValue("dilutionId", d.getId())) == 1)) {
      emPCR e = d.getEmPCR();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (e != null) emPcrDAO.save(e);
      }
View Full Code Here

    //if a profile already exists then delete all the old rows first, and repopulate.
    //easier than trying to work out which rows need to be updated and which don't
    if(securityProfile.getProfileId() != SecurityProfile.UNSAVED_ID) {
      MapSqlParameterSource delparams = new MapSqlParameterSource();
      delparams.addValue("profileId", securityProfile.getProfileId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(PROFILE_USERS_GROUPS_DELETE, delparams);

      List<SecurityProfile> results = template.query(PROFILE_SELECT_BY_ID, new Object[]{securityProfile.getProfileId()}, new SecurityProfileMapper());
      if (results.size() > 0) {
        log.error("SecurityProfile deletion failed!");
      }
View Full Code Here

      Number newId = insert.executeAndReturnKey(params);
      partition.setId(newId.longValue());
    }
    else {
      params.addValue("partitionId", partition.getId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(PARTITION_UPDATE, params);
    }

    if (this.cascadeType != null) {
      purgeListCache(partition);
    }
View Full Code Here

            params.addValue("identificationBarcode", barcode);

            Number newId = insert.executeAndReturnKey(params);
            if (newId.longValue() != sample.getId()) {
              log.error("Expected Sample ID doesn't match returned value from database insert: rolling back...");
              new NamedParameterJdbcTemplate(template).update(SAMPLE_DELETE, new MapSqlParameterSource().addValue("sampleId", newId.longValue()));
              throw new IOException("Something bad happened. Expected Sample ID doesn't match returned value from DB insert");
            }
          }
          else {
            throw new IOException("Cannot save sample - invalid field:" + sample.toString());
          }
        }
        catch (MisoNamingException e) {
          throw new IOException("Cannot save sample - issue with naming scheme", e);
        }
      }
    }
    else {
      SqlRowSet ss = template.queryForRowSet(SAMPLE_SELECT_BY_ALIAS, new Object[]{sample.getAlias()});
      if (ss.next() && ss.getLong("sampleId") != sample.getId()) {
        throw new IOException("UPD: A sample with this alias already exists in the database");
      }
      else {
        try {
          if (sampleNamingScheme.validateField("name", sample.getName()) && sampleNamingScheme.validateField("alias", sample.getAlias())) {
            params.addValue("sampleId", sample.getId())
                  .addValue("name", sample.getName())
                  .addValue("identificationBarcode", sample.getName() + "::" + sample.getAlias());
            NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
            namedTemplate.update(SAMPLE_UPDATE, params);
          }
          else {
            throw new IOException("Cannot save sample - invalid field value: " + sample.toString());
          }
        }
View Full Code Here

                      @Property(name="includeParameterTypes", value="false")
              }
          )
  )
  public boolean remove(Sample sample) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (sample.isDeletable() &&
           (namedTemplate.update(SAMPLE_DELETE,
                                 new MapSqlParameterSource().addValue("sampleId", sample.getId())) == 1)) {
      Project p = sample.getProject();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (p!=null) projectDAO.save(p);
      }
View Full Code Here

    if (submission.getId() != Submission.UNSAVED_ID) {
      try {
        if (namingScheme.validateField("name", submission.getName())) {
          MapSqlParameterSource delparams = new MapSqlParameterSource();
          delparams.addValue("submissionId", submission.getId());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          log.debug("Deleting Submission elements for " + submission.getId());
          namedTemplate.update(SUBMISSION_ELEMENTS_DELETE, delparams);

          params.addValue("submissionId", submission.getId())
                .addValue("name", submission.getName());
          namedTemplate.update(SUBMISSION_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save Submission - invalid field:" + submission.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Submission - issue with naming scheme", e);
      }
      /*
      params.addValue("submissionId", submission.getSubmissionId())
              .addValue("name", submission.getName());
      namedTemplate.update(SUBMISSION_UPDATE, params);
      */
    }
    else {
      insert.usingGeneratedKeyColumns("submissionId");
      try {
        submission.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

        if (namingScheme.validateField("name", submission.getName())) {
          params.addValue("name", name)
                .addValue("creationDate", new Date());

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != submission.getId()) {
            log.error("Expected Submission ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(SUBMISSION_DELETE, new MapSqlParameterSource().addValue("submissionId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Submission ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Submission - invalid field:" + submission.toString());
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.