public void incrementProperty(Connection conn, String project, Object userId, String property, double value)
throws SQLException {
Map<String, FieldType> columns = createMissingColumns(project, userId, ImmutableList.of(new SimpleImmutableEntry<>(property, new DoubleNode(value))), new CommitConnection(conn));
FieldType fieldType = columns.get(property);
if (fieldType == null) {
createColumn(project, userId, property, JsonHelper.numberNode(0));
}
if (!fieldType.isNumeric()) {
throw new RakamException(String.format("The property the is %s and it can't be incremented.", fieldType.name()),
BAD_REQUEST);
}
String tableRef = checkTableColumn(stripName(property, "table column"));
Statement statement = conn.createStatement();
ProjectCollection userTable = getUserTable(project, false);
String table = checkProject(userTable.project, '"') + "." + checkCollection(userTable.collection);
int execute = statement.executeUpdate("update " + table +
" set " + tableRef + " = " + value + " + coalesce(" + tableRef + ", 0)");
if (execute == 0) {
create(project, userId, JsonHelper.jsonObject().put(property, value));
}
}