Author: rfeng
Date: Sat Oct 10 06:16:46 2009
New Revision: 823799
URL: http://svn.apache.org/viewvc?rev=823799&view=rev
Log:
Add calls to Datastore service
Modified:
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
Modified:
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java?rev=823799&r1=823798&r2=823799&view=diff
==============================================================================
---
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
(original)
+++
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java
Sat Oct 10 06:16:46 2009
@@ -29,6 +29,12 @@
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 @@
@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 @@
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 @@
+ content
+ "<p>History<hr>"
+ stack
- + "</p>";
+ + "</p><b>"
+ + count
+ + "</b>";
}
@Init
Modified:
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
URL:
http://svn.apache.org/viewvc/tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite?rev=823799&r1=823798&r2=823799&view=diff
==============================================================================
---
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
(original)
+++
tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite
Sat Oct 10 06:16:46 2009
@@ -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">
Modified: tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
URL:
http://svn.apache.org/viewvc/tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp?rev=823799&r1=823798&r2=823799&view=diff
==============================================================================
--- tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp
(original)
+++ tuscany/sandbox/rfeng/helloworld-jsp-google-appengine/war/hello.jsp Sat Oct
10 06:16:46 2009
@@ -53,5 +53,8 @@
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>