
jodd.db.oom.DbListOneIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jodd-db Show documentation
Show all versions of jodd-db Show documentation
Jodd DB is efficient and thin database facade; DbOom is convenient database object mapper.
// Copyright (c) 2003-2012, Jodd Team (jodd.org). All Rights Reserved.
package jodd.db.oom;
import jodd.db.oom.mapper.ResultSetMapper;
import java.util.Iterator;
/**
* Internal database iterator for single type.
*/
class DbListOneIterator implements Iterator {
protected DbOomQuery query;
protected ResultSetMapper resultSetMapper;
protected boolean closeOnEnd;
protected Class type;
protected boolean one;
// ---------------------------------------------------------------- ctors
DbListOneIterator(DbOomQuery query, Class type) {
this(query, type, true);
}
DbListOneIterator(DbOomQuery query, Class type, boolean closeOnEnd) {
this.query = query;
this.resultSetMapper = query.executeAndBuildResultSetMapper();
this.type = (type == null ? resultSetMapper.resolveTables()[0] : type);
this.closeOnEnd = closeOnEnd;
}
// ---------------------------------------------------------------- iterate
public void remove() {
throw new UnsupportedOperationException("Removing is not supported.");
}
public boolean hasNext() {
if (resultSetMapper.next() == true) {
return true;
}
if (closeOnEnd == true) {
query.close();
} else {
query.closeResultSet(resultSetMapper.getResultSet());
}
return false;
}
@SuppressWarnings({"unchecked"})
public T next() {
return (T) resultSetMapper.parseOneObject(type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy