The previous chapter (Chapter 3, Designing Your VoltDB Application) explains how to develop your VoltDB database application using the full power and flexibility of the Java client interface. However, some database tasks — such as inserting records into a table or retrieving a specific column value — do not need all of the capabilities that the Java API provides.
Now that you know how the VoltDB programming interface works, VoltDB has features to simplify common tasks and make your application development easier. Those features include:
Default procedures for partitioned tables
Shortcuts for defining simple stored procedures
Verifying expected SQL query results
The following sections describe each of these features separately.
Although it is possible to define quite complex SQL queries, often the simplest are also the most common. Inserting, selecting, updating, and deleting records based on a specific key value are the most basic operations for a database.
To simplify these operations, VoltDB defines default stored procedures to perform these queries for any partitioned table where the partitioning column is part of the primary key index. When you compile the application catalog, these default procedures are added to the catalog automatically.
The default stored procedures use a standard naming scheme, where the name of the procedure is composed of the name of the table (in all uppercase), a period, and the name of the query in lowercase. The parameters to the procedures differ based on the procedure. For the insert procedure, the parameters are the columns of the table, in the same order as defined in the schema. For the select and delete procedures, only the primary key column values are required (listed in the order they appear in the primary key definition). For the update procedure, the columns are the new column values, in the order defined by the schema, followed by the primary key column values. (This means the primary key column values are specified twice, once as their corresponding new column values and once as the primary key value.)
For example, the Hello World tutorial contains a single table, HELLOWORLD, with three columns and the partitioning column, DIALECT, as the primary key. As a result, the application catalog includes four default stored procedures, in addition to any user-defined procedures declared in the schema. Those default procedures are:
The following code example uses the default procedures for the HELLOWORLD table to insert, retrieve, update, and delete a new record with the key value "American":
VoltTable results; client.callProcedure("HELLOWORLD.insert", "American","Howdy","Earth"); results = client.callProcedure("HELLOWORLD.select", "American").getResults(); client.callProcedure("HELLOWORLD.update", "American","Yo","Biosphere", "American"); client.callProcedure("HELLOWORLD.delete", "American");