Package org.springframework.jdbc.core.namedparam

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


  public boolean removeOverview(ProjectOverview overview) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    return (overview.isDeletable() &&
           (namedTemplate.update(OVERVIEW_DELETE,
                                 new MapSqlParameterSource().addValue("overviewId", overview.getOverviewId())) == 1));
  }
View Full Code Here


    this.cascadeType = cascadeType;
  }

  @Transactional(readOnly = false, rollbackFor = IOException.class)
  public long save(LibraryQC libraryQC) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("library_libraryId", libraryQC.getLibrary().getId())
            //.addValue("qcUserName", SecurityContextHolder.getContext().getAuthentication().getName())
            .addValue("qcUserName", libraryQC.getQcCreator())
            .addValue("qcDate", libraryQC.getQcDate())
            .addValue("qcMethod", libraryQC.getQcType().getQcTypeId())
            .addValue("results", libraryQC.getResults())
            .addValue("insertSize", libraryQC.getInsertSize());

    if (libraryQC.getId() == AbstractLibraryQC.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName(TABLE_NAME)
                              .usingGeneratedKeyColumns("qcId");
      Number newId = insert.executeAndReturnKey(params);
      libraryQC.setId(newId.longValue());
    }
    else {
      params.addValue("qcId", libraryQC.getId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(LIBRARY_QC_UPDATE, params);
    }

    if (this.cascadeType != null) {
View Full Code Here

  public boolean remove(LibraryQC qc) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (qc.isDeletable() &&
           (namedTemplate.update(LIBRARY_QC_DELETE,
                                 new MapSqlParameterSource().addValue("qcId", qc.getId())) == 1)) {
      Library l = qc.getLibrary();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (l != null) libraryDAO.save(l);
      }
      else if (this.cascadeType.equals(CascadeType.REMOVE)) {
View Full Code Here

    this.template = template;
  }

  public long save(Platform platform) throws IOException {
    // execute this procedure...
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("name", platform.getPlatformType().getKey())
            .addValue("instrumentModel", platform.getInstrumentModel())
            .addValue("description", platform.getDescription())
            .addValue("numContainers", platform.getNumContainers());

    if (platform.getPlatformId() == null) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
              .withTableName(TABLE_NAME)
              .usingGeneratedKeyColumns("platformId");
      Number newId = insert.executeAndReturnKey(params);
      platform.setPlatformId(newId.longValue());
    }
    else {
      params.addValue("platformId", platform.getPlatformId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(PLATFORM_UPDATE, params);
    }
   
    return platform.getPlatformId();
View Full Code Here

    Long securityProfileId = study.getSecurityProfile().getProfileId();
    if (this.cascadeType != null) {// && this.cascadeType.equals(CascadeType.PERSIST)) {
      securityProfileId = securityProfileDAO.save(study.getSecurityProfile());
    }

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("alias", study.getAlias())
            .addValue("accession", study.getAccession())
            .addValue("description", study.getDescription())
            .addValue("securityProfile_profileId", securityProfileId)
            .addValue("project_projectId", study.getProject().getProjectId())
            .addValue("studyType", study.getStudyType());

    if (study.getId() == AbstractStudy.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                            .withTableName(TABLE_NAME)
                            .usingGeneratedKeyColumns("studyId");
      try {
        study.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

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

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != study.getId()) {
            log.error("Expected Study ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(STUDY_DELETE, new MapSqlParameterSource().addValue("studyId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Study ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Study - invalid field:" + study.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Study - issue with naming scheme", e);
      }
      /*
      String name = "STU"+ DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      Number newId = insert.executeAndReturnKey(params);
      study.setStudyId(newId.longValue());
      study.setName(name);
      */

      Project p = study.getProject();

      SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
                            .withTableName("Project_Study");

      MapSqlParameterSource poParams = new MapSqlParameterSource();
      poParams.addValue("Project_projectId", p.getProjectId())
              .addValue("studies_studyId", study.getId());
      try {
        pInsert.execute(poParams);
      }
      catch(DuplicateKeyException dke) {
View Full Code Here

  )
  public boolean remove(Study study) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (study.isDeletable() &&
           (namedTemplate.update(STUDY_DELETE,
                                 new MapSqlParameterSource().addValue("studyId", study.getId())) == 1)) {
      Project p = study.getProject();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (p!=null) projectDAO.save(p);
      }
      else if (this.cascadeType.equals(CascadeType.REMOVE)) {
View Full Code Here

    this.cascadeType = cascadeType;
  }

  @Transactional(readOnly = false, rollbackFor = IOException.class)
  public long save(PoolQC poolQC) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("pool_poolId", poolQC.getPool().getId())
            .addValue("qcUserName", poolQC.getQcCreator())
            .addValue("qcDate", poolQC.getQcDate())
            .addValue("qcMethod", poolQC.getQcType().getQcTypeId())
            .addValue("results", poolQC.getResults());

    if (poolQC.getId() == AbstractPoolQC.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName(TABLE_NAME)
                              .usingGeneratedKeyColumns("qcId");
      Number newId = insert.executeAndReturnKey(params);
      poolQC.setId(newId.longValue());
    }
    else {
      params.addValue("qcId", poolQC.getId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(POOL_QC_UPDATE, params);
    }

    if (this.cascadeType != null) {
View Full Code Here

  public boolean remove(PoolQC qc) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (qc.isDeletable() &&
           (namedTemplate.update(POOL_QC_DELETE,
                                 new MapSqlParameterSource().addValue("qcId", qc.getId())) == 1)) {
      Pool l = qc.getPool();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (l != null) poolDAO.save(l);
      }
      else if (this.cascadeType.equals(CascadeType.REMOVE)) {
View Full Code Here

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

    MapSqlParameterSource params = new MapSqlParameterSource();

    params.addValue("securityProfile_profileId", securityProfileId);
    params.addValue("identificationBarcode", sequencerPartitionContainer.getIdentificationBarcode());
    params.addValue("locationBarcode", sequencerPartitionContainer.getLocationBarcode());
    params.addValue("validationBarcode", sequencerPartitionContainer.getValidationBarcode());

    if (sequencerPartitionContainer.getPlatformType() != null) {
      params.addValue("platformType", sequencerPartitionContainer.getPlatformType().getKey());
    }

    if (sequencerPartitionContainer.getId() == AbstractSequencerPartitionContainer.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
              .withTableName(TABLE_NAME)
              .usingGeneratedKeyColumns("containerId");
      //try {
        sequencerPartitionContainer.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

        /*
        String name = namingScheme.generateNameFor("name", sequencerPartitionContainer);
        sequencerPartitionContainer.setName(name);

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

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != sequencerPartitionContainer.getId()) {
            log.error("Expected SequencerPartitionContainer ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(SEQUENCER_PARTITION_CONTAINER_DELETE, new MapSqlParameterSource().addValue("containerId", newId.longValue()));
            throw new IOException("Something bad happened. Expected SequencerPartitionContainer ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save SequencerPartitionContainer - invalid field:" + sequencerPartitionContainer.toString());
        }

      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save SequencerPartitionContainer - issue with naming scheme", e);
      }
      */
      Number newId = insert.executeAndReturnKey(params);
      sequencerPartitionContainer.setId(newId.longValue());
    }
    else {
      /*
      try {
        if (namingScheme.validateField("name", sequencerPartitionContainer.getName())) {
          params.addValue("containerId", sequencerPartitionContainer.getId())
                .addValue("name", sequencerPartitionContainer.getName());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(SEQUENCER_PARTITION_CONTAINER_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save SequencerPartitionContainer - invalid field:" + sequencerPartitionContainer.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save SequencerPartitionContainer - issue with naming scheme", e);
      }
      */

      params.addValue("containerId", sequencerPartitionContainer.getId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(SEQUENCER_PARTITION_CONTAINER_UPDATE, params);
    }

    //MapSqlParameterSource delparams = new MapSqlParameterSource();
    //delparams.addValue("container_containerId", sequencerPartitionContainer.getContainerId());
    //NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    //namedTemplate.update(SEQUENCER_PARTITION_CONTAINER_PARTITION_DELETE_BY_SEQUENCER_PARTITION_CONTAINER_ID, delparams);

    if (sequencerPartitionContainer.getPartitions() != null && !sequencerPartitionContainer.getPartitions().isEmpty()) {
      //log.info(sequencerPartitionContainer.getName()+":: Saving " + sequencerPartitionContainer.getPartitions().size() + " partitions...");

      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
              .withTableName("SequencerPartitionContainer_Partition");

      for (SequencerPoolPartition l : sequencerPartitionContainer.getPartitions()) {
        l.setSecurityProfile(sequencerPartitionContainer.getSecurityProfile());
        long partitionId = partitionDAO.save(l);

        //log.info(sequencerPartitionContainer.getName()+":: Saved partition " + l.getPartitionNumber() + " ("+partitionId+")");

        MapSqlParameterSource flParams = new MapSqlParameterSource();
        flParams.addValue("container_containerId", sequencerPartitionContainer.getId())
                .addValue("partitions_partitionId", partitionId);
        try {
          eInsert.execute(flParams);
        }
        catch (DuplicateKeyException dke) {
View Full Code Here

    Long securityProfileId = library.getSecurityProfile().getProfileId();
    if (this.cascadeType != null) { // && this.cascadeType.equals(CascadeType.PERSIST)) {
      securityProfileId = securityProfileDAO.save(library.getSecurityProfile());
    }

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("alias", library.getAlias())
            .addValue("accession", library.getAccession())
            .addValue("description", library.getDescription())
            .addValue("locationBarcode", library.getLocationBarcode())
            .addValue("paired", library.getPaired())
            .addValue("sample_sampleId", library.getSample().getId())
            .addValue("securityProfile_profileId", securityProfileId)
            .addValue("libraryType", library.getLibraryType().getLibraryTypeId())
            .addValue("librarySelectionType", library.getLibrarySelectionType().getLibrarySelectionTypeId())
            .addValue("libraryStrategyType", library.getLibraryStrategyType().getLibraryStrategyTypeId())
            .addValue("platformName", library.getPlatformName())
            .addValue("concentration", library.getInitialConcentration())
            .addValue("creationDate", library.getCreationDate());
            //.addValue("qcPassed", library.getQcPassed());

    if (library.getQcPassed() != null) {
      params.addValue("qcPassed", library.getQcPassed().toString());
    }
    else {
      params.addValue("qcPassed", library.getQcPassed());
    }

    if (library.getId() == AbstractLibrary.UNSAVED_ID) {
      if (getByAlias(library.getAlias()) != null) {
        throw new IOException("NEW: A library with this alias already exists in the database");
      }
      else {
        SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                .withTableName(TABLE_NAME)
                .usingGeneratedKeyColumns("libraryId");
        /*
        String name = Library.PREFIX + DbUtils.getAutoIncrement(template, TABLE_NAME);
        params.addValue("name", name);
        params.addValue("identificationBarcode", name + "::" + library.getAlias());
        Number newId = insert.executeAndReturnKey(params);
        library.setLibraryId(newId.longValue());
        library.setName(name);
        */

        try {
          library.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

          String name = libraryNamingScheme.generateNameFor("name", library);
          library.setName(name);
          if (libraryNamingScheme.validateField("name", library.getName()) && libraryNamingScheme.validateField("alias", library.getAlias())) {
            String barcode = name + "::" + library.getAlias();
            params.addValue("name", name);

            params.addValue("identificationBarcode", barcode);

            Number newId = insert.executeAndReturnKey(params);
            if (newId.longValue() != library.getId()) {
              log.error("Expected library ID doesn't match returned value from database insert: rolling back...");
              new NamedParameterJdbcTemplate(template).update(LIBRARY_DELETE, new MapSqlParameterSource().addValue("libraryId", newId.longValue()));
              throw new IOException("Something bad happened. Expected library ID doesn't match returned value from DB insert");
            }
          }
          else {
            throw new IOException("Cannot save library - invalid field:" + library.toString());
          }
        }
        catch (MisoNamingException e) {
          throw new IOException("Cannot save library - issue with naming scheme", e);
        }
      }
    }
    else {
      try {
        if (libraryNamingScheme.validateField("name", library.getName()) && libraryNamingScheme.validateField("alias", library.getAlias())) {
          params.addValue("libraryId", library.getId())
                .addValue("name", library.getName())
                .addValue("identificationBarcode", library.getName() + "::" + library.getAlias());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(LIBRARY_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save library - invalid field:" + library.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save library - issue with naming scheme", e);
      }
    }

    MapSqlParameterSource libparams = new MapSqlParameterSource();
    libparams.addValue("library_libraryId", library.getId());
    NamedParameterJdbcTemplate libNamedTemplate = new NamedParameterJdbcTemplate(template);
    libNamedTemplate.update(LIBRARY_TAGBARCODE_DELETE_BY_LIBRARY_ID, libparams);

    /*
    if (library.getTagBarcode() != null) {
      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
              .withTableName("Library_TagBarcode");

      MapSqlParameterSource ltParams = new MapSqlParameterSource();
      ltParams.addValue("library_libraryId", library.getLibraryId())
              .addValue("barcode_barcodeId", library.getTagBarcode().getTagBarcodeId());

      eInsert.execute(ltParams);
    }
    */

    if (library.getTagBarcodes() != null && !library.getTagBarcodes().isEmpty()) {
      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template)
              .withTableName("Library_TagBarcode");

      for (TagBarcode t : library.getTagBarcodes().values()) {
        MapSqlParameterSource ltParams = new MapSqlParameterSource();
        ltParams.addValue("library_libraryId", library.getId())
              .addValue("barcode_barcodeId", t.getId());
        eInsert.execute(ltParams);
      }
    }

View Full Code Here

TOP

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

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.