groovy

How do you get the path the running script in groovy?

I'm writing a groovy script that I want to be controlled via a properties file stored in the same folder. However, I want to be able to call this script from anywhere. When I run the script it always looks for the properties file based on where it is run from, not where the script is. How can I access the path of the script file from ...

Best Scala imitation of Groovy's safe-dereference operator (?.)?

I would like to know what the best Scala imitation of Groovy's safe-dereference operator (?.), or at least some close alternatives are? I've discussed it breifly on Daniel Spiewak's blog, but would like to open it up to StackOverFlow... For the sake of everyone's time, here is Daniel's initial response, my counter, and his 2nd response...

how to define if domain has more than one unique field in grails?

Hi, I have domain that has more than one unique fields like the following class Shoes{ String name; Brand brand ; Color color ; Supplier supplier ; Integer size ; BigDecimal price; } name, brand, color and supplier need to be unique ... so if there are product with same name brand color and supplier it would retu...

Issue with multiple hasMany relationships to the same domain class when using composite id

I am getting this exception: org.hibernate.MappingException: collection foreign key mapping has wrong number of columns: Room.cellsOrig type: component[locationX,locationY] class Room implements Serializable { Integer locationX; Integer locationY; List cellsOrig = [] List cells = [] static hasMany = [cellsOrig: Cell...

What's the best way to build a queue for long-running jobs in a Grails app?

I have a Grails app that has some computationally intensive optimizations with a running time of ~5 minutes (perhaps more). Currently, I'm doing these in the main request thread, i.e. it takes 5 minutes for the request to return. It works, but is of course horrible from a usability perspective. So what's the best way to implement this i...

Can i use Hibernate ORM framework without any restriction in Groovy and/or JRuby ?

Hi, I like Groovy/JRuby simplicity. But in order to use it, i would like to know whether Hibernate ORM framework works same way as in Java language ? Is there some limitation or restriction ? regards, ...

groovy zipping a directory with files in use

I am trying to zip an entire directory in a groovy program. I have used the built in ant target to zip the directory and normally this works, except that sometimes 2-3 files are in use which I don't care about but the zip code actually aborts because of that - any ideas on how to fix this? Thanks! Code: def ant = new AntBuilder() an...

Can I use grails tag outside of GSP

For example, i can put <g:createLink controller="user" action="show" /> inside a .gsp file and it will work nicely. But also I'd like to use the same closure createLink inside a .groovy file which is not part of the grails views ...

Is there a way to have callable objects in Groovy?

If for example I have a class named A. Can I make an object be callable, just like Python does? For example : def myObject = new A() myObject() and that would call some object method. Can it be done? ...

Groovy map syntax error

If I have this code : import javax.swing.* import java.awt.image.* def xMap = [ BufferedImage.TYPE_3BYTE_BGR : "3 byte BGR", BufferedImage.TYPE_4BYTE_ABGR : "4 byte ABGR", ] the IDE will generate this error : illegal colon after argument expression; solution: a complex label expression before a colon must be paren...

Grails + sqlite

Is there any way to use SQLite as a database storage for my Grails app? If I use a SQLite JDBC driver (http://www.zentus.com/sqlitejdbc/), my app fails to start with "Could not determine Hibernate dialect for database name [SQLite]" The only workaround I found was http://d.hatena.ne.jp/torutk/20090711/p3 (it's in Japanese, have it goog...

Debugging Ruby/Python/Groovy

I'm rephrasing this question because it was either too uninteresting or too incomprehensible. :) The original question came about because I'm making the transation from Java to Groovy, but the example could apply equally when transitioning to any of the higher-level languages (Ruby, Python, Groovy). Java is easy to debug because there ...

alternated default sort in GRAILS

Hi, why the following Groovy snippet returns alternating [Account: 2222 and 2222, Account: 1111 and 1111] or [Account: 1111 and 1111, Account: 2222 and 2222] if you run it multiple times within the Groovy Console ? I thought the sort statement leads to an ALWAYS descending sort order of the list ??? class Account { long number ...

XWiki insert text into a page

Does anyone know the best way to insert some text into an XWiki document preferably using Groovy (though Velocity will work, too)? The API documentation is rather, erm, terse and uninformative in places such as this. ...

What are the Grails bugs that developers have to work around?

In some of the articles I've read, and some of the podcasts I've heard, people have been saying they need to work around a number of bugs existing in Grails. As a beginner Grails developer, how will I know what those bugs are ( so that I wouldn't have to waste time researching them )? Are they listed somewhere? ...

GRAILS: Find all children in a self-referenced one-to-many relationship

In grails, How would one find all the children in a one-to-many relationship e.g., class Employee { static hasMany = [ subordinates: Employee ] static belongsTo = [ manager: Employee ] } Using a single manager, how would one get the subordinates of all subordinates (like traversing a object graph)? ...

How can I add a field dynamically to a Java class using Groovy?

In Ruby I can add instance variables to a class by opening it, and doing something like this : class Whatever def add_x @x = 20 end end and this would add me an instance variable by the name of x. How can I do the same thing in Groovy? ...

I can't get the grails controller "render" method to work with an explicit template

I'm just getting started with grails, and I'm having an issue. I have a "controller" and "view" for the projects home page (there's no model for the home page) I called the view "index.gsp", and put it in a directory views/home However, no matter what I do, grails is trying to read the page "home.gsp" (and then home.jsp), despite me h...

How can I intercept execution of all the methods in a Java application using Groovy?

Is it possible to intercept all the methods called in a application? I'd like to do something with them, and then let them execute. I tried to override this behaviour in Object.metaClass.invokeMethod, but it doesn't seem to work. Is this doable? ...

Two charset tags on a page, which to take?

I'm working on crawling pages for information, and have run into many problems with parsing the pages in Groovy. I've made semi-solution that works most of the time using juniversal chardet and just scanning the page for tag in the head, but sometimes two of these tags are found on one page, for example: <meta http-equiv="Content-Ty...