Key-Value Containers
KeyValueContainer
and KeyValueCollectionContainer
are designed to work with key-value entities. Such entities can contain an arbitrary number of attributes that are defined at runtime.
KeyValueContainer
and KeyValueCollectionContainer
can be defined in a view XML descriptor using keyValueInstance
and keyValueCollection
elements.
XML definition of a key-value container must include the properties
element that defines the KeyValueEntity
attributes (actually, keys and their types). The order of nested property elements should conform to the order of result set columns returned by the query. In the following example the username
attribute will get its value from us.user.username
column and the stepsCount
attribute from count(us)
column:
<keyValueCollection id="summaryDc">
<loader id="summaryDl">
<query>
<![CDATA[select us.user.username, count(us) from UserStep us
where us.dueDate < current_date and us.completedDate is null
group by us.user.username]]>
</query>
</loader>
<properties>
<property name="username" datatype="string"/>
<property name="stepsCount" datatype="int"/>
</properties>
</keyValueCollection>
Besides, you can configure key-value containers using their Java API which includes the following methods:
-
addProperty()
- allows you to define the entity attributes (keys). The method accepts a name of the attribute and its type in the form of a Datatype or a Java class. In the latter case, the class should be either an entity class or a class supported by one of the datatypes. This method is used by the framework under the hood when you define properties of the key-value container declartively in XML as explained above. -
setIdName()
is an optional method that allows you to define one of the attributes as an identifier attribute of the entity. It means thatKeyValueEntity
instances stored in this container will have identifiers obtained from the given attribute. Otherwise,KeyValueEntity
instances get randomly generated UUIDs. -
getEntityMetaClass()
returns a dynamic implementation of the MetaClass interface that represents the current schema ofKeyValueEntity
instances. It is determined by previous calls toaddProperty()
.