Пример #1
0
  public void removeFriends(String from_uname, List<String> to_unames) {

    Mutator<String> mutator = cassandra.getMutator();
    for (String uname : to_unames) {
      mutator
          .addDeletion(from_uname, FRIENDS, uname, SE)
          .addDeletion(uname, FOLLOWERS, from_uname, SE);
      mutator.decrementCounter(from_uname, MISC_COUNTS, "friends", 1);
      mutator.decrementCounter(uname, MISC_COUNTS, "followers", 1);
    }
    mutator.execute();
  }
Пример #2
0
 public void addFriends(String from_uname, List<String> to_unames) {
   long timestamp = System.currentTimeMillis();
   Mutator<String> mutator = cassandra.getMutator();
   for (String uname : to_unames) {
     mutator
         .addInsertion(
             from_uname, FRIENDS, HFactory.createStringColumn(uname, String.valueOf(timestamp)))
         .addInsertion(
             uname, FOLLOWERS, HFactory.createStringColumn(from_uname, String.valueOf(timestamp)))
         .addCounter(from_uname, MISC_COUNTS, HFactory.createCounterColumn("friends", 1))
         .addCounter(uname, MISC_COUNTS, HFactory.createCounterColumn("followers", 1));
   }
   mutator.execute();
 }
Пример #3
0
  public void saveTweet(Tweet tweet) {

    long timestamp = System.currentTimeMillis();
    String key = bToS(tweet.getKey());

    Mutator<String> mutator = cassandra.getMutator();

    mutator
        .addInsertion(key, TWEETS, createStringColumn("uname", tweet.getUname()))
        .addInsertion(key, TWEETS, createStringColumn("body", tweet.getBody()))
        .addInsertion(key, TWEETS, createStringColumn("timestamp", String.valueOf(timestamp)))
        .addInsertion(
            tweet.getUname(), USERLINE, createStringColumn(String.valueOf(timestamp), key))
        .addInsertion(PUBLIC, USERLINE, createStringColumn(String.valueOf(timestamp), key))
        .addCounter(tweet.getUname(), MISC_COUNTS, HFactory.createCounterColumn("tweets", 1))
        .addCounter(PUBLIC, MISC_COUNTS, HFactory.createCounterColumn("tweets", 1));

    ArrayList<String> followerUnames = new ArrayList<String>(getFollowerUnames(tweet.getUname()));
    for (String follower : followerUnames) {
      mutator.addInsertion(follower, TIMELINE, createColumn(timestamp, key));
    }
    mutator.execute();
  }