summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
diff options
context:
space:
mode:
authoreranda <eranda@13f79535-47bb-0310-9956-ffa450edef68>2011-07-09 09:02:32 +0000
committereranda <eranda@13f79535-47bb-0310-9956-ffa450edef68>2011-07-09 09:02:32 +0000
commit611747a6fea6b03c16d955af639d101319cf0b7f (patch)
tree314c6e820ba60d23fe00e9e44fad7cd5bf7c3fa9 /collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java
parent800d0da7d863cc75004b9e034646d457156edf97 (diff)
1. Remove static variable in SessionFactory
2. Set spaces to 4 3. Exception handling 4. Rename *Test to *TestCase 5. Convert test cases in to JUnit 6. Rename addValue() method in Group.java to addEntry() 7. Updated the addEntry method signature to accept String type only git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1144620 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java')
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraSession.java57
1 files changed, 36 insertions, 21 deletions
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 7a9faf7b43..186d9f8d1a 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
@@ -20,31 +20,46 @@ package org.apache.tuscany.nosqldatastore.cassandra;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
+import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;
import org.apache.tuscany.nosqldatastore.Database;
import org.apache.tuscany.nosqldatastore.Session;
+import org.apache.tuscany.nosqldatastore.exception.DatabaseNotFoundException;
+import org.apache.tuscany.nosqldatastore.exception.GroupNotFoundException;
+import org.apache.tuscany.nosqldatastore.exception.SessionException;
public class CassandraSession implements Session {
-
- private CassandraHostConfigurator cassandraHostConfigurator;
- private Cluster cluster;
-
- public CassandraSession(String clusterName) {
- cluster = HFactory.getOrCreateCluster("Test Cluster", "127.0.0.1:9160");
- }
-
- public Database createDatabase(String keyspaceName) {
- Database database = new CassandraDatabase(keyspaceName, cluster);
- return database;
- }
-
- public Database getDatabase(String keyspaceName) {
- Database database = new CassandraDatabase(keyspaceName, cluster);
- return database;
- }
-
- public void deleteDatabase(String keyspaceName) {
- cluster.dropKeyspace(keyspaceName);
- }
+
+ private CassandraHostConfigurator cassandraHostConfigurator;
+ private Cluster cluster;
+
+ public CassandraSession(String clusterName) {
+ cluster = HFactory.getOrCreateCluster("Test Cluster", "127.0.0.1:9160");
+ }
+
+ public Database createDatabase(String databaseName) throws SessionException {
+ Database database = null;
+ try{
+ database = new CassandraDatabase(databaseName, cluster);
+ } catch (HectorException e){
+ throw new SessionException("Session error");
+ }
+ return database;
+ }
+
+ public Database getDatabase(String databaseName) throws SessionException {
+ return createDatabase(databaseName);
+ }
+
+ public void deleteDatabase(String databaseName) throws DatabaseNotFoundException, SessionException {
+ try{
+ cluster.dropKeyspace(databaseName);
+ } catch(HInvalidRequestException e){
+ throw new DatabaseNotFoundException("Database "+databaseName+" not found");
+ } catch (HectorException e){
+ throw new SessionException("Session error");
+ }
+ }
}