groovy

Session Clustering a Grails app in Tomcat

Has any one done it yet? I am having class loader problems de-serializing the grails session object. Here is the error: WARN net.spy.memcached.transcoders.SerializingTranscoder: Caught CNFE decoding 1168 bytes of data [exec] java.lang.ClassNotFoundException: com.myapp.User [exec] at org.codehaus.groovy.tools.RootLoad...

how to debug a gsp page? (no grails, just gsp)

I've tried with netbeans and eclipse, with no luck... (coudn't try IntelliJ idea) I gave a quick look ant the code http://kickjava.com/src/groovy/servlet/TemplateServlet.java.htm and it gives me the impression that .gsp pages are translated to .groovy servlets (groovlets) in memory (I might be wrong)... so perhaps it's not so easy to...

what does final mean in Groovy

Hi, If you run the following code in the Groovy console it prints "8" class F { private final Integer val = 2 def set(v) {val = v} def print() {println val} } def f = new F() f.set(8) f.print() In Java this code wouldn't compile because you can't assign a final reference after the constructor has run. I know that for proper...

Create page result list in grails

Probably a stupid question, but I tried looking this up without much success. In a Grails app, I have a service with several methods that basically search for certain data using the Domain.createCriteria().list(...){...} construct. For one of those searches ("list all users") I now already have the data (part of a hasMany relationship)...

Using groovy AST Transform for modifying java

Would it be possible to use groovy ast transformations code to manipulate java classes? If yes, please give an example. If no, please specify why. ...

"Overloading" standard GORM CRUD methods

Wanna do the following: BootStrap { def init = {servletContext -> ........ MyDomainClass.metaClass.save = {-> delegate.extraSave() //////// how to call original save() here? } } ......... } P.S. MyDomainClass#extraSave is defined as public void extraSave(){.....} ...

Can Groovy be a client to JAX-RPC-style web service?

Apparently, Groovy easily consumes web services. Can it consume a web service that needs JAX-RPC instead of JAX-WS? Should I use an older version of Groovy or its libraries to do so? ...

Groovy FindAll statement for finding values that don't exist.

Hi. I am trying to construct a Groovy statement to find values that don't exist in a pre-populated list. I'm using SQL and think I want to do something like : myList = [a, b, c, d, e ... lots more data] sql.findAll("SELECT * FROM table WHERE code not in " + <myList>) I have a feeling this is very simple .. I'm just not sure how...

Loading and analyzing massive amounts of data

So for some research work, I need to analyze a ton of raw movement data (currently almost a gig of data, and growing) and spit out quantitative information and plots. I wrote most of it using Groovy (with JFreeChart for charting) and when performance became an issue, I rewrote the core parts in Java. The problem is that analysis and pl...

Using XmlSlurper: How to select sub-elements while iterating over a GPathResult

I am writing an HTML parser, which uses TagSoup to pass a well-formed structure to XMLSlurper. Here's the generalised code: def htmlText = """ <html> <body> <div id="divId" class="divclass"> <h2>Heading 2</h2> <ol> <li><h3><a class="box" href="#href1">href1 link text</a> <span>extra stuff</span></h3><address>Here is the address<span>Te...

How to mock abstract class with static members in Grails?

I need to mock a GrailsControllerClass interface. Instance should have a static variable defined. The problem is that MockFor and StubFor don’t give you an option for adding static members. So, I write my abstract class that extends GrailsControllerClass abstract class MyController implements GrailsControllerClass { static myDefiniti...

Found shared references to a collection org.hibernate.HibernateException

Hi, I got this error message : error: Found shared references to a collection: Person.relatedPersons when I tried to save addToRelatedPersons(anotherPerson) : person.addToRelatedPersons(anotherPerson); anotherPerson.addToRelatedPersons(person); anotherPerson.save(); person.save(); my domain : Person { static hasMany = [relatedPe...

How do I use PL/SQL to_date with a variable in Groovy?

I've got the following small Groovy script that just does a count of rows in the database for a specific date. import groovy.sql.Sql def today= new GregorianCalendar() def dateString = "${today.get(Calendar.MONTH)+1}/${today.get(Calendar.DAY_OF_MONTH)-1}/${today.get(Calendar.YEAR)}" def sql = Sql.newInstance("jdbc:oracle:thin:bc/bc@ne...

Using groovy metaClass to mock out Shiro SecurityUtils in bootstrap

For further background, see http://grails.markmail.org/message/62w2xpbgneapmhpd I'm trying to mock out the Shiro SecurityUtils.getSubject() method in my BootStrap.groovy. I decided on this approach because the Subject builder in the latest Shiro version isn't available in the current version of the Nimble plugin (which I'm using). I d...

groovy language bugs

Hi, In the Groovy console, the following code executes without error: class F { private def getFoo() {"foo"} private def barValue = "bar" } def f = new F() assert f.barValue == "bar" assert f.properties.containsKey("foo") This implies that: One can access private members of classes outside the class A class' properties are der...

Groovy String to int

I have a String that represents an integer value and would like to convert it to an int. Is there a groovy equivalent of Java's Integer.parseInt(String)? ...

Grails: String(username) as primary key, but save and get id string(username) with ignorecase?

I am using a string "username" as the primary-key of a table, But when saving and getting the column with the username id I want the case to be ignored so that new users can't try to impersonate another user. e.g. When registering a new user username = Daxon username = DaXoN //this should not be allowed When getting the unique user...

Snow Leopard + Grails 1.1.1 + Groovy 1.6.5

I have Grails 1.1.1 and Groovy 1.6.3 on Leopard. Will I have any issues with this combo: Snow Leopard + Grails 1.1.1 + Groovy 1.6.5? ...

Is functional Clojure or imperative Groovy more readable?

OK, no cheating now. No, really, take a minute or two and try this out. What does "positions" do? Edit: simplified according to cgrand's suggestion. (defn redux [[current next] flag] [(if flag current next) (inc next)]) (defn positions [coll] (map first (reductions redux [1 2] (map = coll (rest coll))))) Now, how about this vers...

Why doesn't .collect() work in the following GString?

This works as expected in a GSP-page: <td>${Foo.findAllByBar(bar)}</td> But when adding a collect statement the code breaks .. <td>${Foo.findAllByBar(bar).collect { it.name }}</td> with Error 500: Could not parse script [...gsp]: startup failed, ...: 129: expecting '}', found ')' @ line 129, column 196. 1 error`. I wa...