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
Hide 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
...
@@ -141,9 +141,9 @@ public class PostgresPatientStore extends PostgresExtension<I2b2Patient> impleme
private
void
loadMaxPatientNum
()
throws
SQLException
{
private
void
loadMaxPatientNum
()
throws
SQLException
{
Statement
s
=
db
.
createStatement
()
;
try
(
Statement
s
=
db
.
createStatement
()
){
String
sql
=
"SELECT MAX(patient_num) FROM patient_dimension"
;
String
sql
=
"SELECT MAX(patient_num) FROM patient_dimension"
;
try
(
ResultSet
rs
=
s
.
executeQuery
(
sql
)
){
ResultSet
rs
=
s
.
executeQuery
(
sql
)
;
if
(
rs
.
next
()
){
if
(
rs
.
next
()
){
maxPatientNum
=
rs
.
getInt
(
1
);
maxPatientNum
=
rs
.
getInt
(
1
);
}
else
{
}
else
{
...
@@ -151,6 +151,7 @@ public class PostgresPatientStore extends PostgresExtension<I2b2Patient> impleme
...
@@ -151,6 +151,7 @@ public class PostgresPatientStore extends PostgresExtension<I2b2Patient> impleme
// start numbering patients with 1
// start numbering patients with 1
maxPatientNum
=
1
;
maxPatientNum
=
1
;
}
}
rs
.
close
();
}
}
log
.
info
(
"MAX(patient_num) = "
+
maxPatientNum
);
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>{
...
@@ -113,9 +113,9 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
}
}
private
void
loadMaxEncounterNum
()
throws
SQLException
{
private
void
loadMaxEncounterNum
()
throws
SQLException
{
Statement
s
=
db
.
createStatement
()
;
try
(
Statement
s
=
db
.
createStatement
()
){
String
sql
=
"SELECT MAX(encounter_num) FROM visit_dimension"
;
String
sql
=
"SELECT MAX(encounter_num) FROM visit_dimension"
;
try
(
ResultSet
rs
=
s
.
executeQuery
(
sql
)
){
ResultSet
rs
=
s
.
executeQuery
(
sql
)
;
if
(
rs
.
next
()
){
if
(
rs
.
next
()
){
maxEncounterNum
=
rs
.
getInt
(
1
);
maxEncounterNum
=
rs
.
getInt
(
1
);
}
else
{
}
else
{
...
@@ -123,6 +123,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
...
@@ -123,6 +123,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
// start numbering patients with 1
// start numbering patients with 1
maxEncounterNum
=
1
;
maxEncounterNum
=
1
;
}
}
rs
.
close
();
}
}
log
.
info
(
"MAX(encounter_num) = "
+
maxEncounterNum
);
log
.
info
(
"MAX(encounter_num) = "
+
maxEncounterNum
);
}
}
...
@@ -143,6 +144,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
...
@@ -143,6 +144,7 @@ public class PostgresVisitStore extends PostgresExtension<I2b2Visit>{
count
++;
count
++;
}
}
}
}
stmt
.
close
();
log
.
info
(
"Loaded MAX(instance_num) for "
+
count
+
" encounters"
);
log
.
info
(
"Loaded MAX(instance_num) for "
+
count
+
" encounters"
);
if
(
noMatch
!=
0
){
if
(
noMatch
!=
0
){
log
.
warning
(
"Encountered "
+
noMatch
+
" encounter_num in observation_fact without matching visits"
);
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;
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
...
@@ -75,14 +76,17 @@ public class Import implements AutoCloseable{
...
@@ -75,14 +76,17 @@ public class Import implements AutoCloseable{
deleteConcepts
.
setString
(
1
,
sourceId
);
deleteConcepts
.
setString
(
1
,
sourceId
);
count
=
deleteConcepts
.
executeUpdate
();
count
=
deleteConcepts
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getConceptTable
());
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getConceptTable
());
deleteConcepts
.
close
();
deleteAccess
.
setString
(
1
,
sourceId
+
"%"
);
deleteAccess
.
setString
(
1
,
sourceId
+
"%"
);
count
=
deleteAccess
.
executeUpdate
();
count
=
deleteAccess
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getAccessTable
());
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getAccessTable
());
deleteAccess
.
close
();
deleteOnt
.
setString
(
1
,
sourceId
);
deleteOnt
.
setString
(
1
,
sourceId
);
count
=
deleteOnt
.
executeUpdate
();
count
=
deleteOnt
.
executeUpdate
();
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getMetaTable
());
System
.
out
.
println
(
"Deleted "
+
count
+
" rows from "
+
getMetaTable
());
deleteOnt
.
close
();
}
}
...
@@ -409,7 +413,9 @@ public class Import implements AutoCloseable{
...
@@ -409,7 +413,9 @@ public class Import implements AutoCloseable{
}
}
Properties
ont_props
=
new
Properties
();
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"
);
String
ontClass
=
ont_props
.
getProperty
(
"ontology.class"
);
if
(
ontClass
==
null
){
if
(
ontClass
==
null
){
...
@@ -422,7 +428,10 @@ public class Import implements AutoCloseable{
...
@@ -422,7 +428,10 @@ public class Import implements AutoCloseable{
// open database
// open database
props
=
new
Properties
();
props
=
new
Properties
();
props
.
load
(
new
FileInputStream
(
impConfig
));
try
(
InputStream
in
=
new
FileInputStream
(
impConfig
)
){
props
.
load
(
in
);
}
try
{
try
{
o
.
openDatabase
((
Map
)
props
);
o
.
openDatabase
((
Map
)
props
);
}
catch
(
ClassNotFoundException
e
)
{
}
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;
...
@@ -3,6 +3,7 @@ package de.sekmi.histream.i2b2.services;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.Reader
;
import
java.io.StringReader
;
import
java.io.StringReader
;
import
java.nio.file.FileSystem
;
import
java.nio.file.FileSystem
;
import
java.nio.file.FileSystems
;
import
java.nio.file.FileSystems
;
...
@@ -54,21 +55,14 @@ public class HiveServer implements Provider<Source>{
...
@@ -54,21 +55,14 @@ public class HiveServer implements Provider<Source>{
//scriptEngine = scriptManager.getEngineByName("nashorn");
//scriptEngine = scriptManager.getEngineByName("nashorn");
// load scripts
// load scripts
}
}
public
void
loadMainScript
(){
public
void
loadMainScript
()
throws
IOException
,
ScriptException
{
scriptEngine
=
scriptManager
.
getEngineByName
(
"nashorn"
);
scriptEngine
=
scriptManager
.
getEngineByName
(
"nashorn"
);
try
{
try
(
Reader
scriptFile
=
new
FileReader
(
scriptDir
.
resolve
(
"main.js"
).
toFile
())
)
{
scriptEngine
.
eval
(
new
FileReader
(
scriptDir
.
resolve
(
"main.js"
).
to
File
())
);
scriptEngine
.
eval
(
script
File
);
Object
o
=
scriptEngine
.
eval
(
"typeof httpRequest === 'function'"
);
Object
o
=
scriptEngine
.
eval
(
"typeof httpRequest === 'function'"
);
if
(
o
==
null
||
!(
o
instanceof
Boolean
)
||
((
Boolean
)
o
)
!=
true
){
if
(
o
==
null
||
!(
o
instanceof
Boolean
)
||
((
Boolean
)
o
)
!=
true
){
throw
new
ScriptException
(
"global function 'httpRequest(?,?,?,?)' needed"
);
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>{
...
@@ -83,7 +77,12 @@ public class HiveServer implements Provider<Source>{
break
;
break
;
}
}
System
.
out
.
println
(
"Reloading scripts.."
);
System
.
out
.
println
(
"Reloading scripts.."
);
loadMainScript
();
try
{
loadMainScript
();
}
catch
(
IOException
|
ScriptException
e1
)
{
System
.
err
.
println
(
"Error loading script"
);
e1
.
printStackTrace
();
}
// pollEvents() is needed for the key to reset properly
// pollEvents() is needed for the key to reset properly
for
(
WatchEvent
<?>
e
:
key
.
pollEvents
()
){
for
(
WatchEvent
<?>
e
:
key
.
pollEvents
()
){
if
(
e
==
null
)
continue
;
// noop
if
(
e
==
null
)
continue
;
// noop
...
@@ -95,7 +94,9 @@ public class HiveServer implements Provider<Source>{
...
@@ -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
();
FileSystem
fs
=
FileSystems
.
getDefault
();
scriptDir
=
fs
.
getPath
(
"src"
,
"main"
,
"scripts"
,
"i2b2-ws"
);
scriptDir
=
fs
.
getPath
(
"src"
,
"main"
,
"scripts"
,
"i2b2-ws"
);
if
(
!
Files
.
isDirectory
(
scriptDir
)
)
throw
new
FileNotFoundException
(
"Script dir not found: "
+
scriptDir
);
if
(
!
Files
.
isDirectory
(
scriptDir
)
)
throw
new
FileNotFoundException
(
"Script dir not found: "
+
scriptDir
);
...
@@ -118,7 +119,7 @@ public class HiveServer implements Provider<Source>{
...
@@ -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
();
HiveServer
hs
=
new
HiveServer
();
hs
.
loadScipts
();
hs
.
loadScipts
();
Endpoint
e
=
Endpoint
.
create
(
HTTPBinding
.
HTTP_BINDING
,
hs
);
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{
...
@@ -150,6 +150,7 @@ public class RunConfiguration implements Closeable{
if
(
inputStream
!=
null
){
if
(
inputStream
!=
null
){
Properties
props
=
new
Properties
();
Properties
props
=
new
Properties
();
props
.
load
(
inputStream
);
props
.
load
(
inputStream
);
inputStream
.
close
();
version
=
props
.
getProperty
(
"version"
,
"[unknown]"
);
version
=
props
.
getProperty
(
"version"
,
"[unknown]"
);
}
else
{
}
else
{
// file is not run from jar
// file is not run from jar
...
@@ -200,6 +201,7 @@ public class RunConfiguration implements Closeable{
...
@@ -200,6 +201,7 @@ public class RunConfiguration implements Closeable{
if
(
p
!=
null
){
if
(
p
!=
null
){
System
.
out
.
println
(
"ETL("
+
p
.
getMeta
(
"etl.strategy"
)+
"): "
+
file
);
System
.
out
.
println
(
"ETL("
+
p
.
getMeta
(
"etl.strategy"
)+
"): "
+
file
);
rc
.
processFile
(
p
);
rc
.
processFile
(
p
);
p
.
close
();
}
else
{
}
else
{
System
.
err
.
println
(
"Unable to find parser for file "
+
file
);
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
...
@@ -40,6 +40,7 @@ public class FlatProviderFactory implements FileObservationSupplierFactory, Plug
// don't need to close anything
// don't need to close anything
}
}
@SuppressWarnings
(
"resource"
)
@Override
@Override
public
ObservationSupplier
forFile
(
File
file
,
ObservationFactory
factory
)
throws
IOException
{
public
ObservationSupplier
forFile
(
File
file
,
ObservationFactory
factory
)
throws
IOException
{
return
new
FlatObservationSupplier
(
factory
,
new
FileInputStream
(
file
));
return
new
FlatObservationSupplier
(
factory
,
new
FileInputStream
(
file
));
...
...
histream-core/src/test/java/de/sekmi/histream/io/TransformerTest.java
View file @
4e295426
...
@@ -9,18 +9,20 @@ import org.junit.Test;
...
@@ -9,18 +9,20 @@ import org.junit.Test;
public
class
TransformerTest
{
public
class
TransformerTest
{
@SuppressWarnings
(
"resource"
)
@Test
@Test
public
void
testPullTransformerIdentity
()
throws
FileNotFoundException
,
IOException
{
public
void
testPullTransformerIdentity
()
throws
FileNotFoundException
,
IOException
{
FileObservationProviderTest
f
=
new
FileObservationProviderTest
();
FileObservationProviderTest
f
=
new
FileObservationProviderTest
();
f
.
initializeObservationFactory
();
f
.
initializeObservationFactory
();
Transformation
t
=
Transformation
.
Identity
;
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
);
PullTransformer
p
=
new
PullTransformer
(
sup
,
t
);
// validate content after identity transformation
// validate content after identity transformation
f
.
initializeHandler
();
f
.
initializeHandler
();
f
.
validateExample
(
p
);
f
.
validateExample
(
p
);
f
.
closeHandler
();
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