Skip to content

Commit 52d75a5

Browse files
committed
fix
1 parent f0208ed commit 52d75a5

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/main/java/org/ohdsi/webapi/trexsql/TrexSQLInstanceManager.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ private Map<String, Object> buildConfig() {
8585

8686
@PreDestroy
8787
public void shutdown() {
88-
if (trexsqlDb != null) {
89-
log.info("Shutting down TrexSQL instance");
90-
try {
91-
Trexsql.shutdown(trexsqlDb);
92-
log.info("TrexSQL instance shut down successfully");
93-
} catch (Exception e) {
94-
log.error("Error shutting down TrexSQL instance: {}", e.getMessage(), e);
95-
} finally {
96-
trexsqlDb = null;
88+
initLock.lock();
89+
try {
90+
if (trexsqlDb != null) {
91+
log.info("Shutting down TrexSQL instance");
92+
try {
93+
Trexsql.shutdown(trexsqlDb);
94+
log.info("TrexSQL instance shut down successfully");
95+
} catch (Exception e) {
96+
log.error("Error shutting down TrexSQL instance: {}", e.getMessage(), e);
97+
} finally {
98+
trexsqlDb = null;
99+
}
97100
}
101+
} finally {
102+
initLock.unlock();
98103
}
99104
}
100105
}

src/main/java/org/ohdsi/webapi/trexsql/TrexSQLService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
77
import org.springframework.stereotype.Service;
88

9-
import java.io.File;
9+
import java.nio.file.Paths;
1010
import java.util.HashMap;
1111
import java.util.List;
1212
import java.util.Map;
@@ -37,8 +37,12 @@ public boolean isCacheAvailable(String sourceKey) {
3737
if (sourceConfig == null) {
3838
return false;
3939
}
40-
String cachePath = config.getCachePath() + "/" + sourceConfig.getDatabaseCode() + ".db";
41-
return new File(cachePath).exists();
40+
String databaseCode = sourceConfig.getDatabaseCode();
41+
if (databaseCode == null || databaseCode.isEmpty()) {
42+
return false;
43+
}
44+
return Paths.get(config.getCachePath(), databaseCode + ".db")
45+
.toFile().exists();
4246
}
4347

4448
@SuppressWarnings("unchecked")
@@ -51,6 +55,9 @@ public List<Map<String, Object>> searchVocab(String sourceKey, String searchTerm
5155
}
5256

5357
String databaseCode = sourceConfig.getDatabaseCode();
58+
if (databaseCode == null || databaseCode.isEmpty()) {
59+
throw new IllegalStateException("TrexSQL database code not configured for source: " + sourceKey);
60+
}
5461

5562
Map<String, Object> options = new HashMap<>();
5663
options.put("database-code", databaseCode);

src/main/java/org/ohdsi/webapi/trexsql/TrexSQLSourceConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.ohdsi.webapi.trexsql;
22

33
/**
4-
* Per-source configuration for trexsql integration.
4+
* Per-source configuration for TrexSQL integration.
55
* Maps to trexsql.sources.{sourceKey} in application properties.
66
*/
77
public class TrexSQLSourceConfig {

0 commit comments

Comments
 (0)