/ Published in: Groovy
Using Groovy you can extend the Sql, DataSet and GroovyResultSet objects present in the language to do simple object mapping similar to iBatis et al. An example of using the code below
/* POGO used in the mapping */
class BranchFax {
def faxCodeId, nsc, faxNumber, branchName, address1
}
/* Connect to the DB */
def db = Sql.newInstance(
"jdbc:oracle:thin:@//10.7.1.79/DATABSE",
"user1", "test1",
"oracle.jdbc.driver.OracleDriver"
)
/* create a dataset */
def bf = db.dataSet("BRANCH_FAX")
/* now work some magic */
def result01 = bf.firstRow().coerce(BranchFax)
def result02 = bf.firstRow().transmogrify(BranchFax)
def result03 = bf.transmogrify(BranchFax)
def result04 = db.transmogrify("SELECT * FROM BRANCH_FAX", BranchFax)
/* POGO used in the mapping */
class BranchFax {
def faxCodeId, nsc, faxNumber, branchName, address1
}
/* Connect to the DB */
def db = Sql.newInstance(
"jdbc:oracle:thin:@//10.7.1.79/DATABSE",
"user1", "test1",
"oracle.jdbc.driver.OracleDriver"
)
/* create a dataset */
def bf = db.dataSet("BRANCH_FAX")
/* now work some magic */
def result01 = bf.firstRow().coerce(BranchFax)
def result02 = bf.firstRow().transmogrify(BranchFax)
def result03 = bf.transmogrify(BranchFax)
def result04 = db.transmogrify("SELECT * FROM BRANCH_FAX", BranchFax)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
targetProps."${it.toLowerCase()}" = it }) resultant."$property" = delegate."$it" } } return resultant } delegate.coerce(clazz) } row.coerce(clazz) } } row.coerce(clazz) } }