当前位置: 首页>>代码示例>>Java>>正文


Java SimpleJdbcInsert.executeAndReturnKey方法代码示例

本文整理汇总了Java中org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleJdbcInsert.executeAndReturnKey方法的具体用法?Java SimpleJdbcInsert.executeAndReturnKey怎么用?Java SimpleJdbcInsert.executeAndReturnKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.jdbc.core.simple.SimpleJdbcInsert的用法示例。


在下文中一共展示了SimpleJdbcInsert.executeAndReturnKey方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
/**
 * Insert a new Book into the database.
 * 
 * @throws RuntimeException
 *             if id is not null
 */
@Override
public Book save(Book book) {
	if (book.getId() == null) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("title", book.getTitle());
		map.put("author", book.getAuthor());
		SimpleJdbcInsert sji = new SimpleJdbcInsert(getJdbcTemplate());
		sji.setTableName("book");
		sji.setGeneratedKeyName("id");
		Long id = (Long) sji.executeAndReturnKey(map);
		book.setId(id);
		return book;
	} else {
		throw new RuntimeException("Book exist");
	}
}
 
开发者ID:lucaslouca,项目名称:springmvc-architecture-gradle,代码行数:23,代码来源:BookDaoImpl.java

示例2: saveSpectrum

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public void saveSpectrum(final SpectrumDetail spectrum) {
    logger.debug("Insert a spectrum into database: {}", spectrum.getReferenceId());

    SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(template);

    simpleJdbcInsert.withTableName("spectrum").usingGeneratedKeyColumns("spectrum_pk");

    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("assay_fk", spectrum.getAssayId());
    parameters.put("spectrum_ref", spectrum.getReferenceId());
    parameters.put("precursor_mz", spectrum.getPrecursorMz());
    parameters.put("precursor_charge", spectrum.getPrecursorCharge());
    parameters.put("is_identified", spectrum.isIdentified());

    Number key = simpleJdbcInsert.executeAndReturnKey(new MapSqlParameterSource(parameters));
    spectrum.setId(key.longValue());
}
 
开发者ID:PRIDE-Cluster,项目名称:cluster-repo,代码行数:19,代码来源:ClusterWriter.java

示例3: migrate

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
    LOG.info("Set up initial values");

    LOG.debug("Insert default billing plan");
    SimpleJdbcInsert billingJdbcInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName("s_billing_plan")
            .usingColumns("billingType", "numUsers", "volume", "numProjects", "pricing").usingGeneratedKeyColumns("id");

    Map<String, Object> billingParameters = new HashMap<>();
    billingParameters.put("billingType", "Community");
    billingParameters.put("numUsers", 99999999);
    billingParameters.put("volume", 999999999999L);
    billingParameters.put("numProjects", 999999);
    billingParameters.put("pricing", 0);

    Number billingPlanId = billingJdbcInsert.executeAndReturnKey(billingParameters);

    LOG.debug("Insert default account");
    SimpleJdbcInsert accountJdbcInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName("s_account")
            .usingColumns("status", "billingPlanId", "paymentMethod", "subdomain").usingGeneratedKeyColumns("id");
    Map<String, Object> accountParameters = new HashMap<>();
    accountParameters.put("status", "Active");
    accountParameters.put("billingPlanId", billingPlanId);
    accountParameters.put("paymentMethod", "None");
    accountParameters.put("subdomain", "");
    accountJdbcInsert.executeAndReturnKey(accountParameters);
}
 
开发者ID:MyCollab,项目名称:mycollab,代码行数:27,代码来源:V20150401_2__Insert_Default_Values.java

示例4: insertConstructor

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
private static void insertConstructor(JdbcTemplate jdbc) {
    separator("insertConstructor");
    SimpleJdbcInsert insertActor = new SimpleJdbcInsert(jdbc).withSchemaName("region").withTableName("jc_region").usingGeneratedKeyColumns("region_id");

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("region_name", "new region name");
    Number number = insertActor.executeAndReturnKey(parameters);
    log.debug("Inserted region id: {}", number.longValue());
}
 
开发者ID:java-course-ee,项目名称:java-course-ee,代码行数:10,代码来源:SpringJDBCTemplateExample.java

示例5: saveClusterSummary

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
private void saveClusterSummary(final ClusterDetail cluster) {
    SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(template);

    simpleJdbcInsert.withTableName("spectrum_cluster").usingGeneratedKeyColumns("cluster_pk");

    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("uuid", cluster.getUUID());
    parameters.put("avg_precursor_mz", cluster.getAveragePrecursorMz());
    parameters.put("avg_precursor_charge", cluster.getAveragePrecursorCharge());
    parameters.put("number_of_spectra", cluster.getNumberOfSpectra());
    parameters.put("total_number_of_spectra", cluster.getTotalNumberOfSpectra());
    parameters.put("number_of_psms", cluster.getNumberOfPSMs());
    parameters.put("total_number_of_psms", cluster.getTotalNumberOfPSMs());
    parameters.put("max_ratio", 0);
    parameters.put("number_of_projects", cluster.getNumberOfProjects());
    parameters.put("total_number_of_projects", cluster.getTotalNumberOfProjects());
    parameters.put("number_of_species", cluster.getNumberOfSpecies());
    parameters.put("total_number_of_species", cluster.getTotalNumberOfSpecies());
    parameters.put("number_of_modifications", cluster.getNumberOfModifications());
    parameters.put("total_number_of_modifications", cluster.getTotalNumberOfModifications());
    parameters.put("quality", cluster.getQuality().getQualityLevel());
    parameters.put("annotation", cluster.getAnnotation());
    parameters.put("consensus_spectrum_mz", cluster.getConsensusSpectrumMz());
    parameters.put("consensus_spectrum_intensity", cluster.getConsensusSpectrumIntensity());

    MapSqlParameterSource parameterSource = new MapSqlParameterSource(parameters);
    parameterSource.registerSqlType("consensus_spectrum_mz", Types.CLOB);
    parameterSource.registerSqlType("consensus_spectrum_intensity", Types.CLOB);

    Number key = simpleJdbcInsert.executeAndReturnKey(parameterSource);
    long clusterId = key.longValue();
    cluster.setId(clusterId);

    // update cluster id for all the clustered spectra
    List<ClusteredSpectrumDetail> clusteredSpectrumSummaries = cluster.getClusteredSpectrumDetails();
    for (ClusteredSpectrumDetail clusteredSpectrumDetail : clusteredSpectrumSummaries) {
        clusteredSpectrumDetail.setClusterId(clusterId);
    }
}
 
开发者ID:PRIDE-Cluster,项目名称:cluster-repo,代码行数:40,代码来源:ClusterWriter.java

示例6: insertAndReturnKey

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public Number insertAndReturnKey(T entity) {
    callBeforeInsert(entity);

    SimpleJdbcInsert jdbcInsert = createJdbcInsert();

    Set<String> generatedKeyColumns = EntityUtils.generatedValueColumnNames(domainClass);
    jdbcInsert.usingGeneratedKeyColumns(generatedKeyColumns.toArray(new String[generatedKeyColumns.size()]));

    Map<String, Object> values = EntityUtils.values(entity, domainClass, false);

    Number key = jdbcInsert.executeAndReturnKey(values);
    callAfterInsert(entity);

    return key;
}
 
开发者ID:cybozu,项目名称:spring-data-jdbc-template,代码行数:17,代码来源:JdbcTemplateRepositoryInternal.java

示例7: save

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public Number save(final T element) {
    SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate).withTableName(tableName);
    return insert.executeAndReturnKey(beanMap.getBeanMap(element));
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:5,代码来源:BaseInsertDao.java

示例8: insertAndReturnKey

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public Number insertAndReturnKey(BaseRecord rec) {
    SimpleJdbcInsert insert = getInsert();
    Map<String, Object> map = rec.asMap();
    map.remove(insert.getGeneratedKeyNames()[0]);
    return insert.executeAndReturnKey(map);
}
 
开发者ID:huherto,项目名称:springyRecords,代码行数:7,代码来源:AbstractBaseTable.java

示例9: create

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public void create(DhcpOption option) 
{
	SimpleJdbcInsert insertOption = new SimpleJdbcInsert(getDataSource())
                   							.withTableName("dhcpoption")
                   							.usingGeneratedKeyColumns("id");
	
	Long iaId = option.getIdentityAssocId();
	Long iaAddrId = option.getIaAddressId();
	Long iaPrefixId = option.getIaPrefixId();
	
	if ((iaId == null) && (iaAddrId == null) && (iaPrefixId == null)) {
		throw new IllegalStateException(
				"DhcpOption must reference either an IdentityAssoc, an IaAddress");
	}
	if ((iaId != null) && (iaAddrId != null)) {
		throw new IllegalStateException(
				"DhcpOption cannot reference both an IdentityAssoc and an IaAddress");
	}
	if ((iaId != null) && (iaPrefixId != null)) {
		throw new IllegalStateException(
				"DhcpOption cannot reference both an IdentityAssoc and an IaPrefix");
	}
	if ((iaAddrId != null) && (iaPrefixId != null)) {
		throw new IllegalStateException(
				"DhcpOption cannot reference both an IaAddress and an IaPrefix");
	}
	
       Map<String, Object> parameters = new HashMap<String, Object>(3);
       parameters.put("code", option.getCode());
       parameters.put("value", option.getValue());
       // TODO: verify that the option has only one foreign key
       if (iaId != null) {
       	parameters.put("identityassoc_id", iaId);
       	insertOption.usingColumns("code", "value", "identityassoc_id");
       }
       else if (iaAddrId != null) {
       	parameters.put("iaaddress_id", iaAddrId);
       	insertOption.usingColumns("code", "value", "iaaddress_id");
       }
       else if (iaPrefixId != null) {
       	parameters.put("iaprefix_id", iaAddrId);
       	insertOption.usingColumns("code", "value", "iaprefix_id");
       }
	/**
	 * Note: see https://issues.apache.org/jira/browse/DERBY-3609
	 * "Formally, Derby does not support getGeneratedKeys since 
	 * DatabaseMetaData.supportsGetGeneratedKeys() returns false. 
	 * However, Statement.getGeneratedKeys() is partially implemented,
	 * ... since it will only return a meaningful result when an single 
	 * row insert is done with INSERT...VALUES"
	 * 
	 * Spring has thus provided a workaround as described here:
	 * http://jira.springframework.org/browse/SPR-5306
	 */
       Number newId = insertOption.executeAndReturnKey(parameters);
       if (newId != null) {
       	option.setId(newId.longValue());
       }
}
 
