You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by cj...@apache.org on 2007/10/05 16:42:41 UTC
svn commit: r582290 -
/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java
Author: cjblythe
Date: Fri Oct 5 07:42:37 2007
New Revision: 582290
URL: http://svn.apache.org/viewvc?rev=582290&view=rev
Log:
DAYTRADER-56 Updated TradeSLSBBean to handle duplicate register gracefully
Modified:
geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java
Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java?rev=582290&r1=582289&r2=582290&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java (original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/ejb3/TradeSLSBBean.java Fri Oct 5 07:42:37 2007
@@ -538,21 +538,36 @@
AccountProfileDataBean profile = entityManager.find(AccountProfileDataBean.class, userID);
AccountDataBean account = profile.getAccount();
+ account.logout();
+
if (Log.doTrace())
Log.trace("TradeSLSBBean:logout(" + userID + ") success");
- account.logout();
}
public AccountDataBean register(String userID, String password, String fullname, String address, String email, String creditcard, BigDecimal openBalance) {
- AccountDataBean account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID);
- AccountProfileDataBean profile = new AccountProfileDataBean(userID, password, fullname, address, email, creditcard);
- account.setProfile(profile);
- // are both of these necessary?
- profile.setAccount(account);
- // this should save the linked profile as well?
- entityManager.persist(account);
- // apparently doesn't??
- entityManager.persist(profile);
+ AccountDataBean account = null;
+ AccountProfileDataBean profile = null;
+
+ if (Log.doTrace())
+ Log.trace("TradeSLSBBean:register", userID, password, fullname, address, email, creditcard, openBalance);
+
+ // Check to see if a profile with the desired userID already exists
+ profile = entityManager.find(AccountProfileDataBean.class, userID);
+
+ if (profile != null) {
+ Log.error("Failed to register new Account - AccountProfile with userID(" + userID + ") already exists");
+ return null;
+ } else {
+ profile = new AccountProfileDataBean(userID, password, fullname, address, email, creditcard);
+ account = new AccountDataBean(0, 0, null, new Timestamp(System.currentTimeMillis()), openBalance, openBalance, userID);
+
+ profile.setAccount(account);
+ account.setProfile(profile);
+
+ entityManager.persist(profile);
+ entityManager.persist(account);
+ }
+
return account;
}