com.fnklabs.draenei.orm.MapToObjectFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fnklabs-draenei Show documentation
Show all versions of fnklabs-draenei Show documentation
ORM for Cassandra but with distributed cache and analytics utils from package
package com.fnklabs.draenei.orm;
import com.datastax.driver.core.Row;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.function.Function;
/**
* Map data from {@link Row} to object
*
* @param
*/
class MapToObjectFunction implements Function {
private static final Logger LOGGER = LoggerFactory.getLogger(MapToObjectFunction.class);
private final Class clazz;
private final EntityMetadata entityMetadata;
MapToObjectFunction(Class clazz, EntityMetadata entityMetadata) {
this.clazz = clazz;
this.entityMetadata = entityMetadata;
}
@Override
public ReturnValue apply(Row row) {
ReturnValue instance = null;
try {
instance = clazz.newInstance();
List columns = entityMetadata.getFieldMetaData();
for (ColumnMetadata column : columns) {
if (row.getColumnDefinitions().contains(column.getName())) {
Object deserializedValue = column.deserialize(row.getBytesUnsafe(column.getName()));
column.writeValue(instance, deserializedValue);
}
}
} catch (InstantiationException | IllegalAccessException e) {
LOGGER.warn("Cant retrieve entity instance", e);
}
return instance;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy