You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Alexandru Dovlecel <al...@siemens.com> on 2004/04/13 12:11:25 UTC

SetFkId throws TorqueException

Hi all,

Another inconsistency: I have a table X that has a foreign key column called
IdY. When generating the code, the method SetIdY has the following
signature:
public void setIdY( int id ) throws TorqueException

The method does not have to contain the throws clause because there is no
method call in this method that could throw such an exception. So each time
I use such an setFkIdMethod I have to surround it with a Try Catch. Yuch.
The fields that are NOT foreign keys receive methods that don't throw a
TorqueException. I think here it could be a slight inconsistency???

Pls correct me if I am wrong.

In order to correct this, I think I have to change one velocity template.
But I would like to stick to the official version, without changing to much
of the templates. Should this change of the templates be made in the
following release, what do you think?

Alex


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


Save (insert) in cascade

Posted by Alexandru Dovlecel <al...@siemens.com>.
Hi all,

Another question to ask&propose a possible solution.

I have X with a ToMany Y.

When I want to create an X with (let's say) 3 Ys, I have to do the
following:

con = Transaction.begin( mydb ) ;
X = new X() ;
X.save() ;
y1 = new Y() ;
X.addY( y1 ) ;
y2 = new Y() ;
X.addY( y2 ) ;
y3 = new Y() ;
X.addY( y3 ) ;
X.save() ;

// or y1.save, y2.save, y3.save...

It is quite complicated... I think. It would be nice and elegant if doing
like this:
x = new X() ;
y1 = new Y() ;
x.addY( y1 ) ;
y2 = new Y() ;
x.addY( y2) ;
x.save() ;

Now, if X has an autoincrement PK, this does not work. But we could change
the Object.vm in order to make it work. In each for (relation)
if the X is new, then
	Y.setIdX( this.getId() ) ;
	Y.save() ;

The same solution could be implemented for ToOne relations.

As a result, this change will ease the use of torque (I think), but I don't
know what problems might arrise because of those changes. And also it
reduces the number of queries to the DBServer (by one): when doing the first
addY( y1 ), there is a query to DB in order to retrieve the Ys from the
database.

What is your oppinion? Has somebody tried this? And if so, did they hit any
wall when doing this?

Regards,
Alex


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


RE: SetFkId throws TorqueException

Posted by Dave Newton <da...@solaraccess.com>.
On Tue, 2004-04-13 at 17:16, Michael Manske wrote:
> After a short look into several generated sources i have to agree with Alex,
> imho these throws declarations are not neccessary for the mentioned
> setSomeForeignKey() methods. I would appreciate if the declarations would be
> removed with the next release.

Is it the case that the methods _never_ throw the exception regardless
of targeted database?

Dave



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


RE: SetFkId throws TorqueException

Posted by Michael Manske <ne...@manskes.de>.
After a short look into several generated sources i have to agree with Alex,
imho these throws declarations are not neccessary for the mentioned
setSomeForeignKey() methods. I would appreciate if the declarations would be
removed with the next release.

so long
Micha

> -----Original Message-----
> From: Alexandru Dovlecel [mailto:alexandru.dovlecel@siemens.com]
> Sent: Tuesday, April 13, 2004 12:11 PM
> To: 'Apache Torque Users List'
> Subject: SetFkId throws TorqueException
>
>
> Hi all,
>
> Another inconsistency: I have a table X that has a foreign key
> column called
> IdY. When generating the code, the method SetIdY has the following
> signature:
> public void setIdY( int id ) throws TorqueException
>
> The method does not have to contain the throws clause because there is no
> method call in this method that could throw such an exception. So
> each time
> I use such an setFkIdMethod I have to surround it with a Try Catch. Yuch.
> The fields that are NOT foreign keys receive methods that don't throw a
> TorqueException. I think here it could be a slight inconsistency???
>
> Pls correct me if I am wrong.
>
> In order to correct this, I think I have to change one velocity template.
> But I would like to stick to the official version, without
> changing to much
> of the templates. Should this change of the templates be made in the
> following release, what do you think?
>
> Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.656 / Virus Database: 421 - Release Date: 09.04.2004
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.656 / Virus Database: 421 - Release Date: 09.04.2004


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