本文整理汇总了Java中org.springframework.jdbc.core.simple.SimpleJdbcInsert.execute方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleJdbcInsert.execute方法的具体用法?Java SimpleJdbcInsert.execute怎么用?Java SimpleJdbcInsert.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.core.simple.SimpleJdbcInsert
的用法示例。
在下文中一共展示了SimpleJdbcInsert.execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveSpectrumLibrary
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public void saveSpectrumLibrary(SpectrumLibraryDetail spectrumLibraryDetail) {
logger.debug("Inserting a spectral library detail record");
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(template);
simpleJdbcInsert.withTableName("spectral_library");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("release_version", spectrumLibraryDetail.getVersion());
parameters.put("release_date", spectrumLibraryDetail.getReleaseDate());
parameters.put("taxonomy_id", spectrumLibraryDetail.getTaxonomyId());
parameters.put("species_scientific_name", spectrumLibraryDetail.getSpeciesScientificName());
parameters.put("species_name", spectrumLibraryDetail.getSpeciesName());
parameters.put("number_of_spectra", spectrumLibraryDetail.getNumberOfSpectra());
parameters.put("number_of_peptides", spectrumLibraryDetail.getNumberOfPeptides());
parameters.put("file_size", spectrumLibraryDetail.getFileSize());
parameters.put("file_name", spectrumLibraryDetail.getFileName());
MapSqlParameterSource parameterSource = new MapSqlParameterSource(parameters);
parameterSource.registerSqlType("release_date", Types.DATE);
simpleJdbcInsert.execute(parameterSource);
}
示例2: grantJdbcAccess
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public static final void grantJdbcAccess(JdbcTemplate jdbcTemplate,
Group group, Role role) {
long count = jdbcTemplate.queryForObject(
"select count(*) from "
+ TableUtilities.getTableName(RoleGroup.class)
+ " where " + RoleGroup.ROLE_ID + " = ? and "
+ RoleGroup.GROUP_ID + " = ?", Long.class,
role.getId(), group.getId());
if (count <= 0) {
SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
insert.withTableName(TableUtilities.getTableName(RoleGroup.class));
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(RoleGroup.ROLE_ID, role.getId());
fields.put(RoleGroup.GROUP_ID, group.getId());
insert.execute(fields);
}
}
示例3: grantAccess
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public static final void grantAccess(JdbcTemplate jdbcTemplate,
Long userId, Group group) {
long count = jdbcTemplate.queryForObject(
"select count(*) from "
+ TableUtilities.getTableName(UserGroup.class)
+ " where " + UserGroup.USER_ID + " = ? and "
+ UserGroup.GROUP_ID + " = ?", Long.class, userId,
group.getId());
if (count <= 0) {
SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
insert.withTableName(TableUtilities.getTableName(UserGroup.class));
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(UserGroup.GROUP_ID, group.getId());
fields.put(UserGroup.USER_ID, userId);
insert.execute(fields);
}
}
示例4: update
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public static final void update(Gson gson, JdbcTemplate jdbcTemplate, String identity, String name, Object value) {
PluginSetting pluginSetting = null;
try {
pluginSetting = jdbcTemplate.queryForObject("select * from " + TableUtilities.getTableName(PluginSetting.class) + " where " + PluginSetting.IDENTITY + " = ? and " + PluginSetting.NAME + " = ?", new PluginSettingMapper(), identity, name);
} catch (EmptyResultDataAccessException e) {
}
if (pluginSetting != null) {
jdbcTemplate.update("update " + TableUtilities.getTableName(PluginSetting.class) + " set value = ? where " + PluginSetting.IDENTITY + " = ? and " + PluginSetting.NAME + " = ?", gson.toJson(value), identity, name);
} else {
SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
insert.withTableName(TableUtilities.getTableName(PluginSetting.class));
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(PluginSetting.IDENTITY, identity);
fields.put(PluginSetting.NAME, name);
fields.put(PluginSetting.VALUE, gson.toJson(value));
insert.execute(fields);
}
}
示例5: insert
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
public void insert(T entity) {
callBeforeInsert(entity);
SimpleJdbcInsert jdbcInsert = createJdbcInsert();
Map<String, Object> values = EntityUtils.values(entity, domainClass, false);
jdbcInsert.execute(values);
callAfterInsert(entity);
}
示例6: createJdbcJob
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public static final Job createJdbcJob(JdbcTemplate jdbcTemplate,
Class<? extends AbstractJob> clazz) {
Scheduled scheduled = clazz.getAnnotation(Scheduled.class);
String tableName = TableUtilities.getTableName(Job.class);
String id = clazz.getName();
Job job = null;
if (jdbcTemplate.queryForObject("select count(*) from " + tableName
+ " where " + Job.ID + " = ?", Long.class, id) > 0) {
job = jdbcTemplate.queryForObject("select * from " + tableName
+ " where " + Job.ID + " = ?", new JobMapper(), id);
job.setPause(false);
job.setStatus(Job.Status.IDLE);
jdbcTemplate.update("UPDATE " + tableName + " set " + Job.CRON
+ " = ?, " + Job.PAUSE + " = ?, " + Job.STATUS
+ " = ? where " + Job.ID + " = ?", scheduled.cron(), false,
Job.Status.IDLE, id);
} else {
job = new Job();
job.setId(id);
job.setCron(scheduled.cron());
job.setDescription(scheduled.description());
job.setDisable(scheduled.disable());
job.setPause(false);
job.setStatus(Job.Status.IDLE);
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(Job.ID, id);
fields.put(Job.CRON, scheduled.cron());
fields.put(Job.DESCRIPTION, scheduled.description());
fields.put(Job.DISABLE, scheduled.disable());
fields.put(Job.PAUSE, false);
fields.put(Job.STATUS, Job.Status.IDLE);
SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
insert.withTableName(tableName);
insert.execute(fields);
}
return job;
}
示例7: importResult
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Secured(roles = {@Role(name = "ROLE_REST_QUERY_PLUGIN_IMPORT", description = "Access Query Plugin Rest Import")})
@RequestMapping(value = "/queryplugin/api/import", method = RequestMethod.POST)
@ApiMethod(description = "import data")
public Result<Void> importResult(
AbstractWebApplication application,
WebRequest request,
WebResponse response,
Gson gson,
@ApiParam(name = "table", description = "table name", required = true, type = String.class) StringValue table,
@ApiParam(name = "field", description = "field {'name':'value'}", required = true, type = String[].class) StringValue[] field)
throws JsonIOException, IOException {
if ("".equals(table.toString("")) || field == null || field.length == 0) {
return Result.badRequest(response, "application/json", Void.class);
}
SimpleJdbcInsert insert = new SimpleJdbcInsert(
application.getJdbcTemplate());
insert.withTableName(table.toOptionalString());
Map<String, Object> fields = new HashMap<String, Object>();
for (StringValue f : field) {
Field fi = gson.fromJson(f.toOptionalString(), Field.class);
fields.put(fi.getName(), fi.getValue());
}
try {
insert.execute(fields);
} catch (DuplicateKeyException duplicateKeyException) {
// LOGGER.info(duplicateKeyException.getMessage());
}
return Result.ok(response, "application/json", Void.class);
}
示例8: importResult
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Secured(roles = { @Role(name = "ROLE_REST_QUERY_PLUGIN_IMPORT", description = "Access Query Plugin Rest Import") })
@RequestMapping(value = "/queryplugin/api/import", method = RequestMethod.POST)
@ApiMethod(description = "import data", requestObject = Table.class, responseObject = Void.class)
public Result importResult(AbstractWebApplication application,
HttpServletRequest request, HttpServletResponse response)
throws JsonIOException, IOException {
Gson gson = application.getGson();
InputStreamReader streamReader = new InputStreamReader(
request.getInputStream(), "UTF-8");
Table table = gson.fromJson(streamReader, Table.class);
if (table == null || table.getName() == null
|| "".equals(table.getName()) || table.getFields() == null
|| table.getFields().length == 0) {
return Result.badRequest(response, "application/json");
}
SimpleJdbcInsert insert = new SimpleJdbcInsert(
application.getJdbcTemplate());
insert.withTableName(table.getName());
Map<String, Object> fields = new HashMap<String, Object>();
for (Field field : table.getFields()) {
fields.put(field.getName(), field.getValue());
}
try {
insert.execute(fields);
} catch (DuplicateKeyException duplicateKeyException) {
// LOGGER.info(duplicateKeyException.getMessage());
}
return Result.ok(response, "application/json");
}