When a user logs in a new channel is created, and I add an entity of
kind "ChannelClient" to datastore and store the token.
When the user logs in again or refreshes the page, it should check the
datastore to see if the ChannelClient entity exists. If it does, it
uses that token. If it doesn't, then it creates a new channel and new
ChannelClient entity with corresponding channel token.
However, every time I refresh the JSP page it creates a new channel,
instead of seeing the existing ChannelClient entity in the datastore
and using the token in there.
Here is my code:
Key k = KeyFactory.createKey("ChannelClient",
user.getNickname());
Transaction tx = datastore.beginTransaction();
try {
// if a ChannelClient entity is found.... save token
from that
entity
client = datastore.get(k);
token = (String) client.getProperty("token");
out.println("channel client exists with token: " +
token);
}
catch (EntityNotFoundException e) {
// if not...create a new channel
ChannelService channelService =
ChannelServiceFactory.getChannelService();
token =
channelService.createChannel(user.getNickname());
out.println("creating channel...");
// ...and save token in ChannelClient entity
client = new Entity("ChannelClient",
user.getNickname());
client.setProperty("token", token);
datastore.put(client);
out.println("created entity with token: " + token);
}
finally {
tx.commit();
}
--
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.