'Is there a working example of the Quarkus Cassandra Client for Pagination?
I am still lost using the Quarkus Cassandra client https://quarkus.io/guides/cassandra I am trying the whole day to get a pagination done with the quarkus integration but the documentation is not realy helpful at all. Somebody else here has a working example for pagination with the Quarkus Cassandra client? Please share your knowledge with me. Thanks in advance.
EDIT: This my sample project/playground: https://github.com/edward-fakhouri/quarkus-cassandra-playground Here you can find a working example.
I have found something in this cassandra documentation: https://docs.datastax.com/en/developer/java-driver/3.1/manual/paging/ and implemented OffsetPagination but it isn't realy what I am searching for...
Solution 1:[1]
With the latest cassandra bom you can run those tests
<dependency>
<groupId>com.datastax.oss.quarkus</groupId>
<artifactId>cassandra-quarkus-bom</artifactId>
<version>1.1.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
with that docker cassandra started working, after that your function started working
@Override
public List<Customer> findPagedCustomerByCustomerNumber(String customerNumber, int pageNumber, int pageSize) {
List<Customer> result = new ArrayList<>();
PreparedStatement query = cqlSession.prepare(
"SELECT * FROM test.customer WHERE customer_number = :customerNumber ORDER BY creation_date");
BoundStatement completeStatement = query.bind().setString("customerNumber", customerNumber);
OffsetPager pager = new OffsetPager(pageSize);
ResultSet resultSet = cqlSession.execute(completeStatement);
OffsetPager.Page<Row> page = pager.getPage(resultSet, pageNumber);
List<Row> pageElements = page.getElements();
pageElements.forEach(c -> result.add(Customer.builder()
.customerNumber(c.getString("customer_number"))
.creationDate(c.getLocalDate("creation_date"))
.description(c.getString("description"))
.state(c.getString("state"))
.build())
);
return result;
}
I have been using querybuilder for a long time so I added that too
public List<Customer> findPagedCustomerByCustomerNumberPaging(String customerNumber, int pageNumber, int pageSize) {
List<Customer> result = new ArrayList<>();
Select select = QueryBuilder.selectFrom("test", "customer")
.columns("customer_number", "creation_date", "description", "state")
.whereColumn("customer_number").isEqualTo(literal(customerNumber))
.orderBy("createtion_date", ClusteringOrder.ASC)
.allowFiltering();
SimpleStatement completeStatement = select.build();
OffsetPager pager = new OffsetPager(pageSize);
ResultSet resultSet = cqlSession.execute(completeStatement);
OffsetPager.Page<Row> page = pager.getPage(resultSet, pageNumber);
List<Row> pageElements = page.getElements();
pageElements.forEach(c -> result.add(Customer.builder()
.customerNumber(c.getString("customer_number"))
.creationDate(c.getLocalDate("creation_date"))
.description(c.getString("description"))
.state(c.getString("state"))
.build())
);
return result;
}
I understand cassandra-quarkus-test-framework brings docker but in case you dont have docker you can always use CassandraUnit which is lighter then docker. All code can be found here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |