RBB Programming in Java

This java tutorial is given as a simple java code listing that performs basic RBB functions. The Java bindings for RBB can be used instead of calling the RBB stored procedures through SQL queries directly. This simplifies coding somewhat (java objects are used instead of RBB IDs, reducing parameter count) and provides compile-time checking.

Although not shown here, the Java interface to RBB also provides the Tagset interface for constructing and manipulating tagsets (e.g. adding or removing name/value pairs and superset/subset testing).


  1. Creating an RBB
  2. Creating a Timeseries
  3. Adding an Observation to a Timeseries
  4. Ending a Timeseries
  5. Finding Timeseries
  6. Retrieving data
  7. Deleting timeseries
  8. Event-driven processing
package gov.sandia.rbb;

public class RBBTutorial
    public static void main(String[] args)
            ////// Create an RBB
            // This creates the H2 database, and adds RBB functionality to it.
            RBB rbb = RBB.create("jdbc:h2:mem:HelloWorldDB", "Any Name");

            //// Events
            // create Events
            double start=0, end=10;
            Event ev = new Event(rbb.db(), start, end, new Tagset("name1=value1,name2=value2"));
            double start2=20, end2=30;
            Event ev2 = new Event(rbb.db(), start2, end2, new Tagset("name1=value1,name3=value3"));
            // retrieve events by taget
            Event[] found = Event.find(rbb.db(), RBBFilter.byTags("name1=value1"));
            for(Event e : found)
            	System.err.println("Found event: " + e);
            //// Timeseries
	    // Creating a Timeseries
            int dim = 2; // 2-dimensional (x,y) data
	    Timeseries t = new Timeseries(rbb, dim, start, new Tagset("name4=value4"));
	    t.add(rbb, 1.0, 2.0, 3.0);
	    t.add(rbb, 2.0, 3.14, 2.718);
	    t.setEnd(rbb.db(), 5.0);

	    /// Finding Timeseries
	    Timeseries[] a = Timeseries.findWithSamples(rbb.db(), RBBFilter.byTags("name4=value4"));

	    for(Timeseries ts : a)
            	System.err.println("Found timeseries: " + ts);
        catch (java.sql.SQLException e)
            System.err.println("error: " + e.getLocalizedMessage());

///// todo: Show event-driven processing with RBB.addEventListener()