Skip to content

Instantly share code, notes, and snippets.

@LCHCAPITALHUMAIN
Forked from kdabir/gstorm_getter.groovy
Created January 27, 2016 10:46
Show Gist options
  • Save LCHCAPITALHUMAIN/a7b344057f7f5b87ef1f to your computer and use it in GitHub Desktop.
Save LCHCAPITALHUMAIN/a7b344057f7f5b87ef1f to your computer and use it in GitHub Desktop.
example of effect of getter in gstorm
@GrabResolver(name='gstorm', root='http://dl.bintray.com/kdabir/maven')
@Grab('io.github.kdabir.gstorm:gstorm:0.7')
@GrabConfig(systemClassLoader = true)
@Grab('org.hsqldb:hsqldb:2.3.2')
import groovy.sql.*
import gstorm.*
// using sql object explicitly to create Gstorm instance, this can be any other jdbc driver
def sql = Sql.newInstance("jdbc:hsqldb:mem:database1", "sa", "", "org.hsqldb.jdbcDriver")
@Table("Employees") // if have a different table name
class Employee {
@Id Integer empId // annotate Id if you dont want want implicit id
String name
String department
String getName(){
this.name.toUpperCase()
}
}
new Gstorm(sql).stormify(Employee)
new Employee(name: "John Doe", department: "Accounts").save()
new Employee(name: "Donald Duck", department: "Marketing").save()
new Employee(name: "Alfred Hitchcock", department: "Marketing").save()
Employee.where("department = 'Marketing'").each { // pass any standard SQL where clause
println "${it.name} is in Marketing"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment