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 Dave Newton <da...@solaraccess.com> on 2003/08/12 20:59:27 UTC
Re: Foreign keys another great mystery... (longish w/ code)
On Tue, 2003-08-12 at 13:50, Mark Lowe wrote:
> Thanks.. for pointing me to the docs, they're great aren't they i've
> been reading them for days, its just a shame that as soon as you try
> anything useful they don't seem to be right..
Yeah, Jakarta documentation often leaves much to be desired. That's a
pain in the ass and wastes a lot of time. *sigh* OTOH, it's free :D
> Tell you what i'll even give you
> back the pics I've got of you and your ma.
Even if that was meant as a joke it's pretty rude.
> So come on then Dave show me how stupid I am
Redundancy sucks. You'll do fine.
> The api gives me a setApplicant(Applicant v) method which is great..
> Despite the fact it doesn't work.. Now I don't mind the fact this
> doesn't work, just that all these little not worky things seem to be a
> tad esoteric and not mentioned in the docs.. Variations of this have be
> trying the addApplication(Application v) in the applicant api, but alas
> no.
What do you mean by "doesn't work?" Do you get an exception or does it
appear as though nothing at all is happening?
Here's a simple schema file and some Jython code that works fine. I use
Jython features, but it's mostly syntactic sugar around getters/setters.
--- schema snippet ---
<table name="publisher" description="Publisher Table">
<column name="publisher_id" required="true" type="INTEGER" [...]/>
<!-- etc. -->
</table>
<table name="author" description="Author Table">
<column name="author_id" required="true" type="INTEGER" [...]/>
<!-- etc. -->
</table>
<table name="book" description="Book Table">
<column name="book_id" required="true" type="INTEGER" [...]/>
<!-- etc. -->
<foreign-key foreignTable="publisher">
<reference local="publisher_id" foreign="publisher_id"/>
</foreign-key>
<foreign-key foreignTable="author">
<reference local="author_id" foreign="author_id"/>
</foreign-key>
</table>
--- jython snippet ---
#
# _MY_ question: What's a good way to delete all objects from
# a table w/o knowing table structure or writing
# SQL or modifying the templates?
#
# Blechy code to delete all from the publisher table
allpub = Crit().add(PubPeer.NAME, "%", Crit.LIKE)
PubPeer.doDelete(allpub)
# Add publishers
addison = Pub(name = "Addison Wesley Professional")
oreilly = Pub(name = "O'Reilly")
addison.save()
oreilly.save()
# Add authors
dave = Author(firstName = "Dave", lastName = "Newton", \
email="dave@sa.com", lastLogin = awhileago)
matt = Author(firstName = "Matt", lastName = "Stoops", \
email="matt@sa.com", lastLogin = lastlogin)
dave.save()
matt.save()
# Add books
b1 = Book(title="Struts for Dave", ISBN="", pages=666, \
publisher=addison, author=matt)
b2 = Book(title="JDBC does MySQL", ISBN="", pages=300, \
publisher=oreilly ,author=matt)
b3 = Book(title="Extreme Programming", ISBN="", pages=666, \
publisher=addison ,author=dave)
b4 = Book(title="Jython Cookbook", ISBN="", pages=300, \
publisher=addison ,author=dave)
b5 = Book(title="Physical Security", ISBN="", pages=500, \
publisher=oreilly ,author=dave)
books = [b1, b2, b3, b4, b5]
for book in books:
book.save()
--- end snippets --
I've done a few other mappings with Torque and have Jython code for
most; I can send it to you if necessary (once I find it--switching
machines/states/etc.)
Dave
Re: Foreign keys another great mystery... (longish w/ code)
Posted by Dave Newton <da...@solaraccess.com>.
On Tue, 2003-08-12 at 15:32, Mark Lowe wrote:
> Sorry If the ma gag was a bit heavy.. But so was give me "read the
> docs".. You're example is great...
My example is a Jython version of the tutorial on the Torque site, which
is how ya' learn to use stuff. Worked for me, anyway.
Dave "And DANG I like Jython!*" Newton
* Although it makes working in real Java seem really annoying ;)
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Foreign keys another great mystery... (longish w/ code)
Posted by Mark Lowe <ma...@talk21.com>.
Thanks Dave
Sorry If the ma gag was a bit heavy.. But so was give me "read the
docs".. You're example is great... The important thing I've been
missing was the fact that a newly inserted object returns an id.. I'm
one happy bunny woo hoo!!
The rest interlaced
On Tuesday, August 12, 2003, at 07:59 PM, Dave Newton wrote:
> On Tue, 2003-08-12 at 13:50, Mark Lowe wrote:
>> Thanks.. for pointing me to the docs, they're great aren't they i've
>> been reading them for days, its just a shame that as soon as you try
>> anything useful they don't seem to be right..
>
> Yeah, Jakarta documentation often leaves much to be desired. That's a
> pain in the ass and wastes a lot of time. *sigh* OTOH, it's free :D
Agreed its free, and that's why i don't mind if it doesn't work. Docs
that are several leaps beyond its present capabilities aren't not a
norm of open source projects and i think the "its free" excuse at
best.. lame. I'd love to have a look in torque and see if there's
anything useful I can contribute, but I have to be able to use it first.
>
>> Tell you what i'll even give you
>> back the pics I've got of you and your ma.
>
> Even if that was meant as a joke it's pretty rude.
>
>> So come on then Dave show me how stupid I am
>
> Redundancy sucks. You'll do fine.
You tell me..
>
>> The api gives me a setApplicant(Applicant v) method which is great..
>> Despite the fact it doesn't work.. Now I don't mind the fact this
>> doesn't work, just that all these little not worky things seem to be a
>> tad esoteric and not mentioned in the docs.. Variations of this have
>> be
>> trying the addApplication(Application v) in the applicant api, but
>> alas
>> no.
>
> What do you mean by "doesn't work?" Do you get an exception or does it
> appear as though nothing at all is happening?
Problem is I'm getting no exceptions. I'd love some action to be going
off but not a whisper.
>
> Here's a simple schema file and some Jython code that works fine. I use
> Jython features, but it's mostly syntactic sugar around
> getters/setters.
>
> --- schema snippet ---
>
> <table name="publisher" description="Publisher Table">
> <column name="publisher_id" required="true" type="INTEGER" [...]/>
> <!-- etc. -->
> </table>
>
> <table name="author" description="Author Table">
> <column name="author_id" required="true" type="INTEGER" [...]/>
> <!-- etc. -->
> </table>
>
> <table name="book" description="Book Table">
> <column name="book_id" required="true" type="INTEGER" [...]/>
> <!-- etc. -->
> <foreign-key foreignTable="publisher">
> <reference local="publisher_id" foreign="publisher_id"/>
> </foreign-key>
> <foreign-key foreignTable="author">
> <reference local="author_id" foreign="author_id"/>
> </foreign-key>
> </table>
>
> --- jython snippet ---
>
> #
> # _MY_ question: What's a good way to delete all objects from
> # a table w/o knowing table structure or writing
> # SQL or modifying the templates?
> #
>
> # Blechy code to delete all from the publisher table
> allpub = Crit().add(PubPeer.NAME, "%", Crit.LIKE)
> PubPeer.doDelete(allpub)
>
> # Add publishers
> addison = Pub(name = "Addison Wesley Professional")
> oreilly = Pub(name = "O'Reilly")
> addison.save()
> oreilly.save()
>
> # Add authors
> dave = Author(firstName = "Dave", lastName = "Newton", \
> email="dave@sa.com", lastLogin = awhileago)
>
> matt = Author(firstName = "Matt", lastName = "Stoops", \
> email="matt@sa.com", lastLogin = lastlogin)
>
> dave.save()
> matt.save()
>
> # Add books
> b1 = Book(title="Struts for Dave", ISBN="", pages=666, \
> publisher=addison, author=matt)
> b2 = Book(title="JDBC does MySQL", ISBN="", pages=300, \
> publisher=oreilly ,author=matt)
> b3 = Book(title="Extreme Programming", ISBN="", pages=666, \
> publisher=addison ,author=dave)
> b4 = Book(title="Jython Cookbook", ISBN="", pages=300, \
> publisher=addison ,author=dave)
> b5 = Book(title="Physical Security", ISBN="", pages=500, \
> publisher=oreilly ,author=dave)
> books = [b1, b2, b3, b4, b5]
> for book in books:
> book.save()
>
> --- end snippets --
>
> I've done a few other mappings with Torque and have Jython code for
> most; I can send it to you if necessary (once I find it--switching
> machines/states/etc.)
>
> Dave
>
> <emailtool-
> schema.xml><populate.py>-----------------------------------------------
> ----------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
Cheers Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org