Class MappingConverter
java.lang.Object
com.aerospike.mapper.tools.converters.MappingConverter
public class MappingConverter extends Object
-
Constructor Summary
Constructors Constructor Description MappingConverter(IBaseAeroMapper mapper, com.aerospike.client.IAerospikeClient aerospikeClient)
-
Method Summary
Modifier and Type Method Description <T> List<Object>
convertToList(T instance)
Given an instance of a class (of any type), convert its properties to a list<T> Map<String,Object>
convertToMap(T instance)
Given an instance of a class (of any type), convert its properties to a map, properties names will use as the key and properties values will be the values.<T> T
convertToObject(Class<T> clazz, com.aerospike.client.Record record)
Given a record loaded from Aerospike and a class type, attempt to convert the record to an instance of the passed class.<T> T
convertToObject(Class<T> clazz, com.aerospike.client.Record record, ClassCacheEntry<T> entry)
Given a record loaded from Aerospike and a class type, attempt to convert the record to an instance of the passed class.<T> T
convertToObject(Class<T> clazz, com.aerospike.client.Record record, ClassCacheEntry<T> entry, boolean resolveDependencies)
This method should not be used, it is public only to allow mappers to see it.<T> T
convertToObject(Class<T> clazz, List<Object> record)
Given a list of records loaded from Aerospike and a class type, attempt to convert the records to an instance of the passed class.<T> T
convertToObject(Class<T> clazz, List<Object> record, boolean resolveDependencies)
This method should not be used, it is public only to allow mappers to see it.<T> T
convertToObject(Class<T> clazz, Map<String,Object> record)
Given a map of records loaded from Aerospike and a class type, attempt to convert the records to an instance of the passed class.void
resolveDependencies(ClassCacheEntry<?> parentEntity)
If an object refers to other objects (eg A has a list of B via references), then reading the object will populate the ids.<T> T
translateFromAerospike(@NotNull Object obj, @NotNull Class<T> expectedClazz)
Translate an Aerospike object to a Java object.Object
translateToAerospike(Object obj)
Translate a Java object to an Aerospike format object.
-
Constructor Details
-
MappingConverter
public MappingConverter(IBaseAeroMapper mapper, com.aerospike.client.IAerospikeClient aerospikeClient)
-
-
Method Details
-
translateToAerospike
Translate a Java object to an Aerospike format object. Note that this could potentially have performance issues as the type information of the passed object must be determined on every call.- Parameters:
obj
- A given Java object.- Returns:
- An Aerospike format object.
-
translateFromAerospike
public <T> T translateFromAerospike(@NotNull @NotNull Object obj, @NotNull @NotNull Class<T> expectedClazz)Translate an Aerospike object to a Java object. Note that this could potentially have performance issues as the type information of the passed object must be determined on every call.- Parameters:
obj
- A given Java object.- Returns:
- An Aerospike format object.
-
convertToObject
Given a record loaded from Aerospike and a class type, attempt to convert the record to an instance of the passed class.- Parameters:
clazz
- The class type to convert the Aerospike record to.record
- The Aerospike record to convert.- Returns:
- A virtual list.
- Throws:
com.aerospike.client.AerospikeException
- an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.
-
convertToObject
public <T> T convertToObject(Class<T> clazz, com.aerospike.client.Record record, ClassCacheEntry<T> entry) throws ReflectiveOperationExceptionGiven a record loaded from Aerospike and a class type, attempt to convert the record to an instance of the passed class.- Parameters:
clazz
- The class type to convert the Aerospike record to.record
- The Aerospike record to convert.entry
- The entry that holds information on how to store the provided class.- Returns:
- A virtual list.
- Throws:
com.aerospike.client.AerospikeException
- an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.ReflectiveOperationException
-
convertToObject
public <T> T convertToObject(Class<T> clazz, com.aerospike.client.Record record, ClassCacheEntry<T> entry, boolean resolveDependencies) throws ReflectiveOperationExceptionThis method should not be used, it is public only to allow mappers to see it.- Throws:
ReflectiveOperationException
-
convertToObject
Given a list of records loaded from Aerospike and a class type, attempt to convert the records to an instance of the passed class.- Parameters:
clazz
- The class type to convert the Aerospike record to.record
- The Aerospike records to convert.- Returns:
- A virtual list.
- Throws:
com.aerospike.client.AerospikeException
- an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.
-
convertToObject
This method should not be used, it is public only to allow mappers to see it. -
convertToObject
Given a map of records loaded from Aerospike and a class type, attempt to convert the records to an instance of the passed class.- Parameters:
clazz
- The class type to convert the Aerospike record to.record
- The Aerospike records to convert.- Returns:
- A virtual list.
- Throws:
com.aerospike.client.AerospikeException
- an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.
-
convertToList
Given an instance of a class (of any type), convert its properties to a list- Parameters:
instance
- The instance of a class (of any type).- Returns:
- a List of the properties of the given instance.
-
convertToMap
Given an instance of a class (of any type), convert its properties to a map, properties names will use as the key and properties values will be the values.- Parameters:
instance
- The instance of a class (of any type).- Returns:
- the properties
Map
of the given instance.
-
resolveDependencies
If an object refers to other objects (eg A has a list of B via references), then reading the object will populate the ids. If configured to do so, these objects can be loaded via a batch load and populated back into the references which contain them. This method performs this batch load, translating the records to objects and mapping them back to the references. These loaded child objects can themselves have other references to other objects, so we iterate through this until the list of deferred objects is empty. The deferred objects are stored in aThreadLocalData
list, so are thread safe
- Parameters:
parentEntity
- - the ClassCacheEntry of the parent entity. This is used to get the batch policy to use.
-