Skip to content

Commit d326274

Browse files
committed
Merge branch 'hotfix-1.1.34'
2 parents 414120d + f9ab1fd commit d326274

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>baseCode</name>
66
<groupId>baseCode</groupId>
77
<artifactId>baseCode</artifactId>
8-
<version>1.1.33</version>
8+
<version>1.1.34</version>
99
<inceptionYear>2003</inceptionYear>
1010
<description>
1111
<![CDATA[Data structures, math and statistics tools, and utilities that are often needed across projects.]]>
@@ -717,7 +717,7 @@
717717
<pavlab.server>frink.pavlab.msl.ubc.ca</pavlab.server>
718718
<pavlab.repoDir>/space/maven2</pavlab.repoDir>
719719
<pavlab.siteDir>/space/web/maven-sites</pavlab.siteDir>
720-
<log4j.version>2.25.2</log4j.version>
720+
<log4j.version>2.25.3</log4j.version>
721721
<lucene.version>3.6.2</lucene.version>
722722
<!-- rJava -->
723723
<!-- You may override this in ~/.m2/settings.xml -->

src/ubic/basecode/ontology/jena/TdbOntologyService.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public class TdbOntologyService extends AbstractOntologyService {
2828
@Nullable
2929
private Dataset dataset;
3030

31-
/**
32-
* Temporary d
33-
*/
31+
@Nullable
3432
private Path tempDir;
3533

34+
private boolean deleteTempDir = false;
35+
3636
/**
3737
* @param readOnly open the TDB database in read-only mode, allowing multiple JVMs to share a common TDB. For this
3838
* to work safely, all the TDB files must not be writable. Additionally, a temporary directory with
@@ -57,14 +57,27 @@ protected OntologyModel loadModel( boolean processImports, LanguageLevel languag
5757
try ( Stream<Path> z = Files.list( tdbDir ) ) {
5858
filesToLink = z.collect( Collectors.toSet() );
5959
}
60-
tempDir = Files.createTempDirectory( getOntologyName() + ".tdb" );
60+
if ( tempDir == null ) {
61+
log.info( "Creating temporary directory for read-only TDB model." );
62+
tempDir = Files.createTempDirectory( getOntologyName() + ".tdb" );
63+
deleteTempDir = true;
64+
} else if ( !Files.exists( tempDir ) ) {
65+
log.info( "Creating temporary directory at {} for read-only TDB model.", tempDir );
66+
Files.createDirectories( tempDir );
67+
deleteTempDir = true;
68+
} else {
69+
log.info( "Reusing existing temporary directory at {} for read-only TDB model. Note that the directory will not be removed.", tempDir );
70+
// never delete a temporary directory that wasn't created by this service (I've learned this the hard way!)
71+
deleteTempDir = false;
72+
}
6173
for ( Path p : filesToLink ) {
6274
Files.copy( p, tempDir.resolve( p.getFileName() ) );
6375
}
6476
} finally {
6577
loc.getLock().release();
6678
}
6779
log.info( "Reading read-only TDB model from {}.", tempDir );
80+
assert tempDir != null;
6881
dataset = TDBFactory.createDataset( tempDir.toString() );
6982
} else {
7083
dataset = TDBFactory.createDataset( tdbDir.toString() );
@@ -78,6 +91,19 @@ protected OntologyModel loadModelFromStream( InputStream is, boolean processImpo
7891
throw new UnsupportedOperationException( "TDB cannot be loaded from an input stream." );
7992
}
8093

94+
/**
95+
* Set the temporary directory used when opening the TDB in read-only mode.
96+
* <p>
97+
* This can only be set once, before the first model is loaded. Note that the directory will be removed when the
98+
* service is closed.
99+
*/
100+
public void setTempDir( Path tempDir ) {
101+
if ( this.tempDir != null ) {
102+
throw new IllegalStateException( "Temporary directory has already been set." );
103+
}
104+
this.tempDir = tempDir;
105+
}
106+
81107
@Override
82108
public void close() throws Exception {
83109
try {
@@ -86,7 +112,7 @@ public void close() throws Exception {
86112
if ( dataset != null ) {
87113
TDBFactory.release( dataset );
88114
}
89-
if ( tempDir != null ) {
115+
if ( tempDir != null && deleteTempDir ) {
90116
PathUtils.delete( tempDir );
91117
}
92118
}

0 commit comments

Comments
 (0)