Sample code for 30+ languages & platforms
CkJava Requires Chilkat v11.6.0+

Azure Table: Save and Resume an Entity Query

See more Azure Table Service Examples

Fetches one page per invocation and saves private JSON plus a checkpoint bound to the account, collection path, filter, projection, page size and API version. Refuses to overwrite an unprocessed page. Process/archive qa_output/table-page.json before the next run; keep table-checkpoint.json until completion.

This demonstrates at-least-once processing, not an atomic transaction between output and checkpoint. A crash or failed checkpoint write can replay a page; deduplicate by entity identity/version. A malformed checkpoint stops instead of restarting. Use a single caller, protect files, and use transactional durable state for stronger guarantees. Table contents can change during enumeration.

Targets Azure Storage Table service in the public cloud, not Azure Cosmos DB for Table. Uses Chilkat 11.6.0 or later and an unlocked library. Direct data requests pin x-ms-version 2026-04-06 and OData 3.0. Shared Key examples read private qa_data/azure/storage.json with account and access_key string fields. Authentication examples explain their additional fields. Create private local directories before running; keep credentials, tokens, SAS, entity values, checkpoints and diagnostics outside public content and source control.

HTTPS certificates are verified. Transport completion and HTTP status are checked separately. Writes are not automatically retried after an uncertain outcome. Entity keys, ETags and continuation tokens remain strings. Examples operate on the existing ExampleCustomers table unless noted; review the targets before adapting them. Microsoft Entra ID with suitable Table data roles is preferred where available.

Microsoft reference.

