Question

I am writing the logic for pagination with Azure Java SDK. The obvious thought would be to store the last retrieved row's RowKey and use that in query next time. However for queries that go across partitions, I need to retrieve the x-ms-continuation-NextPartitionKey and x-ms-continuation-NextRowKey continuation tokens from response headers. I have seen the C# examples (http://msdn.microsoft.com/en-us/library/dd135718.aspx) but I am unable to find the Java equivalent.

How can I get these continuation tokens using Azure Java-SDK ? I am using CloudTableClient.execute to get TableResult, something like

TableQuery<DynamicTableEntity> myQuery = TableQuery
                    .from("test", DynamicTableEntity.class)
                    .where(where_condition).take(size);
CloudTableClient client = Table.getInstance().getConnection();
Iterator<DynamicTableEntity> rows = client.execute(query).iterator();
Was it helpful?

Solution

The reason you are not seeing continuation is that you are executing the query via the iterable which handles the continuations for you. If you use the ExecuteQuerySegmented methods you will receive a ResultSegment object which contains both the segment of results and the continuationtoken.

If your simply need access to the headers you may make use of the getResponseReceivedEventHandler in the OperationContext which will give you access to the HTTPUrlConnection for every request that is sent to the service.

For Example :

OperationContext opContext = new OperationContext();
opContext.getResponseReceivedEventHandler().addListener(new StorageEvent<ResponseReceivedEvent>() {

        @Override
        public void eventOccurred(ResponseReceivedEvent eventArg) {
            HttpURLConnection conn = (HttpURLConnection) eventArg.getConnectionObject();

            // Access headers here
        }
    });

Iterator<DynamicTableEntity> rows = client.execute(query, null /* requestOptions */, opContext).iterator();
...

joe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top