Yes, the exception gets thrown in the addAccount method. This is where
I first invoke a jdo call. Here is the code for this method:
public UserAccount addAccount(UserAccount account) throws
ServiceException {
xLogger.info("addAccount: entered");
boolean userExists = false;
//Assuming that all other fields including registeredBy is set
by
the calling function
//TODO: Encrypt the password before storing to the database
//Set the memberSince and lastLogin timestamp to now
Date now = new Date();
account.setTimeStamp(now);
account.setMemberSince(now);
//Create the key for the useraccount object
Key k = KeyFactory.createKey(UserAccount.class.getSimpleName(),
account.getUserId());
account.setKey(k);
PersistenceManager pm = PMF.get().getPersistenceManager();
//We use an atomic transaction here to check if the user already
exists, and if not, create it
Transaction tx = pm.currentTransaction();
try {
tx.begin();
try {
//First check if the user already exists in the
database
@SuppressWarnings("unused")
UserAccount user =
pm.getObjectById(UserAccount.class,
account.getUserId());
//If we get here, it means the user exists
userExists = true;
} catch (JDOObjectNotFoundException e) {
pm.makePersistent(account);
} catch (Exception e) {
e.printStackTrace();
}
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
if (userExists == true) {
throw new ServiceException("addAccount: Failed.
User already
exists");
}
return account;
}
}
Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---