-
Notifications
You must be signed in to change notification settings - Fork 1
/
CalcgrpXmlExporter.scala
68 lines (59 loc) · 1.79 KB
/
CalcgrpXmlExporter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.citi.gta
import java.io.{InputStream, FileOutputStream}
import java.nio.ByteBuffer
import java.nio.channels.{ ReadableByteChannel, Channels, FileChannel }
import java.sql.DriverManager
import java.sql.{Statement, ResultSet, Clob}
import db._
import util.ResUtil._
object CalcgrpXmlExporter {
def save(filename: String, xml: Clob) {
var fos: FileOutputStream = null
var fc: FileChannel = null
var clob: ReadableByteChannel = null
try {
val name = filename.replace("/", "_")
fos = new FileOutputStream("./calcgrp_tadeva/" + name)
fc = fos.getChannel()
clob = Channels.newChannel(xml.getAsciiStream)
val buffer = ByteBuffer.allocateDirect(512)
while (clob.read(buffer) != -1) {
buffer.flip
fc.write(buffer)
buffer.clear
}
} finally {
if (clob != null) clob.close
if (fc != null) fc.close
if (fos != null) fos.close
}
}
def main(args: Array[String]) = {
var user1 = "workbrain"
var pass1 = "dev2004apac"
// val TADEVA = new OracleVendor("corpdb305d.nam.nsroot.net", 3757, "CEGTDVA1") {
// val user = user1
// val pass = pass1
// }
val TADEVA = new OracleVendor("gtadb1d.nam.nsroot.net", 18802, "TADEVA") {
val user = user1
val pass = pass1
}
val sql = """
select calcgrp_name, cgv_xml
from calc_group_version v, calc_group grp
where v.calcgrp_id = grp.calcgrp_id
and cgv_id not in(10492, 10493)
and calcgrp_name not like '%TEST%'
and cgv_xml is not null
"""
runQuery(TADEVA.getConnection, sql,
rs =>
while (rs.next) {
val name = rs.getString(1)
val xml = rs.getClob(2)
save(name + ".xml", xml)
}
)
}
}