本文整理汇总了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");
}
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
}
示例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;
}
示例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));
}
示例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);
}
示例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());
}
}
示例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());
}
示例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());
}