Esempio n. 1
0
 public Optional<List<Response>> getBatch(Optional<List<Request>> requests) {
   if (!valid) {
     Logger.error("CANNOT GET! NO VALID CONNECTION");
     return Optional.empty();
   }
   List<Response> responses = new ArrayList<>();
   requests.ifPresent(
       reqs ->
           reqs.forEach(r -> get(Optional.of(r)).ifPresent(response -> responses.add(response))));
   return Optional.of(responses);
 }
Esempio n. 2
0
 public Optional<Response> get(Optional<Request> request) {
   if (!valid) {
     Logger.error("CANNOT GET! NO VALID CONNECTION");
     return Optional.empty();
   }
   Response response = new Response();
   if (request.isPresent()) {
     Request r = request.get();
     response.key = r.key;
     response.table = r.table;
     try {
       final Table htable = connection.getTable(TableName.valueOf(r.table));
       Result result = htable.get(new Get(r.key));
       if (result == null || result.isEmpty()) {
         return Optional.empty();
       }
       r.columns.forEach(
           c ->
               response.columns.add(
                   new Request.Column(
                       c.family,
                       c.qualifier,
                       result.getValue(c.family.getBytes(), c.qualifier.getBytes()))));
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return Optional.of(response);
 }
Esempio n. 3
0
 public Optional<Put> getPut() {
   if (valid()) {
     Put p = new Put(key);
     columns.forEach(c -> p.addColumn(c.family.getBytes(), c.qualifier.getBytes(), c.value));
     return Optional.of(p);
   }
   return Optional.empty();
 }