groovy

connecting groovy to sql server

I am trying to connect a simple groovy script to the DB. Code: import groovy.sql.Sql class GroovySqlExample2{ static void main(String[] args) { def sql = Sql.newInstance("jdbc:sqlserver://MYSERVERIP", "uname", "pwd", "net.sourceforge.jtds.jdbc.Driver") sql.eachRow("select * from word"){ println it.spelling +...

Groovy 1.5.x / Grails 1.0.x If-Else statement bug

I have this code in a Grails 1.0.4 Groovy console: def devices = Device.getAll() def found = devices.findAll { if(it?.localNumber && it?.areaCode){ def pattern = ~".*${it.areaCode + it.localNumber}" def matches = "$msisdn" ==~ pattern println "$matches == msisdn: $msisdn ==~ pattern: $pattern" matche...

How to match whole word that is preceded by a tab?

I am trying to get the first word in the line that matches the whole word 'number'. But I am only interested where whole word 'number' is matched and is preceded by a tab. For example if following is the text: tin identification number 4/10/2007 LB num number 9/27/2006 PAT I want to get back num Regex I have is: match whole word...

Groovy vs Scala [vs JRuby vs Closure vs Jython]

I'm planning to broaden my perspectives in JVM platform, and I've got a dilemma: what should I learn first? Could you please explain, what are the advantages of Groovy, Scala and other languages for JVM? Thanks. ...

unable to connect groovy to oracle

I have placed the ojdbc14.jar in the lib folder and am using the code below to connect to oracle: import java.sql.Connection import java.sql.DriverManager import javax.sql.DataSource import groovy.sql.Sql import oracle.jdbc.driver.OracleTypes driver = oracle.jdbc.driver.OracleDriver Connection conn = DriverManager.getConnection( '...

Encoding problem undr Groovy

Hi! I am developing an application which should work under different languages (german, spanish, etc). The application uses an Oracle DB. I have CRUD business processes and I have the standard views (create, edit, show, list). No problems for creating, showing and listing any record containing special chars like ä,ö,ü, etc. But when I e...

Groovy: generate equals and hashCode methods

Hi, If I have a simple Groovy class such as class Address { Integer streetNumber String streetName String state String zip Country country } Although I could write (or use an IDE to generate) hashCode and equals methods like: boolean equals(o) { if (this.is(o)) return true; if (!o || getClass() != o.class) re...

cache key generation

Hi, I'm using ehcache (via the Grails plugin). The method that adds objects to the cache requires the keys to be serializable, so a typical usage would be: def key = 22 def someObject = new Object(); cacheService.cache(key, true, someObject) (The boolean param indicates whether the object should be added to a distributed or local cac...

Groovy Eclipse Plugin Organize Imports

I've been using the newest version of the groovy eclipse plugin (for eclipse 3.4) and I noticed that when I run organize imports on the file, it actually removes some of the imports that I need. It seems to remove the ones in my project, not java.* imports. Any ideas why? thanks, Jeff ...

Inject log object in Grails class outside of grails-app

I have a class in src/groovy in my grails project. How do i make a log field that gets injected with the correct logger for that class ? Is there a commons logging or just log4j in grails ? ...

Where are the source files of Groovy's collection extensions located?

I am looking for how the methods like ArrayList#sort(Closure) are implemented in Groovy. I've downloaded Groovy's source in a zip (http://groovy.codehaus.org/Building+Groovy+from+Source), but I can't find any file containing the source of extension methods to ArrayList. Does anyone know where these Groovy extensions for Java's collecti...

Why does Ruby Builder's XmlMarkup use different syntax to groovys' NodeBuilder

Groovys' NodeBuilder uses def someBuilder = new NodeBuilder() someBuilder.people(kind:'folks', groovy:true) { person(x:123, name:'James', cheese:'edam') { project(name:'groovy') project(name:'geronimo') } person(x:234, name:'bob', cheese:'cheddar') { project(name:'groovy') project(name:'drools') } } whereas ...

How do hasMany and hasOne work in Grails?

Hi, I am having problems defining one-to-one and one-to-many relationships with domain classes. I have the following domain classes class Team { static hasMany = [players: Player] static hasOne = [coach: Coach] } class Person { String name } class Player extends Person { } class Coach extends Person { } So my question...

Eager fetching of an object

I am Serializing an object which has a deep hierarchy of objects. After deserialization, i am able to access only those fields which were available in object before serialization. For rest, i get LazyInitializationException. class A { List<B> objs } class B { C c } class C { D d } Initially, i used to get LazyInitiali...

What are Groovy/Grails/Hibernate/JBoss/Jade in very simple terms?

I am new to Java. Its only been six months but I do understand Java. While reading about it sometimes, I come across these terms - Groovy, Grails, Hibernate, JBoss, Jade and many more. I know I can read all about them individually. But can somebody give me a treetop view of what is happening here? What is all this? We have Java and th...

How can I return a 404/50x status code from a Grails Controller?

I have a controller that needs to return a 404 page and status code on certain conditions. I can't seem to find out how to do this in Grails. A coworker recommended this method: response.sendError(HttpServletResponse.SC_NOT_FOUND) which works perfectly fine, but it's not very Grails-like. I know Rails' render method take a status argu...

Prevent System.exit in a Groovy web console without security policy file

We have an admin debug console in our app that lets you enter a script and submit it to get the result back. We're not worried about malicious users, but would like to prevent basic stuff like someone entering System.exit(1) just to see what it does. Unfortunately, adding a security policy file isn't an option. Is there any other way to...

relative path to a groovy application

Hi I am developing an application -called smtool- using Groovy and Grails. This application must be integrated to a portal. The portal have the restriction that every link must be relative. No absolute paths are allowed neither for links nor for images, js files, css files, etc. My application has a menu with many links pointing to di...

Anonymous inner class in groovy

I am looking into the groovy-wicket integration and lack of anonymous inner classes seems to be a problem when writing the event handlers. Is there a groovier way of writing this code import org.apache.wicket.PageParameters import org.apache.wicket.markup.html.basic.Label import org.apache.wicket.markup.html.link.Link import org.apache....

Grails: Supplying Data to a Global UI Element

Please pardon this newbie question... In Grails, if I want a partial to be embedded in a layout so that it appears globally, which requires live data, let's say a list of categories, where is the best place to pull the category data to feed it into the view? I realize this is a very basic question, but I haven't seen this covered in a...