You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+170-2Lines changed: 170 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1728,10 +1728,177 @@ The reference structure is used when the object being referenced is not to be em
1728
1728
1729
1729
When mapping a Java object to Aerospike the most common operations to do are to save the whole object and load the whole object. The AeroMapper is set up primarily for these use cases. However, there are cases where it makes sense to manipulate objects directly in the database, particularly when it comes to manipulating lists and maps. This functionality is provided via virtual lists.
1730
1730
1731
+
Consider a TODO list, where there are Items which contain the items to be performed and a container for these items:
1732
+
1733
+
```java
1734
+
@AerospikeRecord(namespace = "test", set = "item")
Note that in thiscase the items are embedded into the container and not refrenced. This is what is needed for virtual lists, they must have a list of items in the database associated with a single record.
1766
+
1767
+
These items can be populated using the functionally presented above. For example:
Note that whilst in thiscase the list is pre-populated with information, this is not a requirement for using virtual list.
1796
+
1797
+
A virtual list is created through the mapper:
1798
+
1799
+
```java
1800
+
VirtualList<Item> list = mapper.asBackedList(container, "items", Item.class);
1801
+
```
1802
+
1803
+
The container is passed as the first parameter, and is used for2 things: The classtype (so the annotations and field definitions can be discovered) and the primary key. It is possible to pass these 2 parameters instead of explicitly passing an object.
1804
+
1805
+
Once a virtual list has been created, methods to manipulate the list can be executed. For example:
1806
+
1807
+
```java
1808
+
list.append(new Item(500, new Date(), "Item5"));
1809
+
```
1810
+
1811
+
After this, the list in the database looks like:
1812
+
1813
+
```
1814
+
id: 1
1815
+
items: KEY_ORDERED_MAP('{
1816
+
100:["Item 1", 1618442036607],
1817
+
200:["Item 2", 1618442036607],
1818
+
300:["Item 3", 1618442036607],
1819
+
400:["Item 4", 1618442036607],
1820
+
500:["Item5", 1618442991205]}')
1821
+
name: "container"
1822
+
```
1823
+
1824
+
Note however that the list in the object in memory still contains only 4 items. *Virtual lists affect only the database representation of the data and not the Java POJO.*
1825
+
eVirutal Lists tend to use the (Operate)[https://www.aerospike.com/docs/client/java/usage/kvs/multiops.html] command which allows multiple operations to be performed on the same key at the same time. As a consequence, multiple commands can be done on a list with a single Aerospike operation. For example:
This operation will add a new item (600) into the list, remove key 200 and get any keys between 100 (inclusive) and 450 (exclusive). As a result, the data in the database is:
1836
+
1837
+
```
1838
+
id: 1
1839
+
items: KEY_ORDERED_MAP('{
1840
+
100:["Item 1", 1618442036607],
1841
+
300:["Item 3", 1618442036607],
1842
+
400:["Item 4", 1618442036607],
1843
+
500:["Item5", 1618442991205],
1844
+
600:["Item6", 1618445996551]}')
1845
+
name: "container"
1846
+
```
1847
+
1848
+
The result of the call is the result of the last read operation in the list of calls if one exists, otherwise it is the last write operation. So in this case, the result will be the result of the `getByKeyRange` call, which is 3 items: 100, 300, 400.
Then the result would be the result of the `removeByKey`, which by default is null. (Write operations pass a ReturnType of NONE to CDT operations by default)
1860
+
1861
+
However, if we wanted a particular operation in the list to return it's result, we can flag it with `asResult()`.For example:
Thereturn type of the method is now going to be a long as it represents the count of elements removed (2 in thiscase).Note that this example is not very practical -- there is no point in calling `getByKeyRange(...)` in this call as the result is ignored.
1885
+
1886
+
Also note that virtual lists allow operations only on the list, not on other bins on the same record. Todothis, you would have to use the underlying nativeAerospikeAPI. There are however convenience methods on the AeroMapper which can help map between Aerospike and Java formats..For example:
public<T>T convertToObject(Class<T> clazz, Record record);
1894
+
```
1895
+
1896
+
Note:At the moment not all CDT operations are supported, and if the underlying CDTs are of the wrong type, a different API call may be used. For example, if you invoke `getByKeyRange` on items represented in the database as a list, `getByValueRange` is invoked instead as a list has no key.
1897
+
1898
+
1731
1899
----
1732
1900
1733
1901
## To finish
1734
-
- Document virtual lists
1735
1902
- Add interfaceto adaptiveMap, including changing EmbedType
1736
1903
- Document all parameters to annotations and examples of types
1737
1904
- Document enums, dates, instants.
@@ -1742,4 +1909,5 @@ When mapping a Java object to Aerospike the most common operations to do are to
1742
1909
- Ensure batch loading option exists in AerospikeReference Configuration
1743
1910
- handle object graph circularities (A->B->C). Be careful of: A->B(Lazy), A->C->B: B should end up fully hydrated in both instances, not lazy in both instances
1744
1911
- Consider the items on virtual list which return a list to be able to return a map as well (ELEMENT_LIST, ELEMENT_MAP)
1745
-
- Test a constructor which requires a sub-object. For example, Account has a Property, Property has an Address. All 3 a referenced objects. Constructor for Property requires Address
1912
+
- Test a constructor which requires a sub-object. For example, Account has a Property, Property has an Address. All 3 a referenced objects. Constructor for Property requires Address
1913
+
- Create a batch get method which loads sub-objects in parallel
0 commit comments