Package org.springframework.jdbc.core.simple

Examples of org.springframework.jdbc.core.simple.SimpleJdbcInsert


    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("name", group.getName())
            .addValue("description", group.getDescription());

    if (group.getGroupId() == Group.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName("_Group")
                              .usingGeneratedKeyColumns("groupId");
      Number newId = insert.executeAndReturnKey(params);
      group.setGroupId(newId.longValue());
    }
    else {
      params.addValue("groupId", group.getGroupId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
View Full Code Here


            .addValue("qcDate", sampleQC.getQcDate())
            .addValue("qcMethod", sampleQC.getQcType().getQcTypeId())
            .addValue("results", sampleQC.getResults());

    if (sampleQC.getId() == AbstractSampleQC.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
                              .withTableName(TABLE_NAME)
                              .usingGeneratedKeyColumns("qcId");
      Number newId = insert.executeAndReturnKey(params);
      sampleQC.setId(newId.longValue());
    }
    else {
      params.addValue("qcId", sampleQC.getId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
View Full Code Here

    else {
      params.addValue("owner_userId", note.getOwner().getUserId());
    }

    if (note.getNoteId() == Note.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
              .withTableName(TABLE_NAME)
              .usingGeneratedKeyColumns("noteId");
      Number newId = insert.executeAndReturnKey(params);
      note.setNoteId(newId.longValue());
    }
    return note.getNoteId();
  }
View Full Code Here

    return note.getNoteId();
  }

  public long saveProjectOverviewNote(ProjectOverview overview, Note note) throws IOException {
    long noteId = save(note);
    SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
            .withTableName("ProjectOverview_Note");

    MapSqlParameterSource poParams = new MapSqlParameterSource();
    poParams.addValue("overview_overviewId", overview.getOverviewId())
            .addValue("notes_noteId", noteId);

    try {
      pInsert.execute(poParams);
    }
    catch(DuplicateKeyException se) {
      //ignore
    }
    return note.getNoteId();
View Full Code Here

    return note.getNoteId();
  }

  public long saveKitNote(Kit kit, Note note) throws IOException {
    long noteId = save(note);
    SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
            .withTableName("Kit_Note");

    MapSqlParameterSource poParams = new MapSqlParameterSource();
    poParams.addValue("kit_kitId", kit.getId())
            .addValue("notes_noteId", noteId);
    try {
      pInsert.execute(poParams);
    }
    catch(DuplicateKeyException se) {
      //ignore
    }
    return note.getNoteId();
View Full Code Here

    return note.getNoteId();
  }

  public long saveSampleNote(Sample sample, Note note) throws IOException {
    long noteId = save(note);
    SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
            .withTableName("Sample_Note");

    MapSqlParameterSource poParams = new MapSqlParameterSource();
    poParams.addValue("sample_sampleId", sample.getId())
            .addValue("notes_noteId", noteId);

    try {
      pInsert.execute(poParams);
    }
    catch(DuplicateKeyException se) {
      //ignore
    }
    return note.getNoteId();
View Full Code Here

    return note.getNoteId();
  }

  public long saveLibraryNote(Library library, Note note) throws IOException {
    long noteId = save(note);
    SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
            .withTableName("Library_Note");

    MapSqlParameterSource poParams = new MapSqlParameterSource();
    poParams.addValue("library_libraryId", library.getId())
            .addValue("notes_noteId", noteId);

    try {
      pInsert.execute(poParams);
    }
    catch(DuplicateKeyException se) {
      //ignore
    }
    return note.getNoteId();
View Full Code Here

    return note.getNoteId();
  }

  public long saveRunNote(Run run, Note note) throws IOException {
    long noteId = save(note);
    SimpleJdbcInsert pInsert = new SimpleJdbcInsert(template)
            .withTableName("Run_Note");

    MapSqlParameterSource poParams = new MapSqlParameterSource();
    poParams.addValue("run_runId", run.getId())
            .addValue("notes_noteId", noteId);

    try {
      pInsert.execute(poParams);
    }
    catch(DuplicateKeyException se) {
      //ignore
    }
    return note.getNoteId();
View Full Code Here

    else {
      params.addValue("qcPassed", pool.getQcPassed());
    }

    if (pool.getId() == AbstractPool.UNSAVED_ID) {
      SimpleJdbcInsert insert = new SimpleJdbcInsert(template)
          .withTableName(TABLE_NAME)
          .usingGeneratedKeyColumns("poolId");
      try {
        pool.setId(DbUtils.getAutoIncrement(template, TABLE_NAME));

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

        if (namingScheme.validateField("name", pool.getName())) {
          String barcode = name + "::" + pool.getPlatformType().getKey();
          params.addValue("name", name);

          params.addValue("identificationBarcode", barcode);

          Number newId = insert.executeAndReturnKey(params);
          if (newId.longValue() != pool.getId()) {
            log.error("Expected Pool ID doesn't match returned value from database insert: rolling back...");
            new NamedParameterJdbcTemplate(template).update(POOL_DELETE, new MapSqlParameterSource().addValue("poolId", newId.longValue()));
            throw new IOException("Something bad happened. Expected Pool ID doesn't match returned value from DB insert");
          }
        }
        else {
          throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Pool - issue with naming scheme", e);
      }
      /*
      String name = AbstractPool.lookupPrefix(pool.getPlatformType())+ DbUtils.getAutoIncrement(template, TABLE_NAME);
      params.addValue("name", name);
      params.addValue("identificationBarcode", name + "::" + pool.getPlatformType().getKey());
      Number newId = insert.executeAndReturnKey(params);
      pool.setPoolId(newId.longValue());
      pool.setName(name);
      */
    }
    else {
      try {
        if (namingScheme.validateField("name", pool.getName())) {
          params.addValue("poolId", pool.getId())
              .addValue("name", pool.getName())
              .addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
          NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
          namedTemplate.update(POOL_UPDATE, params);
        }
        else {
          throw new IOException("Cannot save Pool - invalid field:" + pool.toString());
        }
      }
      catch (MisoNamingException e) {
        throw new IOException("Cannot save Pool - issue with naming scheme", e);
      }
      /*
      params.addValue("poolId", pool.getPoolId())
              .addValue("name", pool.getName())
              .addValue("identificationBarcode", pool.getName() + "::" + pool.getPlatformType().getKey());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(POOL_UPDATE, params);
      */
    }

    //log.info("Unlinking elements from pool " + pool.getId());
    MapSqlParameterSource delparams = new MapSqlParameterSource();
    delparams.addValue("pool_poolId", pool.getId());
    NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
    namedTemplate.update(POOL_ELEMENT_DELETE_BY_POOL_ID, delparams);

    if (pool.getPoolableElements() != null && !pool.getPoolableElements().isEmpty()) {
      String type = pool.getPoolableElements().iterator().next().getClass().getSimpleName();

      SimpleJdbcInsert eInsert = new SimpleJdbcInsert(template).withTableName("Pool_Elements");
      String lc = type.substring(0, 1).toLowerCase() + type.substring(1);

      Cache dc = cacheManager.getCache(lc + "Cache");
      Cache ldc = cacheManager.getCache("lazy" + type + "Cache");

      for (Poolable d : pool.getPoolableElements()) {
        //log.debug("Linking "+d.getName() + " to " + pool.getName());
        MapSqlParameterSource esParams = new MapSqlParameterSource();
        esParams.addValue("elementId", d.getId())
            .addValue("pool_poolId", pool.getId())
            .addValue("elementType", d.getClass().getName());

        eInsert.execute(esParams);

        if (this.cascadeType != null) {
          if (this.cascadeType.equals(CascadeType.PERSIST)) {
            Store<? super Poolable> dao = daoLookup.lookup(d.getClass());
            if (dao != null) {
              dao.save(d);
            }
          }
          else if (this.cascadeType.equals(CascadeType.REMOVE)) {
            if (d instanceof Plate) {
              dc = cacheManager.getCache("plateCache");
              ldc = cacheManager.getCache("lazyPlateCache");
            }
            //if (dc != null) dc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            //if (ldc != null) ldc.remove(DbUtils.hashCodeCacheKeyFor(d.getId()));
            if (dc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
            if (ldc != null) DbUtils.updateCaches(cacheManager, d, Poolable.class);
          }
        }
      }
    }

    MapSqlParameterSource poolparams = new MapSqlParameterSource();
    poolparams.addValue("pool_poolId", pool.getId());
    NamedParameterJdbcTemplate poolNamedTemplate = new NamedParameterJdbcTemplate(template);
    poolNamedTemplate.update(POOL_EXPERIMENT_DELETE_BY_POOL_ID, poolparams);

    if (pool.getExperiments() != null && !pool.getExperiments().isEmpty()) {
      //Cache ec = cacheManager.getCache("experimentCache");

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

      for (Experiment e : pool.getExperiments()) {
        MapSqlParameterSource esParams = new MapSqlParameterSource();
        esParams.addValue("experiments_experimentId", e.getId())
            .addValue("pool_poolId", pool.getId());

        eInsert.execute(esParams);

        if (this.cascadeType != null) {
          if (this.cascadeType.equals(CascadeType.PERSIST)) {
            experimentDAO.save(e);
          }
View Full Code Here

 
  protected org.springframework.jdbc.core.simple.SimpleJdbcTemplate jdbcTemplate;
  protected SimpleJdbcInsert simpleJdbcInsert;
  public SimpleJdbcTemplate(DataSource dataSource){
    jdbcTemplate=new org.springframework.jdbc.core.simple.SimpleJdbcTemplate(dataSource);
    simpleJdbcInsert=new SimpleJdbcInsert(dataSource);
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.simple.SimpleJdbcInsert

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.