Accessing VoltDB Through the Spring Framework JDBC

VoltDB was designed from the ground up to be revolutionary, while still keeping what you love about relational databases. The SQL is the same. The data model is the same. It's the performance that's different. This makes VoltDB suitable for all kinds of applications, from stream processing to telecommunications. To make it easy to develop these diverse applications, VoltDB supports a number of different programming frameworks.  

In this blog I’ll describe how, using the Spring JDBC template, application developers can access and integrate their apps with VoltDB. The example described in this blog is available to download and run yourself here: https://github.com/VoltDB/example-spring-jdbc.git.

Let’s look at the example. Say you have an online voting application that identifies a set of contestants for whom people will vote. The following DDL describes the contestants’ table:

 

It is easy to use the Spring JDBC template to access this table in VoltDB. Spring JDBC allows you to define your SQL Data Access Object; additionally, you can map the result to a Java POJO object.

The steps to do this simple abstraction are as follows: 

Define your POJO, which is your transfer object consisting of firstName, lastName and code fields. Your POJO will look like:

 

Next, define your queries and implement ContestantDao (Data Access Object). Your ContestantDao is a Spring bean defined in your application context file. The bean extends the NamedParameterJdbcTemplate, which has all the methods to access your data. Queries can be static in ContestantDao or defined externally as part of the bean definition. Shown below is the code for ContestantDao:

 

Now that you have the DAO bean and transfer  POJO defined, glue them together by specifying a data source. Shown below is a snippet of what a data source will look like. Note the DAO constructor takes dataSource as an argument, which is specified in the bean definition as a reference to the dataSource bean.

 

Finally, write a client which initializes the Spring context and wires in the beans and data sources. Here is what your main application will look like:

 

See the full sample on our GitHub page here: https://github.com/VoltDB/example-spring-jdbc.git!

by Anish Khanzode