日期:2014-05-16 浏览次数:20406 次
... class Insert extends SqlUpdate { private final Logger logger = Logger.getLogger(Insert.class); public Insert(DataSource dataSource) { super(dataSource, INSERT_SQL); initInsertParams(this); //初始化insert参数,与此处没有直接关系 this.setReturnGeneratedKeys(true); //设置可以返回主键信息 if(logger.isDebugEnabled()) logger.debug(" sql =" + this.getSql()); } } private Insert insert; private synchronized void insert(Object obj) { Object[] values = getInsertValues(obj); //返回的主键信息将保存在GeneratedKeyHolder的LinkedList中 KeyHolder keyHolder = new GeneratedKeyHolder(); this.insert.update(values, keyHolder); ((ObjectId) obj).setId(keyHolder.getKey().longValue()); } ...