On Jan 8, 2004, at 6:38 PM, Jeremy Boynes wrote:
Brendan W.McAdams wrote:
OK. I got a working instance (Test Case) of CMP working with Sybase ASE.
Cool :)
Essentially, I changed the ejbCreate method to be a query instead of an update. Immediately after the insert, it does a "select @@identity" which fetches the ID which was generated by the insert.
FYI, SQL Server 2000 supports a batch of the form
INSERT INTO table(...) VALUES(?,?, ...) SELECT SCOPE_IDENTITY()
which does the insert and returns the identity in a single database call rather than two (you access it with Statement.getMoreResults()). Does this work for Sybase?
... works exactly the same on Sybase as far as batches go - that's what i did . ejbCreate's query is INSERT INTO identity_test values (?) SELECT @@identity
I just read the return value in my code...
With a custom AutoGeneratedPKCreateMethod, modified slightly from CMPCreateMethod to use ejbCreate as a Query rather than an update
Please can you post the code to the Geronimo Jira.
Sure... I'm on the bus right now thanks to signal problems on the NY Penn Station train lines (gotta love bluetooth + GPRS) ... I'll be home in an hour or so and post it then.
For the record, this has to be done as part of ejbCreate, as ejbCreate is responsible according to specs and the monson-haefel book for creating the bean's identity, and setting it up in the database table. As far as I can tell, all this, including 'whats the ID', must be done before ejbPostCreate, which exists primarily for CMR Stuff (I could be wrong here - please correct me if I am).
This methodology works fine, basically developing on the assumption that the EJB creation classes will setup ejbCreate to be a Query Method with the Server Specific "Fetch generated Identity" code, and simply notifying the CMPOperationFactory that it needs to call AutoGeneratedPKCreateMethod in this case. A set of classes would ideally be generated with the cmp-rdbms xml parser to do this job. I've hardcoded CMPOperationFactory at the moment, due to a failure to find an effective way of notifying the Operation Factory that it needs to handle this as a DB generated Primary Key.
Obviously, UnknownPK detection can be done by looking at return Type. What I need now is a methodology for notifying the CMPOperationFactory that it needs to use the AutoGeneratedPKCreateMethod. I'm not sure what to do - whether I should put a boolean or some kind of indicator in one of the contexts or container classes; I'm looking for feedback on this.
I would suggest adding a new element to geronimo-ejb-jar.xml (there is no cmp-rdbms.xml thingy and we don't really want one) that specifies the type of CreateMethod VOP to use for a given signature and the key factory that it needs. It may be possible to merge CMPCreateMethod, UnknownPKCreateMethod and your AutoGeneratedPKCreateMethod into one interface - something like CMPIdentityDefiner which does the necessary manipulation of the InstanceData and the UpdateCommand to get/set the values for EJB and in the database. Something like
interface CMPIdentityDefiner { void defineIdentity(CMPInstanceContext ctx) throws Exception; }
as it can get the instance, the InstanceData and the id from the ctx.
I'll need to look at this further but I think I understand...
We should probably discuss this a bit further - I think the idea is sound and merging everything into a common typing would be good.
At the moment, I'm having some separate issues with findByPrimaryKey related to the Transaction policy which I'm looking into, but as I said - inserting into the database and then fetching and assigning the identity back to the bean works perfectly. I'm waiting on feedback about how to make this 'arrangement' more permanent before I proceed.
I'm thinking in the interim while we work out the questions, and while I'm straightening out these other issues I might like to also take a stab at some prototype classes to define the CMP / Database relationship in XML and automatically setup some of the code, which is done manually now in for example BasicCMPEntityContainerTest.setup ... Anyone have any feedback or objections to this?
Nope. Good luck, it's a big job :-)
... something tells me I should have kept my mouth shut.. But it also sounds like an interesting (hence fun in a sick twisted perveted kind of way) undertaking.
I'll put a tarball of my (slightly messy) code onto jira... as I mentioned right now I have create working but not findByPrimaryKey (something with transactions) so it's slightly incomplete but should serve as a good example. It will be an amalgamation of diffs and new files but shouldn't be too bad.
-Brendan
