ReadTable API Sample

Introduction

This sample provides Java code that illustrates the StreamBaseClient.readTable()method, which is used to display all or a specified number of rows from a Query Table. The Java code is provided in the ReadTableClient.java program in the src/main/java/package-name folder.

The sample contains an EventFlow application, ReadTable.sbapp that contains the following elements:

  • A local Query Table named SimpleTable.

  • A module reference to ReadTableModule.sbapp, which contains a shared table named SharedTable.

  • A module reference to ReadTableModuleWithPlaceholder.sbapp, which contains a placeholder table named PlaceholderTable that is mapped to ConcreteTable.

The sample demonstrates the ability to retrieve rows from any of these tables, using the following paths at runtime:

[containername.]SimpleTable
[containername.]ReadTableModuleRef.SharedTable
[containername.]ReadTableModuleWithPlaceholderRef.PlaceholderTable
[containername.]ConcreteTable

where containername is optional if you run ReadTable.sbapp in the default container named default, but must be present for non-default container names.

You run this sample in two steps:

  1. Run the ReadTable.sbapp application.

    On startup, a CSV File Reader adapter populates all tables with the same contents, which are read from the file InitialData.txt. (You can supplement this populated data by sending tuples to the InsertToAllTables input stream.) The application then awaits further input or a client connection.

  2. Run the ReadTableClient.java program as a Java application. This StreamBase client program connects to the ReadTable.sbapp application, reads values from its various table constructs, and prints its output to the console.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter readt to narrow the list of options.

  • Select the Read Query Table from Java clients sample from the Client Libraries category.

  • Click Import Now.

StreamBase Studio creates a project for this sample.

Running This Sample in StreamBase Studio

Follow these steps:

  1. In the Project Explorer view, open this sample's folder.

    Keep an eye on the bottom right status bar of the Studio window. Make sure any Updating, Downloading, Building, or Rebuild project messages finish before you proceed.

  2. Open the src/main/eventflow/packageName folder.

  3. Double-click to open the ReadTable.sbapp module. Make sure the module is the currently active tab in the EventFlow Editor.

  4. Click the Run button. This opens the SB Test/Debug perspective and starts the module.

  5. Wait for the Waiting for fragment to initialize message to clear.

  6. Return to the SB Authoring perspective.

  7. In the Project Explorer view, open the src/main/java/package-name folder tree to expose the ReadTableClient.java file.

  8. Right-click the ReadTableClient.java file and from the context menu, select Run As>Java Application.

  9. Observe the results of the Java program in the Console view.

  10. When done, press F9 or click the Terminate EventFlow Fragment button.

Sample Location

When you load the sample into StreamBase® Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase® Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_ReadTable

See Default Installation Directories for the default location of studio-workspace on your system.