<commit_before>package com.alvazan.orm.layer9z.spi.db.cassandra;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.inject.Provider;

import com.alvazan.orm.api.z8spi.BatchListener;
import com.alvazan.orm.api.z8spi.Cache;
import com.alvazan.orm.api.z8spi.KeyValue;
import com.alvazan.orm.api.z8spi.Row;
import com.alvazan.orm.api.z8spi.conv.ByteArray;
import com.alvazan.orm.api.z8spi.iter.AbstractCursor;
import com.alvazan.orm.layer5.nosql.cache.RowHolder;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.Rows;
import com.netflix.astyanax.query.ColumnFamilyQuery;
import com.netflix.astyanax.query.RowSliceQuery;

public class FindRowsCursor extends AbstractCursor<KeyValue<Row>> {

	private Info info;
	private Iterable<byte[]> rowKeys;
	private int batchSize;
	private BatchListener list;
	private Keyspace keyspace;
	private Iterator<byte[]> theKeys;
	private int lastRowCount;
	private Iterator<KeyValue<Row>> cachedRows;
	private Provider<Row> rowProvider;
	private Cache cache;

	public FindRowsCursor(Info info, Iterable<byte[]> rowKeys, Cache cache, int batchSize,
			BatchListener list, Keyspace keyspace, Provider<Row> rowProvider) {
		this.cache = cache;
		this.rowProvider = rowProvider;
		this.info = info;
		this.rowKeys = rowKeys;
		this.batchSize = batchSize;
		this.list = list;
		this.keyspace = keyspace;
		beforeFirst();
	}

	@Override
	public void beforeFirst() {
		theKeys = rowKeys.iterator();
		cachedRows = null;
	}

	@Override
	public com.alvazan.orm.api.z8spi.iter.AbstractCursor.Holder<KeyValue<Row>> nextImpl() {
		loadCache();
		if(!cachedRows.hasNext())
			return null;
		
		return new Holder<KeyValue<Row>>(cachedRows.next());
	}

	@SuppressWarnings("unchecked")
	private void loadCache() {
		if(cachedRows != null && cachedRows.hasNext())
			return; //There are more rows so return and the code will return the next result from cache
		else if(lastRowCount >= batchSize)
			return; //There will be now rows so don't waste time querying!!!!<commit_msg>fix bug where the key set is empty<commit_after>package com.alvazan.orm.layer9z.spi.db.cassandra;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.inject.Provider;

import com.alvazan.orm.api.z8spi.BatchListener;
import com.alvazan.orm.api.z8spi.Cache;
import com.alvazan.orm.api.z8spi.KeyValue;
import com.alvazan.orm.api.z8spi.Row;
import com.alvazan.orm.api.z8spi.conv.ByteArray;
import com.alvazan.orm.api.z8spi.iter.AbstractCursor;
import com.alvazan.orm.layer5.nosql.cache.RowHolder;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.Rows;
import com.netflix.astyanax.query.ColumnFamilyQuery;
import com.netflix.astyanax.query.RowSliceQuery;

public class FindRowsCursor extends AbstractCursor<KeyValue<Row>> {

	private Info info;
	private Iterable<byte[]> rowKeys;
	private int batchSize;
	private BatchListener list;
	private Keyspace keyspace;
	private Iterator<byte[]> theKeys;
	private Integer lastRowCount;
	private Iterator<KeyValue<Row>> cachedRows;
	private Provider<Row> rowProvider;
	private Cache cache;

	public FindRowsCursor(Info info, Iterable<byte[]> rowKeys, Cache cache, int batchSize,
			BatchListener list, Keyspace keyspace, Provider<Row> rowProvider) {
		this.cache = cache;
		this.rowProvider = rowProvider;
		this.info = info;
		this.rowKeys = rowKeys;
		this.batchSize = batchSize;
		this.list = list;
		this.keyspace = keyspace;
		beforeFirst();
	}

	@Override
	public void beforeFirst() {
		theKeys = rowKeys.iterator();
		cachedRows = null;
	}

	@Override
	public com.alvazan.orm.api.z8spi.iter.AbstractCursor.Holder<KeyValue<Row>> nextImpl() {
		loadCache();
		if(cachedRows == null || !cachedRows.hasNext())
			return null;
		
		return new Holder<KeyValue<Row>>(cachedRows.next());
	}

	@SuppressWarnings("unchecked")
	private void loadCache() {
		if(cachedRows != null && cachedRows.hasNext())
			return; //There are more rows so return and the code will return the next result from cache
{'fraction_non_alphanumeric': 0.11226980252939871, 'fraction_numerical': 0.0039937874417572666, 'mean_word_length': 5.29608938547486, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6204798', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1507, 'n_words': 322}