You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jon Stevens <jo...@latchkey.com> on 2001/04/20 02:52:51 UTC

Re: Proposal for ObjectKey return value on BaseObjects save()

on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:

> An RFC regarding save() on the BaseObject variants that are generated by
> Torque.
> 
> Currently this method returns void.  Perhaps it should return an ObjectKey
> instead?
> 
> Here's my case:  I'm saving a BaseObject subclass for the first time, and
> like the idea of using the generated save() method, rather than rolling my
> own [and then being subject to manual code changes should my schema
> change].  My object maps to a new row in a single table, with an
> autoincremented key.  Apart from this key, the row is not unique.  At
> present (using TDK1a13), when I use save(), this key is lost (unless I've
> misread the code).  Given that the new row may not be unique, I'm unable to
> identify same row again without extra workarounds.
> 
> J.

The object that you just .save()'d will have its primary key set after the
.save().

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: [PATCH] Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jon Stevens <jo...@latchkey.com>.
Thanks jason!

You code is now in CVS and shows up on the website...

on 4/21/01 8:43 AM, "Jason Grant" <ja...@logular.com> wrote:

> Thanks Jon,
> 
> patchfile.txt included.

The only other suggestion is to line wrap the .xml file at 78 columns.

> I must say it's good to be a contributor at last - hoping to help out in
> more small ways...

Well, once we get a feeling that you know what you are up to, we can give
you commit access so that you can commit things yourself. :-) It has been a
while since we have added a new contributor to Turbine...it would be nice to
get some fresh blood in here...

thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


[PATCH] Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jason Grant <ja...@logular.com>.
Thanks Jon,

patchfile.txt included.

I must say it's good to be a contributor at last - hoping to help out in
more small ways...

J.



On 2001.04.20 21:04:25 -0400 Jon Stevens wrote:
> on 4/21/01 7:58 AM, "Jason Grant" <ja...@logular.com> wrote:
> 
> > I'm not sure what tool is used to convert XML->HTML, so
> > the rendered appearance is untested (i.e. I'm not sure how the embedded
> XML
> > turns out).
> 
> <http://jakarta.apache.org/site/jakarta-site2.html>
> <http://jakarta.apache.org/velocity/anakia.html>
> 
> All you need to do is this:
> 
> cvs co jakarta-site2
> cvs co jakarta-turbine
> cd jakarta-turbine/build
> ./build-turbine.sh docs
> 
> >  I'm happy to test/fix tho.  Also, is this sort of diff
> > acceptable (output from diff -C)?
> 
> Close. Your email application wrapped the lines badly so it might be a
> good
> idea to put the patch file on a website for someone to download or
> enclose
> it as an enclosure in your email instead of inline...
> 
> Instead of this:
> [xdocs] $ diff -C 5 peers.xml peers.xml.orig
> 
> It should be this:
> [xdocs] $ diff -u peers.xml.orig peers.xml >> patchfile.txt
> 
> You should also prefix your Subject: with [PATCH]
> 
> This is also documented at:
> 
> <http://jakarta.apache.org/site/source.html>
> 
> thanks,
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 

Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jon Stevens <jo...@latchkey.com>.
on 4/21/01 7:58 AM, "Jason Grant" <ja...@logular.com> wrote:

> I'm not sure what tool is used to convert XML->HTML, so
> the rendered appearance is untested (i.e. I'm not sure how the embedded XML
> turns out).

<http://jakarta.apache.org/site/jakarta-site2.html>
<http://jakarta.apache.org/velocity/anakia.html>

All you need to do is this:

cvs co jakarta-site2
cvs co jakarta-turbine
cd jakarta-turbine/build
./build-turbine.sh docs

>  I'm happy to test/fix tho.  Also, is this sort of diff
> acceptable (output from diff -C)?

Close. Your email application wrapped the lines badly so it might be a good
idea to put the patch file on a website for someone to download or enclose
it as an enclosure in your email instead of inline...

