本文整理汇总了Java中org.springframework.jdbc.core.simple.SimpleJdbcInsert.usingColumns方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleJdbcInsert.usingColumns方法的具体用法?Java SimpleJdbcInsert.usingColumns怎么用?Java SimpleJdbcInsert.usingColumns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.core.simple.SimpleJdbcInsert
的用法示例。
在下文中一共展示了SimpleJdbcInsert.usingColumns方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJdbcInsert
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
private SimpleJdbcInsert createJdbcInsert() {
JdbcTemplate jdbcTemplate = (JdbcTemplate) operations().getJdbcOperations();
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(jdbcTemplate);
jdbcInsert.withTableName(EntityUtils.tableName(domainClass));
Set<String> usingColumns = EntityUtils.columnNamesExceptGeneratedValues(domainClass);
jdbcInsert.usingColumns(usingColumns.toArray(new String[usingColumns.size()]));
return jdbcInsert;
}
示例2: insert
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
public static void insert(DataSource dataSource, String tableName, List<String> usingColumns, List<Map<String, Object>> fields) {
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dataSource);
jdbcInsert.withTableName(tableName);
List<String> pp = new ArrayList<>();
pp.addAll(usingColumns);
pp.add(tableName + "_id");
jdbcInsert.usingColumns(pp.toArray(new String[usingColumns.size()]));
for (Map<String, Object> field : fields) {
field.put(tableName + "_id", UUID.randomUUID().toString());
}
Map<String, Object>[] batch = fields.toArray(new Map[fields.size()]);
jdbcInsert.executeBatch(batch);
}
示例3: insert
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void insert(DataSource dataSource, String tableName, List<String> usingColumns, List<Map<String, Object>> fields) {
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dataSource);
jdbcInsert.withTableName(tableName);
List<String> pp = new ArrayList<>();
pp.addAll(usingColumns);
pp.add(tableName + "_id");
jdbcInsert.usingColumns(pp.toArray(new String[usingColumns.size()]));
for (Map<String, Object> field : fields) {
field.put(tableName + "_id", UUID.randomUUID().toString());
}
Map<String, Object>[] batchs = fields.toArray(new Map[fields.size()]);
jdbcInsert.executeBatch(batchs);
}
示例4: buildJdbcInsert
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; //导入方法依赖的package包/类
@Override
protected SimpleJdbcInsert buildJdbcInsert() {
SimpleJdbcInsert ret = super.buildJdbcInsert();
return ret.usingColumns("name", "article_id", "size");
}
示例5: 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());
}
}