Re: MySql driver code

"hkara1" <[email protected]> Mon, 26 Jul 2010 07:23:52 -0000
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hi, I took some time during my vacations to dig into MySql
driver key generation, and the latest simpleorm.
I checked out revision 1084 from svn and started from there.
A fresh rebuild failed right away, because of errors caused
by @Override annotations. Also under JDK 1.5 I had even more
errors. I corrected those minor errors (essentially annotations)
so the code would compile under JDK 1.5.
When unit-testing MySql driver, test code failed because MySql
uses it's own char to quote names; thus I had to add a method
to SDriver to get the column quoting char and replaced all '\"'
with the column quoting char.
While I was at it, I added a class I use frequently, to control
slf4j logging more easily and per-session; this class is in
package simpleorm.logging
As the modifications are numerous, I made a patch file that I
uploaded to the "files" area, it is named :

hk-r1084-b.patch 

With all these modifications, all tests ran OK, and also a key
is generated correctly when the table is empty.

This is a little step towards a correct MySql support; however I
am no MySql expert, so a bit of additional testing from someone
more fluent with MySql would be best.

Best regards,

Harry Karadimas

--- In [email protected], berglas@... wrote:
>
> To clarify, Harry, could you please test your code for a completely empty table.  Also please confirm that the supplied test cases work with your patch on MySQL.
> 
> Thanks for the contribution,
> 
> Anthony
> 
> At 05:59 PM 11/06/2010, Franck Routier wrote:
> >  
> >
> >Hi,
> >
> >thanks for this. I had a look on the other drivers that implement this,
> >and they return 0 on null result.
> >
> >Is this something we would want to do for MySql ?
> >
> >Franck
> >
> >Le vendredi 11 juin 2010 à 07:17 +0000, hkara1 a écrit :
> >> 
> >> Hi,
> >> 
> >> I am using simpleorm with MySql for a project, and I was surprised
> >> to see that the SDriverMySql does not handle "insert key generation"
> >> though this is mentioned in the docs.
> >> 
> >> here is what I added to make it work :
> >> 
> >> @Override
> >> public boolean supportsInsertKeyGeneration() { return true; }
> >> 
> >> @Override
> >> protected long retrieveInsertedKey(SRecordMeta<?> rec, SFieldScalar
> >> keyFld) 
> >> {
> >> Object lastInsertIdObj = getSession().rawQuerySingle("SELECT
> >> LAST_INSERT_ID()", false);
> >> if (lastInsertIdObj instanceof Number) {
> >> Number lastInsertId = (Number) lastInsertIdObj;
> >> return lastInsertId.longValue();
> >> }
> >> else {
> >> throw new SException.Error("Not a number : " + lastInsertIdObj);
> >> }
> >> }
> >> 
> >> Hope it helps,
> >> 
> >> Harry Karadimas
> >> 
> >> 
> >> 
> >> 
> >> 
> >
> >
> 
> 
> Spreadsheet Detective,
> Southern Cross Software Queensland Pty Limited
> 54 Gerler Street
> Bardon, Queensland 4065, Australia.
> 
> Email: berglas@...
> www.SpreadsheetDetective.com
> Ph: +61 427 830248 (Australian Eastern Standard Time)
> 
> "If the model seems correct only because the numbers look right, 
> then why build the model in the first place?"
>




------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/