Interface JsonEntityPropertyManager
- All Known Implementing Classes:
JsonEntityPropertyManagerImpl
@ExperimentalApi
public interface JsonEntityPropertyManager
Low-level database API for accessing JSON entity properties.
JSON entity properties are similar to PropertySet
s
in that they are permitted to hold more or less arbitrary collections of data. There are, however, several
important differences:
- Property sets support a wider range of data types, including things like XML documents, Properties, and any serializable object. JSON entity properties support only those data types that JSON itself supports.
- Property sets are stored as an individual database row for each property while JSON Entity Properties are stored as a single row containing the entire data structure.
- Property sets are expected to be directly associated with an OfBiz entity of some kind, and only one such property set can exist for any given entity. JSON entity properties are more flexible, in that they are keyed by an entity name, entity ID, and a key. This allows multiple kinds of metadata to be attached to the entity, such as both issue links and issue properties, without the data colliding.
- Property sets are loaded by direct reference using the owning entity name and entity ID. JSON entity
properties are more flexible in this regard as there is a fluent
query service
for locating them.
Note: The entityName
used here MUST be unique to the service that maintains
the properties. To reduce the risk of collision, it SHOULD NOT be the same as the
name of the owning entity itself, as there may be other services that also which to attach properties
to that same entity. For example, the
RemoteVersionLinkService
uses "RemoteVersionLink"
as its entityName
, not "Version"
.
- Since:
- v6.1
-
Method Summary
Modifier and TypeMethodDescriptionlong
countByEntity
(String entityName, Long entityId) Counts the number of properties that match the given entity.long
countByEntityNameAndPropertyKey
(String entityName, String key) Counts the number of properties that match the given entity name and property key.void
Deletes the stored value for an entity property, if it exists.void
deleteByEntity
(String entityName, Long entityId) Deletes all properties that are associated with the provided entity.void
deleteByEntityNameAndEntityIds
(String entityName, List<Long> entityIds) Deletes all properties that are associated with the provided entities.void
deleteByEntityNameAndPropertyKey
(String entityName, String key) Deletes all properties that are associated with the provided entity name and property key.boolean
Returns whether or not a given property exists.Produces a list of entity property keys that match the provided entity name and entity id.Produces a list of entity property keys that match the provided entity name and key prefix.Retrieve all entity properties by the entity name, entity id.Look up an entity property by the entity name, entity id, and property key.Retrieve all entity properties by the entity name, entity id and the supplied keysint
The maximum allowed length (in characters) permitted for theString json
value when callingput(String, Long, String, String)
(orputDryRun(String, String, String)
).void
put
(ApplicationUser user, String entityName, Long entityId, String key, String json, BiFunction<ApplicationUser, EntityProperty, ? extends EntityPropertySetEvent> eventFunction, boolean dispatchEvent) Set the value for an entity property, creating, updating, or deleting it as necessary.void
Deprecated.In 6.2.3 as this method does not properly throw events.void
Performs all of the validation that would be performed during aput(String, Long, String, String)
request, but does not actually store the value.query()
Returns a query object for finding, counting, or deleting properties with various restrictions.
-
Method Details
-
get
Look up an entity property by the entity name, entity id, and property key.- Parameters:
entityName
- the entity name of the propertyentityId
- the entity ID of the propertykey
- the key of the property- Returns:
- the matching property, or
null
if the property does not exist.
-
get
Retrieve all entity properties by the entity name, entity id.- Parameters:
entityName
- the entity name of the propertyentityId
- the entity ID of the property- Returns:
- a map with the property key as the map key of all properties for the entity.
-
get
Retrieve all entity properties by the entity name, entity id and the supplied keys- Parameters:
entityName
- the entity name of the propertyentityId
- the entity ID of the propertykeys
- list of property keys to match- Returns:
- a map with the property key as the map key of all properties for the entity.
-
put
@Deprecated void put(@Nonnull String entityName, @Nonnull Long entityId, @Nonnull String key, @Nullable String json) Deprecated.In 6.2.3 as this method does not properly throw events. Useput(com.atlassian.jira.user.ApplicationUser, String, Long, String, String, BiFunction, boolean)
instead.Set the value for an entity property, creating, updating, or deleting it as necessary.- Parameters:
entityName
- the entity name for the property (maximum length255
). As explained in theclass documentation
, this value should be unique to the service creating the properties and will generally not be the same as the entity to which the properties are attached.entityId
- the entity ID for the property. In general, this will be the same as the ID of the owning entity; for example, theRemoteVersionLinkService
uses theversion ID
for this value.key
- the key for the property (maximum length255
). This value should generally be suitable for a reverse lookup when the same data might be associated with multiple entities. For example, theRemoteVersionLinkService
uses theglobal ID
of the remote object, which is the same identifier used by applinks to identify a Confluence page, Bamboo project, etc.json
- the new value for the property, ornull
to delete it (maximum length is available by callinggetMaximumValueLength()
)- Throws:
FieldTooLongJsonPropertyException
- if any of the values exceed the maximum permitted lengthInvalidJsonPropertyException
- ifjson
is malformedIllegalArgumentException
- ifentityId
isnull
, or ifentityName
orkey
is eithernull
or blank.- See Also:
-
put
void put(ApplicationUser user, @Nonnull String entityName, @Nonnull Long entityId, @Nonnull String key, @Nullable String json, BiFunction<ApplicationUser, EntityProperty, ? extends EntityPropertySetEvent> eventFunction, boolean dispatchEvent) Set the value for an entity property, creating, updating, or deleting it as necessary.- Parameters:
user
- The user performing the action. The event will be actioned as this userentityName
- the entity name for the property (maximum length255
). As explained in theclass documentation
, this value should be unique to the service creating the properties and will generally not be the same as the entity to which the properties are attached.entityId
- the entity ID for the property. In general, this will be the same as the ID of the owning entity; for example, theRemoteVersionLinkService
uses theversion ID
for this value.key
- the key for the property (maximum length255
). This value should generally be suitable for a reverse lookup when the same data might be associated with multiple entities. For example, theRemoteVersionLinkService
uses theglobal ID
of the remote object, which is the same identifier used by applinks to identify a Confluence page, Bamboo project, etc.json
- the new value for the property, ornull
to delete it (maximum length is available by callinggetMaximumValueLength()
)eventFunction
- the function that generates the event to be thrown. SeeEntityPropertyHelper
for some functions that may be used to generate eventsdispatchEvent
- true if the method should dispatch an event after it is run.- Throws:
FieldTooLongJsonPropertyException
- if any of the values exceed the maximum permitted lengthInvalidJsonPropertyException
- ifjson
is malformedIllegalArgumentException
- ifentityId
isnull
, or ifentityName
orkey
is eithernull
or blank.- Since:
- 7.0.0
- See Also:
-
putDryRun
Performs all of the validation that would be performed during aput(String, Long, String, String)
request, but does not actually store the value.- Parameters:
entityName
- as forput(String, Long, String, String)
key
- as forput(String, Long, String, String)
json
- as forput(String, Long, String, String)
- Throws:
FieldTooLongJsonPropertyException
- as forput(String, Long, String, String)
InvalidJsonPropertyException
- as forput(String, Long, String, String)
IllegalArgumentException
- as forput(String, Long, String, String)
- See Also:
-
delete
Deletes the stored value for an entity property, if it exists.- Parameters:
entityName
- the entity name of the property to be deletedentityId
- the entity ID of the property to be deletedkey
- the key of the property to be deleted
-
getMaximumValueLength
int getMaximumValueLength()The maximum allowed length (in characters) permitted for theString json
value when callingput(String, Long, String, String)
(orputDryRun(String, String, String)
). This value is currently32,768
, but this may change in the future. -
query
EntityPropertyQuery<?> query()Returns a query object for finding, counting, or deleting properties with various restrictions. SeeEntityPropertyQuery
for usage and minimum requirements.- Returns:
- the query object
-
findKeys
Produces a list of entity property keys that match the provided entity name and key prefix. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.keyPrefix(keyPrefix)
.findDistinctKeys()
- Parameters:
entityName
- the entity name for the entities that are associated with the properties.keyPrefix
- the prefix to apply for limiting which keys are returned; must not benull
or a blank string- Returns:
- the list of distinct matching keys, sorted in ascending alphabetical order
- Throws:
IllegalArgumentException
- if eitherentityName
orkeyPrefix
isnull
or blank
-
findKeys
Produces a list of entity property keys that match the provided entity name and entity id. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.entityId(entityId)
.EntityPropertyQuery.ExecutableQuery.findKeys()
- Parameters:
entityName
- the entity name for the entities that are associated with the properties.entityId
- the id of the entity.- Returns:
- the list of distinct matching keys, sorted in ascending alphabetical order
- Throws:
IllegalArgumentException
- if eitherentityName
orentityId
isnull
or blank
-
exists
Returns whether or not a given property exists. This convenience method is equivalent toget(String, Long, String)
!= null
, but does not actually retrieve the JSON data from the database, so it may have better performance characteristics when the JSON content is not needed.- Parameters:
entityName
- the entity name for the propertyentityId
- the entity ID for the propertykey
- the key for the property
-
countByEntity
Counts the number of properties that match the given entity. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.entityId(entityId)
.count()
- Parameters:
entityName
- the entity name of the owning entityentityId
- the entity ID of the owning entity- Returns:
- the count of properties assigned to that entity
- Throws:
IllegalArgumentException
- if eitherentityName
isnull
or blank orentityId
isnull
.
-
countByEntityNameAndPropertyKey
Counts the number of properties that match the given entity name and property key. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.key(key)
.count()
- Parameters:
entityName
- the entity name of the owning entitieskey
- the property key to look for- Returns:
- the count of properties with that key which are assigned to entities with the given name
- Throws:
IllegalArgumentException
- if eitherentityName
orkey
isnull
or blank
-
deleteByEntity
Deletes all properties that are associated with the provided entity. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.entityId(entityId)
.delete()
- Parameters:
entityName
- the entity name for the propertiesentityId
- the entity ID for the properties
-
deleteByEntityNameAndPropertyKey
Deletes all properties that are associated with the provided entity name and property key. This convenience method is exactly equivalent to:query()
.entityName(entityName)
.key(key)
.delete()
- Parameters:
entityName
- the entity name for the propertieskey
- the property key for the properties
-
deleteByEntityNameAndEntityIds
Deletes all properties that are associated with the provided entities.- Parameters:
entityName
- the entity name for the propertiesentityIds
- the IDs of the entities
-