Package org.springframework.jdbc.core.namedparam

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


  )
  public boolean remove(Library library) throws IOException {
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    if (library.isDeletable() &&
           (namedTemplate.update(LIBRARY_DELETE,
                            new MapSqlParameterSource().addValue("libraryId", library.getId())) == 1)) {
      if (this.cascadeType.equals(CascadeType.PERSIST)) {
//        if (!poolDAO.listByLibraryId(library.getId()).isEmpty()) {
          //DbUtils.flushCache(cacheManager, "poolCache");
//        }
        for (Pool p : poolDAO.listByLibraryId(library.getId())) {
View Full Code Here


    this.cascadeType = cascadeType;
  }

  public Collection<LibraryDilution> listAllLibraryDilutionsBySearch(String query, PlatformType platformType) {
    String squery = "%" + query + "%";
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("search", squery);
          //.addValue("platformName", platformType.getKey());
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    return namedTemplate.query(LIBRARY_DILUTION_SELECT_BY_SEARCH, params, new LazyLibraryDilutionMapper());
  }
View Full Code Here

    }
  }

  public Collection<emPCRDilution> listAllEmPcrDilutionsBySearch(String query, PlatformType platformType) {
    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

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

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("concentration", dilution.getConcentration())
            .addValue("library_libraryId", dilution.getLibrary().getId())
            .addValue("creationDate", dilution.getCreationDate())
            .addValue("securityProfile_profileId", securityProfileId)
            .addValue("dilutionUserName", dilution.getDilutionCreator());

    if (dilution.getId() == AbstractDilution.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName("LibraryDilution")
                              .usingGeneratedKeyColumns("dilutionId");
      try {
        dilution.setId(DbUtils.getAutoIncrement(template, "LibraryDilution"));

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

        if (namingScheme.validateField("name", dilution.getName())) {
          String barcode = name + "::" + dilution.getLibrary().getAlias();
          params.addValue("name", name);

          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);
        }
View Full Code Here

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

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("concentration", dilution.getConcentration())
            .addValue("emPCR_pcrId", dilution.getEmPCR().getId())
            .addValue("creationDate", dilution.getCreationDate())
            .addValue("dilutionUserName", dilution.getDilutionCreator())
            .addValue("securityProfile_profileId", securityProfileId);

    if (dilution.getId() == AbstractDilution.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName("emPCRDilution")
                              .usingGeneratedKeyColumns("dilutionId");

      try {
        dilution.setId(DbUtils.getAutoIncrement(template, "emPCRDilution"));

        String name = namingScheme.generateNameFor("name", dilution);
        dilution.setName(name);
        if (namingScheme.validateField("name", dilution.getName())) {
          String barcode = name + "::" + dilution.getEmPCR().getName();
          params.addValue("name", name);

          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);
        }
View Full Code Here

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

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

                  )
  )
  public long save(SecurityProfile securityProfile) throws IOException {
    SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
            .withTableName(TABLE_NAME);
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("allowAllInternal", securityProfile.isAllowAllInternal());

    if (securityProfile.getOwner() != null) {
      params.addValue("owner_userId", securityProfile.getOwner().getUserId());
    }

    //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!");
      }
      else {
        params.addValue("profileId", securityProfile.getProfileId());
        insert.execute(params);
      }
    }
    else {
      insert.usingGeneratedKeyColumns("profileId");
      Number newId = insert.executeAndReturnKey(params);
      securityProfile.setProfileId(newId.longValue());
    }

    //profile read users
    if (securityProfile.getReadUsers() != null && !securityProfile.getReadUsers().isEmpty()) {
      SimpleJdbcInsert uInsert = new SimpleJdbcInsert(template)
              .withTableName("SecurityProfile_ReadUser");

      for (User u : securityProfile.getReadUsers()) {
        MapSqlParameterSource uParams = new MapSqlParameterSource();
        uParams.addValue("SecurityProfile_profileId", securityProfile.getProfileId())
                .addValue("readUser_userId", u.getUserId());
        uInsert.execute(uParams);
      }
    }

    //profile write users
    if (securityProfile.getWriteUsers() != null && !securityProfile.getWriteUsers().isEmpty()) {
      SimpleJdbcInsert uInsert = new SimpleJdbcInsert(template)
              .withTableName("SecurityProfile_WriteUser");

      for (User u : securityProfile.getWriteUsers()) {
        MapSqlParameterSource uParams = new MapSqlParameterSource();
        uParams.addValue("SecurityProfile_profileId", securityProfile.getProfileId())
                .addValue("writeUser_userId", u.getUserId());
        uInsert.execute(uParams);
      }
    }

    //profile read groups
    if (securityProfile.getReadGroups() != null && !securityProfile.getReadGroups().isEmpty()) {
      SimpleJdbcInsert uInsert = new SimpleJdbcInsert(template)
              .withTableName("SecurityProfile_ReadGroup");

      for (Group g : securityProfile.getReadGroups()) {
        MapSqlParameterSource uParams = new MapSqlParameterSource();
        uParams.addValue("SecurityProfile_profileId", securityProfile.getProfileId())
                .addValue("readGroup_groupId", g.getGroupId());
        uInsert.execute(uParams);
      }
    }

    //profile read groups
    if (securityProfile.getWriteGroups() != null && !securityProfile.getWriteGroups().isEmpty()) {
      SimpleJdbcInsert uInsert = new SimpleJdbcInsert(template)
              .withTableName("SecurityProfile_WriteGroup");

      for (Group g : securityProfile.getWriteGroups()) {
        MapSqlParameterSource uParams = new MapSqlParameterSource();
        uParams.addValue("SecurityProfile_profileId", securityProfile.getProfileId())
                .addValue("writeGroup_groupId", g.getGroupId());
        uInsert.execute(uParams);
      }
    }
   
View Full Code Here

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

    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("partitionNumber", partition.getPartitionNumber())
          .addValue("securityProfile_profileId", securityProfileId);

    if (partition.getPool() != null) {
      params.addValue("pool_poolId", partition.getPool().getId());

      // if this pool is marked as ready to run, and is now added to a partition, unmark it
      if (partition.getPool().getReadyToRun()) {
        partition.getPool().setReadyToRun(false);
      }
      poolDAO.save(partition.getPool());
    }
    else {
      params.addValue("pool_poolId", null);
    }
   
    if (partition.getId() == AbstractPartition.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
        .withTableName(TABLE_NAME)
        .usingGeneratedKeyColumns("partitionId");
      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) {
View Full Code Here

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

        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue("alias", sample.getAlias())
              .addValue("accession", sample.getAccession())
              .addValue("description", sample.getDescription())
              .addValue("scientificName", sample.getScientificName())
              .addValue("taxonIdentifier", sample.getTaxonIdentifier())
              //.addValue("identificationBarcode", sample.getIdentificationBarcode())
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.