Commit a9585ed3 authored by Øyvin Halfdan Thuv's avatar Øyvin Halfdan Thuv
Browse files

Re-using prepared statement.

parent 029883ad
......@@ -20,7 +20,8 @@ public class IncidentController {
Cluster cluster;
Session session;
PreparedStatement insertStmt;
/*
* CREATE KEYSPACE storage WITH REPLICATION = {
* 'class': 'SimpleStrategy',
......@@ -32,6 +33,9 @@ public class IncidentController {
cluster = Cluster.builder()
.addContactPoint("127.0.0.1").build();
session = cluster.connect("storage");
insertStmt = session
.prepare("INSERT INTO incident (id, name) VALUES (?, ?)");
}
/*
......@@ -61,10 +65,7 @@ public class IncidentController {
@RequestMapping(value="/incidents", method=RequestMethod.POST)
public Incident newIncident(@RequestBody Incident i) {
UUID id = UUID.randomUUID();
PreparedStatement statement =
session.prepare("INSERT INTO incident (id, name)" +
" VALUES (?, ?)");
session.execute(statement.bind(id, i.getName()));
session.execute(insertStmt.bind(id, i.getName()));
i.setId(id);
return i;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment