Transaction to find an entity - locks all entities of that type?
        Posted  
        
            by user246114
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user246114
        
        
        
        Published on 2010-04-29T04:52:16Z
        Indexed on 
            2010/04/29
            4:57 UTC
        
        
        Read the original article
        Hit count: 325
        
google-app-engine
Hi,
Reading the docs for transactions:
http://code.google.com/appengine/docs/java/datastore/transactions.html
An example provided shows one way to make an instance of an object:
try {
    tx.begin();
    Key k = KeyFactory.createKey("SalesAccount", id);
    try {
        account = pm.getObjectById(Employee.class, k);
    } catch (JDOObjectNotFoundException e) {
        account = new SalesAccount();
        account.setId(id);
    }
    ...
When the above transaction gets executed, it will probably block all other write attempts on Account objects? I'm wondering because I'd like to have a user signup which checks for a username or email already in use:
tx.begin();
"select from User where mUsername == str1 LIMIT 1";
if (count > 0) {
    throw new Exception("username already in use!");
}
"select from User where mEmail == str1 LIMIT 1";
if (count > 0) {
    throw new Exception("email already in use!");
}
pm.makePersistent(user(username, email)); // ok.
tx.commit();
but the above would be even more time consuming I think, making an even worse bottleneck? Am I understanding what will happen correctly?
Thanks
© Stack Overflow or respective owner