All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.ugli.habanero.j.internal.SingleValueIterator Maven / Gradle / Ivy

There is a newer version: 1.8.1.1
Show newest version
package se.ugli.habanero.j.internal;

import java.sql.ResultSet;
import java.sql.SQLException;

import se.ugli.habanero.j.HabaneroException;
import se.ugli.habanero.j.ResultSetIterator;
import se.ugli.habanero.j.TypeAdaptor;
import se.ugli.habanero.j.TypeRegister;
import se.ugli.habanero.j.util.Option;

public class SingleValueIterator extends ResultSetIterator {

	private final TypeAdaptor typeAdaptor;
	private final Class type;

	public SingleValueIterator(final Class type) {
		if (type == null)
			throw new IllegalArgumentException();
		this.type = type;
		final Option typeAdaptorOpt = TypeRegister.get(type);
		if (typeAdaptorOpt.isDefined())
			this.typeAdaptor = typeAdaptorOpt.get();
		else
			throw new HabaneroException(type.getName() + " isn't registered.");
	}

	@SuppressWarnings("unchecked")
	@Override
	protected T nextObject(final ResultSet resultSet) throws SQLException {
		return (T) typeAdaptor.toTypeValue(type, resultSet.getObject(1));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy