RE: get the SQL to be executed

Greg Monroe <[email protected]> Thu, 19 Jan 2012 13:19:46 -0500
Newsgroups gmane.comp.jakarta.turbine.torque.user
Message-ID <55B8568AFA5F144F886F18186BAD5B2C2BEC7C1876@durham-e2k7mb1.dukece.com>
Or, if the info you're exporting maps to your Torque app's =0D=0Atables, yo=
u could probably just add "toSQL()" methods to=0D=0Athe record stubs that c=
reates the INSERT statements=2E=0D=0A=0D=0AE=2Eg=2E if you have a User reco=
rd object, modify the User=2Ejava=0D=0ATorque created with something like:=
=0D=0A=0D=0APublic String toSQL() {=0D=0A   StringBuffer sql =3D new String=
Buffer;=0D=0A   =0D=0A// Build SQL statement from current object contents=
=0D=0A=0D=0A   return sql=2EtoString();=0D=0A}=0D=0A=0D=0AThen just do a no=
rmal Torque query to get the data you're =0D=0Ainterested in and loop thru =
the results calling toSQL to =0D=0Acreate your output file=2E=0D=0A=0D=0ANo=
te that once the "stub" classes are built, Torque will not=0D=0Areplace the=
m if your regenerate the code=2E So the toSQL() code =0D=0Ais safe=2E=0D=0A=
=0D=0AIt would also be possible to create some generic Torque record to=0D=
=0ASQL code by using the "map" information=2E  This lets you determine=0D=
=0Athe column info in a table=2E  So you could look up the table info =0D=
=0Afor a record object, then create the sql by iterating over the =0D=0Acol=
umn names and using the column type to determine the string =0D=0Aformat to=
 use=2E=0D=0A=0D=0ABut for a few table objects, it might be easier to just =
do the =0D=0Amanually created toSQL() methods=2E=0D=0A=0D=0A-----Original M=
essage-----=0D=0AFrom: Thomas Vandahl [mailto:tv@apache=2Eorg] =0D=0ASent: =
Thursday, January 19, 2012 12:51 PM=0D=0ATo: Apache Torque Users List=0D=0A=
Subject: Re: get the SQL to be executed=0D=0A=0D=0AOn 19=2E01=2E12 18:38, I=
vano Luberti wrote:=0D=0A> Thanks all for your responses=2E=0D=0A> Just to =
clarify, I need to generate sql commands inside my code to=0D=0A> generate =
a file that can be used by another software (not written by me)=0D=0A> to i=
mport data=2E=0D=0A> =0D=0A> I would like not to execute commands but only =
write them (because this=0D=0A> is what I need)=2E=0D=0A> If I cannot find =
alternatives, I can execute them and use one of the=0D=0A> logging faciliti=
es that have been suggested=2E=0D=0A=0D=0AWell, inserts are sort of tricky =
because the actual SQL generation=0D=0Ahappens deep inside Village=2E If yo=
u have control over your class loader,=0D=0Ayou may modify a copy of the co=
m=2Eworkingdogs=2Evillage=2ERecord class and=0D=0Aput that first in the cha=
in=2E Look for the saveWithInsert() method=2E This=0D=0Ais probably the clo=
sest you can get, IMHO=2E=0D=0A=0D=0ABye, Thomas=2E=0D=0A=0D=0A------------=
---------------------------------------------------------=0D=0ATo unsubscri=
be, e-mail: torque-user-unsubscribe@db=2Eapache=2Eorg=0D=0AFor additional c=
ommands, e-mail: torque-user-help@db=2Eapache=2Eorg=0D=0A=0D=0ADukeCE Priva=
cy Statement:=0D=0APlease be advised that this e-mail and any files transmi=
tted with=0D=0Ait are confidential communication or may otherwise be privil=
eged or=0D=0Aconfidential and are intended solely for the individual or ent=
ity=0D=0Ato whom they are addressed=2E If you are not the intended recipien=
t=0D=0Ayou may not rely on the contents of this email or any attachments,=
=0D=0Aand we ask that you please not read, copy or retransmit this=0D=0Acom=
munication, but reply to the sender and destroy the email, its=0D=0Acontent=
s, and all copies thereof immediately=2E Any unauthorized=0D=0Adisseminatio=
n, distribution or copying of this communication is=0D=0Astrictly prohibite=
d=2E