コード例 #1
0
  public User createUser() {
    User user = new User();

    user.setId("u" + System.currentTimeMillis());

    return user;
  }
コード例 #2
0
  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;
  }