Package org.springframework.jdbc.core.namedparam

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


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

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("concentration", pcr.getConcentration())
          .addValue("creationDate", pcr.getCreationDate())
          .addValue("pcrUserName", pcr.getPcrCreator())
          .addValue("dilution_dilutionId", pcr.getLibraryDilution().getId())
          .addValue("securityProfile_profileId", securityProfileId);

    if (pcr.getId() == emPCR.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName(TABLE_NAME)
                              .usingGeneratedKeyColumns("pcrId");
      try {
        pcr.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

        if (namingScheme.validateField("name", pcr.getName())) {
          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 {
View Full Code Here


  )
  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);
      }
      else if (this.cascadeType.equals(CascadeType.REMOVE)) {
View Full Code Here

        @Property(name = "includeParameterTypes", value = "false")
      }
    )
  )
  public long save(Alert alert) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("title", alert.getAlertTitle())
            .addValue("text", alert.getAlertText())
            .addValue("date", alert.getAlertDate())
            .addValue("isRead", alert.getAlertRead())
            .addValue("level", alert.getAlertLevel().getKey());

    if (alert.getAlertUser() != null) {
      params.addValue("userId", alert.getAlertUser().getUserId());
    }

    if (alert.getAlertId() == DefaultAlert.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                            .withTableName(TABLE_NAME)
                            .usingGeneratedKeyColumns("alertId");
      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

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

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("alias", experiment.getAlias())
            .addValue("accession", experiment.getAccession())
            .addValue("description", experiment.getDescription())
            .addValue("title", experiment.getTitle())
            .addValue("platform_platformId", experiment.getPlatform().getPlatformId())
            .addValue("securityProfile_profileId", securityProfileId)
            .addValue("study_studyId", experiment.getStudy().getId());

    if (experiment.getId() == AbstractExperiment.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                            .withTableName(TABLE_NAME)
                            .usingGeneratedKeyColumns("experimentId");
      try {
        experiment.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

        if (namingScheme.validateField("name", experiment.getName())) {
          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");

        MapSqlParameterSource esParams = new MapSqlParameterSource();
        esParams.addValue("experiments_experimentId", experiment.getId())
                .addValue("pool_poolId", experiment.getPool().getId());
        eInsert.execute(esParams);

        if (this.cascadeType.equals(CascadeType.PERSIST)) {
          DbUtils.flushCache(cacheManager, "poolCache");
        }
        else if (this.cascadeType.equals(CascadeType.REMOVE)) {
          //Cache pc = cacheManager.getCache("poolCache");
          //pc.remove(DbUtils.hashCodeCacheKeyFor(experiment.getPool().getId()));
          DbUtils.updateCaches(cacheManager, experiment.getPool(), Pool.class);
        }
      }

      Study s = experiment.getStudy();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (s!=null) studyDAO.save(s);
      }
      else if (this.cascadeType.equals(CascadeType.REMOVE)) {
        if (s != null) {
          //Cache pc = cacheManager.getCache("studyCache");
          //pc.remove(DbUtils.hashCodeCacheKeyFor(s.getId()));
          DbUtils.updateCaches(cacheManager, s, Study.class);
        }
      }

      if (!experiment.getKits().isEmpty()) {
        for (Kit k : experiment.getKits()) {
          kitDAO.save(k);

          SimpleJdbcInsert kInsert = new SimpleJdbcInsert(template)
                                .withTableName("Experiment_Kit");

          MapSqlParameterSource kParams = new MapSqlParameterSource();
          kParams.addValue("experiments_experimentId", experiment.getId())
                  .addValue("kits_kidId", k.getId());
          try {
            kInsert.execute(kParams);
          }
          catch(DuplicateKeyException dke) {
View Full Code Here

  )
  public boolean remove(Experiment experiment) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (experiment.isDeletable() &&
           (namedTemplate.update(EXPERIMENT_DELETE,
                            new MapSqlParameterSource().addValue("experimentId", experiment.getId())) == 1)) {
      Study s = experiment.getStudy();
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        if (s!=null) studyDAO.save(s);
        if (experiment.getPool() != null) {
          //DbUtils.flushCache(cacheManager, "poolCache");
View Full Code Here

  public void setPlatformDAO(PlatformStore platformDAO) {
    this.platformDAO = platformDAO;
  }

  public long save(SequencerReference sequencerReference) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();

    Blob ipBlob = null;
    try {
       ipBlob = new SerialBlob(sequencerReference.getIpAddress().getAddress());
    }
    catch (SQLException e) {
      e.printStackTrace();
    }

    params.addValue("name", sequencerReference.getName())
            .addValue("ipAddress", ipBlob)
            .addValue("platformId", sequencerReference.getPlatform().getPlatformId())
            .addValue("available", sequencerReference.getAvailable());

    if (sequencerReference.getId() == AbstractSequencerReference.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                            .withTableName(TABLE_NAME)
                            .usingGeneratedKeyColumns("referenceId");

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

    return sequencerReference.getId();
View Full Code Here

  public boolean remove(SequencerReference r) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    return (r.isDeletable() &&
           (namedTemplate.update(SEQUENCER_REFERENCE_DELETE,
                                 new MapSqlParameterSource().addValue("referenceId", r.getId())) == 1));
  }
View Full Code Here

    if (securityProfileId == SecurityProfile.UNSAVED_ID ||
        (this.cascadeType != null)) { // && this.cascadeType.equals(CascadeType.PERSIST))) {
      securityProfileId = securityProfileDAO.save(project.getSecurityProfile());
    }

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("alias", project.getAlias())
            .addValue("description", project.getDescription())
            .addValue("creationDate", project.getCreationDate())
            .addValue("securityProfile_profileId", securityProfileId)
            .addValue("progress", project.getProgress().getKey());

    if (project.getId() == AbstractProject.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
              .withTableName(TABLE_NAME)
              .usingGeneratedKeyColumns("projectId");
      try {
        project.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

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

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

    if (this.cascadeType != null) {
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
        MapSqlParameterSource eParams = new MapSqlParameterSource();
        eParams.addValue("project_projectId", project.getProjectId());
        NamedParameterJdbcTemplate eNamedTemplate = new NamedParameterJdbcTemplate(template);
        eNamedTemplate.update(PROJECT_ISSUES_DELETE_BY_PROJECT_ID, eParams);

        if (project.getIssueKeys() != null && !project.getIssueKeys().isEmpty()) {
          for (String s : project.getIssueKeys()) {
            SimpleJdbcInsert fInsert = new SimpleJdbcInsert(template).withTableName("Project_Issues");
            MapSqlParameterSource fcParams = new MapSqlParameterSource();
            fcParams.addValue("project_projectId", project.getProjectId())
                    .addValue("issueKey", s);

            try {
              fInsert.execute(fcParams);
            }
View Full Code Here

  }

  public long saveOverview(ProjectOverview overview) throws IOException {
    User user = securityManager.getUserByLoginName(SecurityContextHolder.getContext().getAuthentication().getName());

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("principalInvestigator", overview.getPrincipalInvestigator())
            .addValue("startDate", overview.getStartDate())
            .addValue("endDate", overview.getEndDate())
            .addValue("numProposedSamples", overview.getNumProposedSamples())
            .addValue("locked", overview.getLocked())
            .addValue("allSampleQcPassed", overview.getAllSampleQcPassed())
            .addValue("libraryPreparationComplete", overview.getLibraryPreparationComplete())
            .addValue("allLibraryQcPassed", overview.getAllLibrariesQcPassed())
            .addValue("allPoolsConstructed", overview.getAllPoolsConstructed())
            .addValue("allRunsCompleted", overview.getAllRunsCompleted())
            .addValue("primaryAnalysisCompleted", overview.getPrimaryAnalysisCompleted());

    if (overview.getOverviewId() == ProjectOverview.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
              .withTableName("ProjectOverview")
              .usingGeneratedKeyColumns("overviewId");
      Number newId = insert.executeAndReturnKey(params);
      overview.setOverviewId(newId.longValue());

      Project p = overview.getProject();

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

      MapSqlParameterSource poParams = new MapSqlParameterSource();
      poParams.addValue("project_projectId", p.getProjectId())
              .addValue("overviews_overviewId", overview.getOverviewId());

      try {
        pInsert.execute(poParams);
      }
View Full Code Here

  public boolean remove(Project project) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    boolean ok = true;
    if (project.isDeletable() &&
        (namedTemplate.update(PROJECT_DELETE,
                              new MapSqlParameterSource().addValue("projectId", project.getProjectId())) == 1)) {
      if (!project.getSamples().isEmpty()) {
        for (Sample s : project.getSamples()) {
          ok = sampleDAO.remove(s);
        }
      }
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.