Package com.motomapia.action

Source Code of com.motomapia.action.TxnTest

/*
*/

package com.motomapia.action;

import static com.motomapia.OfyService.ofy;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import lombok.extern.slf4j.Slf4j;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.TxnType;
import com.motomapia.entity.Person;
import com.motomapia.util.txn.Transact;

/**
* Test out some odd issues with the @Transact code
*/
@Path("/txntest")
@Slf4j
public class TxnTest
{
  /**
   */
  @GET
  @Path("/{id}")
  @Produces(MediaType.APPLICATION_JSON)
  public Person update(@PathParam("id") long id, @QueryParam("id2") @DefaultValue("4") long id2) {
    return update(Key.create(Person.class, id), id2);
  }

  /**
   * Transactionally update arbitrary field in person
   */
  @Transact(TxnType.REQUIRED)
  Person update(Key<Person> key, long id2) {
    ofy().transactionless().load().type(Person.class).id(id2).now();

    Person pers = ofy().load().key(key).now();
    pers.loggedIn();
    ofy().save().entity(pers);

    log.debug("Last login date is now " + pers.getLastLogin());
    return pers;
  }
}
TOP

Related Classes of com.motomapia.action.TxnTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.