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

io.codemonastery.jdbj.ResultSetSpliterator Maven / Gradle / Ivy

The newest version!
package io.codemonastery.jdbj;

import io.codemonastery.jdbj.lambda.ResultMapper;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * Wrapper around {@link ResultSet} and {@link ResultMapper} to create a {@link Spliterator} or {@link E}.
 * 

* Does not close the {@link ResultSet}. * @param element type * @see StreamQuery */ public class ResultSetSpliterator implements Spliterator { private final SmartResultSet rs; private final ResultMapper mapper; public ResultSetSpliterator(ResultSet rs, ResultMapper mapper) { this.rs = new SmartResultSet(rs); this.mapper = mapper; } @Override public boolean tryAdvance(Consumer action) { try { final boolean advanced = rs.next(); if (advanced) { action.accept(mapper.map(rs)); } return advanced; } catch (Exception e) { throw new AdvanceFailedException(e); } } @Override public @Nullable Spliterator trySplit() { return null; } @Override public long estimateSize() { return Long.MAX_VALUE; } @Override public int characteristics() { return Spliterator.IMMUTABLE; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy