Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Raphael
histream
Commits
4e295426
Commit
4e295426
authored
Jul 24, 2015
by
rwm
Browse files
Potential resource leaks closed
parent
9be23954
Changes
7
Show whitespace changes
Inline
Side-by-side
HIStream-i2b2/src/main/java/de/sekmi/histream/i2b2/PostgresPatientStore.java
View file @
4e295426
...
...
@@ -141,9 +141,9 @@ public class PostgresPatientStore extends PostgresExtension<I2b2Patient> impleme
private
void
loadMaxPatientNum
()
throws
SQLException
{
Statement
s
=
db
.
createStatement
()
;
try
(
Statement
s
=
db
.
createStatement
()
){
String
sql
=
"SELECT MAX(patient_num) FROM patient_dimension"
;
try
(
ResultSet
rs
=
s
.
executeQuery
(
sql
)
){
ResultSet
rs
=
s
.
executeQuery
(
sql
)
;
if
(
rs
.
next
()
){
maxPatientNum
=
rs
.
getInt
(
1
);
}
else
{
...
...
@@ -151,6 +151,7 @@ public class PostgresPatientStore extends PostgresExtension<I2b2Patient> impleme
// start numbering patients with 1
maxPatientNum
=
1
;
}
rs
.
close
();
}
log
.
info
(
"MAX(patient_num) = "
+
maxPatientNum
);
}
...
...
HIStream-i2b2/src/main/java/de/sekmi/histream/i2b2/PostgresVisitStore.java
View file @
4e295426
...
...
@@ -113,9 +113,9 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
}
private
void
loadMaxEncounterNum
()
throws
SQLException
{
Statement
s
=
db
.
createStatement
()
;
try
(
Statement
s
=
db
.
createStatement
()
){
String
sql
=
"SELECT MAX(encounter_num) FROM visit_dimension"
;
try
(
ResultSet
rs
=
s
.
executeQuery
(
sql
)
){
ResultSet
rs
=
s
.
executeQuery
(
sql
)
;
if
(
rs
.
next
()
){
maxEncounterNum
=
rs
.
getInt
(
1
);
}
else
{
...
...
@@ -123,6 +123,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
// start numbering patients with 1
maxEncounterNum
=
1
;
}
rs
.
close
();
}
log
.
info
(
"MAX(encounter_num) = "
+
maxEncounterNum
);
}
...
...
@@ -143,6 +144,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
count
++;
}
}
stmt
.
close
();
log
.
info
(
"Loaded MAX(instance_num) for "
+
count
+
" encounters"
);
if
(
noMatch
!=
0
){
log
.
warning
(
"Encountered "
+
noMatch
+
" encounter_num in observation_fact without matching visits"
);
...
...
HIStream-i2b2/src/main/java/de/sekmi/histream/i2b2/ont/Import.java
View file @
4e295426
...
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.StringWriter
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
...
...
@@ -75,14 +76,17 @@ public class Import implements AutoCloseable{
deleteConcepts
.
setString
(
1
,
sourceId
);
count
=
deleteConcepts
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getConceptTable
());
deleteConcepts
.
close
();
deleteAccess
.
setString
(
1
,
sourceId
+
"%"
);
count
=
deleteAccess
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getAccessTable
());
deleteAccess
.
close
();
deleteOnt
.
setString
(
1
,
sourceId
);
count
=
deleteOnt
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getMetaTable
());
deleteOnt
.
close
();
}
...
...
@@ -409,7 +413,9 @@ public class Import implements AutoCloseable{
}
Properties
ont_props
=
new
Properties
();
ont_props
.
load
(
new
FileInputStream
(
ontConfig
));
try
(
InputStream
in
=
new
FileInputStream
(
ontConfig
)
){
ont_props
.
load
(
in
);
}
String
ontClass
=
ont_props
.
getProperty
(
"ontology.class"
);
if
(
ontClass
==
null
){
...
...
@@ -422,7 +428,10 @@ public class Import implements AutoCloseable{
// open database
props
=
new
Properties
();
props
.
load
(
new
FileInputStream
(
impConfig
));
try
(
InputStream
in
=
new
FileInputStream
(
impConfig
)
){
props
.
load
(
in
);
}
try
{
o
.
openDatabase
((
Map
)
props
);
}
catch
(
ClassNotFoundException
e
)
{
...
...
HIStream-i2b2/src/main/java/de/sekmi/histream/i2b2/services/HiveServer.java
View file @
4e295426
...
...
@@ -3,6 +3,7 @@ package de.sekmi.histream.i2b2.services;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.StringReader
;
import
java.nio.file.FileSystem
;
import
java.nio.file.FileSystems
;
...
...
@@ -54,21 +55,14 @@ public class HiveServer implements Provider<Source>{
//scriptEngine = scriptManager.getEngineByName("nashorn");
// load scripts
}
public
void
loadMainScript
(){
public
void
loadMainScript
()
throws
IOException
,
ScriptException
{
scriptEngine
=
scriptManager
.
getEngineByName
(
"nashorn"
);
try
{
scriptEngine
.
eval
(
new
FileReader
(
scriptDir
.
resolve
(
"main.js"
).
to
File
())
);
try
(
Reader
scriptFile
=
new
FileReader
(
scriptDir
.
resolve
(
"main.js"
).
toFile
())
)
{
scriptEngine
.
eval
(
script
File
);
Object
o
=
scriptEngine
.
eval
(
"typeof httpRequest === 'function'"
);
if
(
o
==
null
||
!(
o
instanceof
Boolean
)
||
((
Boolean
)
o
)
!=
true
){
throw
new
ScriptException
(
"global function 'httpRequest(?,?,?,?)' needed"
);
}
}
catch
(
ScriptException
e
)
{
e
.
printStackTrace
();
scriptEngine
=
null
;
}
catch
(
FileNotFoundException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
scriptEngine
=
null
;
}
}
...
...
@@ -83,7 +77,12 @@ public class HiveServer implements Provider<Source>{
break
;
}
System
.
out
.
println
(
"Reloading scripts.."
);
try
{
loadMainScript
();
}
catch
(
IOException
|
ScriptException
e1
)
{
System
.
err
.
println
(
"Error loading script"
);
e1
.
printStackTrace
();
}
// pollEvents() is needed for the key to reset properly
for
(
WatchEvent
<?>
e
:
key
.
pollEvents
()
){
if
(
e
==
null
)
continue
;
// noop
...
...
@@ -95,7 +94,9 @@ public class HiveServer implements Provider<Source>{
}
}
}
public
void
loadScipts
()
throws
IOException
{
@SuppressWarnings
(
"resource"
)
// cannot close default filesystem
public
void
loadScipts
()
throws
IOException
,
ScriptException
{
FileSystem
fs
=
FileSystems
.
getDefault
();
scriptDir
=
fs
.
getPath
(
"src"
,
"main"
,
"scripts"
,
"i2b2-ws"
);
if
(
!
Files
.
isDirectory
(
scriptDir
)
)
throw
new
FileNotFoundException
(
"Script dir not found: "
+
scriptDir
);
...
...
@@ -118,7 +119,7 @@ public class HiveServer implements Provider<Source>{
}
}*/
}
public
static
void
main
(
String
args
[])
throws
IOException
{
public
static
void
main
(
String
args
[])
throws
IOException
,
ScriptException
{
HiveServer
hs
=
new
HiveServer
();
hs
.
loadScipts
();
Endpoint
e
=
Endpoint
.
create
(
HTTPBinding
.
HTTP_BINDING
,
hs
);
...
...
histream-core/src/main/java/de/sekmi/histream/impl/RunConfiguration.java
View file @
4e295426
...
...
@@ -150,6 +150,7 @@ public class RunConfiguration implements Closeable{
if
(
inputStream
!=
null
){
Properties
props
=
new
Properties
();
props
.
load
(
inputStream
);
inputStream
.
close
();
version
=
props
.
getProperty
(
"version"
,
"[unknown]"
);
}
else
{
// file is not run from jar
...
...
@@ -200,6 +201,7 @@ public class RunConfiguration implements Closeable{
if
(
p
!=
null
){
System
.
out
.
println
(
"ETL("
+
p
.
getMeta
(
"etl.strategy"
)+
"): "
+
file
);
rc
.
processFile
(
p
);
p
.
close
();
}
else
{
System
.
err
.
println
(
"Unable to find parser for file "
+
file
);
}
...
...
histream-core/src/main/java/de/sekmi/histream/io/FlatProviderFactory.java
View file @
4e295426
...
...
@@ -40,6 +40,7 @@ public class FlatProviderFactory implements FileObservationSupplierFactory, Plug
// don't need to close anything
}
@SuppressWarnings
(
"resource"
)
@Override
public
ObservationSupplier
forFile
(
File
file
,
ObservationFactory
factory
)
throws
IOException
{
return
new
FlatObservationSupplier
(
factory
,
new
FileInputStream
(
file
));
...
...
histream-core/src/test/java/de/sekmi/histream/io/TransformerTest.java
View file @
4e295426
...
...
@@ -9,13 +9,14 @@ import org.junit.Test;
public
class
TransformerTest
{
@SuppressWarnings
(
"resource"
)
@Test
public
void
testPullTransformerIdentity
()
throws
FileNotFoundException
,
IOException
{
FileObservationProviderTest
f
=
new
FileObservationProviderTest
();
f
.
initializeObservationFactory
();
Transformation
t
=
Transformation
.
Identity
;
FlatObservationSupplier
sup
=
new
FlatObservationSupplier
(
f
.
getFactory
(),
new
FileInputStream
(
"examples/dwh-flat.txt"
))
;
try
(
FlatObservationSupplier
sup
=
new
FlatObservationSupplier
(
f
.
getFactory
(),
new
FileInputStream
(
"examples/dwh-flat.txt"
))
){
PullTransformer
p
=
new
PullTransformer
(
sup
,
t
);
// validate content after identity transformation
...
...
@@ -23,4 +24,5 @@ public class TransformerTest {
f
.
validateExample
(
p
);
f
.
closeHandler
();
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment