Contents
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 or Materialized Window. The Java code
is provided in the ReadTableClient.java
program in the java-src
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 namedSharedTable
. -
A module reference to
ReadTableModuleWithPlaceholder.sbapp
, which contains a placeholder table namedPlaceholderTable
that is mapped toConcreteTable
. -
A materialized window named
MatWindow
.
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
|
[containername .]MatWindow
|
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:
-
Run the
ReadTable.sbapp
application.On startup, a CSV File Reader adapter populates all tables and the Materialized Window with the same contents, which are read from the file
InitialData.txt
. (You can supplement this populated data by sending tuples to theInsertToAllTables
input stream.) The application then awaits further input or a client connection. -
Run the
ReadTableClient.java
program as a Java application. This StreamBase client program connects to theReadTable.sbapp
application, reads values from its various table constructs, and prints Its output to the console.
Follow these steps:
-
In the Package Explorer view, double-click to open the
ReadTable.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the
button. This opens the SB Test/Debug perspective and starts the application.
Notice in the Application Output view the set of key-value pairs that was used to populate the tables.
-
Return to the SB Authoring perspective.
-
In the Package Explorer view, open the
java-src
folder tree to expose theReadTableClient.java
file. -
Right-click the
ReadTableClient.java
file and from the context menu, select → . -
Observe the results of the Java program in the Console view.
-
When done, press F9 or click the
Stop Running Application button.
This section describes how to run the sample in UNIX terminal windows or Windows command prompt windows. On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.
-
Open two terminal windows on UNIX, or two StreamBase Command Prompt s on Windows. In each window, navigate to your workspace copy of the sample.
-
In window 1, start the EventFlow application with the following command:
sbd ReadTable.sbapp
-
In window 2, run the provided ReadTableClient program with the following commands:
- For Windows
set CLASSPATH=%CLASSPATH%;.\java-bin java com.streambase.sample.ReadTableClient
- For UNIX
export CLASSPATH=`sb-config --classpath`:./java-bin java com.streambase.sample.ReadTableClient
-
While the EventFlow application is running, you can also invoke the
readTable
subcommand of the sbc and jsbc commands. Usesbc list -m
to get a list of available table names. This returns, in part:table ConcreteTable table MatWindow table ReadTableModuleRef.SharedTable table ReadTableModuleWithPlaceholderRef.PlaceholderTable table SimpleTable
-
Type commands using the following syntax:
sbc readTable --all
containername
.TableName
For example, omitting the name of the
default
container:sbc readTable --all ConcreteTable sbc readTable --all ReadTableModuleRef.SharedTable
-
When done, enter this command in window 2 to close the EventFlow application:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Type
table
in the search field to narrow the list. -
From the Client Libraries category, select the Read Query Tables sample.
-
Click OK.
StreamBase Studio creates a project for this sample.
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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:
studio-workspace
/sample_ReadTable
See Default Installation Directories for the location of studio-workspace
on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
streambase-install-dir
/sample/ReadTable
See Default Installation Directories for the default location of studio-workspace
on your system.