Ok, I actually read that article before but somehow didnt think it
would apply to me... Now I am using a counter object which I am
retrieving by id, and trying to increment a value in an array by 1 and
then just referencing that counter object to retrieve the values
(instead of creating a new Vote object every time there is a vote)
What I am experiencing now is that the integer in the array is not
being incremented. It increments but then when I submit a new vote,
retrieve the counter by poll_id, and read the value in the array, it is
mysteriously back to its original value of zero.
Its like its not being persistent, I am calling
pm.makePersistent(counter) after incrementing, is there any
known "gotchas" to incrementing an object or maintaining persistence?
Attached is my counter object and vote(int answerId) is the method I am
calling to increment the value in the array...
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.
package net.creativelift.snappypoll;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Counter
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String poll_id;
@Persistent
private int[] answers;
public Counter(String poll_id, int[] answers)
{
this.poll_id = poll_id;
this.answers = answers;
}
public Key getKey()
{
return key;
}
public int[] getAnswers()
{
return answers;
}
public String getPollId()
{
return poll_id;
}
public void setPollId(String poll_id)
{
this.poll_id = poll_id;
}
public int getVote(Integer answerId)
{
return answers[answerId];
}
public int vote(int answerId)
{
answers[answerId] += 1;
return answers[answerId];
}
}