IteratorImplpublic final class IteratorImpl extends Object implements org.hibernate.engine.HibernateIteratorAn implementation of java.util.Iterator that is
returned by iterate() query execution methods. |
Fields Summary |
---|
private static final Log | log | private ResultSet | rs | private final org.hibernate.event.EventSource | session | private final org.hibernate.type.Type[] | types | private final boolean | single | private Object | currentResult | private boolean | hasNext | private final String[] | names | private PreparedStatement | ps | private Object | nextResult | private org.hibernate.hql.HolderInstantiator | holderInstantiator |
Methods Summary |
---|
public void | close()
if (ps!=null) {
try {
log.debug("closing iterator");
nextResult = null;
session.getBatcher().closeQueryStatement(ps, rs);
ps = null;
rs = null;
hasNext = false;
}
catch (SQLException e) {
log.info( "Unable to close iterator", e );
throw JDBCExceptionHelper.convert(
session.getFactory().getSQLExceptionConverter(),
e,
"Unable to close iterator"
);
}
finally {
try {
session.getPersistenceContext().getLoadContexts().cleanup( rs );
}
catch( Throwable ignore ) {
// ignore this error for now
log.trace( "exception trying to cleanup load context : " + ignore.getMessage() );
}
}
}
| public boolean | hasNext()
return hasNext;
| public java.lang.Object | next()
if ( !hasNext ) throw new NoSuchElementException("No more results");
try {
currentResult = nextResult;
postNext();
log.debug("returning current results");
return currentResult;
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
session.getFactory().getSQLExceptionConverter(),
sqle,
"could not get next iterator result"
);
}
| private void | postNext()
this.hasNext = rs.next();
if (!hasNext) {
log.debug("exhausted results");
close();
}
else {
log.debug("retrieving next results");
boolean isHolder = holderInstantiator.isRequired();
if ( single && !isHolder ) {
nextResult = types[0].nullSafeGet( rs, names[0], session, null );
}
else {
Object[] nextResults = new Object[types.length];
for (int i=0; i<types.length; i++) {
nextResults[i] = types[i].nullSafeGet( rs, names[i], session, null );
}
if (isHolder) {
nextResult = holderInstantiator.instantiate(nextResults);
}
else {
nextResult = nextResults;
}
}
}
| public void | remove()
if (!single) {
throw new UnsupportedOperationException("Not a single column hibernate query result set");
}
if (currentResult==null) {
throw new IllegalStateException("Called Iterator.remove() before next()");
}
if ( !( types[0] instanceof EntityType ) ) {
throw new UnsupportedOperationException("Not an entity");
}
session.delete(
( (EntityType) types[0] ).getAssociatedEntityName(),
currentResult,
false,
null
);
|
|