Exemplo n.º 1
0
  public void removeQuery(final String creator, final String id) throws IOException {
    List<Query> queries = getQueries(creator);
    Iterator<Query> queryIter = queries.iterator();

    boolean changed = false;
    while (queryIter.hasNext()) {
      Query temp = queryIter.next();
      if (temp.getId().equals(id)) {
        queryIter.remove();
        changed = true;
        break;
      }
    }

    if (!changed) {
      return;
    }

    Query[] queryArray = new Query[queries.size()];
    byte[] bytes = querySerializer.serialize(queries.toArray(queryArray));
    HTableInterface htable = null;
    try {
      htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
      Put put = new Put(Bytes.toBytes(creator));
      put.add(Bytes.toBytes(USER_QUERY_FAMILY), Bytes.toBytes(USER_QUERY_COLUMN), bytes);

      htable.put(put);
      htable.flushCommits();
    } finally {
      IOUtils.closeQuietly(htable);
    }
  }
Exemplo n.º 2
0
  public List<Query> getQueries(final String creator) throws IOException {
    if (null == creator) {
      return null;
    }

    List<Query> queries = new ArrayList<Query>();
    HTableInterface htable = null;
    try {
      htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
      Get get = new Get(Bytes.toBytes(creator));
      get.addFamily(Bytes.toBytes(USER_QUERY_FAMILY));
      Result result = htable.get(get);
      Query[] query =
          querySerializer.deserialize(
              result.getValue(Bytes.toBytes(USER_QUERY_FAMILY), Bytes.toBytes(USER_QUERY_COLUMN)));

      if (null != query) {
        queries.addAll(Arrays.asList(query));
      }
    } finally {
      IOUtils.closeQuietly(htable);
    }

    return queries;
  }
Exemplo n.º 3
0
  public void saveQuery(final String creator, final Query query) throws IOException {
    List<Query> queries = getQueries(creator);
    queries.add(query);
    Query[] queryArray = new Query[queries.size()];

    byte[] bytes = querySerializer.serialize(queries.toArray(queryArray));
    HTableInterface htable = null;
    try {
      htable = HBaseConnection.get(hbaseUrl).getTable(userTableName);
      Put put = new Put(Bytes.toBytes(creator));
      put.add(Bytes.toBytes(USER_QUERY_FAMILY), Bytes.toBytes(USER_QUERY_COLUMN), bytes);

      htable.put(put);
      htable.flushCommits();
    } finally {
      IOUtils.closeQuietly(htable);
    }
  }