Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.reumann.examples
- import groovy.sql.Sql
- class PersistenceGroovy {
- def getSystems() {
- def sql = Sql.newInstance("jdbc:jtds:sybase://d1npp.nielsenmedia.com:2025;DatabaseName=NPP_GUI", "npp_user", "npp_user", "net.sourceforge.jtds.jdbc.Driver")
- def results = []
- sql.eachRow("SELECT nppSystemID, statusCodeID, nppSystemName, archiveDays, versionNumber, internalModeFlag FROM NPPSystem") {
- results.add( it.toRowResult() ) //or could do results << it.toRowResult()
- }
- //iterate
- results.each {
- print "nppSystemID: $it.nppSystemID"
- println " --- nppSystemName: $it.nppSystemName"
- }
- return results
- }
- def getSystems2() {
- def sql = Sql.newInstance("jdbc:jtds:sybase://d1npp.nielsenmedia.com:2025;DatabaseName=NPP_GUI", "npp_user", "npp_user", "net.sourceforge.jtds.jdbc.Driver")
- def results = []
- sql.eachRow("SELECT nppSystemID, statusCodeID, nppSystemName, archiveDays, versionNumber, internalModeFlag FROM NPPSystem") {
- //we can act like SystemNPP has a constuctor even though we didn't make one:
- results << new SystemNPP(nppSystemID: it.nppSystemID, statusCodeID: it.statusCodeID, nppSystemName: it.nppSystemName, archiveDays: it.archiveDays,
- versionNumber: it.versionNumber, internalModeFlag: it.internalModeFlag )
- }
- //iterate
- results.each {
- print "nppSystemID: $it.nppSystemID"
- println " --- nppSystemName: $it.nppSystemName"
- }
- return results
- }
- }
- /*
- * We can just use the rowResult as is, which is nice and easy when you just plan to access by the db field names directly.
- * However if we wanted to make an object we could as shown below, and note we don't need to create getters setters. Behind the
- * scenes groovy will make them and code that needs to call them will. Here is that example:
- *
- *
- */
- class SystemNPP {
- def nppSystemID
- def statusCodeID
- def nppSystemName
- def archiveDays
- def versionNumber
- def internalModeFlag
- }
Add Comment
Please, Sign In to add comment