當前位置: 首頁>>代碼示例>>Java>>正文


Java GeneratedKeyHolder.getKey方法代碼示例

本文整理匯總了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();
}
 
開發者ID:doomdagger,項目名稱:s_framework,代碼行數:17,代碼來源:BaseDaoImpl.java

示例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();
}
 
開發者ID:doomdagger,項目名稱:s_framework,代碼行數:17,代碼來源:BaseDaoImpl.java

示例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());
	}
}
 
開發者ID:jagornet,項目名稱:dhcp,代碼行數:38,代碼來源:JdbcIdentityAssocDAO.java

示例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());
	}
}
 
開發者ID:jagornet,項目名稱:dhcp,代碼行數:48,代碼來源:JdbcIaPrefixDAO.java

示例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());
	}
}
 
開發者ID:jagornet,項目名稱:dhcp,代碼行數:47,代碼來源:JdbcIaAddressDAO.java


注:本文中的org.springframework.jdbc.support.GeneratedKeyHolder.getKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。