Cassandra Paging не работает из-за неправильной сериализации объекта страницы - PullRequest
0 голосов
/ 29 октября 2018

Я пытаюсь реализовать простую подкачку к набору результатов запроса cassandra. Я пытаюсь следовать этой статье http://niels.nu/blog/2016/cassandra-resultset-paging.html. Вот так выглядит мой веб-сервис:

@GET
@Path("products")
@Produces(MediaType.APPLICATION_JSON)

public Response resources(@QueryParam(value = "next") String next,@QueryParam(value = "size") String size) {

    Cluster cluster = null;
    Session session = null;

    System.out.println("Next is "+ next);
    System.out.println("Size is "+ size);

    int nextValue =Integer.parseInt(next);
    int sizeValue =Integer.parseInt(size);


    final Cluster.Builder clusterBuilder = Cluster.builder()
            .addContactPoint("127.0.0.1").withPort(9042)
            .withCredentials("cassandra", "cassandra");
    cluster = clusterBuilder.build();
    session = cluster.connect("paging");

    CassandraPaging cassandraPaging = new CassandraPaging(session);


    return Response.status(Status.OK.getStatusCode()).entity(cassandraPaging.getProductsWithArgs(next, size))
            .type(MediaType.APPLICATION_JSON).build();

}

Вот что я имею в методе getProductsWithArgs (next, size):

public ResultSet getResourcesWithArgs(String next, String size){

    ResultSet result =null;
    String savingPageState =null;
    boolean isEnd = false;

    Select selectAll =QueryBuilder.select().all().from("paging", "users");
    selectAll.setFetchSize(3);

    List<Row> pageList = new ArrayList<Row>();

    if (next != null) {
        selectAll.setPagingState(
            PagingState.fromString(savingPageState));
    } 
    result =session.execute(selectAll);

    PagingState pagingState = result.getExecutionInfo()
            .getPagingState();
    if (null != pagingState) {
        savingPageState = result.getExecutionInfo().getPagingState()
                .toString();
    }

    System.out.println("Paging state "+ pagingState);
    if (result.isFullyFetched() && null == pagingState) {
        // if hit the end more than once, then nothing to return,
        // otherwise, mark the isEnd to 'true'
        if (true == isEnd) {
            return null;
        } else {
            isEnd = true;
        }
    }

    List<Row> rowsList =getRows(result, 4, 3);
    printUser(rowsList);
    return result;


}

Когда я пытаюсь получить доступ к веб-сервису:

http://localhost:8080/PagingService/cass/app/resources?next=4&size=3

Я получаю следующее исключение:

com.datastax.driver.core.exceptions.PagingStateException: Cannot deserialize 
paging state, invalid format. The serialized form was corrupted, or not 
initially generated from a PagingState object.
com.datastax.driver.core.PagingState.fromString(PagingState.java:148)
com.devjavasource.cassandra.PagingExample.CassandraPaging.getResourcesWithAr gs(CassandraPaging.java:58)
com.devjavasource.cassandra.PagingExample.PagingWebService.resources(PagingWebService.java:44)

Хотя если я закомментировал код для setPagingState, то

savingPageState = result.getExecutionInfo().getPagingState()
            .toString();

действительно получает действительное значение для pagingState. Может кто-нибудь помочь мне с тем, что я здесь делаю неправильно? Был бы очень признателен. Благодаря.

1 Ответ

0 голосов
/ 29 октября 2018

похоже на эту строчку PagingState.fromString(savingPageState)); пытается создать объект PagingState из пустой строки. Это то, что вы намеревались?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...