@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); }
@Override public final boolean deleteUserAccount(final UserAccount userAccount) { if (userAccount == null) { throw new IllegalArgumentException("The passed user account was null."); } final RowDeletor deletor = connectionPool.createRowDeletor(); final String userid = userAccount.getId(); final String username = userAccount.getUsername(); deletor.deleteRow(COLUMN_FAMILY_USER, userid, CONSISTENCY_LEVEL_WRITE); deletor.deleteRow(COLUMN_FAMILY_USERNAME, username, CONSISTENCY_LEVEL_WRITE); return true; }
@Override public final UserAccount findUserAccountByUsername(final String username) { if (username == null) { throw new IllegalArgumentException("The passed username was null."); } final Selector selector = connectionPool.createSelector(); final List<Column> columns = selector.getColumnsFromRow(COLUMN_FAMILY_USERNAME, username, false, CONSISTENCY_LEVEL_READ); if (!columns.isEmpty()) { final String userid = Selector.getColumnStringValue(columns, "userid"); return findUserAccountByPrimaryKey(userid); } return null; }