I want to write an insert query in Grails. I have tried all possible combinations but cant get the syntax correct. Can anybody please help?
class Person {
int age
String name
}
i tried the following:
Person.executeUpdate("insert into Person values (20,"ABC")")
p.s.:Please do not mention using save()
...
Hi,
I have a request which I am changing using some groovy and property transfers. However after the test case has finished I would like to reset that request to its original code. I am guessing I do this using groovy but am not sure how.
The setup is as follows:
TestSuite1 has a property which is the request.
TestCase1 has a number...
As simple as this must be I still can't understand where am I wrong:
class A {
boolean equals(o) { true }
}
def s = [new A(), new A()] as Set
assert s.size() == 1 // Assertion failed: actually gives 2
Which method should I override in order to get uniqueness?
...
I've been starting to learn Groovy and am currently looking at the metaclass functionality. I have seen the examples of adding a new method, and removing all methods, but nothing about removing a single method. For example:
String.metaClass.foo = {delegate.toUpperCase()}
String.metaClass.bar = {delegate.toLowerCase()}
with the obvious...
I'm writing code where I retrieve XML from a web api, then parse that XML using Groovy. Unfortunately, it seems that both XmlParser and XmlSlurper for Groovy strip newline characters from the attributes of nodes when .text() is called.
How can I get at the text of the attribute including the newlines?
Sample code:
def xmltest = '''
...
Hello fellow Grails Developers!
I was wondering if you could help me with what must be a very common issue. I have come from a world of Java and eclipse where JavaDocs and APIs are at your fingertips. Grails has some great features and plugins but I find their inner workings completely undescoverable and that makes me sad.
Take for exa...
Groovy adds each() and a number of other methods to java.lang.Object. I can't figure out how to use the Groovy metaclass to dynamically replace the default each() on a Java class.
I can see how to add new methods:
MyJavaClass.metaClass.myNewMethod = { closure -> /* custom logic */ }
new MyJavaClass().myNewMethod { item -> println item ...
on Groovy 1.72, I can do this:
import org.codehaus.groovy.scriptom.*
however, i cannot do this:
import org.codehaus.groovy.scriptom.ActiveXObject
it says it cannot reslove class ActiveXObject class......
why?
...
Is there a way in Groovy to get the duration between two Date objects? The duration format I'm looking for would be something like: 2 days, 10 hours, 30 minutes...
Thanks
...
I'm doing a groovy/grails form file-upload operation, as is described here
http://www.grails.org/File+Upload
I'd like to get the name of the file that the user is uploading. Is there any way to do that? I've dumped out the params and request dictionaries and don't see them in there.
...
Hi everyone (my first post!),
I have an HQL question (in Groovy/Grails) I was hoping someone could help me with.
I have a simple Asset object with a one-to-many Tags collection.
class Asset {
Set tags
static hasMany = [tags:Tag]
}
class Tag {
String name
}
What I'm trying to do in HQL:
A user passes in some tags in params...
When I run my grails application using embedded jetty server(tomcat for grails 1.2), I can make changes to my controllers, services and other java files on-the-fly at runtime without restarting the application. How can I achieve the same functionality on my application deployed on Tomcat(or any server) for that matter. I have observed th...
I have a java project (not using groovy) but I'd like to interactively play with my java classes within groovysh. Is there an easy way to use the pom from my project to set the classpath of groovysh?
...
All of my tests for my Groovy code look like this
public void testButtons() {
try {
page.getButtons();
} catch (Exception e) {
throw org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e);
}
}
because I need to sanitize any possible StackTrace that appears (otherwise it's very hard to read since it'...
I have the following switch statement
switch (points) {
case 0: name = "new"; break;
case 1..14: badgeName = "bronze-coin"; break;
case 15..29: badgeName = "silver-coin"; break;
default: badgeName = "ruby";
}
I'd like the first case (case 0) to include points less than or equal to 0. How can I do th...
I want to execute a build.xml (Ant buildfile) from using GMaven (Maven Plugin for inline execution of Groovy in a POM). Since I have to execute the buildfile several times using the maven-antrun-plugin is not an option. The buildfile is evolving and taken from a partner project with little changes. That's why I don't want to put the logi...
I try to use more of the parameters but could not get it working with
<g:helpBalloon title="foo" content="bla" useEvent="['mouseover']" />
should result in
<script type="text/javascript"> new HelpBalloon({ title: 'foo', content: 'bla', useEvent: ['mouseover'] }); </script>
but useEvent="['mouseover']" seems not to be recognized?!
...
Hi,
Assume i have a book entity with an isbn field.
When entered a isbn number, i want 2 fields to be updated: title and author.
My controller looks like this:
def ajaxGetBook = {
def book = Book.findByIsbn(params.isbn)
if(book==null) book = new Book()
render book as JSON
}
So my call works, and i get a f...
Is this valid ?
def CallableStatement st
try {
...
st = sqlConn.prepareCall("call....")
...
}
what I'm really worried about is can you specify type and also use def at the same time?
...
I would like to parse this Gstring with groovy :
Format type : Key, Value.
def txt = """ <Lane_Attributes>
ID,1
FovCount,600
FovCounted,598
...
</Lane_Attributes> """
And get a map like :
Map = [ID:1, FovCount:600, FovCounted:598]
How can ...