Commit d483370b authored by Axel Auweter's avatar Axel Auweter
Browse files

Some more refactoring...

parent 2a6a15e3
......@@ -53,10 +53,10 @@ public:
void createKeyspace(string name, int replicationFactor);
void selectKeyspace(string name);
bool existsColumnFamily(string name);
void createColumnFamilies();
void createColumnFamily(string name, string fields, string primaryKey, string options);
/* Database data access operations */
void insert(string key, uint64_t ts, uint64_t value);
void insert(string columnFamily, string key, uint64_t ts, uint64_t value);
/* Class constructor / desctructor */
CassandraBackend();
......
......@@ -5,10 +5,6 @@
* Author: Axel Auweter
*/
/* FIXME - remove this include (table naming and creation should be controlled by sensordatastore) */
#include "sensordatastore_internal.h"
#include "cassandraBackend.h"
void CassandraBackend::connect(string hostname, int port)
......@@ -82,13 +78,17 @@ bool CassandraBackend::existsColumnFamily(string name)
return false;
}
void CassandraBackend::createColumnFamilies()
void CassandraBackend::createColumnFamily(string name, string fields, string primaryKey, string options)
{
CqlResult res;
string query;
stringstream query;
/* FIXME: Secure this and use proper types for fields, primaryKey, and options. */
query << "CREATE TABLE " << name
<< " ( " << fields << ", PRIMARY KEY (" << primaryKey << "))"
<< " WITH " << options << ";";
query = "CREATE TABLE " CF_SENSORDATA " ( sid blob, ts bigint, value bigint, PRIMARY KEY (sid, ts)) WITH COMPACT STORAGE;";
myClient->execute_cql3_query(res, query, Compression::NONE, ConsistencyLevel::ONE);
myClient->execute_cql3_query(res, query.str(), Compression::NONE, ConsistencyLevel::ONE);
}
bool CassandraBackend::validateName(string name)
......@@ -115,14 +115,14 @@ string CassandraBackend::int64Convert(uint64_t n)
return string((char*)&n, 8);
}
void CassandraBackend::insert(string key, uint64_t ts, uint64_t value)
void CassandraBackend::insert(string columnFamily, string key, uint64_t ts, uint64_t value)
{
try {
ColumnParent cparent;
Column c;
string key, name, cvalue;
cparent.column_family = CF_SENSORDATA;
cparent.column_family = columnFamily;
/*
* Convert to Cassandra formats and assign
......
......@@ -62,7 +62,10 @@ void SensorDataStoreImpl::init(string hostname, int port) {
if (!csBackend->existsColumnFamily(CF_SENSORDATA)) {
cout << "Creating Column Familiy " CF_SENSORDATA "...\n";
csBackend->createColumnFamilies();
csBackend->createColumnFamily(CF_SENSORDATA,
"sid blob, ts bigint, value bigint",
"sid, ts",
"COMPACT STORAGE");
}
}
catch(const TTransportException& te){
......@@ -81,7 +84,7 @@ void SensorDataStoreImpl::init(string hostname, int port) {
void SensorDataStoreImpl::insert(SensorId* sid, uint64_t ts, uint64_t value)
{
csBackend->insert(sidConvert(sid), ts, value);
csBackend->insert(CF_SENSORDATA, sidConvert(sid), ts, value);
}
SensorDataStoreImpl::SensorDataStoreImpl(CassandraBackend *csb)
......
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