Instead of this:
[xdocs] $ diff -C 5 peers.xml peers.xml.orig

It should be this:
[xdocs] $ diff -u peers.xml.orig peers.xml >> patchfile.txt

You should also prefix your Subject: with [PATCH]

This is also documented at:

<http://jakarta.apache.org/site/source.html>

thanks,

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jason Grant <ja...@logular.com>.
I thought that peers.xml could use an extra section that outlines schema
definition in XML.  I'm not sure what tool is used to convert XML->HTML, so
the rendered appearance is untested (i.e. I'm not sure how the embedded XML
turns out).  I'm happy to test/fix tho.  Also, is this sort of diff
acceptable (output from diff -C)?

J.


[xdocs] $ diff -C 5 peers.xml peers.xml.orig 
*** peers.xml	Sat Apr 21 10:42:56 2001
--- peers.xml.orig	Sat Apr 21 10:15:13 2001
***************
*** 169,213 ****
                  on update cascade);
  </source>
  
  </section>
  
- <section name="Schema Definition">
- <p>
- Peer classes are typically generated by invoking one of the build-project
scripts that is provided by the TDK.  On a unix host, for example, the
relevant script is called build-project.sh and this should be invoked with
the init argument to generate the peers.
- </p>
- 
- <p>
- Peer class source code is generated based on the project database schema.
 The definition of this schema is in XML, and the associated DTD is
included with the TDK.  For the schema described above, the XML would look
something like
- </p>
- 
- <source>
-   <app-data>
- 	<database>
- 	  <table name="category" idMethod="autoincrement">
- 		<column name="category_id" required="true"
autoIncrement="true" primaryKey="true" type="INTEGER"/>
- 		<column name="name" size="100" type="VARCHAR"/>
- 	  </table>
- 	  <table name="item" idMethod="autoincrement">
- 		<column name="item_id" required="true"
autoIncrement="true" primaryKey="true" type="INTEGER"/>
- 		<column name="name" size="100" type="VARCHAR"/>
- 		<column name="price" required="true" type="INTEGER"/>
- 		<column name="category_id" required="true"
type="INTEGER"/>
- 		<foreign-key foreignTable="category">
- 			<reference local="category_id" foreign="category_id"/>
- 		</foreign-key>
- 	  </table>
-     <app-data>
-   <database>
- </source>
- 
- <p>
- Note that the XML will vary according to the target database - for
example, the autoincrement value may be used with mysql, and causes
generation of peer source which keeps keys up to date in the associated
java objects during inserts, etc.  For more information, refer to the DTD
which is shipped with Turbine and the TDK.
- </p>
- 
- </section>
- 
  <section name="Selects">
  <p>
  Probably the most common use of Peers is to select data from a database.
  If we want to extract all the Categories from the database we can use the
  following code.  Because we want all the objects we don't need to add
--- 169,178 ----



On 2001.04.20 19:45:49 -0400 Jon Stevens wrote:
> on 4/21/01 6:37 AM, "Jason Grant" <ja...@logular.com> wrote:
> 
> > Thanks John,
> > 
> > That was it - works nicely now.  Could be a common trap for new
> players...
> > 
> > J.
> 
> Submit a patch for the xdocs to help us document things better....
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jon Stevens <jo...@latchkey.com>.
on 4/21/01 6:37 AM, "Jason Grant" <ja...@logular.com> wrote:

> Thanks John,
> 
> That was it - works nicely now.  Could be a common trap for new players...
> 
> J.

Submit a patch for the xdocs to help us document things better....

-jon


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jason Grant <ja...@logular.com>.
Thanks John,

That was it - works nicely now.  Could be a common trap for new players...

J.

On 2001.04.20 19:15:20 -0400 John McNally wrote:
> In the xml:
> 
> <table idMethod="idbroker" ...
> 
> The options are idbroker,autoincrement,none, and sequence.
> 
> If set to none, then torque assumes any primary keys will already be set
> prior to a save(), which is generally what you want for a join table, as
> an example.
> 
> For mysql, the options idbroker or autoincrement are what you want.
> 
> john mcnally
> 
> Jason Grant wrote:
> > 
> > Thats's exactly my problem - the generated peer classes do not contain
> that
> > code.  Instead:
> > 
> >     /** Method to do inserts */
> >     public static void doInsert( User obj ) throws Exception
> >     {
> >                 doInsert(buildCriteria(obj));
> >                 obj.setNew(false);
> >     }
> > 
> > I've just upgraded turbine from the CVS head (was using 1a13
> previously).
> > I copied all of the new torque templates across to the new project, and
> > regenerated the peers.  There is still no call to setPrimaryKey.
> > 
> > Looking at the templates just now, there is a conditional
> >   #if ($table.IdMethod.equals("none"))
> > that removes the setPrimaryKey call.  I'm now trying to figure out why
> this
> > expression evaluates to true in my case, and whether it means that my
> > configuration is broken.  I'm using mysql.
> > 
> > J.
> > 
> > On 2001.04.20 13:45:19 -0400 John McNally wrote:
> > > John McNally wrote:
> > > >
> > > > The primary key is set in the generated Peers.  Here is an example
> > > which
> > > > you should find in BaseUserPeer.java
> > > >
> > > >     /** Method to do inserts */
> > > >     public static void doInsert( User obj ) throws Exception
> > > >     {
> > > >                 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
> > > >                 obj.setNew(false);
> > > >     }
> > > > ...
> > > >
> > > >     /**
> > > >      * Method to do inserts.  This method is to be used during a
> > > > transaction,
> > > >      * otherwise use the doInsert(Issue) method.  It will take
> > > >      * care of the connection details internally.
> > > >      *
> > > >      * @param obj the data object to insert into the database.
> > > >      */
> > > >     public static void doInsert( User obj, DBConnection dbCon)
> throws
> > > > Exception
> > > >     {
> > > >                 obj.setPrimaryKey(doInsert(buildCriteria(obj),
> dbCon));
> > > >                 obj.setNew(false);
> > > >     }
> > > >
> > > > Jason Grant wrote:
> > > > >
> > > > > I can't see this in the source, and my app is not behaving this
> way,
> > > even
> > > > > though I intuitively expected the key remain up to date.
> > > > >
> > > > > Here's a call stack, based on my reading of the turbine code that
> I
> > > have
> > > > > (my BaseObject is called User):
> > > > >
> > > > > // BasePeer internals not shown - they operate on criteria
> > > > > BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > > > UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > > > UserPeer.doInsert( User obj, DBConnection dbCon) // X
> > > > > User.save(DBConnection dbCon)
> > > > > User.save()
> > > > >
> > > > > The two methods with asterisks return ObjectKeys.  I cannot see
> these
> > > keys
> > > > > being written back into the User object, in fact, it is lost at
> the
> > > method
> > > > > marked X.  The methods above this deal with criteria, and I don't
> > > think
> > > > > that they otherwise gain access to the BaseObject or modify the
> > > object
> > > > > reference to the primary key.
> > > > >
> > > > > Apologies if I've missed something trivial (a few too many
> coffees
> > > today).
> > > > >
> > > > > J.
> > > > >
> > > > > On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> > > > > > on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com>
> wrote:
> > > > > >
> > > > > > > An RFC regarding save() on the BaseObject variants that are
> > > generated
> > > > > > by
> > > > > > > Torque.
> > > > > > >
> > > > > > > Currently this method returns void.  Perhaps it should return
> an
> > > > > > ObjectKey
> > > > > > > instead?
> > > > > > >
> > > > > > > Here's my case:  I'm saving a BaseObject subclass for the
> first
> > > time,
> > > > > > and
> > > > > > > like the idea of using the generated save() method, rather
> than
> > > rolling
> > > > > > my
> > > > > > > own [and then being subject to manual code changes should my
> > > schema
> > > > > > > change].  My object maps to a new row in a single table, with
> an
> > > > > > > autoincremented key.  Apart from this key, the row is not
> unique.
> > >  At
> > > > > > > present (using TDK1a13), when I use save(), this key is lost
> > > (unless
> > > > > > I've
> > > > > > > misread the code).  Given that the new row may not be unique,
> I'm
> > > > > > unable to
> > > > > > > identify same row again without extra workarounds.
> > > > > > >
> > > > > > > J.
> > > > > >
> > > > > > The object that you just .save()'d will have its primary key
> set
> > > after
> > > > > > the
> > > > > > .save().
> > > > > >
> > > > > > -jon
> > > > > >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by John McNally <jm...@collab.net>.
In the xml:

<table idMethod="idbroker" ...

The options are idbroker,autoincrement,none, and sequence.

If set to none, then torque assumes any primary keys will already be set
prior to a save(), which is generally what you want for a join table, as
an example.

For mysql, the options idbroker or autoincrement are what you want.

john mcnally

Jason Grant wrote:
> 
> Thats's exactly my problem - the generated peer classes do not contain that
> code.  Instead:
> 
>     /** Method to do inserts */
>     public static void doInsert( User obj ) throws Exception
>     {
>                 doInsert(buildCriteria(obj));
>                 obj.setNew(false);
>     }
> 
> I've just upgraded turbine from the CVS head (was using 1a13 previously).
> I copied all of the new torque templates across to the new project, and
> regenerated the peers.  There is still no call to setPrimaryKey.
> 
> Looking at the templates just now, there is a conditional
>   #if ($table.IdMethod.equals("none"))
> that removes the setPrimaryKey call.  I'm now trying to figure out why this
> expression evaluates to true in my case, and whether it means that my
> configuration is broken.  I'm using mysql.
> 
> J.
> 
> On 2001.04.20 13:45:19 -0400 John McNally wrote:
> > John McNally wrote:
> > >
> > > The primary key is set in the generated Peers.  Here is an example
> > which
> > > you should find in BaseUserPeer.java
> > >
> > >     /** Method to do inserts */
> > >     public static void doInsert( User obj ) throws Exception
> > >     {
> > >                 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
> > >                 obj.setNew(false);
> > >     }
> > > ...
> > >
> > >     /**
> > >      * Method to do inserts.  This method is to be used during a
> > > transaction,
> > >      * otherwise use the doInsert(Issue) method.  It will take
> > >      * care of the connection details internally.
> > >      *
> > >      * @param obj the data object to insert into the database.
> > >      */
> > >     public static void doInsert( User obj, DBConnection dbCon) throws
> > > Exception
> > >     {
> > >                 obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
> > >                 obj.setNew(false);
> > >     }
> > >
> > > Jason Grant wrote:
> > > >
> > > > I can't see this in the source, and my app is not behaving this way,
> > even
> > > > though I intuitively expected the key remain up to date.
> > > >
> > > > Here's a call stack, based on my reading of the turbine code that I
> > have
> > > > (my BaseObject is called User):
> > > >
> > > > // BasePeer internals not shown - they operate on criteria
> > > > BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > > UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > > UserPeer.doInsert( User obj, DBConnection dbCon) // X
> > > > User.save(DBConnection dbCon)
> > > > User.save()
> > > >
> > > > The two methods with asterisks return ObjectKeys.  I cannot see these
> > keys
> > > > being written back into the User object, in fact, it is lost at the
> > method
> > > > marked X.  The methods above this deal with criteria, and I don't
> > think
> > > > that they otherwise gain access to the BaseObject or modify the
> > object
> > > > reference to the primary key.
> > > >
> > > > Apologies if I've missed something trivial (a few too many coffees
> > today).
> > > >
> > > > J.
> > > >
> > > > On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> > > > > on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:
> > > > >
> > > > > > An RFC regarding save() on the BaseObject variants that are
> > generated
> > > > > by
> > > > > > Torque.
> > > > > >
> > > > > > Currently this method returns void.  Perhaps it should return an
> > > > > ObjectKey
> > > > > > instead?
> > > > > >
> > > > > > Here's my case:  I'm saving a BaseObject subclass for the first
> > time,
> > > > > and
> > > > > > like the idea of using the generated save() method, rather than
> > rolling
> > > > > my
> > > > > > own [and then being subject to manual code changes should my
> > schema
> > > > > > change].  My object maps to a new row in a single table, with an
> > > > > > autoincremented key.  Apart from this key, the row is not unique.
> >  At
> > > > > > present (using TDK1a13), when I use save(), this key is lost
> > (unless
> > > > > I've
> > > > > > misread the code).  Given that the new row may not be unique, I'm
> > > > > unable to
> > > > > > identify same row again without extra workarounds.
> > > > > >
> > > > > > J.
> > > > >
> > > > > The object that you just .save()'d will have its primary key set
> > after
> > > > > the
> > > > > .save().
> > > > >
> > > > > -jon
> > > > >

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jason Grant <ja...@logular.com>.
Thats's exactly my problem - the generated peer classes do not contain that
code.  Instead:

    /** Method to do inserts */
    public static void doInsert( User obj ) throws Exception
    {
                doInsert(buildCriteria(obj));
                obj.setNew(false);
    }

I've just upgraded turbine from the CVS head (was using 1a13 previously). 
I copied all of the new torque templates across to the new project, and
regenerated the peers.  There is still no call to setPrimaryKey.

Looking at the templates just now, there is a conditional 
  #if ($table.IdMethod.equals("none"))
that removes the setPrimaryKey call.  I'm now trying to figure out why this
expression evaluates to true in my case, and whether it means that my
configuration is broken.  I'm using mysql.

J.




On 2001.04.20 13:45:19 -0400 John McNally wrote:
> John McNally wrote:
> > 
> > The primary key is set in the generated Peers.  Here is an example
> which
> > you should find in BaseUserPeer.java
> > 
> >     /** Method to do inserts */
> >     public static void doInsert( User obj ) throws Exception
> >     {
> >                 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
> >                 obj.setNew(false);
> >     }
> > ...
> > 
> >     /**
> >      * Method to do inserts.  This method is to be used during a
> > transaction,
> >      * otherwise use the doInsert(Issue) method.  It will take
> >      * care of the connection details internally.
> >      *
> >      * @param obj the data object to insert into the database.
> >      */
> >     public static void doInsert( User obj, DBConnection dbCon) throws
> > Exception
> >     {
> >                 obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
> >                 obj.setNew(false);
> >     }
> > 
> > Jason Grant wrote:
> > >
> > > I can't see this in the source, and my app is not behaving this way,
> even
> > > though I intuitively expected the key remain up to date.
> > >
> > > Here's a call stack, based on my reading of the turbine code that I
> have
> > > (my BaseObject is called User):
> > >
> > > // BasePeer internals not shown - they operate on criteria
> > > BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > > UserPeer.doInsert( User obj, DBConnection dbCon) // X
> > > User.save(DBConnection dbCon)
> > > User.save()
> > >
> > > The two methods with asterisks return ObjectKeys.  I cannot see these
> keys
> > > being written back into the User object, in fact, it is lost at the
> method
> > > marked X.  The methods above this deal with criteria, and I don't
> think
> > > that they otherwise gain access to the BaseObject or modify the
> object
> > > reference to the primary key.
> > >
> > > Apologies if I've missed something trivial (a few too many coffees
> today).
> > >
> > > J.
> > >
> > > On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> > > > on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:
> > > >
> > > > > An RFC regarding save() on the BaseObject variants that are
> generated
> > > > by
> > > > > Torque.
> > > > >
> > > > > Currently this method returns void.  Perhaps it should return an
> > > > ObjectKey
> > > > > instead?
> > > > >
> > > > > Here's my case:  I'm saving a BaseObject subclass for the first
> time,
> > > > and
> > > > > like the idea of using the generated save() method, rather than
> rolling
> > > > my
> > > > > own [and then being subject to manual code changes should my
> schema
> > > > > change].  My object maps to a new row in a single table, with an
> > > > > autoincremented key.  Apart from this key, the row is not unique.
>  At
> > > > > present (using TDK1a13), when I use save(), this key is lost
> (unless
> > > > I've
> > > > > misread the code).  Given that the new row may not be unique, I'm
> > > > unable to
> > > > > identify same row again without extra workarounds.
> > > > >
> > > > > J.
> > > >
> > > > The object that you just .save()'d will have its primary key set
> after
> > > > the
> > > > .save().
> > > >
> > > > -jon
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> turbine-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by John McNally <jm...@collab.net>.
John McNally wrote:
> 
> The primary key is set in the generated Peers.  Here is an example which
> you should find in BaseUserPeer.java
> 
>     /** Method to do inserts */
>     public static void doInsert( User obj ) throws Exception
>     {
>                 obj.setPrimaryKey(doInsert(buildCriteria(obj)));
>                 obj.setNew(false);
>     }
> ...
> 
>     /**
>      * Method to do inserts.  This method is to be used during a
> transaction,
>      * otherwise use the doInsert(Issue) method.  It will take
>      * care of the connection details internally.
>      *
>      * @param obj the data object to insert into the database.
>      */
>     public static void doInsert( User obj, DBConnection dbCon) throws
> Exception
>     {
>                 obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
>                 obj.setNew(false);
>     }
> 
> Jason Grant wrote:
> >
> > I can't see this in the source, and my app is not behaving this way, even
> > though I intuitively expected the key remain up to date.
> >
> > Here's a call stack, based on my reading of the turbine code that I have
> > (my BaseObject is called User):
> >
> > // BasePeer internals not shown - they operate on criteria
> > BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> > UserPeer.doInsert( User obj, DBConnection dbCon) // X
> > User.save(DBConnection dbCon)
> > User.save()
> >
> > The two methods with asterisks return ObjectKeys.  I cannot see these keys
> > being written back into the User object, in fact, it is lost at the method
> > marked X.  The methods above this deal with criteria, and I don't think
> > that they otherwise gain access to the BaseObject or modify the object
> > reference to the primary key.
> >
> > Apologies if I've missed something trivial (a few too many coffees today).
> >
> > J.
> >
> > On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> > > on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:
> > >
> > > > An RFC regarding save() on the BaseObject variants that are generated
> > > by
> > > > Torque.
> > > >
> > > > Currently this method returns void.  Perhaps it should return an
> > > ObjectKey
> > > > instead?
> > > >
> > > > Here's my case:  I'm saving a BaseObject subclass for the first time,
> > > and
> > > > like the idea of using the generated save() method, rather than rolling
> > > my
> > > > own [and then being subject to manual code changes should my schema
> > > > change].  My object maps to a new row in a single table, with an
> > > > autoincremented key.  Apart from this key, the row is not unique.  At
> > > > present (using TDK1a13), when I use save(), this key is lost (unless
> > > I've
> > > > misread the code).  Given that the new row may not be unique, I'm
> > > unable to
> > > > identify same row again without extra workarounds.
> > > >
> > > > J.
> > >
> > > The object that you just .save()'d will have its primary key set after
> > > the
> > > .save().
> > >
> > > -jon
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by John McNally <jm...@collab.net>.
The primary key is set in the generated Peers.  Here is an example which
you should find in BaseUserPeer.java


    /** Method to do inserts */
    public static void doInsert( User obj ) throws Exception
    {
                obj.setPrimaryKey(doInsert(buildCriteria(obj)));
                obj.setNew(false);
    }
...

    /** 
     * Method to do inserts.  This method is to be used during a
transaction,
     * otherwise use the doInsert(Issue) method.  It will take 
     * care of the connection details internally. 
     *
     * @param obj the data object to insert into the database.
     */
    public static void doInsert( User obj, DBConnection dbCon) throws
Exception
    {
                obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
                obj.setNew(false);
    }


Jason Grant wrote:
> 
> I can't see this in the source, and my app is not behaving this way, even
> though I intuitively expected the key remain up to date.
> 
> Here's a call stack, based on my reading of the turbine code that I have
> (my BaseObject is called User):
> 
> // BasePeer internals not shown - they operate on criteria
> BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
> UserPeer.doInsert( User obj, DBConnection dbCon) // X
> User.save(DBConnection dbCon)
> User.save()
> 
> The two methods with asterisks return ObjectKeys.  I cannot see these keys
> being written back into the User object, in fact, it is lost at the method
> marked X.  The methods above this deal with criteria, and I don't think
> that they otherwise gain access to the BaseObject or modify the object
> reference to the primary key.
> 
> Apologies if I've missed something trivial (a few too many coffees today).
> 
> J.
> 
> On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> > on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:
> >
> > > An RFC regarding save() on the BaseObject variants that are generated
> > by
> > > Torque.
> > >
> > > Currently this method returns void.  Perhaps it should return an
> > ObjectKey
> > > instead?
> > >
> > > Here's my case:  I'm saving a BaseObject subclass for the first time,
> > and
> > > like the idea of using the generated save() method, rather than rolling
> > my
> > > own [and then being subject to manual code changes should my schema
> > > change].  My object maps to a new row in a single table, with an
> > > autoincremented key.  Apart from this key, the row is not unique.  At
> > > present (using TDK1a13), when I use save(), this key is lost (unless
> > I've
> > > misread the code).  Given that the new row may not be unique, I'm
> > unable to
> > > identify same row again without extra workarounds.
> > >
> > > J.
> >
> > The object that you just .save()'d will have its primary key set after
> > the
> > .save().
> >
> > -jon
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Proposal for ObjectKey return value on BaseObjects save()

