summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Eranda/couchdb
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration/GSoC-2011-Eranda/couchdb')
-rw-r--r--collaboration/GSoC-2011-Eranda/couchdb/pom.xml16
-rw-r--r--collaboration/GSoC-2011-Eranda/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java67
-rw-r--r--collaboration/GSoC-2011-Eranda/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java71
-rw-r--r--collaboration/GSoC-2011-Eranda/couchdb/src/main/resources/META-INF/sca-contribution.xml7
-rw-r--r--collaboration/GSoC-2011-Eranda/couchdb/src/main/resources/datastore.composite16
5 files changed, 176 insertions, 1 deletions
diff --git a/collaboration/GSoC-2011-Eranda/couchdb/pom.xml b/collaboration/GSoC-2011-Eranda/couchdb/pom.xml
index 32c17907ad..4e3aff6542 100644
--- a/collaboration/GSoC-2011-Eranda/couchdb/pom.xml
+++ b/collaboration/GSoC-2011-Eranda/couchdb/pom.xml
@@ -30,13 +30,27 @@ under the License.
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <jcouchdb.version>0.10.0-1</jcouchdb.version>
+ <tuscany.version>2.0-M5</tuscany.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.jcouchdb</groupId>
<artifactId>jcouchdb</artifactId>
- <version>0.10.0-1</version>
+ <version>${jcouchdb.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>
diff --git a/collaboration/GSoC-2011-Eranda/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java b/collaboration/GSoC-2011-Eranda/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreService.java
new file mode 100644
index 0000000000..e63fb16bf5
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/couchdb/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/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java b/collaboration/GSoC-2011-Eranda/couchdb/src/main/java/org/apache/tuscany/nosqldatastore/DatastoreServiceImpl.java
new file mode 100644
index 0000000000..a153f0ce0f
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/couchdb/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()).getCouchDBSession();
+ }
+
+ 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/couchdb/src/main/resources/META-INF/sca-contribution.xml b/collaboration/GSoC-2011-Eranda/couchdb/src/main/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..b9960d1bac
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/couchdb/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/couchdb/src/main/resources/datastore.composite b/collaboration/GSoC-2011-Eranda/couchdb/src/main/resources/datastore.composite
new file mode 100644
index 0000000000..bf67ad5eee
--- /dev/null
+++ b/collaboration/GSoC-2011-Eranda/couchdb/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>