|
From: JP P. <jp....@ti...> - 2003-05-24 11:12:35
|
Hi Isabelle,
Why should code such as below not work?=20
Both for Oracle and MySql, the Incrementer is able to provide a key =
before the main statement. Letting the developer request for a key and =
letting him handling this value as it came from the user request will =
always be possible. There is no always need for sophistication.
If the keys are picked by bunches, we don=E2=80=99t have two database =
requests.=20
Just we don't use the Oracle's common approach to give a null and =
setting a trigger providing the value.=20
Modified test:
/**
* Test an insert that is using sequencing
* @throws Exception if anything goes wrong
*/
public void testInsertWithSequence() throws Exception {
int[] types =3D new int[] { Types.INTEGER, Types.INTEGER };
Object[] params =3D new Object[] { null, new Integer(1) };
JdbcTemplate tpl =3D new JdbcTemplate(ds);
MySQLMaxValueIncrementer incr =3D new MySQLMaxValueIncrementer(ds, =
"insert_test_seq", "seq2");
params[0] =3D new Integer(incr.nextIntValue());
PreparedStatementCreator psc =3D=20
PreparedStatementCreatorFactory.newPreparedStatementCreator("insert =
into insert_test values(?, ?)", types, params);
numRows =3D tpl.update(psc);
assertTrue("Row was not inserted", 1 =3D=3D result.getRowsAffected());
// assertTrue("Key should have been 101", 101 =3D=3D =
((Integer)result.getKey()).intValue());
// Don't need getKey() as we have used incr.nextIntValue()
}
Best Regards,
Jean-Pierre
> -----Message d'origine-----
> De : Isabelle Muszynski [mailto:isa...@me...]
> Envoy=C3=A9 : samedi 24 mai 2003 11:18
> =C3=80 : JP Pawlak
> Cc : spr...@li...
> Objet : Re: RE : [Springframework-developer] SqlUpdate and insert
> functionality
>=20
> Hi Jean-Pierre,
>=20
> As I said in the mail I sent a minute ago, the fundamental difference
> between Oracle and MySQL is that in the first you can get the next =
value
> beforehand, while in the latter you get if afterwards. So I don't =
think
> your way would work.
>=20
> Anyway, the thing is badly broken right now.
>=20
> Isabelle
>=20
> On Sat, May 24, 2003 at 12:41:36AM +0200, JP Pawlak wrote:
> > Ken,
> >
> > If the javadoc says that a column with auto_increment is to be used,
> > it's clearly a mistake.
> > But that doesn't solve the issue!
> > I used a similar approach with the old framework, but without the =
Binder
> > technique. I get manually the nextValue in each DAO and set its =
value
> > like the others parameters in the callback method and it works fine.
> > For now, the Binder mechanism has an open issue (ref last Isabelle's
> > post).
> >
> > Regards,
> > Jean-Pierre
> >
> > -----Message d'origine-----
> > De=C3=82 : spr...@li...
> > [mailto:spr...@li...] De la
> > part de Ken Krebs
> > Envoy=C3=83=C2=A9=C3=82 : samedi 24 mai 2003 00:09
> > =C3=83=E2=82=AC=C3=82 : Isabelle Muszynski
> > Cc=C3=82 : spr...@li...
> > Objet=C3=82 : [Springframework-developer] SqlUpdate and insert =
functionality
> >
> > Isabelle,
> >
> > I don't understand this. I thought auto_increment on the visits id
> > column is what makes it work. The javadoc for =
MySQLMaxValueIncrementer
> > says that is to be used with an auto_increment column.
> >
> > I tried removing the auto_increment as you suggested and it no =
longer
> > works.
> >
> > Ken
> >
> > As I said earlier:
> >
> > "The data is written correctly to the DB using the auto-incremented
> > visit_id. The problem is that the getKey() function of the
> > returned InsertRetval returns 0, not the id that was used for the
> > insert. I wanted to use the value to update my cache directly =
without
> > having to requery the DB for all this pet's visits. I am working =
around
> > it by doing just that."
> >
> > Isabelle Muszynski wrote:
> >
> > Hi Ken,
> >
> > Looking at the mail you sent me this morning (included below), in =
table
> > visits, column id is auto-increment, and it shouldn't be. Neither =
should
> > the sequence column be, which is correct in the code below.
> >
> > The definition of column id should be "int not null primary key"
> >
> > Does this help?
> >
> > Isabelle
> >
> > On Fri, May 23, 2003 at 09:04:01AM -0500, Ken Krebs wrote:
> >
> > Isabelle,
> >
> > My key column isn't auto-incremented, only the actual id column is.
> >
> > My latest code snapshot is attached.
> >
|