summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Eranda/cassandra
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration/GSoC-2011-Eranda/cassandra')
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/pom.xml29
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java67
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java71
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/META-INF/sca-contribution.xml7
-rw-r--r--collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/datastore.composite16
5 files changed, 182 insertions, 8 deletions
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/pom.xml b/collaboration/GSoC-2011-Eranda/cassandra/pom.xml
index 1194cdfd26..bc74631d4e 100644
--- a/collaboration/GSoC-2011-Eranda/cassandra/pom.xml
+++ b/collaboration/GSoC-2011-Eranda/cassandra/pom.xml
@@ -22,39 +22,52 @@ under the License.
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tuscany</groupId>
- <artifactId>nosql-datastore</artifactId>
+ <artifactId>nosql-datastore-cassandra</artifactId>
<version>0.0.1</version>
-
<packaging>jar</packaging>
<name>tuscany</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <cassandra.version>0.7.1</cassandra.version>
+ <hector.version>0.7.0-29</hector.version>
+ <tuscany.version>2.0-M5</tuscany.version>
</properties>
-
<dependencies>
<dependency>
<groupId>me.prettyprint</groupId>
<artifactId>hector-core</artifactId>
- <version>0.7.0-29</version>
+ <version>${hector.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-javautils</artifactId>
- <version>0.7.1</version>
+ <version>${cassandra.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
- <version>0.7.4</version>
+ <version>${cassandra.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>${tuscany.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>1.1.1</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.8.2</version>
+ <version>4.8.1</version>
+ <scope>test</scope>
</dependency>
</dependencies>
-
<build>
<plugins>
<plugin>
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java
new file mode 100644
index 0000000000..e63fb16bf5
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.nosqldatastore;
+
+import org.apache.tuscany.nosqldatastore.exception.*;
+import org.oasisopen.sca.annotation.Remotable;
+
+import javax.ws.rs.*;
+
+@Remotable
+public interface DatastoreService {
+
+ @GET
+ @Path("echoTest")
+ String echoTest(@QueryParam("database") String database);
+
+ @POST
+ @Path("addEntry")
+ void addEntry(@QueryParam("database") String database,
+ @QueryParam("group") String group,
+ @QueryParam("key") String key,
+ @QueryParam("value") String value) throws DuplicateEntryException, SessionException;
+
+ @POST
+ @Path("updateEntry")
+ void updateEntry(@QueryParam("database") String database,
+ @QueryParam("group") String group,
+ @QueryParam("key") String key,
+ @QueryParam("value") String value) throws EntryNotFoundException, SessionException;
+
+ @POST
+ @Path("deleteEntry")
+ void deleteEntry(@QueryParam("database") String database,
+ @QueryParam("group") String group,
+ @QueryParam("key") String key) throws EntryNotFoundException, SessionException;
+
+ @GET
+ @Path("getEntry")
+ String getEntry(@QueryParam("database") String database,
+ @QueryParam("group") String group,
+ @QueryParam("key") String key) throws EntryNotFoundException, SessionException;
+
+ @DELETE
+ @Path("deleteGroup")
+ void deleteGroup(@QueryParam("database") String database,
+ @QueryParam("group") String group) throws GroupNotFoundException, SessionException;
+
+ @DELETE
+ @Path("deleteDatabase")
+ void deleteDatabase(@QueryParam("database") String database) throws DatabaseNotFoundException, SessionException;
+}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java
new file mode 100644
index 0000000000..6c63f74cef
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.nosqldatastore;
+
+import org.apache.tuscany.nosqldatastore.exception.*;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class DatastoreServiceImpl implements DatastoreService{
+
+ private Session session;
+
+ @Init
+ public void init(){
+ session = (new SessionFactory()).getCassandraSession();
+ }
+
+ public String echoTest(String database){
+ return "Database "+database;
+ }
+
+ public void addEntry(String database, String group, String key, String value) throws DuplicateEntryException, SessionException {
+ Database db = session.getDatabase(database);
+ Group grp = db.getGroup(group);
+ grp.addEntry(key, value);
+ }
+
+ public void updateEntry(String database, String group, String key, String value) throws EntryNotFoundException, SessionException {
+ Database db = session.getDatabase(database);
+ Group grp = db.getGroup(group);
+ grp.updateEntry(key, value);
+ }
+
+ public void deleteEntry(String database, String group, String key) throws EntryNotFoundException, SessionException {
+ Database db = session.getDatabase(database);
+ Group grp = db.getGroup(group);
+ grp.deleteEntry(key);
+ }
+
+ public String getEntry(String database, String group, String key) throws EntryNotFoundException, SessionException {
+ Database db = session.getDatabase(database);
+ Group grp = db.getGroup(group);
+ return grp.getEntry(key);
+ }
+
+ public void deleteGroup(String database, String group) throws GroupNotFoundException, SessionException {
+ Database db = session.getDatabase(database);
+ db.deleteGroup(group);
+ }
+
+ public void deleteDatabase(String database) throws DatabaseNotFoundException, SessionException {
+ session.deleteDatabase(database);
+ }
+}
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/META-INF/sca-contribution.xml b/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..b9960d1bac
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:datastore="http://datastore">
+
+ <deployable composite="datastore:datastore-contribution" />
+
+</contribution>
diff --git a/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/datastore.composite b/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/datastore.composite
new file mode 100644
index 0000000000..bf67ad5eee
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/cassandra/src/main/resources/datastore.composite
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://datastore"
+ name="datastore-contribution">
+ <component name="DatastoreComponent">
+ <implementation.java class="org.apache.tuscany.nosqldatastore.DatastoreServiceImpl"/>
+ <service name="DatastoreService">
+ <interface.java interface="org.apache.tuscany.nosqldatastore.DatastoreService"/>
+ <tuscany:binding.rest uri="http://localhost:8085/DatastoreService">
+ <tuscany:wireFormat.json/>
+ <tuscany:operationSelector.jaxrs/>
+ </tuscany:binding.rest>
+ </service>
+ </component>
+</composite>