本文整理汇总了Java中org.springframework.jdbc.support.GeneratedKeyHolder.getKey方法的典型用法代码示例。如果您正苦于以下问题:Java GeneratedKeyHolder.getKey方法的具体用法?Java GeneratedKeyHolder.getKey怎么用?Java GeneratedKeyHolder.getKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.support.GeneratedKeyHolder
的用法示例。
在下文中一共展示了GeneratedKeyHolder.getKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.springframework.jdbc.support.GeneratedKeyHolder; //导入方法依赖的package包/类
@Override
public Object add(final T param) {
this.query = SQLWrapper.instance().insert((EntityObject) param).setModel(meta.getTableName()).getQuery();
final String preQuery = this.query;
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
System.out.println(this.query);
getJdbcTemplate().update((new PreparedStatementCreator() {
@Override
public java.sql.PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
PreparedStatement preparedStatement = con.prepareStatement(preQuery,Statement.RETURN_GENERATED_KEYS);
return preparedStatement;
}
}), keyHolder);
return keyHolder.getKey()==null?null:keyHolder.getKey().intValue();
}
示例2: addByWrapper
import org.springframework.jdbc.support.GeneratedKeyHolder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object addByWrapper(SQLWrapper sqlWrapper) {
this.query = sqlWrapper.setModel(meta.getTableName()).preparedInsert((Class<EntityObject>) cls);
final String preQuery = this.query;
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
getJdbcTemplate().update((new PreparedStatementCreator() {
@Override
public java.sql.PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
PreparedStatement preparedStatement = con.prepareStatement(preQuery,Statement.RETURN_GENERATED_KEYS);
return preparedStatement;
}
}), keyHolder);
return keyHolder.getKey()==null?null:keyHolder.getKey().intValue();
}
示例3: create
import org.springframework.jdbc.support.GeneratedKeyHolder; //导入方法依赖的package包/类
public void create(final IdentityAssoc ia)
{
/**
* 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
*/
GeneratedKeyHolder newKey = new GeneratedKeyHolder();
getJdbcTemplate().update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException
{
PreparedStatement ps = conn.prepareStatement("insert into identityassoc" +
" (duid, iatype, iaid, state)" +
" values (?, ?, ?, ?)",
PreparedStatement.RETURN_GENERATED_KEYS);
ps.setBytes(1, ia.getDuid());
ps.setByte(2, ia.getIatype());
ps.setLong(3, ia.getIaid());
ps.setByte(4, ia.getState());
return ps;
}
},
newKey);
Number newId = newKey.getKey();
if (newId != null) {
ia.setId(newId.longValue());
}
}
示例4: create
import org.springframework.jdbc.support.GeneratedKeyHolder; //导入方法依赖的package包/类
public void create(final IaPrefix iaPrefix)
{
/**
* 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
*/
GeneratedKeyHolder newKey = new GeneratedKeyHolder();
getJdbcTemplate().update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException
{
PreparedStatement ps = conn.prepareStatement("insert into iaprefix" +
" (prefixaddress, prefixlength, starttime, preferredendtime," +
" validendtime, state, identityassoc_id)" +
" values (?, ?, ?, ?, ?, ?, ?)",
PreparedStatement.RETURN_GENERATED_KEYS);
ps.setBytes(1, iaPrefix.getIpAddress().getAddress());
ps.setInt(2, iaPrefix.getPrefixLength());
java.sql.Timestamp sts =
new java.sql.Timestamp(iaPrefix.getStartTime().getTime());
ps.setTimestamp(3, sts, Util.GMT_CALENDAR);
java.sql.Timestamp pts =
new java.sql.Timestamp(iaPrefix.getPreferredEndTime().getTime());
ps.setTimestamp(4, pts, Util.GMT_CALENDAR);
java.sql.Timestamp vts =
new java.sql.Timestamp(iaPrefix.getValidEndTime().getTime());
ps.setTimestamp(5, vts, Util.GMT_CALENDAR);
ps.setByte(6, iaPrefix.getState());
ps.setLong(7, iaPrefix.getIdentityAssocId());
return ps;
}
},
newKey);
Number newId = newKey.getKey();
if (newId != null) {
iaPrefix.setId(newId.longValue());
}
}
示例5: create
import org.springframework.jdbc.support.GeneratedKeyHolder; //导入方法依赖的package包/类
public void create(final IaAddress iaAddr)
{
/**
* 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
*/
GeneratedKeyHolder newKey = new GeneratedKeyHolder();
getJdbcTemplate().update(
new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection conn)
throws SQLException
{
PreparedStatement ps = conn.prepareStatement("insert into iaaddress" +
" (ipaddress, starttime, preferredendtime, validendtime," +
" state, identityassoc_id)" +
" values (?, ?, ?, ?, ?, ?)",
PreparedStatement.RETURN_GENERATED_KEYS);
ps.setBytes(1, iaAddr.getIpAddress().getAddress());
java.sql.Timestamp sts =
new java.sql.Timestamp(iaAddr.getStartTime().getTime());
ps.setTimestamp(2, sts, Util.GMT_CALENDAR);
java.sql.Timestamp pts =
new java.sql.Timestamp(iaAddr.getPreferredEndTime().getTime());
ps.setTimestamp(3, pts, Util.GMT_CALENDAR);
java.sql.Timestamp vts =
new java.sql.Timestamp(iaAddr.getValidEndTime().getTime());
ps.setTimestamp(4, vts, Util.GMT_CALENDAR);
ps.setByte(5, iaAddr.getState());
ps.setLong(6, iaAddr.getIdentityAssocId());
return ps;
}
},
newKey);
Number newId = newKey.getKey();
if (newId != null) {
iaAddr.setId(newId.longValue());
}
}