You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Karr, David" <da...@wamu.net> on 2006/07/20 21:08:58 UTC

Can Jelly SQL branch on table existence, or error conditions?

I'm guessing the primary commons-user answerers are in a very different
time zone, so I guess I'm going to burst out a bunch of questions,
instead of waiting for answers for each one.

In my Jelly SQL script, I'm going to need to drop and recreate a set of
tables.  In order for this to work, it has to deal with any variation of
those tables existing or not.  For instance, if the table doesn't exist,
dropping the table will fail in some way, so I'll need to be able to
ignore the error, perhaps.  If I did this with plain sql tasks in Ant,
it will just fail the Ant script if the drop fails, and I don't see how
to get back info into the Ant script indicating whether the table exists
or not.

Is this feasible in Jelly SQL?

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


Re: Can Jelly SQL branch on table existence, or error conditions?

Posted by Neal Johnson <ne...@dataactive.com>.
> I'm currently at a stage where I'm trying to figure out
> how to create code blocks that I can call from different places.

There are a few ways to do this using the define tag.

If you just want to execute the same block accessing defined  
variables you can use define:script:

<define:script var="scripNamet">
   <!-- jelly script here -->
</define:script>
<!-- more jelly here -->

And you can call it with define:invoke:

<define:invoke script="${scriptName}"/>

NOTE: this script needs to be defined before any code that uses it as  
Jelly uses a SAX parser.


If you need to parse parameters  to the script it is probably better  
to use define:tag and define:taglib. This is slitty more complicated:

<define:taglib uri="nameSpaceForTag">
   <define:tag name="tagName">
     <!-- jelly script here -->
   </define:tag>
</define:taglib>

You will need to add the name space of this taglib to your j:jelly tag:

<j:jelly xmlns:j="jelly:core" xmlns:define="jelly:define"  
xmlns:foo="nameSpaceForTag">
  <!-- your script -->
</j:jelly>

Now when you want to use the this new tag:

<j:jelly xmlns:j="jelly:core" xmlns:define="jelly:define"  
xmlns:foo="nameSpaceForTag">
  <foo:tagName/>
</j:jelly>

This will then execute the newly defined nameTag. This at the moment  
is the same as define:invoke, but if the foo:tagName tag has attributes:

<j:jelly xmlns:j="jelly:core" xmlns:define="jelly:define"  
xmlns:foo="nameSpaceForTag">
  <foo:tagName attrOne="someData" attrTwo="${someDynamicData}"/>
</j:jelly>

Then inside the definition for tagName (in the taglib) the variables  
attrOne and attrTwo are avalible:

<define:taglib uri="nameSpaceForTag">
   <define:tag name="tagName">
      <j:out value="attrOne: ${attrOne} attrTwo: ${attrTwo}"/>
   </define:tag>
</define:taglib>

If this code is to be used across multiple file it is probably best  
that you place this lib in a separate file and use j:import in the  
script that needs it.

Neal






______________________________________________________________________
LEGAL NOTICE:This e-mail has been sent to you by DataActive
Communications Ltd. This communication, and the information it
contains, is intended for the person(s) or organisation(s) to whom it
is addressed.  Its contents are confidential and may be protected in
law. Unauthorised use, copying or disclosure of any of it may be
unlawful.  If you are not the intended recipient, please notify the
sender by replying with 'Received in error' as the subject and then
delete it from your mailbox. Any views or opinions presented are
solely those of the author and do not necessarily represent those of
DataActive Communications Ltd.  Although this e-mail and any
attachments are believed to be free of any virus or other defects
which might affect any computer or IT system into which they are
received, no responsibility is accepted from DataActive Communications
Ltd, or any of its associated companies for any loss or damage
arising in any way from the receipt or use thereof. We recommend that
you should carry out your own virus checking procedure before opening
any attachment. 

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

RE: Can Jelly SQL branch on table existence, or error conditions?

Posted by "Karr, David" <da...@wamu.net>.
> -----Original Message-----
> From: Paul Libbrecht [mailto:paul@activemath.org] 
> Sent: Friday, July 21, 2006 1:52 PM
> To: Jakarta Commons Users List
> Subject: Re: Can Jelly SQL branch on table existence, or 
> error conditions?
> 
> David,
> 
> you definitely need to see at least the unit test scripts.

Thanks.  I did manage to find them, although by sort of an awkward path.
I found a note in the mail archive showing replacements of the contents
of those scripts, so I was able to see a reasonably current state of
them.  This link to the repository is a better way to get to them.  I
wish this link was on the Jelly site.  I imagine it's up on the Jakarta
site.

> All taglibs in jelly src distribution is under 
> <jelly-home>/jelly-tags/<taglib-name> you can see the current 
> version of the svn trunk at
>     
> http://svn.apache.org/viewvc/jakarta/commons/proper/jelly/trun
> k/jelly-tags/sql/
> among others, I see a catch at:
>   src/test//org/apache/commons/jelly/tags/sql/example3.jelly
> Sorry for the wrong track.. there's no try just a catch...
> 
> As to the var attribute of the query tag... this is really 
> just the result... it is of class 
> org.apache.commons.jelly.tags.sql.ResultImpl I think. Better 
> see the javadoc to see the things you can do on it.
> Among others, if <query var="r"/> then ${r.rows} will give 
> you an array of maps of length ${r.rowCount}. I'm commenting 
> all this only by reading the source right now... so consider 
> these as hints.

This is all helpful.  I managed to get all my simple table drop/create
code working.  I'm currently at a stage where I'm trying to figure out
how to create code blocks that I can call from different places.

> Karr, David wrote:
> > Where is an example of how to wrap a "sql:update" in a 
> try/catch?  I 
> > found some limited examples by grepping the core source 
> tree (I can't 
> > find the source for the SQL tag library anywhere), but I don't 
> > understand them.
> >
> >   
> >> -----Original Message-----
> >> From: Paul Libbrecht [mailto:paul@activemath.org]
> >> Sent: Friday, July 21, 2006 12:38 AM
> >> To: Jakarta Commons Users List
> >> Subject: Re: Can Jelly SQL branch on table existence, or error 
> >> conditions?
> >>
> >> At worst the core's try/catch should help you, or ?
> >> Feel free to suggest added tags such as "tableAvailable" or 
> >> "dbMetadata"
> >> or...
> >> paul
> >>
> >> Karr, David wrote:
> >>     
> >>> I'm guessing the primary commons-user answerers are in a very 
> >>> different time zone, so I guess I'm going to burst out a bunch of 
> >>> questions, instead of waiting for answers for each one.
> >>>
> >>> In my Jelly SQL script, I'm going to need to drop and
> >>>       
> >> recreate a set
> >>     
> >>> of tables.  In order for this to work, it has to deal with any 
> >>> variation of those tables existing or not.  For instance,
> >>>       
> >> if the table
> >>     
> >>> doesn't exist, dropping the table will fail in some way, so
> >>>       
> >> I'll need
> >>     
> >>> to be able to ignore the error, perhaps.  If I did this
> >>>       
> >> with plain sql
> >>     
> >>> tasks in Ant, it will just fail the Ant script if the drop
> >>>       
> >> fails, and
> >>     
> >>> I don't see how to get back info into the Ant script indicating 
> >>> whether the table exists or not.
> >>>
> >>> Is this feasible in Jelly SQL?
> >>>
> >>>   
> >>>       
> >>     
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: 
> commons-user-help@jakarta.apache.org
> >
> >   
> 
> 

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


Re: Can Jelly SQL branch on table existence, or error conditions?

Posted by Paul Libbrecht <pa...@activemath.org>.
David,

you definitely need to see at least the unit test scripts.

All taglibs in jelly src distribution is under 
<jelly-home>/jelly-tags/<taglib-name> you can see the current version of 
the svn trunk at
    
http://svn.apache.org/viewvc/jakarta/commons/proper/jelly/trunk/jelly-tags/sql/
among others, I see a catch at:
  src/test//org/apache/commons/jelly/tags/sql/example3.jelly
Sorry for the wrong track.. there's no try just a catch...

As to the var attribute of the query tag... this is really just the 
result... it is of class org.apache.commons.jelly.tags.sql.ResultImpl I 
think. Better see the javadoc to see the things you can do on it.
Among others, if <query var="r"/> then ${r.rows} will give you an array 
of maps of length ${r.rowCount}. I'm commenting all this only by reading 
the source right now... so consider these as hints.

hope that helps.

paul

Karr, David wrote:
> Where is an example of how to wrap a "sql:update" in a try/catch?  I
> found some limited examples by grepping the core source tree (I can't
> find the source for the SQL tag library anywhere), but I don't
> understand them. 
>
>   
>> -----Original Message-----
>> From: Paul Libbrecht [mailto:paul@activemath.org] 
>> Sent: Friday, July 21, 2006 12:38 AM
>> To: Jakarta Commons Users List
>> Subject: Re: Can Jelly SQL branch on table existence, or 
>> error conditions?
>>
>> At worst the core's try/catch should help you, or ?
>> Feel free to suggest added tags such as "tableAvailable" or 
>> "dbMetadata" 
>> or...
>> paul
>>
>> Karr, David wrote:
>>     
>>> I'm guessing the primary commons-user answerers are in a very 
>>> different time zone, so I guess I'm going to burst out a bunch of 
>>> questions, instead of waiting for answers for each one.
>>>
>>> In my Jelly SQL script, I'm going to need to drop and 
>>>       
>> recreate a set 
>>     
>>> of tables.  In order for this to work, it has to deal with any 
>>> variation of those tables existing or not.  For instance, 
>>>       
>> if the table 
>>     
>>> doesn't exist, dropping the table will fail in some way, so 
>>>       
>> I'll need 
>>     
>>> to be able to ignore the error, perhaps.  If I did this 
>>>       
>> with plain sql 
>>     
>>> tasks in Ant, it will just fail the Ant script if the drop 
>>>       
>> fails, and 
>>     
>>> I don't see how to get back info into the Ant script indicating 
>>> whether the table exists or not.
>>>
>>> Is this feasible in Jelly SQL?
>>>
>>>   
>>>       
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>   


RE: Can Jelly SQL branch on table existence, or error conditions?

Posted by "Karr, David" <da...@wamu.net>.
Ok, I think I've figured this out.  From the examples I managed to find
on the net, a "catch" tag is more like a try block than a catch block.
I can't find any actual documentation that says that, but I infer that
from the code I saw.  I can use "j:if" to test for the exception
afterwards. 

> -----Original Message-----
> From: Karr, David 
> Sent: Friday, July 21, 2006 10:52 AM
> To: Jakarta Commons Users List; paul@activemath.org
> Subject: RE: Can Jelly SQL branch on table existence, or 
> error conditions?
> 
> Where is an example of how to wrap a "sql:update" in a 
> try/catch?  I found some limited examples by grepping the 
> core source tree (I can't find the source for the SQL tag 
> library anywhere), but I don't understand them. 
> 
> > -----Original Message-----
> > From: Paul Libbrecht [mailto:paul@activemath.org]
> > Sent: Friday, July 21, 2006 12:38 AM
> > To: Jakarta Commons Users List
> > Subject: Re: Can Jelly SQL branch on table existence, or error 
> > conditions?
> > 
> > At worst the core's try/catch should help you, or ?
> > Feel free to suggest added tags such as "tableAvailable" or 
> > "dbMetadata"
> > or...
> > paul
> > 
> > Karr, David wrote:
> > > I'm guessing the primary commons-user answerers are in a very 
> > > different time zone, so I guess I'm going to burst out a bunch of 
> > > questions, instead of waiting for answers for each one.
> > >
> > > In my Jelly SQL script, I'm going to need to drop and
> > recreate a set
> > > of tables.  In order for this to work, it has to deal with any 
> > > variation of those tables existing or not.  For instance,
> > if the table
> > > doesn't exist, dropping the table will fail in some way, so
> > I'll need
> > > to be able to ignore the error, perhaps.  If I did this
> > with plain sql
> > > tasks in Ant, it will just fail the Ant script if the drop
> > fails, and
> > > I don't see how to get back info into the Ant script indicating 
> > > whether the table exists or not.
> > >
> > > Is this feasible in Jelly SQL?
> > >
> > >   
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

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


RE: Can Jelly SQL branch on table existence, or error conditions?

Posted by "Karr, David" <da...@wamu.net>.
Where is an example of how to wrap a "sql:update" in a try/catch?  I
found some limited examples by grepping the core source tree (I can't
find the source for the SQL tag library anywhere), but I don't
understand them. 

> -----Original Message-----
> From: Paul Libbrecht [mailto:paul@activemath.org] 
> Sent: Friday, July 21, 2006 12:38 AM
> To: Jakarta Commons Users List
> Subject: Re: Can Jelly SQL branch on table existence, or 
> error conditions?
> 
> At worst the core's try/catch should help you, or ?
> Feel free to suggest added tags such as "tableAvailable" or 
> "dbMetadata" 
> or...
> paul
> 
> Karr, David wrote:
> > I'm guessing the primary commons-user answerers are in a very 
> > different time zone, so I guess I'm going to burst out a bunch of 
> > questions, instead of waiting for answers for each one.
> >
> > In my Jelly SQL script, I'm going to need to drop and 
> recreate a set 
> > of tables.  In order for this to work, it has to deal with any 
> > variation of those tables existing or not.  For instance, 
> if the table 
> > doesn't exist, dropping the table will fail in some way, so 
> I'll need 
> > to be able to ignore the error, perhaps.  If I did this 
> with plain sql 
> > tasks in Ant, it will just fail the Ant script if the drop 
> fails, and 
> > I don't see how to get back info into the Ant script indicating 
> > whether the table exists or not.
> >
> > Is this feasible in Jelly SQL?
> >
> >   
> 
> 

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


Re: Can Jelly SQL branch on table existence, or error conditions?

Posted by Paul Libbrecht <pa...@activemath.org>.
At worst the core's try/catch should help you, or ?
Feel free to suggest added tags such as "tableAvailable" or "dbMetadata" 
or...
paul

Karr, David wrote:
> I'm guessing the primary commons-user answerers are in a very different
> time zone, so I guess I'm going to burst out a bunch of questions,
> instead of waiting for answers for each one.
>
> In my Jelly SQL script, I'm going to need to drop and recreate a set of
> tables.  In order for this to work, it has to deal with any variation of
> those tables existing or not.  For instance, if the table doesn't exist,
> dropping the table will fail in some way, so I'll need to be able to
> ignore the error, perhaps.  If I did this with plain sql tasks in Ant,
> it will just fail the Ant script if the drop fails, and I don't see how
> to get back info into the Ant script indicating whether the table exists
> or not.
>
> Is this feasible in Jelly SQL?
>
>