HBaseEdgeIterator.java

  1. /*
  2.  * Copyright © 2014 - 2021 Leipzig University (Database Research Group)
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.gradoop.storage.hbase.impl.iterator;

  17. import org.apache.hadoop.hbase.client.Result;
  18. import org.apache.hadoop.hbase.client.ResultScanner;
  19. import org.gradoop.common.model.impl.pojo.EPGMEdge;
  20. import org.gradoop.storage.common.iterator.ClosableIterator;
  21. import org.gradoop.storage.hbase.impl.api.EdgeHandler;

  22. import java.util.Iterator;

  23. /**
  24.  * HBase client iterator for EPGMEdge
  25.  */
  26. public class HBaseEdgeIterator implements ClosableIterator<EPGMEdge> {

  27.   /**
  28.    * HBase result scanner
  29.    */
  30.   private final ResultScanner scanner;

  31.   /**
  32.    * Gradoop edge handler
  33.    */
  34.   private final EdgeHandler handler;

  35.   /**
  36.    * Inner result iterator
  37.    */
  38.   private final Iterator<Result> it;

  39.   /**
  40.    * mapper EPGM result
  41.    */
  42.   private Result result;

  43.   /**
  44.    * HBase EPGMGraphHead Iterator
  45.    *
  46.    * @param scanner HBase result scanner
  47.    * @param handler element handler for gradoop
  48.    */
  49.   public HBaseEdgeIterator(ResultScanner scanner, EdgeHandler handler) {
  50.     this.scanner = scanner;
  51.     this.handler = handler;
  52.     this.it = scanner.iterator();
  53.   }

  54.   @Override
  55.   public void close() {
  56.     scanner.close();
  57.   }

  58.   @Override
  59.   public boolean hasNext() {
  60.     if (it.hasNext()) {
  61.       result = it.next();
  62.       return true;
  63.     } else {
  64.       return false;
  65.     }
  66.   }

  67.   @Override
  68.   public EPGMEdge next() {
  69.     return handler.readEdge(result);
  70.   }
  71. }