[
https://issues.apache.org/jira/browse/IBATIS-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12571589#action_12571589
]
brian.diekelman edited comment on IBATIS-142 at 2/22/08 12:49 PM:
------------------------------------------------------------------
Alright, I guess somebody has to bite the bullet and create a patch for this...
how about this:
Single Generated Key:
Using generated in the 'type' attribute since the other options (pre/post) are
implied by generated (which has to be post)
<insert id="insertUser" parameterClass="user">
insert into user_profiles(first_name_tx)values(#firstName#)
<selectKey resultClass="int" type="generated" keyProperty="id"/>
</insert>
Multiple Generated Keys:
The case of a trigger (or several sql statements if the driver supports it)
with multiple generated keys, this would apply them in order (if we got the
int[]
back with two entries, id=[0], otherId=[1])
<insert id="insertUser" parameterClass="user">
insert into user_profiles(first_name_tx)values(#firstName#)
<selectKey resultClass="int" type="generated" keyProperty="id"/>
<selectKey resultClass="int" type="generated" keyProperty="otherId"/>
</insert>
Code changes
--------------------
New Classes:
- create a com.ibatis.sqlmap.engine.mapping.statement.GeneratedKeyStatement
Changes to Existing Files:
- com.ibatis.sqlmap.engine.mapping.statement.InsertStatement
- added a GeneratedKeyStatment[] field + getters/setters
- com.ibatis.engine.builder.xml.SqlStatementParser.parseSelectKey()
- add generated key logic, add to insertStatement
- com.ibatis.engine.impl.SqlMapExecutorDelegate
- line 424, inside insert(SessionScope, String, Object)
- add logic to check for selectKeyStatement/generatedKeyStatement
- add 'generated' to 'selectKey' in sql-map-2.dtd
Outstanding questions to think through:
- Throw an exception if we have a selectKey with type 'generated' and no keys
are generated? (optional setting?)
- Allow a pre/post selectKey *and* a generated selectKey in the same statement?
If I get some halfway decent feedback I might be able to get a patch ready over
the weekend. If nothing else, hopefully this will leave a blueprint of what to
change for the next person if I fail miserably.
was (Author: brian.diekelman):
Alright, I guess somebody has to bite the bullet and create a patch for
this... how about this:
Single Generated Key:
Using generated in the 'type' attribute since the other options (pre/post) are
implied by generated (which has to be post)
<insert id="insertUser" parameterClass="user">
insert into user_profiles(first_name_tx)values(#firstName#)
<selectKey resultClass="int" type="generated" keyProperty="id"/>
</insert>
Multiple Generated Keys:
The case of a trigger (or several sql statements if the driver supports it)
with multiple generated keys, this would apply them in order (if we got the
int[]
back with two entries, id=[0], otherId=[1])
<insert id="insertUser" parameterClass="user">
insert into user_profiles(first_name_tx)values(#firstName#)
<selectKey resultClass="int" type="generated" keyProperty="id"/>
<selectKey resultClass="int" type="generated" keyProperty="otherId"/>
</insert>
Code changes
--------------------
New Classes:
- create a com.ibatis.sqlmap.engine.mapping.statement.GeneratedKeyStatement
Changes to Existing Files:
- com.ibatis.sqlmap.engine.mapping.statement.InsertStatement
- added a GeneratedKeyStatment[] field + getters/setters
- com.ibatis.engine.builder.xml.SqlStatementParser.parseSelectKey()
- add generated key logic, add to insertStatement
- com.ibatis.engine.impl.SqlMapExecutorDelegate
- line 424, inside insert(SessionScope, String, Object)
- add logic to check for selectKeyStatement/generatedKeyStatement
- add 'generated' to 'selectKey' in sql-map-2.dtd
Outstanding questions to think through:
- Throw an exception if we have a selectKey with type 'generated' and no keys
are generated? (optional setting?)
- Allow a pre/post selectKey *and* a generated selectKey in the same statement?
If I get some halfway decent feedback I might be able to get a patch ready over
the weekend. If nothing else, hopefully this will leave a blueprint of what to
change for the next person if I fail miserably.
> JDBC 3 Generated Keys Support
> -----------------------------
>
> Key: IBATIS-142
> URL: https://issues.apache.org/jira/browse/IBATIS-142
> Project: iBatis for Java
> Issue Type: Improvement
> Components: SQL Maps
> Reporter: Brandon Goodin
> Priority: Minor
>
> public int executeUpdate(String sql,int autoGeneratedKeys)
> public boolean execute(String sql,int autoGeneratedKeys)
> public ResultSet getGeneratedKeys()
> We should provide support for jdbc auto generated keys retrieval. This is
> only available in Java 1.4. So, we would have to throw an
> UnsupportedFeatureException if 1.3 or earlier was being used.
> Brandon
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.