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


Java SimpleJdbcInsert.usingColumns方法代码示例

本文整理汇总了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;
}
 
开发者ID:cybozu,项目名称:spring-data-jdbc-template,代码行数:11,代码来源:JdbcTemplateRepositoryInternal.java

示例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);
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:14,代码来源:Serializable.java

示例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);
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:15,代码来源:Source.java

示例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");
}
 
开发者ID:skarpushin,项目名称:summerb,代码行数:6,代码来源:AttachmentDaoExtFilesImpl.java

示例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());
       }
}
 
开发者ID:jagornet,项目名称:dhcp,代码行数:60,代码来源:JdbcDhcpOptionDAO.java


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