Ejemplo n.º 1
0
  public int insertEntity(
      String entitySet,
      String entityPK,
      HashMap<String, ByteIterator> values,
      boolean insertImage) {
    // TODO Auto-generated method stub
    /* Insert into table */
    try {
      long mutator = client.mutator_open(namespace, entitySet, 0, 0);
      List<Cell> cells = new ArrayList<Cell>();
      Key key = null;
      Cell cell = null;

      for (HashMap.Entry<String, ByteIterator> entry : values.entrySet()) {
        key = new Key(entityPK, entry.getKey(), null, KeyFlag.INSERT);
        cell = new Cell(key);
        cell.setValue(entry.getValue().toArray());
        cells.add(cell);
      }

      client.mutator_set_cells(mutator, cells);
      client.mutator_flush(mutator);
      cells.clear();
      client.mutator_close(mutator);
    } catch (ClientException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
    return 0;
  }
Ejemplo n.º 2
0
  public int CreateFriendship(int friendid1, int friendid2) {
    // TODO Auto-generated method stub
    long mutator;
    try {
      mutator = client.mutator_open(namespace, ConfirmedFriendsTable, 0, 0);

      List<Cell> cells = new ArrayList<Cell>();
      Key key = null;
      Cell cell = null;

      key = new Key(friendid1 + "", ConfirmedFriendsTableCF[1], null, KeyFlag.INSERT);
      cell = new Cell(key);
      cell.setValue((friendid2 + "").getBytes("UTF-8"));
      cells.add(cell);

      key = new Key(friendid2 + "", ConfirmedFriendsTableCF[1], null, KeyFlag.INSERT);
      cell = new Cell(key);
      cell.setValue((friendid1 + "").getBytes("UTF-8"));
      cells.add(cell);

      client.mutator_set_cells(mutator, cells);
      client.mutator_flush(mutator);
      cells.clear();

    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return -1;
    }
    return 0;
  }