本文整理匯總了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());
}
}