summaryrefslogtreecommitdiffstats
path: root/collaboration
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration')
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java6
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java1
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java36
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java41
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java9
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java20
6 files changed, 80 insertions, 33 deletions
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
index 02315a6e43..47dab705f1 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
@@ -1,7 +1,7 @@
package org.apache.tuscany.nosqldatastore;
public interface Database {
- org.apache.tuscany.nosqldatastore.Group createGroup(String groupId);
- boolean isAvailable(String key);
- void deleteGroup(String key);
+ Group createGroup(String groupId);
+ Group getGroup(String groupId);
+ void deleteGroup(String groupId);
}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
index 8874494b08..4bd46e0316 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
@@ -4,4 +4,5 @@ public interface Group {
void addEntry(String key, Object value);
void updateEntry(String key, Object value);
void deleteEntry(String key);
+ Object getValue(String key);
}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
index 9572476941..90b95a3019 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
@@ -5,38 +5,44 @@ import java.util.List;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.cassandra.service.ThriftKsDef;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
import me.prettyprint.hector.api.factory.HFactory;
+import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.tuscany.nosqldatastore.Database;
import org.apache.tuscany.nosqldatastore.Group;
class CassandraDatabase implements Database {
- private String keyspace;
- private ThriftCluster cluster;
- private List<ColumnFamilyDefinition> cfDefList;
+ private Keyspace keyspace;
+ private Cluster cluster;
- CassandraDatabase(String databaseName, ThriftCluster cluster) {
- this.keyspace = databaseName;
+ CassandraDatabase(String databaseName, Cluster cluster) {
+ try{
+ KeyspaceDefinition ksDef = new ThriftKsDef(databaseName, "org.apache.cassandra.locator.SimpleStrategy", 1, null);
+ cluster.addKeyspace(ksDef);
+ }catch (HInvalidRequestException e){
+ System.out.println("Connect to the existing database...");
+ }
+ this.keyspace = HFactory.createKeyspace(databaseName, cluster);
this.cluster = cluster;
- KeyspaceDefinition ksDef = cluster.describeKeyspace(keyspace);
- cfDefList = ksDef.getCfDefs();
}
public Group createGroup(String groupId) {
- ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace, groupId);
- cluster.addColumnFamily(cfDef);
- CassandraGroup group = new CassandraGroup(groupId);
+ CassandraGroup group = new CassandraGroup(groupId, keyspace, cluster);
return group;
}
- public boolean isAvailable(String key) {
- return false;
- }
+ public Group getGroup(String groupId) {
+ return createGroup(groupId);
+ }
+
- public void deleteGroup(String key) {
- cluster.dropColumnFamily(keyspace, key);
+ public void deleteGroup(String key) {
+ cluster.dropColumnFamily(keyspace.getKeyspaceName(), key);
}
}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
index 36a5bddf7b..d46e666935 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
@@ -1,25 +1,52 @@
package org.apache.tuscany.nosqldatastore.cassandra;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.template.ColumnFamilyResult;
+import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
+import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
+import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
+import me.prettyprint.hector.api.factory.HFactory;
import org.apache.tuscany.nosqldatastore.Group;
class CassandraGroup implements Group {
- CassandraGroup(String groupName) {
+ private ColumnFamilyTemplate<String,String> template;
+ private ColumnFamilyUpdater<String, String> updater;
+ private final StringSerializer se = StringSerializer.get();
+
+ CassandraGroup(String groupId, Keyspace keyspace, Cluster cluster) {
+ try{
+ ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace.getKeyspaceName(), groupId);
+ cluster.addColumnFamily(cfDef);
+ }catch (HInvalidRequestException e){
+ System.out.println("Connect to the existing group...");
+ }
+ template = new ThriftColumnFamilyTemplate<String, String>(keyspace,groupId,se,se,HFactory.createMutator(keyspace, se));
}
public void addEntry(String key, Object value) {
- // TODO Auto-generated method stub
-
+ updater = template.createUpdater(key);
+ updater.setString(key, (String) value);
+ template.update(updater);
+ template.addColumn(key, se);
}
public void deleteEntry(String key) {
- // TODO Auto-generated method stub
+ template.deleteColumn(key, key);
}
- public void updateEntry(String key, Object value) {
- // TODO Auto-generated method stub
-
+ public Object getValue(String key) {
+ ColumnFamilyResult wrapper = template.queryColumns(key);
+ return wrapper.getString(key);
+ }
+
+ public void updateEntry(String key, Object value) {
+ addEntry(key, value);
}
}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
index f9cd7a62c5..97bd42caf1 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
@@ -3,23 +3,22 @@ package org.apache.tuscany.nosqldatastore.cassandra;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.cassandra.service.ThriftKsDef;
+import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
import org.apache.tuscany.nosqldatastore.Database;
import org.apache.tuscany.nosqldatastore.Session;
public class CassandraSession implements Session {
private CassandraHostConfigurator cassandraHostConfigurator;
- private ThriftCluster cluster;
+ private Cluster cluster;
public CassandraSession(String clusterName) {
- cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9160");
- cluster = new ThriftCluster(clusterName, cassandraHostConfigurator);
+ cluster = HFactory.getOrCreateCluster("Test Cluster", "127.0.0.1:9160");
}
public Database createDatabase(String keyspaceName) {
- KeyspaceDefinition ksDef = new ThriftKsDef(keyspaceName, "org.apache.cassandra.locator.SimpleStrategy", 1, null);
- cluster.addKeyspace(ksDef);
Database database = new CassandraDatabase(keyspaceName, cluster);
return database;
}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java b/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
index 117836ea1f..68862cb619 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
@@ -17,13 +17,27 @@ public class CassandraTest {
public static void main(String[] args){
CassandraTest test = new CassandraTest();
test.create();
- //test.delete();
+ test.delete();
}
public void create(){
Database db = session.createDatabase("TwitApp");
- //Group group1 = db.createGroup("twits");
- //Group group2 = db.createGroup("users");
+ Group group1 = db.createGroup("twits");
+
+ group1.addEntry("twitName1", "Here I am");
+ group1.addEntry("twitName2", "I am not here");
+ group1.addEntry("twitName3", "Sometimes");
+
+ Group group2 = db.createGroup("users");
+
+ group2.addEntry("userName1", "eranda");
+ group2.addEntry("userName2", "ishara");
+ group2.addEntry("userName3", "ravi");
+
+ group2.deleteEntry("userName3");
+ group2.updateEntry("userName2", "eranda");
+
+ System.out.println(group2.getValue("userName1"));
}
public void delete(){