package eu.dnetlib.dlms.benchmark;

import java.math.BigInteger;
import java.util.Iterator;

import eu.dnetlib.dlms.lowlevel.objects.structures.Structure;
import eu.dnetlib.dlms.lowlevel.objects.structures.StructureDAO;

/**
 *This class wraps an Iterator of Long rerpresenting Structures identifiers. The next method will ask hibernate for the
 * structure with the current id hold by the iterator.
 * 
 * @author lexis
 */
public class HibernateQueryResult implements DorotyQueryResult {
	/** DAO to get Structures. */
	private StructureDAO structDAO;
	/** Iterator holding the identifiers of the Structures that are the result of a query. */
	private Iterator<BigInteger> identifiers;

	public void setStructDAO(final StructureDAO structDAO) {
		this.structDAO = structDAO;
	}

	public StructureDAO getStructDAO() {
		return this.structDAO;
	}

	public void setIdentifiers(final Iterator<BigInteger> identifiers) {
		this.identifiers = identifiers;
	}

	public Iterator<BigInteger> getIdentifiers() {
		return this.identifiers;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see eu.dnetlib.dlms.benchmark.DorotyQueryResult#close()
	 */
	public void close() {
		// do nothing
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.util.Iterator#hasNext()
	 */
	public boolean hasNext() {
		return this.identifiers.hasNext();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.util.Iterator#next()
	 */
	public Structure next() {
		BigInteger id = this.identifiers.next();
		return this.structDAO.getByID(id.longValue());
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.util.Iterator#remove()
	 */
	public void remove() {
		throw new UnsupportedOperationException();
	}

}
