Table of Contents

This is a DRAFT PAGE for an unreleased version of Groovy and is incomplete and subject to change

Groovy 1.8.1 release notes

The 1.8.1 release of Groovy is primarily a bug fix release but also comes with the new features outlined below.

Support for begin() / end() methods when processing files line by line with the groovy command

A feature found in other scripting languages like Perl or Awk is to be able to have a begin / end method when processing a file line by line. The groovy command supports this mode of operation, but didn't support the begin / end methods. (this feature is actually going to be available in 1.7.11 and 1.8.1, but time ran short for inclusion in the 1.8 final release)

More concretely, if you have a text file named dummy.txt, and you want to count the number of lines it contains, you could do this on the command-line:

groovy -a -ne 'def begin() { nb = 0 }; def end() { System.err.println nb }; nb++' dummy.txt

Sql batch support that allows PreparedStatements to be used as shown in these examples:

Shown for a batch size of 20:

def updateCounts = sql.withBatch(20, 'insert into TABLENAME(a, b, c) values (?, ?, ?)') { ps ->
    ps.addBatch(10, 12, 5)      // varargs style
    ps.addBatch([7, 3, 98])     // list
    ps.addBatch([22, 67, 11])
    ...
}

Named parameters (into maps or domain objects) are also supported:

def updateCounts = sql.withBatch(20, 'insert into TABLENAME(a, b, c) values (?.foo, :bar, :baz)') { ps ->
    ps.addBatch([foo:10, bar:12, baz:5])  // map
    ps.addBatch(foo:7, bar:3, baz:98)     // Groovy named args allow outer brackets to be dropped
    ...
}

Named ordinal parameters (into maps or domain objects) are also supported:

def updateCounts = sql.withBatch(20, 'insert into TABLENAME(a, b, c) values (?1.foo, ?2.bar, ?2.baz)') { ps ->
    ps.addBatch([[foo:22], [bar:67, baz:11]])  // list of maps or domain objects
    ps.addBatch([foo:10], [bar:12, baz:5])     // varargs allows outer brackets to be dropped
    ps.addBatch([foo:7], [bar:3, baz:98])
    ...
}
def updateCounts2 = sql.withBatch(5, 'insert into TABLENAME(a, b, c) values (?1, ?2.bar, ?2.baz)') { ps ->
    ps.addBatch(10, [bar:12, baz:5])
    ps.addBatch(7, [bar:3, baz:98])
    ...
}