You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Clifton C. Craig" <cc...@icsaward.com> on 2004/11/08 20:20:09 UTC
Giving up on Velocity
I've had it. I'm trying my best but I can't get Velocity/Anakia to
properly convert my XML to SQL. The code is starting to smell and it
just doesn't feel quite right. I'm ready to hang up my efforts and call
it quits. I can't see why something as simple as expanding a constraint
list like this:
<constraint name="simple_constraint">
<values select="exclude">
<val>hum</val>
<val>de</val>
<val>dum</val>
</values>
</constraint>
would take code that looks like this:
#macro( expandIfNodeExists $node $templateStr)
#if( $node )
$!templateStr
#end
#end
#macro( defineConstraints $col )
#set ($colName = $col.getAttributeValue("name"))
#set ( $constraint = $col.selectNodes("constraint") )
#set ($constraintName = $constraint.selectNodes("@name").get(0))
#if( $constraint.selectNodes("values") &&
$constraint.selectNodes("values").selectNodes("val") )
#expandIfNodeExists($constraintName "constraint
$constraintName.getValue()")
#set ($list='')
#foreach ($validVal in
$constraint.selectNodes("values").selectNodes("val"))
#set($qte = '"')
#if($list=='')
#set($list = "$qte$validVal.getText()$qte")
#else
#set($list = "$!list,$qte$validVal.getText()$qte")
#end
#end
check $!colName
#set ( $sltAtr = $constraint.selectNodes("values/@select") )
#set ( $tmpltStr = "#if($sltAtr.get(0).getValue()=='exclude')
not #else #end" )
#expandIfNodeExists($sltAtr $tmpltStr)
in ( $!list )
#end
#end
And even that doesn't work. I know it probably not the technology at
fault and it's just me. However, I feel like I've been slowed to a stop
(if not a backward sprint) using Anakia. I thought it was the perfect
fit at first but now I can't get past the clumsiness of doing anything
sophisticated with it. If anyone can see where I'm coming from, please
chime in and lend a hand. Otherwise, I'm stumped and I give up.
Clifton C. Craig, Software Engineer
Intelligent Computer Systems - A Division of GBG
2101 Embassy Drive
Lancaster, PA 17603
Phone: 717-295-7977 ext. 621
Fax: 717-295-7683
ccc@icsaward.com
ccraig@gbg.com
Clifton C. Craig wrote:
> An un-related question...
> How do you escape double quotes? I'm trying to use #set
> ($var="\"MyValue\"") but $var ends up with \"MyValue\" instead of
> "MyValue". When I try it without the backslashes I get parse errors.
>
> Clifton C. Craig, Software Engineer
> Intelligent Computer Systems - A Division of GBG
> 2101 Embassy Drive
> Lancaster, PA 17603
>
> Phone: 717-295-7977 ext. 621
> Fax: 717-295-7683
> ccc@icsaward.com
> ccraig@gbg.com
>
>
>
> Clifton C. Craig wrote:
>
>> Hello all. I'm still green with Velocity. I'm wondering what's the
>> easiest way to test a string for a numeric. For example, I have a
>> string $myVal that can contain "foo", or "23.2", or "15". I want to
>> 1st check if it is a numeric and then wrap it with quotes if it is not.
>>
>> Clifton C. Craig, Software Engineer
>> Intelligent Computer Systems - A Division of GBG
>> 2101 Embassy Drive
>> Lancaster, PA 17603
>>
>> Phone: 717-295-7977 ext. 621
>> Fax: 717-295-7683
>> ccc@icsaward.com
>> ccraig@gbg.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Giving up on Velocity there hope after all
Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Wow,
Thank you all for suggesting DVSL. So far I have managed to replicate
all of my existing functionality implemented on Anakia with DVSL. The
code is a LOT cleaner and simpler too. I'm really digging this stuff so
far. Maybe there's hope for Velocity after all. Things are looking a lot
better. Thanx.
Clifton C. Craig, Software Engineer
Intelligent Computer Systems - A Division of GBG
2101 Embassy Drive
Lancaster, PA 17603
Phone: 717-295-7977 ext. 621
Fax: 717-295-7683
ccc@icsaward.com
ccraig@gbg.com
Tim Colson wrote:
>>As an alternative to Anakia, you can use DVSL for xml transformation.
>> http://jakarta.apache.org/velocity/dvsl/index.html
>>
>>
>I'll second that. I've had good luck with DVSL.
>
>-Timo
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: Giving up on Velocity
Posted by Tim Colson <tc...@cisco.com>.
> As an alternative to Anakia, you can use DVSL for xml transformation.
> http://jakarta.apache.org/velocity/dvsl/index.html
I'll second that. I've had good luck with DVSL.
-Timo
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Giving up on Velocity
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,
> #macro( expandIfNodeExists $node $templateStr)
> #if( $node )
> $!templateStr
> #end
> #end
## snip
> And then when it encounters another constraint definition in another
> table element things fall apart. I'd get this:
> rateunit varchar constraint valid_values check rateunit
> #if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
> "year"),
At first glance, it looks like you could use the RenderTool. (My first
glance also says, "I think there's a better way to do this...". ;))
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/RenderTool.html
## But I don't know how to set tools in Anakia. :(
As an alternative to Anakia, you can use DVSL for xml transformation.
http://jakarta.apache.org/velocity/dvsl/index.html
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Giving up on Velocity
Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Further info:
The whole big idea is to take input as follows:
<database>
<table name="testtable">
<pk name="id"/>
<col name="id" type="int"/>
<col name="compositekey1" type="int"/>
<col name="compositekey2" type="dec" size="9" scale="3"/>
<col name="compositekey3" type="varchar" size="10"/>
<col name="uniquekey" type="varchar" size="30"/>
<col name="nonnullval" type="varchar" size="30" allownull="no"/>
<col name="nonnullval2" type="varchar" size="30" allownull="no">
<default>DEFAULT VALUE</default>
</col>
<col name="nullableval" type="varchar" allownull="yes"/>
<col name="constrained_col" type="varchar">
<constraint name="simple_constraint">
<values select="exclude">
<val>hum</val>
<val>de</val>
<val>dum</val>
</values>
</constraint>
</col>
<unique-key cols="compositekey1,compositekey2,compositekey3"/>
<unique-key cols="uniquekey"/>
</table>
</database>
And create some SQL similar to the following:
CREATE TABLE testtable id int,
compositekey1 int,
compositekey2 dec(9, 3),
compositekey3 varchar(10),
uniquekey varchar(30),
nonnullval varchar(30) NOT NULL,
nonnullval2 varchar(30) DEFAULT 'DEFAULT VALUE' NOT NULL,
nullableval varchar NULL,
constrained_col varchar constraint simple_constraint check
constrained_col not in ("hum",
"de",
"dum");
It almost works but as I include multiple table elements in my XML it
falls apart. Like in my prior email a subsequent table element:
<table name="employee">
<pk name="id"/>
<col name="id" type="int"/>
<col name="salaried" type="boolean"/>
<col name="rateamt" type="dec" size="9" scale="4"/>
<col name="rateunit" type="varchar">
<doc>Determines the frequency that rateamt is paid.</doc>
<constraint name="valid_values">
<values>
<val>hour</val>
<val>year</val>
</values>
</constraint>
</col>
<col name="grade" type="varchar"/>
<col name="title" type="varchar"/>
<related table="user" how="onetoone">
<match><onpks/></match>
</related>
</table>
...produces the following output:
CREATE TABLE employee id int,
salaried boolean,
rateamt dec(9, 4),
rateunit varchar constraint valid_values check rateunit
#if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
"year"),
grade varchar,
title varchar;
I'm frustrated because as I look back on what I've created it looks less
like a template and more like a programmed procedure. I blame myself for
my lack of experience and lack of understanding Velocity. However I was
hoping that this approach would be something I could hit the ground
running with. Given time I'm sure I'd accept Velocity's syntax (had a
similar experience with Ant). Just feeling frustrated.
Clifton C. Craig, Software Engineer
Intelligent Computer Systems - A Division of GBG
2101 Embassy Drive
Lancaster, PA 17603
Phone: 717-295-7977 ext. 621
Fax: 717-295-7683
ccc@icsaward.com
ccraig@gbg.com
Shinobu Kawai wrote:
>Hi Clifton,
>
>
>
>>I've had it. I'm trying my best but I can't get Velocity/Anakia to
>>properly convert my XML to SQL. The code is starting to smell and it
>>just doesn't feel quite right. I'm ready to hang up my efforts and call
>>it quits. I can't see why something as simple as expanding a constraint
>>list like this:
>> <constraint name="simple_constraint">
>> <values select="exclude">
>> <val>hum</val>
>> <val>de</val>
>> <val>dum</val>
>> </values>
>> </constraint>
>>
>>would take code that looks like this:
>>
>>
>## snip
>
>
>
>>And even that doesn't work.
>>
>>
>Can you explain what output you want, and what you are actually getting?
>
>Best regards,
>-- Shinobu Kawai
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Giving up on Velocity
Posted by "Clifton C. Craig" <cc...@icsaward.com>.
Shinobu,
Sorry for airing my frustrations. I'm just having a lot of trouble
adjusting to Velocity. Anyhowz, My prior snippet listed here:
#macro( expandIfNodeExists $node $templateStr)
#if( $node )
$!templateStr
#end
#end
#macro( defineConstraints $col )
#set ($colName = $col.getAttributeValue("name"))
#set ( $constraint = $col.selectNodes("constraint") )
#set ($constraintName = $constraint.selectNodes("@name").get(0))
#if( $constraint.selectNodes("values") &&
$constraint.selectNodes("values").selectNodes("val") )
#expandIfNodeExists($constraintName "constraint
$constraintName.getValue()")
#set ($list='')
#foreach ($validVal in
$constraint.selectNodes("values").selectNodes("val"))
#set($qte = '"')
#if($list=='')
#set($list = "$qte$validVal.getText()$qte")
#else
#set($list = "$!list,$qte$validVal.getText()$qte")
#end
#end
check $!colName
#set ( $sltAtr = $constraint.selectNodes("values/@select") )
#set ( $tmpltStr = "#if($sltAtr.get(0).getValue()=='exclude')
not #else #end" )
#expandIfNodeExists($sltAtr $tmpltStr)
in ( $!list )
#end
#end
appeared to work as it would produce results like this when it
encountered the 1st table element:
constrained_col varchar constraint simple_constraint check
constrained_col not in ("hum",
"de",
"dum");
And then when it encounters another constraint definition in another
table element things fall apart. I'd get this:
rateunit varchar constraint valid_values check rateunit
#if($sltAtr.get(0) .getValue() =='exclude') not #else #end in ("hour",
"year"),
Maybe I'll have a look tomorrow and see where I muffed it up. Thanks for
all of your replies.
Kind Regards,
Clifton C. Craig, Software Engineer
Intelligent Computer Systems - A Division of GBG
2101 Embassy Drive
Lancaster, PA 17603
Phone: 717-295-7977 ext. 621
Fax: 717-295-7683
ccc@icsaward.com
ccraig@gbg.com
Shinobu Kawai wrote:
>Hi Clifton,
>
>
>
>>I've had it. I'm trying my best but I can't get Velocity/Anakia to
>>properly convert my XML to SQL. The code is starting to smell and it
>>just doesn't feel quite right. I'm ready to hang up my efforts and call
>>it quits. I can't see why something as simple as expanding a constraint
>>list like this:
>> <constraint name="simple_constraint">
>> <values select="exclude">
>> <val>hum</val>
>> <val>de</val>
>> <val>dum</val>
>> </values>
>> </constraint>
>>
>>would take code that looks like this:
>>
>>
>## snip
>
>
>
>>And even that doesn't work.
>>
>>
>Can you explain what output you want, and what you are actually getting?
>
>Best regards,
>-- Shinobu Kawai
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Giving up on Velocity
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Clifton,
> I've had it. I'm trying my best but I can't get Velocity/Anakia to
> properly convert my XML to SQL. The code is starting to smell and it
> just doesn't feel quite right. I'm ready to hang up my efforts and call
> it quits. I can't see why something as simple as expanding a constraint
> list like this:
> <constraint name="simple_constraint">
> <values select="exclude">
> <val>hum</val>
> <val>de</val>
> <val>dum</val>
> </values>
> </constraint>
>
> would take code that looks like this:
## snip
> And even that doesn't work.
Can you explain what output you want, and what you are actually getting?
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org