public User createUser() { User user = new User(); user.setId("u" + System.currentTimeMillis()); return user; }
public User store(User user) { UserRecord record = getEntityManager().find(UserRecord.class, user.getId()); try { getEntityManager().getTransaction().begin(); if (record != null) { user.setStatusCode(IUsersManager.STATUS_ERROR); user.setStatus(user.getId() + " 使用者帳號已存在!"); } else { record = new UserRecord(); record.setUserId(user.getId()); record.setPassword(user.getPassword()); record = parseParameters(record, user.getTicket()); getEntityManager().persist(record); user.setStatusCode(IUsersManager.STATUS_OK); user.setStatus(" 使用者註冊完成. "); } } catch (Throwable e) { e.printStackTrace(); user.setStatusCode(IUsersManager.STATUS_ERROR); user.setStatus(" 使用者註冊處理出現錯誤!! - " + e.getMessage()); } finally { getEntityManager().getTransaction().commit(); } return user; }