Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. class Test {
  2.  
  3. private static final String PROJECT_INFO_FOR_USER ="select PROJECT_ID as PROJECT_NO, NAME as PROJECT_NAME from PROJECT_DIM where PROJECT_ID IN (?)"
  4.  
  5. private def getProjectList(def caseResult) {
  6. def projectList = ""
  7. caseResult.each { projno ->
  8. if (projectList.length() == 0) {
  9. projectList = "'${projno.project_no}',"
  10. } else {
  11. if (projectList.indexOf(projno.project_no) == -1)
  12. projectList+="'${projno.project_no}',"
  13. }
  14. }
  15. projectList = projectList.substring(0, projectList.length() - 1)
  16. return projectList
  17. }
  18.  
  19. private process() {
  20. def db = [url: "jdbc:oracle:thin:@x.xx.xx.xx:1521:ORCL",
  21. user: 'xxxx', password: 'xxxx', driver: 'oracle.jdbc.pool.OracleDataSource']
  22. def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
  23. println "DB connection ready"
  24.  
  25. def caseResult = [['project_no':'x-xxxx', 'case_nos':['12344'], 'updated_on':'1485335172'], ['project_no':'y-yyyy', 'case_nos':['56789'], 'updated_on':1490359241]]
  26. def projectList = "x-xxxx"
  27. def params = getProjectList(caseResult)
  28. def result = sql.rows(PROJECT_INFO_FOR_USER, params).collect { // If I replace params with projectList then <b>result</b> is assigned a row from oracle database
  29. it as Map
  30. }
  31. println result
  32. }
  33.  
  34. public static void main(String[] args) {
  35. Test t = new Test()
  36. t.process()
  37. }
  38. }
  39.  
  40. DB connection ready
  41. []
  42.  
  43. DB connection ready
  44. [[PROJECT_NO:x-xxxx, PROJECT_NAME:Xonions, Inc.]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement