[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-user
Subject:    Re: [groovy-user] Changeable closure-code and "Could not find the ClassNode"
From:       "Siegfried Weigelt" <weigelts () gmx ! de>
Date:       2007-04-29 13:45:12
Message-ID: op.trjshmh3dn7hkz () weigelt
[Download RAW message or body]

Many thanks for your answering me,
the code isn't pre-compiled and in the classpath as a result of  
"groovy,startGroovy and groovy-starter.conf". May be you can try the code  
(hsqldb.jar is needed) ?
Dierk wrote me in the GINA-forum "BTW: have you seen Jochen's latest  
changes to DataSet.findAll ?"
What's the matter with these changes ?


Am 28.04.2007, 16:58 Uhr, schrieb Guillaume Laforge <glaforge@gmail.com>:

> I haven't looked at your code, but your introduction mentions you're
> using the DataSet class which needs the source file to be on the
> classpath -- especially if your code is pre-compiled.
> So make sure that your script source code is on the classpath, that's
> the reason why you have that error message.
>
> On 4/28/07, Siegfried Weigelt <weigelts@gmx.de> wrote:
>>
>> The GINA-book inspired me to try a script using DataSet's findAll with a
>> condition known only at run-time. The problem is how to write the
>> script-part for the findAll-Closure and the evaluation of the resulting
>> DataSet.
>> The script aborts with
>> Caught: groovy.lang.GroovyRuntimeException: Could not find the ClassNode
>> for MetaClass: groovy.lang.MetaClassImpl@12611a7[class
>> Script1$_run_closure1]
>> at b6.run(b6.groovy:81)
>> at b6.main(b6.groovy)
>>
>> Adding "each{println it.firstname}" to #1 also goes wrong.
>> I don't know what's wrong in my code and what means the error-message.
>>
>>
>>
>> import groovy.sql.Sql
>>
>> /*
>> --------------------------------------------------------------------------
>> Part 1
>> ======
>> Create a table and insert 2 records.
>> -----------------------------------------------------------------------------
>> */
>>
>> dbHandle = null
>> def getDb(){
>> if (dbHandle) return dbHandle
>> def source = new org.hsqldb.jdbc.jdbcDataSource()       //use HSQLDB
>> source.database = 'jdbc:hsqldb:mem:GIA'
>> source.user = 'sa'
>> source.password = ''
>> dbHandle = new Sql(source)
>> return dbHandle
>> }
>> def reset() {
>> db.execute '''
>> DROP INDEX athleteIdx IF EXISTS;
>> DROP TABLE Athlete IF EXISTS;
>> CREATE TABLE Athlete (
>> athleteId INTEGER GENERATED BY DEFAULT AS IDENTITY,
>> firstname VARCHAR(64),
>> lastname VARCHAR(64),
>> dateOfBirth DATE
>> );
>> CREATE INDEX athleteIdx ON Athlete (athleteId);
>> '''
>> }
>>
>> // *************** begin
>> reset() //create the table
>>
>> //insert 2 records
>> athleteSet = db.dataSet('Athlete')
>> athleteSet.add(
>> firstname: 'Paula',
>> lastname: 'Radcliffe',
>> dateOfBirth:'1973-12-17'
>> )
>> athleteSet.add(
>> firstname: 'Paul',
>> lastname: 'Tergat',
>> dateOfBirth:'1969-06-17'
>> )
>> athleteSet.each {println it.firstname }
>>
>> /*
>> --------------------------------------------------------------------------
>> Part 2
>> ======
>> Suppose this condition is only known at runtime:
>> "firstname == 'Paula' && lastname == 'Radcliffe'"
>>
>> and I intend to execute the following code-snippet:
>>
>> records = athleteSet.findAll{
>> it.firstname == 'Paula' && it.lastname == 'Radcliffe'
>> }
>> records.each{println "${it.firstname}, ${it.lastname},  
>> ${it.dateOfBirth}"}
>> -----------------------------------------------------------------------------
>> */
>>
>> def fields = ["firstname","lastname","dateOfBirth"]
>> //suppose this string results from an user-input
>> compstr = "firstname == 'Paula' && lastname == 'Radcliffe'"
>> //any fieldname is converted to "it.fieldname"
>> for (i in fields) {
>> compstr = compstr.replaceAll(i, "it." + i)
>> }
>> def form = "records = athleteSet.findAll{$compstr}" //#1
>> println "$form"
>> def binding = new Binding()
>> def shell = new GroovyShell(binding)
>> //make known the DataSet to the script
>> binding.athleteSet = athleteSet
>> shell.evaluate(form) //evaluate the script
>> def rec = binding.records
>> println "DataSet returned ? ${rec instanceof groovy.sql.DataSet}"
>> // rec.each{println "${it.firstname}, ${it.lastname},  
>> ${it.dateOfBirth}"}
>> rec.each{println it.firstname}
>>
>>
>> Can anybody help me ?
>>
>> regards wicki
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>



-- 
Es grüßt Siegfried Weigelt

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic