Permalink
Browse files

New snapshot version with an upgrade to Objectify 4

  • Loading branch information...
1 parent 3f08e99 commit 536d3611ce69ddf559b4f4d3bfcea469d46b3976 @pbackx committed Dec 3, 2013
View
@@ -27,6 +27,13 @@ Build and run the example application
History
=======
+0.0.3-SNAPSHOT
+--------------
+
+Upgrade to Objectify 4.0rc2
+Minor upgrades for both Vaadin and AppEngine
+
+
0.0.2-SNAPSHOT
--------------
View
@@ -3,7 +3,7 @@
<parent>
<groupId>com.pow.paypal</groupId>
<artifactId>pow-paypal</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>0.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -38,13 +38,6 @@
</developer>
</developers>
- <repositories>
- <repository>
- <id>objectify-appengine</id>
- <url>http://objectify-appengine.googlecode.com/svn/maven</url>
- </repository>
- </repositories>
-
<dependencies>
<dependency>
<groupId>com.google.appengine</groupId>
@@ -72,15 +65,10 @@
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
- <version>3.0</version>
+ <version>4.0rc2</version>
</dependency>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-jpa_3.0_spec</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
@@ -15,10 +15,10 @@
*/
package com.streamhead.gae.paypal;
+import static com.googlecode.objectify.ObjectifyService.ofy;
+
import java.util.Date;
-import com.googlecode.objectify.ObjectifyService;
-import com.googlecode.objectify.Query;
import com.streamhead.gae.paypal.ipn.IPNMessage;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
@@ -86,8 +86,7 @@ public void init(VaadinRequest request) {
private void loadIPNMessages() {
ipnTable.removeAllItems();
- Query<IPNMessage> messages = ObjectifyService.begin().query(IPNMessage.class);
- for(IPNMessage m : messages)
+ for(IPNMessage m : ofy().load().type(IPNMessage.class).list())
{
ipnTable.addItem(new Object[] { m.getDate(), m.isValidated(), m.getTransactionType().toString() }, m);
}
@@ -19,30 +19,31 @@
import java.util.Date;
import java.util.Map;
-import javax.persistence.Id;
-
import com.google.appengine.api.datastore.Text;
+import com.googlecode.objectify.annotation.Entity;
+import com.googlecode.objectify.annotation.Id;
+import com.googlecode.objectify.annotation.Index;
import com.streamhead.gae.paypal.variable.PaymentStatus;
import com.streamhead.gae.paypal.variable.TransactionType;
+@Entity
public class IPNMessage implements Serializable {
- private static final long serialVersionUID = 2L;
+ private static final long serialVersionUID = 3L;
- @Id
- private Long id;
- private Date date = new Date();
- private boolean validated = false;
+ @Id private Long id;
+ @Index private Date date = new Date();
+ @Index private boolean validated = false;
private Text fullMessage;
- private TransactionType transactionType;
- private PaymentStatus paymentStatus;
- private String mcGross;
- private String mcCurrency;
- private String custom;
- private String itemNumber;
- private String txnId;
- private String subscrId;
- private String payerEmail;
+ @Index private TransactionType transactionType;
+ @Index private PaymentStatus paymentStatus;
+ @Index private String mcGross;
+ @Index private String mcCurrency;
+ @Index private String custom;
+ @Index private String itemNumber;
+ @Index private String txnId;
+ @Index private String subscrId;
+ @Index private String payerEmail;
private IPNMessage() { }
@@ -1,96 +0,0 @@
-package com.streamhead.gae.paypal.ipn;
-
-import java.util.ConcurrentModificationException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import com.googlecode.objectify.ObjectifyOpts;
-import com.googlecode.objectify.util.DAOBase;
-
-/**
- * This is a straight copy from
- * https://code.google.com/p/objectify-appengine/wiki
- * /BestPractices#Use_Pythonic_Transactions
- *
- * @author Peter
- *
- */
-public class IPNMessageDao extends DAOBase {
-
- private static final Logger log = Logger.getLogger(IPNMessageDao.class.getName());
-
- /** Alternate interface to Runnable for executing transactions */
- public static interface Transactable {
- void run(IPNMessageDao daot);
- }
-
- /**
- * Provides a place to put the result too. Note that the result is only
- * valid if the transaction completes successfully; otherwise it should be
- * ignored because it is not necessarily valid.
- */
- abstract public static class Transact<T> implements Transactable {
- protected T result;
-
- public T getResult() {
- return this.result;
- }
- }
-
- /** Create a default DAOT and run the transaction through it */
- public static void runInTransaction(Transactable t) {
- IPNMessageDao daot = new IPNMessageDao();
- daot.doTransaction(t);
- }
-
- /**
- * Run this task through transactions until it succeeds without an
- * optimistic concurrency failure.
- */
- public static void repeatInTransaction(Transactable t) {
- while (true) {
- try {
- runInTransaction(t);
- break;
- } catch (ConcurrentModificationException ex) {
- log.log(Level.WARNING, "Optimistic concurrency failure for " + t, ex);
- }
- }
- }
-
- /** Starts out with a transaction and session cache */
- public IPNMessageDao() {
- super(new ObjectifyOpts().setSessionCache(true).setBeginTransaction(true));
- }
-
- /** Adds transaction to whatever you pass in */
- public IPNMessageDao(ObjectifyOpts opts) {
- super(opts.setBeginTransaction(true));
- }
-
- /**
- * Executes the task in the transactional context of this DAO/ofy.
- */
- public void doTransaction(final Runnable task) {
- this.doTransaction(new Transactable() {
- @Override
- public void run(IPNMessageDao daot) {
- task.run();
- }
- });
- }
-
- /**
- * Executes the task in the transactional context of this DAO/ofy.
- */
- public void doTransaction(Transactable task) {
- try {
- task.run(this);
- ofy().getTxn().commit();
- } finally {
- if (ofy().getTxn().isActive())
- ofy().getTxn().rollback();
- }
- }
-
-}
@@ -1,5 +1,7 @@
package com.streamhead.gae.paypal.ipn;
+import static com.googlecode.objectify.ObjectifyService.ofy;
+
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -8,8 +10,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import com.googlecode.objectify.Objectify;
-import com.googlecode.objectify.ObjectifyService;
+import com.googlecode.objectify.Key;
public class IPNProcessingServlet extends IPNServlet {
@@ -29,8 +30,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
try {
final long id = Long.parseLong(idStr);
- final Objectify ofy = ObjectifyService.begin();
- final IPNMessage message = ofy.find(IPNMessage.class, id);
+ final IPNMessage message = ofy().load().key(Key.create(IPNMessage.class, id)).now();
//This is where your code goes to handle the IPN message
log.fine("now processing message with txn_id " + message.getTxnId());
@@ -20,6 +20,7 @@
package com.streamhead.gae.paypal.ipn;
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
+import static com.googlecode.objectify.ObjectifyService.ofy;
import java.io.IOException;
import java.util.HashMap;
@@ -33,6 +34,7 @@
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
+import com.googlecode.objectify.VoidWork;
public class IPNServlet extends HttpServlet {
@@ -52,11 +54,11 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
log.info("IPN received");
//store the unvalidated message
- final IPNMessage message = new IPNMessageParser(nvp(req), false).parse();
- IPNMessageDao.repeatInTransaction(new IPNMessageDao.Transactable() {
+ final IPNMessage message = new IPNMessageParser(nvp(req), false).parse();
+ ofy().transact(new VoidWork() {
@Override
- public void run(IPNMessageDao daot) {
- daot.ofy().put(message);
+ public void vrun() {
+ ofy().save().entities(message);
}
});
@@ -1,6 +1,7 @@
package com.streamhead.gae.paypal.ipn;
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
+import static com.googlecode.objectify.ObjectifyService.ofy;
import java.io.IOException;
import java.util.logging.Level;
@@ -12,8 +13,8 @@
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
-import com.googlecode.objectify.Objectify;
-import com.googlecode.objectify.ObjectifyService;
+import com.googlecode.objectify.Key;
+import com.googlecode.objectify.VoidWork;
import com.streamhead.gae.paypal.PayPalEnvironment;
public class IPNValidationServlet extends IPNServlet {
@@ -49,17 +50,16 @@ protected void doPost(final HttpServletRequest req, final HttpServletResponse re
try {
final long id = Long.parseLong(idStr);
- IPNMessageDao.repeatInTransaction(new IPNMessageDao.Transactable() {
+ ofy().transact(new VoidWork() {
@Override
- public void run(IPNMessageDao daot) {
- final IPNMessage message = daot.ofy().find(IPNMessage.class, id);
+ public void vrun() {
+ final IPNMessage message = ofy().load().key(Key.create(IPNMessage.class, id)).now();
// Check for duplicate txn_id
// We can't do this non-ancestor query inside the transaction, so this isn't 100% safe
// If you know of a way to fix this, please let me know
if(message.getTxnId() != null && !"".equals(message.getTxnId())) {
- Objectify ofyNoTxn = ObjectifyService.begin();
- final int count = ofyNoTxn.query(IPNMessage.class).filter("txnId", message.getTxnId()).count();
+ final int count = ofy().transactionless().load().type(IPNMessage.class).filter("txnId", message.getTxnId()).count();
if(count > 1) {
log.severe("duplicate message found with txn_id " + message.getTxnId());
resp.setStatus(204); // return in range of 2xx so AppEngine doesn't retry
@@ -72,12 +72,12 @@ public void run(IPNMessageDao daot) {
if(validation.validate(environment)) {
message.setValidated(true);
- daot.ofy().put(message);
+ ofy().save().entity(message);
//add to queue for final processing
Queue queue = QueueFactory.getQueue("paypal");
queue.add(withUrl(processingTask).param("id", String.valueOf(message.getId())));
- }
+ }
}
});
} catch (NumberFormatException e) {
View
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.pow.paypal</groupId>
<artifactId>pow-paypal</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>0.0.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Powered by Reindeer PayPal IPN integration project</name>
<description>Powered by Reindeer is a high-level application framework integrating
@@ -40,8 +40,8 @@
</parent>
<properties>
- <vaadin.version>7.1.2</vaadin.version>
- <gae.version>1.8.3</gae.version>
+ <vaadin.version>7.1.8</vaadin.version>
+ <gae.version>1.8.8</gae.version>
</properties>
<modules>
View
@@ -3,7 +3,7 @@
<parent>
<groupId>com.pow.paypal</groupId>
<artifactId>pow-paypal</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>0.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -16,6 +16,15 @@
<listener-class>com.streamhead.gae.paypal.ipn.IPNContextListener</listener-class>
</listener>
+ <filter>
+ <filter-name>ObjectifyFilter</filter-name>
+ <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ObjectifyFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
<servlet>
<servlet-name>IPNServlet</servlet-name>
<servlet-class>com.streamhead.gae.paypal.ipn.IPNServlet</servlet-class>

0 comments on commit 536d361

Please sign in to comment.