0

I have been trying solutions from multiple threads but of no luck yet.

Anyone who can get a quick harp on what is happening in by code? I have shared my update code below. Appreciate quick assistance.

@ApiMethod(name="updateContact", path = "updateContact", httpMethod = "GET")
public OpinionModel updateEmployeeTitle(@Named("id") Long id,@Named("selectedOpinionIndex") int opinionIndex) {

    PersistenceManager pm = PMF.get().getPersistenceManager();
    javax.jdo.Transaction tx =  pm.currentTransaction();
    pm.currentTransaction().begin(); // <-------

    OpinionModel e;

    try {
        e = pm.getObjectById(OpinionModel.class,id);

        if (opinionIndex == 1) {
            int foo = Integer.parseInt(e.opinion1ResultCount);
            foo++;
            e.opinion1ResultCount = Integer.toString(foo);
            JDOHelper.makeDirty(e, e.opinion1ResultCount);

        }else if (opinionIndex == 2) {

            int foo = Integer.parseInt(e.opinion2ResultCount);
            foo++;
            e.opinion2ResultCount = Integer.toString(foo);
            JDOHelper.makeDirty(e, e.opinion2ResultCount);

        }
        else if (opinionIndex == 3) {

            int foo = Integer.parseInt(e.opinion3ResultCount);
            foo++;
            e.opinion3ResultCount = Integer.toString(foo);
            JDOHelper.makeDirty(e, e.opinion3ResultCount);

        }
        else if (opinionIndex == 4) {

            int foo = Integer.parseInt(e.opinion4ResultCount);
            foo++;
            e.opinion4ResultCount = Integer.toString(foo);
            JDOHelper.makeDirty(e, e.opinion4ResultCount);
        }
        else {
            System.out.println("Invalid selection");
        }

        pm.currentTransaction().commit(); // <-------
        pm.makePersistent(e);

    } finally {

        if (tx.isActive())
        {
            // Error occurred so rollback the transaction
            tx.rollback();
        }

        pm.close();
    }

    ApiResponse resp = new ApiResponse();
    resp.responsecode = "SUCCESS";
    resp.responseMessage = "Contact Updated ";

    return e;
}
thatzprem
  • 4,697
  • 1
  • 33
  • 41
  • updating public fields ? What century is this?. Use setters to update fields. You don't refer to what the log says when you do this, do we have to guess? – Neil Stockton Dec 09 '14 at 18:49
  • @NeilStockton It's 2014. Only old geezers use setters. The same people that make java look bad. – Peter Knego Dec 09 '14 at 19:51

0 Answers0