tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1130304 - in /tuscany/collaboration/GSoC-2011-Eranda/cassandra/src: main/java/org/apache/tuscany/nosqldatastore/ main/java/org/apache/tuscany/nosqldatastore/cassandra/ test/java/org/apache/tuscany/nosqldatastore/cassandra/
Date Wed, 01 Jun 2011 21:10:35 GMT
Author: antelder
Date: Wed Jun  1 21:10:34 2011
New Revision: 1130304

URL: http://svn.apache.org/viewvc?rev=1130304&view=rev
Log:
TUSCANY-3522: Apply rest-api-1.2.patch from Eranda for the NoSQL GSoC project

Modified:
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
    tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Database.java
Wed Jun  1 21:10:34 2011
@@ -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);
 }

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/Group.java
Wed Jun  1 21:10:34 2011
@@ -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);
 }

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraDatabase.java
Wed Jun  1 21:10:34 2011
@@ -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);
 	}
 
 }

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java
Wed Jun  1 21:10:34 2011
@@ -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);
 	}
 
 }

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
Wed Jun  1 21:10:34 2011
@@ -3,23 +3,22 @@ package org.apache.tuscany.nosqldatastor
 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;
 	}

Modified: tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java?rev=1130304&r1=1130303&r2=1130304&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
(original)
+++ tuscany/collaboration/GSoC-2011-Eranda/cassandra/src/test/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraTest.java
Wed Jun  1 21:10:34 2011
@@ -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(){



Mime
View raw message