admin
This user hasn't shared any biographical information
Posts by admin
Groovy Goodness: Run Remote Scripts via URL
Oct 18th
Since Groovy 1.8.3 we can run remote Groovy scripts. We can use an URL to refer to the Groovy script that we want to execute. This can be very useful to build a library of Groovy scripts and publish them on a web server or a code repository like Github. Then we can run those scripts by referring the scripts by URL.
Groovy Goodness: Run Remote Scripts via URL
Oct 18th
Since Groovy 1.8.3 we can run remote Groovy scripts. We can use an URL to refer to the Groovy script that we want to execute. This can be very useful to build a library of Groovy scripts and publish them on a web server or a code repository like Github. Then we can run those scripts by referring the scripts by URL.
Groovy Goodness: Use inject Method on a Map
Sep 27th
The inject() method is since Groovy 1.8.1 also available for Map objects. The closure arguments accepts two or three arguments. With the three-argument variant we get the key and value separately as arguments. Otherwise we get a map entry as closure argument.
Groovy Goodness: Access ResultSetMetaData with Groovy SQL
Sep 26th
Groovy’s SQL support allows us to access ResultSetMetaData with a closure when we use the query methods rows() and eachRow(). We can pass a closure as the last argument of these methods. The closure parameter is the ResultSetMetaData object. The closure is only invoked once after the query is executed.
Groovy Goodness: Using Named (Ordinal) Parameters with Groovy SQL
Sep 23rd
Groovy has great SQL support built-in. With just a few lines of code we can access a database and write SQL statements and execute them. To query data we can for example use the rows() method. We pass a SQL query and we get a List of GroovyResultSet objects back. But we can also use other methods like query() or eachRow().
Groovy Goodness: Use Connection Parameters to Get Text From URL
Sep 22nd
For a long time we can simply get the text from an URL in Groovy. Since Groovy 1.8.1 we can set parameters to the underlying URLConnection that is used to get the content. The parameters are passed as a Map to the getText() method or to the newReader() or newInputStream() methods for an URL.
Groovy Goodness: Streaming JSON with StreamingJsonBuilder
Sep 21st
Since Groovy 1.8 we can use JSONBuilder to create JSON data structures. With Groovy 1.8.1 we have a variant of JsonBuilder that will not create a data structure in memory, but will stream directly to a writer the JSON structure: StreamingJsonBuilder. This is useful in situations where we don’t have to change the structure and need a memory efficient way to write JSON.
Groovy Goodness: Transform Items into a Collection with collectMany
Sep 20th
In Groovy we can use the collectMany() method to transform items from a collection into a collection. The resulting collection is then flattened into a single collection. This means we can use the closure to return a collection with values and at the end all these collections are flattened into a single collection.
Groovy Goodness: Collect on Nested Collections
Sep 19th
The collect() method has been around in Groovy for a long time and it is very useful. With the collect() method we can iterate through a collection and transform each element with a Closure to another value. To apply a transformation to collections in collections we can use the collectAll() method. Since Groovy 1.8.1 the collectAll() method is deprecated in favor of the new collectNested() method. So with collectNested() we can transform elements in a collection and even in nested collections and the result will be a collection (with nested collections) with transformed elements.
We can pass an initial collection to the method to which the transformed elements are added.
Groovy Goodness: GroupBy with Multiple Closures
Sep 16th
We can group elements in a List or Map with the groupBy() method for a long time in Groovy. We pass a closure with the grouping condition to get a Map with the items grouped. And since Groovy 1.8.1 we can use more than closure to do the grouping. We can use it for both List and Map objects.