Posted by Jason Grant <ja...@logular.com>.
I can't see this in the source, and my app is not behaving this way, even
though I intuitively expected the key remain up to date.

Here's a call stack, based on my reading of the turbine code that I have
(my BaseObject is called User):

// BasePeer internals not shown - they operate on criteria
BasePeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
UserPeer.doInsert( Criteria criteria, DBConnection dbCon ) // *
UserPeer.doInsert( User obj, DBConnection dbCon) // X
User.save(DBConnection dbCon)
User.save()

The two methods with asterisks return ObjectKeys.  I cannot see these keys
being written back into the User object, in fact, it is lost at the method
marked X.  The methods above this deal with criteria, and I don't think
that they otherwise gain access to the BaseObject or modify the object
reference to the primary key.

Apologies if I've missed something trivial (a few too many coffees today).

J.


On 2001.04.19 20:52:51 -0400 Jon Stevens wrote:
> on 4/20/01 7:35 AM, "Jason Grant" <ja...@logular.com> wrote:
> 
> > An RFC regarding save() on the BaseObject variants that are generated
> by
> > Torque.
> > 
> > Currently this method returns void.  Perhaps it should return an
> ObjectKey
> > instead?
> > 
> > Here's my case:  I'm saving a BaseObject subclass for the first time,
> and
> > like the idea of using the generated save() method, rather than rolling
> my
> > own [and then being subject to manual code changes should my schema
> > change].  My object maps to a new row in a single table, with an
> > autoincremented key.  Apart from this key, the row is not unique.  At
> > present (using TDK1a13), when I use save(), this key is lost (unless
> I've
> > misread the code).  Given that the new row may not be unique, I'm
> unable to
> > identify same row again without extra workarounds.
> > 
> > J.
> 
> The object that you just .save()'d will have its primary key set after
> the
> .save().
> 
> -jon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org