Chilkat CkJava Downloads

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  StringBuilder compares text by value in every generated language.
    CkStringBuilder textCompare = new CkStringBuilder();
    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    success = false;
    CkJsonObject config = new CkJsonObject();
    config.put_Strict(true);
    success = config.LoadFile("qa_data/azure/storage.json");
    if (success != true) {
        System.out.println("Could not load private Azure configuration.");
        return;
        }

    textCompare.Clear();
    textCompare.SetString(config.stringOf("account"));
    boolean sameText1 = textCompare.ContentsEqual("",true);
    if ((config.JsonTypeOf("account") != 1) || (sameText1 == true)) {
        System.out.println("Supply the storage account name.");
        return;
        }

    //  access_key is the base64 account key, not a connection string or SAS.
    textCompare.Clear();
    textCompare.SetString(config.stringOf("access_key"));
    boolean sameText2 = textCompare.ContentsEqual("",true);
    if ((config.JsonTypeOf("access_key") != 1) || (sameText2 == true)) {
        System.out.println("Supply the base64 account access key.");
        return;
        }

    CkStringBuilder accountText = new CkStringBuilder();
    success = accountText.Append(config.stringOf("account"));
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    if ((accountText.get_Length() < 3) || (accountText.get_Length() > 24)) {
        System.out.println("Storage account names need 3-24 lowercase letters or digits.");
        return;
        }

    CkStringBuilder allowedAccountChars = new CkStringBuilder();
    success = allowedAccountChars.Append("abcdefghijklmnopqrstuvwxyz0123456789");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    int charIndex = 0;
    while ((charIndex < accountText.get_Length())) {
        if (allowedAccountChars.Contains(accountText.getRange(charIndex,1,false),true) != true) {
            System.out.println("Storage account names need lowercase letters or digits.");
            return;
            }

        charIndex = charIndex+1;
        }

    CkStringBuilder endpoint = new CkStringBuilder();
    success = endpoint.Append(config.stringOf("account"));
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = endpoint.Append(".table.core.windows.net");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    //  Table names contain only letters and digits and are case-insensitive.
    //  Entity PartitionKey and RowKey values are case-sensitive.
    String resourcePath = "/ExampleCustomers()";
    CkRest rest = new CkRest();
    rest.put_ConnectTimeoutMs(20000);
    rest.put_IdleTimeoutMs(60000);
    CkAuthAzureStorage azAuth = new CkAuthAzureStorage();
    azAuth.put_Account(config.stringOf("account"));
    azAuth.put_AccessKey(config.stringOf("access_key"));
    azAuth.put_Service("Table");
    azAuth.put_Scheme("SharedKey");
    azAuth.put_XMsVersion("2026-04-06");
    success = rest.SetAuthAzureStorage(azAuth);
    if (success != true) {
        System.out.println("Could not configure Shared Key signing.");
        return;
        }

    CkSocket connection = new CkSocket();
    connection.put_RequireSslCertVerify(true);
    connection.put_MaxReadIdleMs(60000);
    connection.put_MaxSendIdleMs(60000);
    success = connection.Connect(endpoint.getAsString(),443,true,20000);
    if (success != true) {
        System.out.println("TLS connection failed; inspect diagnostics privately.");
        return;
        }

    //  Do not replay a write automatically after losing its response.
    success = rest.UseConnection(connection,false);
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    String responseText;
    CkJsonObject result = new CkJsonObject();
    result.put_Strict(true);
    success = rest.AddHeader("DataServiceVersion","3.0;NetFx");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = rest.AddHeader("MaxDataServiceVersion","3.0;NetFx");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = rest.AddHeader("Content-Type","application/json");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = rest.AddHeader("Accept","application/json;odata=minimalmetadata");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    //  Single-caller, one-page-per-run example. Archive table-page.json before the next run.
    CkFileAccess files = new CkFileAccess();
    if (files.FileExists("qa_output/table-page.json") == true) {
        System.out.println("Previous page output exists; process and archive it before continuing.");
        return;
        }

    CkJsonObject checkpoint = new CkJsonObject();
    checkpoint.put_Strict(true);
    String nextPartition = "";
    String nextRow = "";
    if (files.FileExists("qa_data/azure/table-checkpoint.json") == true) {
        success = checkpoint.LoadFile("qa_data/azure/table-checkpoint.json");
        if (success != true) {
            System.out.println("Invalid checkpoint; do not silently restart.");
            return;
            }

        textCompare.Clear();
        textCompare.SetString(checkpoint.stringOf("path"));
        boolean sameText3 = textCompare.ContentsEqual(resourcePath,true);
        textCompare.Clear();
        textCompare.SetString(checkpoint.stringOf("filter"));
        boolean sameText4 = textCompare.ContentsEqual("PartitionKey eq 'customers-west'",true);
        textCompare.Clear();
        textCompare.SetString(checkpoint.stringOf("select"));
        boolean sameText5 = textCompare.ContentsEqual("PartitionKey,RowKey,Address,NumberOfOrders",true);
        textCompare.Clear();
        textCompare.SetString(checkpoint.stringOf("top"));
        boolean sameText6 = textCompare.ContentsEqual("100",true);
        textCompare.Clear();
        textCompare.SetString(checkpoint.stringOf("version"));
        boolean sameText7 = textCompare.ContentsEqual("2026-04-06",true);
        if ((checkpoint.stringOf("account") != config.stringOf("account")) || (sameText3 != true) || (sameText4 != true) || (sameText5 != true) || (sameText6 != true) || (sameText7 != true)) {
            System.out.println("Checkpoint belongs to a different account or query.");
            return;
            }

        if ((checkpoint.JsonTypeOf("complete") != 5) || (checkpoint.JsonTypeOf("partition") != 1) || (checkpoint.JsonTypeOf("row") != 1)) {
            System.out.println("Checkpoint fields are invalid.");
            return;
            }

        if (checkpoint.BoolOf("complete") == true) {
            System.out.println("Query already complete.");
            return;
            }

        nextPartition = checkpoint.stringOf("partition");
        nextRow = checkpoint.stringOf("row");
        textCompare.Clear();
        textCompare.SetString(nextPartition);
        boolean sameText8 = textCompare.ContentsEqual("",true);
        if (sameText8 == true) {
            System.out.println("Incomplete checkpoint has no continuation token.");
            return;
            }

        }

    success = rest.AddQueryParam("$filter","PartitionKey eq 'customers-west'");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = rest.AddQueryParam("$select","PartitionKey,RowKey,Address,NumberOfOrders");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = rest.AddQueryParam("$top","100");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    textCompare.Clear();
    textCompare.SetString(nextPartition);
    boolean sameText9 = textCompare.ContentsEqual("",true);
    if (sameText9 != true) {
        success = rest.AddQueryParam("NextPartitionKey",nextPartition);
        if (success != true) {
            System.out.println("Could not prepare the request.");
            return;
            }

        }

    textCompare.Clear();
    textCompare.SetString(nextRow);
    boolean sameText10 = textCompare.ContentsEqual("",true);
    if (sameText10 != true) {
        success = rest.AddQueryParam("NextRowKey",nextRow);
        if (success != true) {
            System.out.println("Could not prepare the request.");
            return;
            }

        }

    responseText = rest.fullRequestNoBody("GET",resourcePath);
    if (rest.get_LastMethodSuccess() != true) {
        System.out.println("Request did not complete; inspect the target before retrying a write.");
        return;
        }

    if (rest.get_ResponseStatusCode() != 200) {
        System.out.println("HTTP status: " + rest.get_ResponseStatusCode());
        System.out.println("Request ID: " + rest.responseHdrByName("x-ms-request-id"));
        //  404 is missing, 409 is conflict, and 412 is a stale ETag: none are success.
        //  Keep response bodies private. Reconcile uncertain writes before retrying.
        return;
        }

    success = result.Load(responseText);
    if (success != true) {
        System.out.println("Expected well-formed JSON.");
        return;
        }

    if (result.JsonTypeOf("value") != 4) {
        System.out.println("Missing entity/table array.");
        return;
        }

    String followingPartition = rest.responseHdrByName("x-ms-continuation-NextPartitionKey");
    String followingRow = rest.responseHdrByName("x-ms-continuation-NextRowKey");
    textCompare.Clear();
    textCompare.SetString(followingPartition);
    boolean sameText11 = textCompare.ContentsEqual("null",true);
    if (sameText11 == true) {
        followingPartition = "";
        }

    textCompare.Clear();
    textCompare.SetString(followingRow);
    boolean sameText12 = textCompare.ContentsEqual("null",true);
    if (sameText12 == true) {
        followingRow = "";
        }

    textCompare.Clear();
    textCompare.SetString(followingPartition);
    boolean sameText13 = textCompare.ContentsEqual("",true);
    textCompare.Clear();
    textCompare.SetString(followingRow);
    boolean sameText14 = textCompare.ContentsEqual("",true);
    if ((sameText13 == true) && (sameText14 != true)) {
        System.out.println("Malformed continuation.");
        return;
        }

    textCompare.Clear();
    textCompare.SetString(followingPartition);
    boolean sameText15 = textCompare.ContentsEqual("",true);
    textCompare.Clear();
    textCompare.SetString(followingPartition);
    boolean sameText16 = textCompare.ContentsEqual(nextPartition,true);
    textCompare.Clear();
    textCompare.SetString(followingRow);
    boolean sameText17 = textCompare.ContentsEqual(nextRow,true);
    if ((sameText15 != true) && (sameText16 == true) && (sameText17 == true)) {
        System.out.println("Service repeated the current checkpoint.");
        return;
        }

    //  Save the page before advancing its checkpoint. Failures can cause replay, never intentional skipping.
    success = result.WriteFile("qa_output/table-page.json");
    if (success != true) {
        System.out.println("Could not save private page output.");
        return;
        }

    success = checkpoint.UpdateString("account",config.stringOf("account"));
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("path",resourcePath);
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("filter","PartitionKey eq 'customers-west'");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("select","PartitionKey,RowKey,Address,NumberOfOrders");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("top","100");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("version","2026-04-06");
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("partition",followingPartition);
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.UpdateString("row",followingRow);
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    boolean completed = false;
    textCompare.Clear();
    textCompare.SetString(followingPartition);
    boolean sameText18 = textCompare.ContentsEqual("",true);
    if (sameText18 == true) {
        completed = true;
        }

    success = checkpoint.UpdateBool("complete",completed);
    if (success != true) {
        System.out.println("Could not prepare the request.");
        return;
        }

    success = checkpoint.WriteFile("qa_data/azure/table-checkpoint.json");
    if (success != true) {
        System.out.println("Page saved but checkpoint write failed. Preserve the page and reconcile before resuming.");
        return;
        }

    System.out.println("Page and continuation checkpoint saved privately.");
  }
}