summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.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/CassandraGroup.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/CassandraGroup.java')
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/cassandra/CassandraGroup.java62
1 files changed, 43 insertions, 19 deletions
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 3b29399e3e..30ab8698b4 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
@@ -29,6 +29,8 @@ 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;
+import org.apache.tuscany.nosqldatastore.exception.DuplicateEntryException;
+import org.apache.tuscany.nosqldatastore.exception.EntryNotFoundException;
class CassandraGroup implements Group {
@@ -36,35 +38,57 @@ class CassandraGroup implements Group {
private ColumnFamilyUpdater<String, String> updater;
private final StringSerializer se = StringSerializer.get();
- CassandraGroup(String groupId, Keyspace keyspace, Cluster cluster) {
+ CassandraGroup(String groupId, Keyspace keyspace, Cluster cluster) {
try{
- ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition(keyspace.getKeyspaceName(), groupId);
- cluster.addColumnFamily(cfDef);
+ 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) {
- updater = template.createUpdater(key);
- updater.setString(key, (String) value);
- template.update(updater);
- template.addColumn(key, se);
- }
+ public void addEntry(String key, String value) throws DuplicateEntryException {
+ ColumnFamilyResult wrapper = template.queryColumns(key);
+ if(wrapper.getString(key) == null){
+ updater = template.createUpdater(key);
+ updater.setString(key, value);
+ template.update(updater);
+ template.addColumn(key, se);
+ return;
+ }
+ throw new DuplicateEntryException("Entry already exist for key "+key);
+ }
- public void deleteEntry(String key) {
- template.deleteColumn(key, key);
-
- }
+ public void deleteEntry(String key) throws EntryNotFoundException {
+ ColumnFamilyResult wrapper = template.queryColumns(key);
+ if(wrapper.getString(key) != null){
+ template.deleteColumn(key, key);
+ return;
+ }
+ throw new EntryNotFoundException("Entry does not exist for key "+key);
+ }
- public Object getValue(String key) {
+ public String getEntry(String key) throws EntryNotFoundException {
ColumnFamilyResult wrapper = template.queryColumns(key);
- return wrapper.getString(key);
+ String entry = wrapper.getString(key);
+ if(entry != null){
+ return entry;
+ }
+ throw new EntryNotFoundException("Entry does not exist for key "+key);
+
}
- public void updateEntry(String key, Object value) {
- addEntry(key, value);
- }
+ public void updateEntry(String key, String value) throws EntryNotFoundException {
+ ColumnFamilyResult wrapper = template.queryColumns(key);
+ if(wrapper.getString(key) != null){
+ updater = template.createUpdater(key);
+ updater.setString(key, value);
+ template.update(updater);
+ template.addColumn(key, se);
+ return;
+ }
+ throw new EntryNotFoundException("Entry does not exist for key "+key);
+ }
}