开发者ID:jagornet,项目名称:dhcp,代码行数:60,代码来源:JdbcDhcpOptionDAO.java

示例10: saveAssay

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public void saveAssay(final AssayDetail assay) {
    logger.debug("Insert assay summary into database: {}", assay.getAccession());


    SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(template);

    simpleJdbcInsert.withTableName("assay").usingGeneratedKeyColumns("assay_pk");

    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("assay_accession", assay.getAccession());
    parameters.put("project_accession", assay.getProjectAccession());

    if (assay.getProjectTitle() != null)
        parameters.put("project_title", assay.getProjectTitle());

    if (assay.getAssayTitle() != null)
        parameters.put("assay_title", assay.getAssayTitle());

    parameters.put("species", assay.getSpecies());
    parameters.put("multi_species", assay.isMultiSpecies());

    if (assay.getTaxonomyId() != null)
        parameters.put("taxonomy_id", assay.getTaxonomyId());

    if (assay.getDisease() != null)
        parameters.put("disease", assay.getDisease());

    if (assay.getTissue() != null)
        parameters.put("tissue", assay.getTissue());

    if (assay.getSearchEngine() != null)
        parameters.put("search_engine", assay.getSearchEngine());

    if (assay.getInstrument() != null)
        parameters.put("instrument", assay.getInstrument());

    parameters.put("biomedical", assay.isBioMedical());

    Number key = simpleJdbcInsert.executeAndReturnKey(new MapSqlParameterSource(parameters));
    assay.setId(key.longValue());

}
 
开发者ID:PRIDE-Cluster,项目名称:cluster-repo,代码行数:44,代码来源:ClusterWriter.java

示例11: savePSM

import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public void savePSM(final PSMDetail psm) {
    logger.debug("Insert a PSM into database: {}", psm.getArchivePSMId());


    SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(template);

    simpleJdbcInsert.withTableName("psm").usingGeneratedKeyColumns("psm_pk");

    HashMap<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("spectrum_fk", psm.getSpectrumId());
    parameters.put("assay_fk", psm.getAssayId());
    parameters.put("archive_psm_id", psm.getArchivePSMId());
    parameters.put("sequence", psm.getSequence());

    if (psm.getModifications() != null)
        parameters.put("modifications", psm.getModifications());

    if (psm.getStandardisedModifications() != null)
        parameters.put("modifications_standardised", psm.getStandardisedModifications());

    if (psm.getSearchEngine() != null)
        parameters.put("search_engine", psm.getSearchEngine());

    if (psm.getSearchEngineScores() != null)
        parameters.put("search_engine_scores", psm.getSearchEngineScores());

    if (psm.getSearchDatabase() != null)
        parameters.put("search_database", psm.getSearchDatabase());

    if (psm.getProteinAccession() != null)
        parameters.put("protein_accession", psm.getProteinAccession());

    if (psm.getProteinGroup() != null)
        parameters.put("protein_group", psm.getProteinGroup());

    if (psm.getProteinName() != null)
        parameters.put("protein_name", psm.getProteinName());

    parameters.put("start_position", psm.getStartPosition());
    parameters.put("stop_position", psm.getStopPosition());

    if (psm.getPreAminoAcid() != null)
        parameters.put("pre_amino_acid", psm.getPreAminoAcid());

    if (psm.getPostAminoAcid() != null)
        parameters.put("post_amino_acid", psm.getPostAminoAcid());

    parameters.put("delta_mz", psm.getDeltaMZ());

    if (psm.getQuantificationLabel() != null)
        parameters.put("quantification_label", psm.getQuantificationLabel());

    Number key = simpleJdbcInsert.executeAndReturnKey(new MapSqlParameterSource(parameters));
    psm.setId(key.longValue());

}
 
开发者ID:PRIDE-Cluster,项目名称:cluster-repo,代码行数:58,代码来源:ClusterWriter.java


注:本文中的org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。