Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Better strategy for generic Iterator

  • Loading branch information...
commit a39d212d49a2cff3a551c0158abad0d72dd92c59 1 parent 667deb8
Patricio Echague authored February 09, 2012
23  core/src/main/java/me/prettyprint/cassandra/service/GenericKeyIterator.java
@@ -3,6 +3,7 @@
3 3
 import java.util.Iterator;
4 4
 
5 5
 import me.prettyprint.cassandra.serializers.AbstractSerializer;
  6
+import me.prettyprint.cassandra.serializers.StringSerializer;
6 7
 import me.prettyprint.hector.api.Keyspace;
7 8
 import me.prettyprint.hector.api.beans.OrderedRows;
8 9
 import me.prettyprint.hector.api.beans.Row;
@@ -23,13 +24,15 @@
23 24
  */
24 25
 public class GenericKeyIterator<K, N, V> implements Iterable<K> {
25 26
 
  27
+  private static StringSerializer stringSerializer = StringSerializer.get();
  28
+
26 29
   private static final int MAX_ROW_COUNT_DEFAULT = 500;
27 30
 
28 31
   private int maxColumnCount = 2;	// we only need this to tell if there are any columns in the row (to test for tombstones)
29 32
 
30  
-  private Iterator<Row<K, N, V>> rowsIterator = null;
  33
+  private Iterator<Row<K, String, String>> rowsIterator = null;
31 34
 
32  
-  private RangeSlicesQuery<K, N, V> query = null;
  35
+  private RangeSlicesQuery<K, String, String> query = null;
33 36
 
34 37
   private K nextValue = null;
35 38
   private K lastReadValue = null;
@@ -59,7 +62,7 @@ private void findNext(boolean fromRunQuery) {
59 62
       return;
60 63
     }
61 64
     while (rowsIterator.hasNext() && nextValue == null) {
62  
-      Row<K, N, V> row = rowsIterator.next();
  65
+      Row<K, String, String> row = rowsIterator.next();
63 66
       lastReadValue = row.getKey();
64 67
       if (!row.getColumnSlice().getColumns().isEmpty()) {
65 68
         nextValue = lastReadValue;
@@ -70,16 +73,14 @@ private void findNext(boolean fromRunQuery) {
70 73
     }
71 74
   }
72 75
   
73  
-  public GenericKeyIterator(Keyspace keyspace, String columnFamily, AbstractSerializer<K> keySerializer, AbstractSerializer<N> nameSerializer,
74  
-      AbstractSerializer<V> valueSerializer) {
  76
+  public GenericKeyIterator(Keyspace keyspace, String columnFamily, AbstractSerializer<K> keySerializer) {
75 77
 
76  
-     this(keyspace, columnFamily, keySerializer, nameSerializer, valueSerializer, null, null, MAX_ROW_COUNT_DEFAULT);
  78
+     this(keyspace, columnFamily, keySerializer, null, null, MAX_ROW_COUNT_DEFAULT);
77 79
   }
78 80
 
79  
-  public GenericKeyIterator(Keyspace keyspace, String columnFamily, AbstractSerializer<K> keySerializer, AbstractSerializer<N> nameSerializer,
80  
-		  AbstractSerializer<V> valueSerializer, K start, K end, int maxRowCount) {
  81
+  public GenericKeyIterator(Keyspace keyspace, String columnFamily, AbstractSerializer<K> keySerializer, K start, K end, int maxRowCount) {
81 82
     query = HFactory
82  
-      .createRangeSlicesQuery(keyspace, keySerializer, nameSerializer, valueSerializer)
  83
+      .createRangeSlicesQuery(keyspace, keySerializer, stringSerializer, stringSerializer)
83 84
       .setColumnFamily(columnFamily)
84 85
       .setKeys(start, end)
85 86
       .setRange(null, null, false, maxColumnCount)
@@ -92,8 +93,8 @@ private void runQuery(K start) {
92 93
     query.setKeys(start, null);
93 94
 
94 95
     rowsIterator = null;
95  
-    QueryResult<OrderedRows<K, N, V>> result = query.execute();
96  
-    OrderedRows<K, N, V> rows = (result != null) ? result.get() : null;
  96
+    QueryResult<OrderedRows<K, String, String>> result = query.execute();
  97
+    OrderedRows<K, String, String> rows = (result != null) ? result.get() : null;
97 98
     rowsIterator = (rows != null) ? rows.iterator() : null;
98 99
 
99 100
     // we'll skip this first one, since it is the same as the last one from previous time we executed

0 notes on commit a39d212

Please sign in to comment.
Something went wrong with that request. Please try again.