This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface Extractor<T> { | |
/** | |
* Extract type T from the current position in the ResultSet. | |
* | |
* @param rs the ResultSet to extract from | |
* @return the type T extracted | |
* @throws SQLException should the extraction fail | |
*/ | |
T extract(ResultSet rs) throws SQLException; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T, B> void copy(B bean, | |
BiConsumer<B, T> setter, | |
ResultSet rs, | |
BiFunction<ResultSet, Integer, T> getter, | |
Integer index) { | |
setter.accept(bean, getter.apply(rs, index)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BiFunction<ResultSet, Integer, String> STRING = (r, i) -> { | |
try { | |
return r.getString(i); | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example1 { | |
final static BiFunction<ResultSet, Integer, String> STRING = | |
(r, index) -> { | |
try { | |
return r.getString(index); | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
void example(ResultSet rs, Integer i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ExtractorFactory<B> { | |
public ExtractorFactory<B> factory(Supplier<B> factory) { /* ... */ } | |
public <T> ExtractorFactory<B> add( | |
BiConsumer<B, T> setter, | |
BiFunction<ResultSet, Integer, T> getter, | |
Integer index) { /* ... */ } | |
public Extractor<B> getExtractor() { /* ... */ } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example { | |
final static BiFunction<ResultSet, Integer, String> STRING = | |
(r, index) -> { | |
try { | |
return r.getString(index); | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
void example() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ExtractorFactory<B> { | |
private BiConsumer<B, ResultSet> consumer = (b, r) -> {}; | |
private Supplier<B> factory; | |
public ExtractorFactory<B> factory(Supplier<B> factory) { | |
this.factory = factory; | |
return this; | |
} | |
public <T> ExtractorFactory<B> add(BiConsumer<B, T> setter, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Extractors { | |
private Extractors() {} | |
public static final BiFunction<ResultSet, Integer, String> STRING_I = (r, i) -> { | |
try { | |
return r.getString(i); | |
} catch (SQLException e) { | |
throw new UncheckedSQLException(e); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
public interface ThrowingBiFunction<T, U, R> extends BiFunction<T, U, R> { | |
@Override | |
default R apply(T t, U u) { | |
try { | |
return applyThrows(t, u); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Extractors { | |
private Extractors() { | |
} | |
public static final ThrowingBiFunction<ResultSet, Integer, String> STRING_I | |
= ResultSet::getString; | |
public static final ThrowingBiFunction<ResultSet, String, String> STRING_S | |
= ResultSet::getString; |
OlderNewer