1.安装voltdb
wget http://voltdb.com/downloads/technologies/server/LINUX-voltdb-ent-3.0-beta2.tar.gz
tar xvf LINUX-voltdb-ent-3.0-beta2.tar.gz
cp LINUX-voltdb-ent-3.0-beta2 /opt/voltdb
配置环境变量
vim /etc/profile
export VOLTDB_PATH=/opt/voltdb/
export PATH=$PATH:$VOLTDB_PATH/bin
export CLASSPATH=./:$VOLTDB_PATH/lib/*:$VOLTDB_PATH/voltdb/*
2.创建源码
mkdir helloworld
cd helloworld
创建源
INSERT类
import org.voltdb.*;
@ProcInfo(partitionInfo = "HELLOWORLD.DIALECT: 2", singlePartition = true)
public class Insert extends VoltProcedure {
public final SQLStmt sql = new SQLStmt(
"INSERT INTO HELLOWORLD VALUES (?, ?, ?);");
public VoltTable[] run(String hello, String world, String language)
throws VoltAbortException {
voltQueueSQL(sql, hello, world, language);
voltExecuteSQL();
return null;
}
}
SELECT类
import org.voltdb.*;
@ProcInfo(partitionInfo = "HELLOWORLD.DIALECT: 0", singlePartition = true)
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();
}
}
Cient类
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("houzb");
/*
* Load the database.
*/
myApp.callProcedure("Insert", "Hello", "World", "English");
myApp.callProcedure("Insert", "Bonjour", "Monde", "French");
myApp.callProcedure("Insert", "Hola", "Mundo", "Spanish");
myApp.callProcedure("Insert", "Hej", "Verden", "Danish");
myApp.callProcedure("Insert", "Ciao", "Mondo", "Italian");
/*
* 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"));
}
}
3.相关配置文件
helloworld.sql
CREATE TABLE HELLOWORLD (
HELLO VARCHAR(15),
WORLD VARCHAR(15),
DIALECT VARCHAR(15) NOT NULL,
PRIMARY KEY (DIALECT)
);
project.xml
<?xml version="1.0"?>
<project>
<database>
<schemas>
<schema path="helloworld.sql" />
</schemas>
<procedures>
<procedure class="Insert" />
<procedure class="Select" />
</procedures>
</database>
</project>
deployment.xml
<?xml version="1.0"?>
<deployment>
<cluster
hostcount="1"
sitesperhost="2" />
<httpd enabled="true" >
<jsonapi enabled="true" />
</httpd>
</deployment>
4.编译运行
##voltdb编译
##voltdb编译
[root@test VoltDBTestSpace]# voltcompiler ./ project.xml helloworld.jar
## 启动voltdb数据库服务
## 启动voltdb数据库服务
[root@test VoltDBTestSpace]# voltdb catalog helloworld.jar deployment deployment.xml host localhost license /opt/voltdb/voltdb/license.xml
非企业版启动命令:voltdb create catalog helloworld.jar deployment deployment.xml leader localhost
非企业版启动命令:voltdb create catalog helloworld.jar deployment deployment.xml leader localhost
##静默启动命令:
[root@test VoltDBTestSpace]# nohup
voltdb catalog helloworld.jar deployment deployment.xml host localhost license /opt/voltdb/voltdb/license.xml &
##调用数据查询
[root@test VoltDBTestSpace]# java Client
5.数据恢复命令:
快照恢复:nohup voltdb recover deployment deployment.xml host hostname zkport 2288 &