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

Adding timestamp to the example.

parent 73bdb925
package statelessws;
import java.util.Date;
import java.util.UUID;
public class Incident {
private UUID id;
private String name;
private Date timestamp;
public Incident() {
......@@ -14,6 +16,7 @@ public class Incident {
public Incident(UUID id, String name) {
this.id = id;
this.name = name;
this.timestamp = new Date();
}
public UUID getId() {
......@@ -24,6 +27,10 @@ public class Incident {
return this.name;
}
public Date getTimestamp() {
return this.timestamp;
}
public void setId(UUID id) {
this.id = id;
}
......@@ -32,4 +39,8 @@ public class Incident {
this.name = name;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
}
......@@ -7,6 +7,7 @@ import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import java.util.concurrent.atomic.AtomicLong;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -46,7 +47,9 @@ public class IncidentController {
deleteStmt = session
.prepare("DELETE FROM incident WHERE id = ?");
createStmt = session
.prepare("INSERT INTO incident (id, name) VALUES (?, ?)");
.prepare("INSERT INTO incident" +
" (id, name, timestamp)" +
" VALUES (?, ?, ?)");
readStmt = session
.prepare("SELECT * FROM incident WHERE id = ?");
updateStmt = session
......@@ -93,8 +96,11 @@ public class IncidentController {
@RequestMapping(value="/incidents", method=RequestMethod.POST)
public Incident createIncident(@RequestBody Incident i) {
UUID id = UUID.randomUUID();
session.execute(createStmt.bind(i.getId(), i.getName()));
Date timestamp = new Date();
i.setId(id);
i.setTimestamp(timestamp);
session.execute(createStmt.bind
(i.getId(), i.getName(), i.getTimestamp()));
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