Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. @Grapes([
  2. @Grab(group='postgresql', module='postgresql', version='9.0-801.jdbc4'),
  3. @Grab(group='com.ibm.icu', module='icu4j', version='56.1'),
  4. @GrabConfig(systemClassLoader=true, initContextClassLoader=true)
  5. ])
  6. import com.ibm.icu.text.Transliterator
  7.  
  8. //------------- script -----------------//
  9. println "-----start-----" + new Date()
  10.  
  11. def lineSeparator = System.properties['line.separator']
  12. def resultFile = new File("C:\\dev\\groovy\\updateLoginIdResult.sql")
  13.  
  14. def db = groovy.sql.Sql.newInstance(
  15. "jdbc:postgresql://localhost:5432/databaseName",
  16. "postgres",
  17. "postgres1",
  18. "org.postgresql.Driver"
  19. )
  20. def query =
  21. """
  22. select p.person_id as id, text.item_text as kana
  23. from person p
  24. inner join text
  25. on text.person_id = p.person_id and text.item_id = 103
  26. order by p.person_id;
  27. """
  28.  
  29. resultFile.text = ""
  30. db.eachRow(query){
  31. row ->
  32. latin = getLatin(row.kana)
  33. resultFile.append(getQuery(row.id, latin) + lineSeparator)
  34. }
  35.  
  36. println "-----finished-----" + new Date()
  37.  
  38. //--------------- functions -----------------//
  39. def String getQuery(userId, login){
  40. def query = "update user set login_id = \'%s\', update_timestamp = current_timestamp, update_function = 'FunctionName' where user_id = %s;"
  41. def f = new Formatter()
  42.  
  43. f.format(query, login, userId)
  44. }
  45.  
  46. def String getLatin(katakana){
  47. tmp = Transliterator.getInstance("Katakana-Latin").transliterate(katakana)
  48. //TODO キタノ シンノスケ->kitano shin'nosukeになるため'を抜いているが、icu4jの設定等で解決できるならそっちでやる
  49. tmp.replace(' ', '.').replace('\'', '')
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement