Appendix A. The Completed Hello World Application

The following examples contain the source code for the completed Hello World application.

Example A.1. helloworld.sql

CREATE TABLE HELLOWORLD (
   HELLO VARCHAR(15),
   WORLD VARCHAR(15),
   DIALECT VARCHAR(15) NOT NULL,
   PRIMARY KEY (DIALECT)
);

PARTITION TABLE HELLOWORLD ON COLUMN DIALECT;

CREATE PROCEDURE FROM CLASS Insert;
CREATE PROCEDURE FROM CLASS Select;

PARTITION PROCEDURE Insert ON TABLE Helloworld COLUMN Dialect;
PARTITION PROCEDURE Select ON TABLE Helloworld COLUMN Dialect;

Example A.2. Insert.java

import org.voltdb.*;

public class Insert extends VoltProcedure {

  public final SQLStmt sql = new SQLStmt(
      "INSERT INTO HELLOWORLD VALUES (?, ?, ?);"
  );

  public VoltTable[] run( String language,
                          String hello,
                          String world)
      throws VoltAbortException {
          voltQueueSQL( sql, hello, world, language );
          voltExecuteSQL();
          return null;
      }
}

Example A.3. Select.java

import org.voltdb.*;

public class Select extends VoltProcedure {

  public final SQLStmt sql = new SQLStmt(
      "SELECT HELLO, WORLD FROM HELLOWORLD " +
      " WHERE DIALECT = ?;"
  );

  public VoltTable[] run( String language)
      throws VoltAbortException {
          voltQueueSQL( sql, language );
          return voltExecuteSQL();
      }
}

Example A.4. Client.java

import org.voltdb.*;
import org.voltdb.client.*;

public class Client {

    public static void main(String[] args) throws Exception {

        /*
         * Instantiate a client and connect to the database.
         */
        org.voltdb.client.Client myApp;
        myApp = ClientFactory.createClient();
        myApp.createConnection("localhost");

        /*
         * Load the database.
         */
        myApp.callProcedure("Insert", "English", "Hello", "World");
        myApp.callProcedure("Insert", "French", "Bonjour", "Monde");
        myApp.callProcedure("Insert", "Spanish", "Hola", "Mundo");
        myApp.callProcedure("Insert", "Danish", "Hej", "Verden");
        myApp.callProcedure("Insert", "Italian", "Ciao", "Mondo");

        /*
         * Retrieve the message.
         */
        final ClientResponse response = myApp.callProcedure("Select",
                                                            "Spanish");
        if (response.getStatus() != ClientResponse.SUCCESS){
            System.err.println(response.getStatusString());
            System.exit(-1);
        }

        final VoltTable results[] = response.getResults();
        if (results.length == 0 || results[0].getRowCount() != 1) {
            System.out.printf("I can't say Hello in that language.\n");
            System.exit(-1);
        }

        VoltTable resultTable = results[0];
        VoltTableRow row = resultTable.fetchRow(0);
        System.out.printf("%s, %s!\n", row.getString("hello"),
                                       row.getString("world"));
    }
}

Example A.5. deployment.xml

<?xml version="1.0"?>
<deployment>
   <cluster hostcount="1"
            sitesperhost="2" 
   />
   <httpd enabled="true">
      <jsonapi enabled="true" />
   </httpd>
</deployment>