Пример #1
0
  @Override
  public final void createOrUpdateUserAccount(final UserAccount userAccount) {

    if (userAccount == null) {
      throw new IllegalArgumentException("The passed user account was null.");
    }

    final Mutator mutator = connectionPool.createMutator();

    final String uuid = UUID.randomUUID().toString();
    final String username = userAccount.getUsername();
    final String password = userAccount.getPassword();

    // first we register the user user account under a new uuid
    mutator.writeColumns(
        COLUMN_FAMILY_USER,
        uuid,
        mutator.newColumnList(
            mutator.newColumn("username", username), mutator.newColumn("password", password)));

    // then we update the inverted index for the uuid
    mutator.writeColumns(
        COLUMN_FAMILY_USERNAME, username, mutator.newColumnList(mutator.newColumn("userid", uuid)));

    // finally commit both updates
    mutator.execute(CONSISTENCY_LEVEL_WRITE);

    userAccount.setId(uuid);
  }