java - Google App Engine Datastore too slow persistence -
i'm developing gae/j app using jdo manage datastore. offers number of endpoints interact data , on. i'm developing javascript client endpoints.
situation:
first have endpoint method token getsessiontoken(user usr)
, generates session token, assigns user , stores both user , session token in datastore.
then have endpoint method info getinfo(token token)
receives session token, checks if session token corresponds user , if so, returns info.
problem
from javascript client, call first method , fine. call second method retreved session token, , receive error saying session token doesn't correspond user...
i've checked , realised error happens because new session token has not been persisted yet!
question
my current solution make javascript client call second method once, , if receives error, wait while , call again... there better solution?
edit:
this code invloved in first method call idea why takes long...
endpoint:
@apimethod( name = "getsessiontoken", path = "get_session_token", httpmethod = httpmethod.get ) public sessiontoken getsessiontoken (@named("email") string email, @named("password") string password) throws internalservererrorexception { sessiontoken sessiontoken = new userscontroller().getsessiontoken(email, password); return sessiontoken; }
control:
public sessiontoken getsessiontoken(string email, string password) throws internalservererrorexception { sessiontoken sessiontoken = null; persistencemanager pm = pmf.get().getpersistencemanager(); transaction txn = datastoreservicefactory.getdatastoreservice().begintransaction(); try { dao dao = new dao(pm); user user = dao.getuserbylogin(email, password); dao.deletesessiontoken(user.getsessiontoken()); sessiontoken = sessiontokenmanager.generatetoken(user.getemail(), user.getpassword()); user.setsessiontoken(sessiontoken); user = dao.insertuser(user); txn.commit(); } catch (exception e) { throw new internalservererrorexception(); } { if (txn.isactive()) { txn.rollback(); } pm.close(); } return sessiontoken; }
dao:
public user getuserbylogin(string email, string password) throws internalservererrorexception { user user = null; query query = null; try { query = this.pm.newquery(user.class); query.setfilter("email == emailparam && password == passwordparam"); query.declareparameters("string emailparam, string passwordparam"); list<user> results = (list<user>) query.execute(email, password); user = results.get(0); } catch (exception e) { e.printstacktrace(); throw new internalservererrorexception("error in dao.getuserbylogin()"); } { query.closeall(); } return user; } ///// public void deletesessiontoken(sessiontoken sessiontoken) throws internalservererrorexception { try { this.pm.deletepersistent(sessiontoken); } catch (exception e) { e.printstacktrace(); throw new internalservererrorexception("error in dao.deletesessiontoken()"); } } ///// public user insertuser(user user) throws internalservererrorexception { try { this.pm.makepersistent(user); } catch (exception e) { e.printstacktrace(); throw new internalservererrorexception("error in dao.insertuser()", e); } return user; }
model:
@persistencecapable public class user { @primarykey @persistent(valuestrategy = idgeneratorstrategy.identity) private key key; @persistent private string name; @persistent private string email; @persistent private string password; @persistent private folder rootfolder; @persistent private sessiontoken sessiontoken; @persistent(defaultfetchgroup = "true") private accountcontainer accountcontainer; //getters & setters } ///// @persistencecapable public class sessiontoken { @primarykey @persistent(valuestrategy = idgeneratorstrategy.identity) private key key; @persistent private string token; @persistent private long created; @persistent private string sha1; //getters & setters }
maybe 1 of following possible , suits needs
can combine 2 calls "getsessiontokenandinfo" call? return token , info together. depending how code works maybe token , user objects available , dont need loaded then?
use form of caching first endpoint leaves in memcache need try retreive datastore in second call removed (at least in cases memcache should reliable enough such scenario).
Comments
Post a Comment