Is the following approach to a GenericDao possible with the v4 java driver? How?
public static <T> List<?> retrieve(Class<?> clazz, BoundStatement boundStatement) throws Exception {
List<?> tList = new ArrayList<>();
Result<?> result = null;
MappingManager manager = null;
Session session = CassandraUtil.getSession();
ResultSet resultSet = session.execute(boundStatement);
int totRows = resultSet.getAvailableWithoutFetching();
if (totRows > 0) {
manager = new MappingManager(session);
Mapper<?> m = manager.mapper(clazz);
result = (Result<?>) m.map(resultSet);
tList = result.all();
}
return tList;
}
This approach provided tremendous productivity by using a GenericDao across the entire application.
I am assessing the changes to move to the V4 of the javadriver but I am hitting the wall as it seems not possible to do the same with the java driver V4.
Thanks
IPVP
You can use @GetEntity
annotation on DAO to convert Row
object into your POJO. You can also convert ResultSet
into POJO, iterable of POJOs, etc. - depending on return value of the function. Here is example from documentation:
@Dao
public interface ProductDao {
@GetEntity
Product asProduct(Row row);
@GetEntity
PagingIterable<Product> asProducts(ResultSet resultSet);
// ...
}
See documentation for more details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.