summaryrefslogtreecommitdiffstats
path: root/sandbox/rfeng/helloworld-jsp-google-appengine
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-10 06:16:46 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-10-10 06:16:46 +0000
commitb7878fb9752f9fdd41449e44743a87534ece73ce (patch)
tree7fc4e2a93ee70d8d8c9a2eb46a555b7cbc602c53 /sandbox/rfeng/helloworld-jsp-google-appengine
parentf0d916a6263878537dde5f76922c6d24913885e2 (diff)
Add calls to Datastore service
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@823799 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/rfeng/helloworld-jsp-google-appengine')
-rw-r--r--sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java29
-rw-r--r--sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite1
-rw-r--r--sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp3
3 files changed, 32 insertions, 1 deletions
diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
index d7867c6a45..4257fea3b1 100644
--- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
+++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
@@ -29,6 +29,12 @@ import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Scope;
import org.oasisopen.sca.annotation.Service;
+import com.google.appengine.api.datastore.DatastoreService;
+import com.google.appengine.api.datastore.Entity;
+import com.google.appengine.api.datastore.EntityNotFoundException;
+import com.google.appengine.api.datastore.Key;
+import com.google.appengine.api.datastore.KeyFactory;
+import com.google.appengine.api.datastore.Transaction;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
@@ -48,6 +54,9 @@ public class HelloworldServiceImpl implements HelloworldService {
@Reference
protected MemcacheService memcacheService;
+ @Reference
+ protected DatastoreService datastoreService;
+
public String sayHello(String name) {
User user = userService.getCurrentUser();
String id = (user == null) ? "" : user.getUserId();
@@ -59,6 +68,22 @@ public class HelloworldServiceImpl implements HelloworldService {
stack.push(new Date().toString() + ": " + name);
memcacheService.put("history", stack);
+ Transaction tx = datastoreService.beginTransaction();
+ Entity entity = null;
+ Key key = KeyFactory.createKey("HitCounter", "countter");
+ try {
+ entity = datastoreService.get(tx, key);
+ } catch (EntityNotFoundException e1) {
+ entity = new Entity(key);
+ entity.setProperty("counter", new Long(0));
+ }
+
+ Long count = (Long)entity.getProperty("counter");
+ entity.setProperty("counter", new Long(count.longValue() + 1));
+
+ datastoreService.put(tx, entity);
+ tx.commit();
+
String content = "";
try {
HTTPResponse response = fetchService.fetch(new URL("http://tuscany.apache.org"));
@@ -76,7 +101,9 @@ public class HelloworldServiceImpl implements HelloworldService {
+ content
+ "<p>History<hr>"
+ stack
- + "</p>";
+ + "</p><b>"
+ + count
+ + "</b>";
}
@Init
diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
index e7f05bb67b..b0c0de7ebc 100644
--- a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
+++ b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
@@ -25,6 +25,7 @@
<reference name="userService" target="UserService"/>
<reference name="fetchService" target="URLFetchService"/>
<reference name="memcacheService" target="MemcacheService"/>
+ <reference name="datastoreService" target="DatastoreService"/>
</component>
<component name="UserService">
diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp b/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
index f4d9b937ca..c0bdf0d91e 100644
--- a/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
+++ b/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
@@ -53,5 +53,8 @@ in</a> to include your name with greetings you post.</p>
Calling HelloworldService sayHello("world, "+$user) returns:
<p><%=service.sayHello("world ("+user+")")%>
+<form action="hello.jsp" method="get">
+ <input type="submit" value="Try Again">
+</form>
</body>
</html>