|
29 | 29 | import org.spdx.library.model.SimpleUriValue; |
30 | 30 | import org.spdx.library.model.TypedValue; |
31 | 31 | import org.spdx.storage.IModelStore; |
| 32 | +import org.spdx.storage.IModelStore.IModelStoreLock; |
32 | 33 | import org.spdx.storage.IModelStore.IdType; |
33 | 34 |
|
34 | 35 | /** |
@@ -196,10 +197,17 @@ public void copy(IModelStore toStore, String toDocumentUri, String toId, |
196 | 197 | */ |
197 | 198 | private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, |
198 | 199 | String fromDocumentUri, String fromId, String propName, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { |
199 | | - if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { |
200 | | - throw new InvalidSPDXAnalysisException("Property "+propName+" is a collection type"); |
201 | | - } |
202 | | - Optional<Object> result = fromStore.getValue(fromDocumentUri, fromId, propName); |
| 200 | + IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); |
| 201 | + //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection |
| 202 | + Optional<Object> result = Optional.empty(); |
| 203 | + try { |
| 204 | + if (fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { |
| 205 | + throw new InvalidSPDXAnalysisException("Property "+propName+" is a collection type"); |
| 206 | + } |
| 207 | + result = fromStore.getValue(fromDocumentUri, fromId, propName); |
| 208 | + } finally { |
| 209 | + fromStoreLock.unlock(); |
| 210 | + } |
203 | 211 | if (result.isPresent()) { |
204 | 212 | if (result.get() instanceof IndividualUriValue) { |
205 | 213 | toStore.setValue(toDocumentUri, toId, propName, new SimpleUriValue((IndividualUriValue)result.get())); |
@@ -232,10 +240,17 @@ private void copyIndividualProperty(IModelStore toStore, String toDocumentUri, S |
232 | 240 | */ |
233 | 241 | private void copyCollectionProperty(IModelStore toStore, String toDocumentUri, String toId, IModelStore fromStore, |
234 | 242 | String fromDocumentUri, String fromId, String propName, boolean excludeLicenseDetails) throws InvalidSPDXAnalysisException { |
235 | | - if (!fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { |
236 | | - throw new InvalidSPDXAnalysisException("Property "+propName+" is not a collection type"); |
237 | | - } |
238 | | - Iterator<Object> fromListIter = fromStore.listValues(fromDocumentUri, fromId, propName); |
| 243 | + IModelStoreLock fromStoreLock = fromStore.enterCriticalSection(fromDocumentUri, false); |
| 244 | + //Note: we use a write lock since the RDF store may end up creating a property to check if it is a collection |
| 245 | + Iterator<Object> fromListIter = null; |
| 246 | + try { |
| 247 | + if (!fromStore.isCollectionProperty(fromDocumentUri, fromId, propName)) { |
| 248 | + throw new InvalidSPDXAnalysisException("Property "+propName+" is not a collection type"); |
| 249 | + } |
| 250 | + fromListIter = fromStore.listValues(fromDocumentUri, fromId, propName); |
| 251 | + } finally { |
| 252 | + fromStoreLock.unlock(); |
| 253 | + } |
239 | 254 | while (fromListIter.hasNext()) { |
240 | 255 | Object listItem = fromListIter.next(); |
241 | 256 | Object toStoreItem; |
|
0 commit comments