Package org.spdx.storage.simple
Class InMemSpdxStore
java.lang.Object
org.spdx.storage.simple.InMemSpdxStore
- All Implemented Interfaces:
AutoCloseable,IModelStore
public class InMemSpdxStore extends Object implements IModelStore
- Author:
- Gary O'Neall
In memory implementation of an SPDX store.
This implementation primarily uses
ConcurrentHashMaps. It is designed to be thread-safe and low CPU utilization. It may use significant amounts of memory for larger SPDX documents.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.spdx.storage.IModelStore
IModelStore.IdType, IModelStore.IModelStoreLock, IModelStore.ModelUpdate -
Field Summary
Fields Modifier and Type Field Description protected Map<String,Map<String,StoredTypedItem>>documentValuesMap of Document URI to items stored in the document.static PatternLICENSE_ID_PATTERN_GENERATED -
Constructor Summary
Constructors Constructor Description InMemSpdxStore() -
Method Summary
Modifier and Type Method Description booleanaddValueToCollection(String documentUri, String id, String propertyName, Object value)Adds a value to a property collection creating the propertyName if it does not existvoidclear(String documentUri)Remove all existing elements, properties, and values for a document including the document itselfvoidclearValueCollection(String documentUri, String id, String propertyName)Sets the value collection for the property to an empty collection creating the propertyName if it does not existvoidclose()booleancollectionContains(String documentUri, String id, String propertyName, Object value)intcollectionSize(String documentUri, String id, String propertyName)voidcreate(String documentUri, String id, String type)Create a new object with IDvoiddelete(String documentUri, String id)Deletes an item from the documentIModelStore.IModelStoreLockenterCriticalSection(String documentUri, boolean readLockRequested)Enter a critical section.booleanexists(String documentUri, String id)Stream<TypedValue>getAllItems(String documentUri, String typeFilter)Optional<String>getCaseSensisitiveId(String documentUri, String caseInsensisitiveId)In SPDX 2.2 license refs are allowed to be matched case insensitive.List<String>getDocumentUris()IModelStore.IdTypegetIdType(String id)protected StoredTypedItemgetItem(String documentUri, String id)Gets the item from the hashmapStringgetNextId(IModelStore.IdType idType, String documentUri)Generate a unique ID for use within the documentList<String>getPropertyValueNames(String documentUri, String id)Optional<TypedValue>getTypedValue(String documentUri, String id)Optional<Object>getValue(String documentUri, String id, String propertyName)booleanisCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz)booleanisCollectionProperty(String documentUri, String id, String propertyName)booleanisPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz)voidleaveCriticalSection(IModelStore.IModelStoreLock lock)Leave a critical section.Iterator<Object>listValues(String documentUri, String id, String propertyName)voidremoveProperty(String documentUri, String id, String propertyName)Removes a property from the document for the given ID if the property exists.booleanremoveValueFromCollection(String documentUri, String id, String propertyName, Object value)Removes a value from a collection of values associated with a propertyvoidsetValue(String documentUri, String id, String propertyName, Object value)Sets a property value for a String or Boolean type of value creating the propertyName if it does not exist
-
Field Details
-
LICENSE_ID_PATTERN_GENERATED
-
documentValues
Map of Document URI to items stored in the document. The key for the items map is the lowercase of the item ID.
-
-
Constructor Details
-
InMemSpdxStore
public InMemSpdxStore()
-
-
Method Details
-
exists
- Specified by:
existsin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX document- Returns:
- true if the id already exists for the document
-
create
Description copied from interface:IModelStoreCreate a new object with ID- Specified by:
createin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documenttype- SPDX model type as defined in the CLASS constants in SpdxConstants- Throws:
InvalidSPDXAnalysisException
-
getItem
protected StoredTypedItem getItem(String documentUri, String id) throws InvalidSPDXAnalysisExceptionGets the item from the hashmap- Parameters:
documentUri-id-- Returns:
- Throws:
InvalidSPDXAnalysisException
-
getPropertyValueNames
public List<String> getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException- Specified by:
getPropertyValueNamesin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX document- Returns:
- Property names for all properties having a value for a given id within a document
- Throws:
InvalidSPDXAnalysisException
-
setValue
public void setValue(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreSets a property value for a String or Boolean type of value creating the propertyName if it does not exist- Specified by:
setValuein interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the propertyvalue- value to set- Throws:
InvalidSPDXAnalysisException
-
clearValueCollection
public void clearValueCollection(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreSets the value collection for the property to an empty collection creating the propertyName if it does not exist- Specified by:
clearValueCollectionin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the property- Throws:
InvalidSPDXAnalysisException
-
addValueToCollection
public boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreAdds a value to a property collection creating the propertyName if it does not exist- Specified by:
addValueToCollectionin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the propertyvalue- value to add- Returns:
- true if the collection was modified
- Throws:
InvalidSPDXAnalysisException
-
removeValueFromCollection
public boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreRemoves a value from a collection of values associated with a property- Specified by:
removeValueFromCollectionin interfaceIModelStore- Parameters:
documentUri- Unique document URIid- ID of the item to associate the property withpropertyName- name of the propertyvalue- Value to be removed- Returns:
- Throws:
InvalidSPDXAnalysisException
-
listValues
public Iterator<Object> listValues(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException- Specified by:
listValuesin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the property- Returns:
- Iterator over the list of values associated with the id, propertyName and document
- Throws:
InvalidSPDXAnalysisException
-
getValue
public Optional<Object> getValue(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException- Specified by:
getValuein interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the property- Returns:
- the single value associated with the id, propertyName and document
- Throws:
InvalidSPDXAnalysisException
-
getNextId
public String getNextId(IModelStore.IdType idType, String documentUri) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreGenerate a unique ID for use within the document- Specified by:
getNextIdin interfaceIModelStore- Parameters:
idType- Type of IDdocumentUri- the SPDX Document URI- Returns:
- next available unique ID for the specific idType
- Throws:
InvalidSPDXAnalysisException
-
removeProperty
public void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisExceptionDescription copied from interface:IModelStoreRemoves a property from the document for the given ID if the property exists. Does not raise any exception if the propertyName does not exist- Specified by:
removePropertyin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the property- Throws:
InvalidSPDXAnalysisException
-
getDocumentUris
- Specified by:
getDocumentUrisin interfaceIModelStore- Returns:
- a list of all Document URI's stored in the model store
-
getAllItems
public Stream<TypedValue> getAllItems(String documentUri, String typeFilter) throws InvalidSPDXAnalysisException- Specified by:
getAllItemsin interfaceIModelStore- Parameters:
documentUri- SPDX Document URI for a document associated with this modeltypeFilter- Optional parameter to specify the type of objects to be retrieved- Returns:
- Stream of all items store within the document
- Throws:
InvalidSPDXAnalysisException
-
collectionSize
public int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException- Specified by:
collectionSizein interfaceIModelStore- Parameters:
documentUri- Unique document URIid- ID of the item to associate the property withpropertyName- name of the property- Returns:
- size of a collection associated with a property. 0 if the property does not exist.
- Throws:
InvalidSPDXAnalysisException
-
collectionContains
public boolean collectionContains(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException- Specified by:
collectionContainsin interfaceIModelStore- Parameters:
documentUri- Unique document URIid- ID of the item to associate the property withpropertyName- name of the property- Returns:
- true if the collection associated with a property contains the value
- Throws:
InvalidSPDXAnalysisException
-
isCollectionMembersAssignableTo
public boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz) throws InvalidSPDXAnalysisException- Specified by:
isCollectionMembersAssignableToin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the propertyclazz- Class to test compatibility with- Returns:
- true if all members of a collection associated with the id and propertyName can be assigned to the clazz
- Throws:
InvalidSPDXAnalysisException
-
isPropertyValueAssignableTo
public boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz) throws InvalidSPDXAnalysisException- Specified by:
isPropertyValueAssignableToin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the propertyclazz- Class to test compatibility with- Returns:
- true if the value associated with the id and propertyName can be assigned to the clazz
- Throws:
InvalidSPDXAnalysisException
-
isCollectionProperty
public boolean isCollectionProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException- Specified by:
isCollectionPropertyin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX documentpropertyName- Name of the property- Returns:
- true if the propertyName represents multiple values
- Throws:
InvalidSPDXAnalysisException
-
getIdType
- Specified by:
getIdTypein interfaceIModelStore- Returns:
- The type of ID based on the string format
-
enterCriticalSection
public IModelStore.IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested)Description copied from interface:IModelStoreEnter a critical section. leaveCriticialSection must be called.- Specified by:
enterCriticalSectionin interfaceIModelStorereadLockRequested- true implies a read lock, false implies write lock.
-
leaveCriticalSection
Description copied from interface:IModelStoreLeave a critical section. Releases the lock form the matching enterCriticalSection- Specified by:
leaveCriticalSectionin interfaceIModelStore
-
getCaseSensisitiveId
Description copied from interface:IModelStoreIn SPDX 2.2 license refs are allowed to be matched case insensitive. This function will return the case sensitivie ID (e.g. if you have LicenseRef-ABC, calling this function with licenseref-abc will return LicenseRef-ABC- Specified by:
getCaseSensisitiveIdin interfaceIModelStore- Parameters:
documentUri- the SPDX Document URI- Returns:
- the case sensitive ID if it exists
-
getTypedValue
public Optional<TypedValue> getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException- Specified by:
getTypedValuein interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX document- Returns:
- type TypedValue containing the type of the ModelObject related to the ID
- Throws:
InvalidSPDXAnalysisException
-
clear
Remove all existing elements, properties, and values for a document including the document itself- Parameters:
documentUri-
-
delete
Description copied from interface:IModelStoreDeletes an item from the document- Specified by:
deletein interfaceIModelStore- Parameters:
documentUri- the SPDX Document URIid- unique ID within the SPDX document- Throws:
InvalidSPDXAnalysisException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-