-
Notifications
You must be signed in to change notification settings - Fork 66
/
simple.cc
62 lines (52 loc) · 1.6 KB
/
simple.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <string.h>
#include <sstream>
#include <iostream>
#include <stdlib.h>
#include <set>
#include <string>
#include <stdio.h>
#include <libcassandra/cassandra_factory.h>
#include <libcassandra/cassandra.h>
#include <libcassandra/column_family_definition.h>
#include <libcassandra/keyspace.h>
#include <libcassandra/keyspace_definition.h>
using namespace std;
using namespace libcassandra;
static string host("127.0.0.1");
static int port= 9160;
int main()
{
CassandraFactory factory(host, port);
tr1::shared_ptr<Cassandra> client(factory.create());
string clus_name= client->getClusterName();
cout << "cluster name: " << clus_name << endl;
vector<KeyspaceDefinition> key_out= client->getKeyspaces();
for (vector<KeyspaceDefinition>::iterator it = key_out.begin(); it != key_out.end(); ++it)
{
cout << "keyspace: " << (*it).getName() << endl;
}
try
{
/* create keyspace */
KeyspaceDefinition ks_def;
ks_def.setName("drizzle");
client->createKeyspace(ks_def);
client->setKeyspace(ks_def.getName());
/* create standard column family */
ColumnFamilyDefinition cf_def;
cf_def.setName("Data");
cf_def.setKeyspaceName(ks_def.getName());
client->createColumnFamily(cf_def);
/* insert data */
client->insertColumn("sarah", "Data", "third", "this is data being inserted!");
/* retrieve that data */
string res= client->getColumnValue("sarah", "Data", "third");
cout << "Value in column retrieved is: " << res << endl;
}
catch (org::apache::cassandra::InvalidRequestException &ire)
{
cout << ire.why << endl;
return 1;
}
return 0;
}