Contents
This sample illustrates the use of the TableAccessor class in the Java Client API. This class lets Java code (such as custom Java operators) interact with data sources in various ways. In particular, this class lets you insert rows, replace rows, read a single row based on the primary index, perform more complex multi-row queries, delete rows, get table size, and truncate entire tables.
This sample includes seven custom Java operators, each of which illustrates a single aspect of the TableAccessor class:
-
InsertJavaOperator
-
ReplaceJavaOperator
-
ReadPrimaryJavaOperator
-
QueryJavaOperator
-
DeleteJavaOperator
-
TruncateJavaOperator
-
SizeJavaOperator
Code shared by these operators exists in a common abstract superclass, AbstractTableOperator. So, for example, the InsertJavaOperator.processTuple method illustrates the use of the corresponding TableAccessor.insert method.
The StreamBase application TableOperator.sbapp
includes an instance of each of those seven Java operators, along with related input, output, and error streams, as appropriate.
To demonstrate Java operator input and output, this sample also includes a StreamBase unit test suite, UnitTest.java
. Thus, instead of running the TableOperator.sbapp
EventFlow application and enqueuing tuples, you just run the unit test. This starts the TableOperator.sbapp
application, populates its Query Table, then runs each of the application's seven Java operators, and reports the results.
A solid green bar in the JUnit view indicates a successful run.
Follow these steps:
-
In the Package Explorer view, open the
java-src
folder tree to expose theUnitTest.java
file. -
Select
UnitTest.java
, right-click, and from its context menu, select → .The JUnit view appears and displays the successful execution of the six tests specified in the
UnitTest.java
file.
You can then explore the sample in other ways. For example:
-
Read the source of
UnitTest.java
to see samples of Java operator input and expected output. -
In the
java-src
tree, read the sources of the Java operators:com.streambase.sample.*JavaOperator
-
Run
TableOperator.sbapp
and interact manually with the operators. Follow these steps:-
In the Package Explorer, double-click to open the
TableOperator.sbapp
application. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the Run button. This opens the SB Test/Debug perspective and starts the application.
-
In the Manual Input view, select the
Insert
stream, and send tuples that populate the application's Query Table with values. -
Once you have a small set of data in the Query Table, select the other input streams one at a time to manage and manipulate the data in the Query Table.
-
When done, press F9 or click the Stop Running Application button.
-
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, click
→ . -
Select this application from the Applications list.
-
Click OK.
StreamBase Studio creates a project for each 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 permission problems. The default workspace location for this sample is:
studio-workspace
/sample_TableOperator
See Default Installation Directories for the default 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/TableOperator
See Default Installation Directories for the default location of studio-workspace
on your system.