Skip to content

Commit 0362b8a

Browse files
authored
Merge pull request #23 from spdx/addclose
Add close to model store interface
2 parents 2198a7c + 78835e5 commit 0362b8a

File tree

7 files changed

+29
-2
lines changed

7 files changed

+29
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.spdx</groupId>
66
<artifactId>java-spdx-library</artifactId>
7-
<version>0.0.2-SNAPSHOT</version>
7+
<version>0.0.3-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>java-spdx-library</name>

src/main/java/org/spdx/library/DefaultModelStore.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public static String getDefaultDocumentUri() {
6262
public static final void reset() {
6363
lock.writeLock().lock();
6464
try {
65+
if (Objects.nonNull(defaultModelStore)) {
66+
try {
67+
defaultModelStore.close();
68+
} catch (Exception e) {
69+
throw new RuntimeException(e);
70+
}
71+
}
6572
defaultModelStore = new InMemSpdxStore();
6673
defaultCopyManager = new ModelCopyManager();
6774
} finally {

src/main/java/org/spdx/storage/IModelStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @author Gary O'Neall
4343
*
4444
*/
45-
public interface IModelStore {
45+
public interface IModelStore extends AutoCloseable {
4646

4747
public interface IModelStoreLock {
4848
public void unlock();

src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseLocalStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ InputStream getExceptionTocInputStream() throws IOException {
7272
InputStream getExceptionInputStream(String exceptionId) throws IOException {
7373
return getLicenseInputStream(exceptionId);
7474
}
75+
76+
@Override
77+
public void close() throws Exception {
78+
// Nothing to do for the either the in-memory or the web store
79+
}
7580
}

src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseWebStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ InputStream getExceptionTocInputStream() throws IOException {
7777
InputStream getExceptionInputStream(String exceptionId) throws IOException {
7878
return getLicenseInputStream(exceptionId); // Same URL using exception ID rather than license ID
7979
}
80+
81+
@Override
82+
public void close() throws Exception {
83+
// Nothing to do for the either the in-memory or the web store
84+
}
8085
}

src/main/java/org/spdx/storage/simple/ExtendedSpdxStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,10 @@ protected void clear(String documentUri) throws InvalidSPDXAnalysisException {
266266
public void delete(String documentUri, String elementId) throws InvalidSPDXAnalysisException {
267267
baseStore.delete(documentUri, elementId);
268268
}
269+
270+
@Override
271+
public void close() throws Exception {
272+
baseStore.close();
273+
}
269274

270275
}

src/main/java/org/spdx/storage/simple/InMemSpdxStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,9 @@ public void delete(String documentUri, String id) throws InvalidSPDXAnalysisExce
410410
throw new SpdxIdNotFoundException("Error deleting - ID "+id+" does not exist.");
411411
}
412412
}
413+
414+
@Override
415+
public void close() throws Exception {
416+
// Nothing to do for the in-memory store
417+
}
413418
}

0 commit comments

Comments
 (0)