private static <T> T getNullableFrom(ResultSet rs, SqlFunction<ResultSet, T> mapper) throws SQLException { final T result = mapper.apply(rs); return rs.wasNull() ? null : result; }
default Function<T, R> unWrap() { return t -> { try { return this.apply(t); } catch (SQLException sqle) { throw new SpeedmentException(sqle); } }; }
@Override public SqlFunction<ResultSet, ENTITY> entityMapper(int offset) { return rs -> { final Object value = rs.getObject(1 + offset + nullableColumnOffset); // We must check rs.wasNull() becaues the joined field might be null // even though it is non-nullable like int, long etc. if (value == null || rs.wasNull()) { return null; } else { return inner.entityMapper(offset).apply(rs); } }; }
@Override public <T0, T1, T> Join<T> createJoin( final List<Stage<?>> stages, final BiFunction<T0, T1, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs) ); return newJoin(stages, rsMapper); }
private <T> T applyOnConnection(Dbms dbms, SqlFunction<Connection, T> mapper) throws SQLException { assertNotClosed(); try (final Connection c = connectionPoolComponent.getConnection(dbms)) { return mapper.apply(c); } }
@Override public <T0, T1, T2, T> Join<T> createJoin( final List<Stage<?>> stages, final TriFunction<T0, T1, T2, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1, final TableIdentifier<T2> t2 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T2> rsMapper2 = rsMapper(stages, 2, t2); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs) ); return newJoin(stages, rsMapper); }
@Override public <T0, T1, T2, T3, T4, T> Join<T> createJoin( final List<Stage<?>> stages, final Function5<T0, T1, T2, T3, T4, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1, final TableIdentifier<T2> t2, final TableIdentifier<T3> t3, final TableIdentifier<T4> t4 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T2> rsMapper2 = rsMapper(stages, 2, t2); final SqlFunction<ResultSet, T3> rsMapper3 = rsMapper(stages, 3, t3); final SqlFunction<ResultSet, T4> rsMapper4 = rsMapper(stages, 4, t4); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs) ); return newJoin(stages, rsMapper); }
@Override public <T0, T1, T2, T3, T> Join<T> createJoin( final List<Stage<?>> stages, final QuadFunction<T0, T1, T2, T3, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1, final TableIdentifier<T2> t2, final TableIdentifier<T3> t3 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T2> rsMapper2 = rsMapper(stages, 2, t2); final SqlFunction<ResultSet, T3> rsMapper3 = rsMapper(stages, 3, t3); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs) ); return newJoin(stages, rsMapper); }
@Override public <T0, T1, T2, T3, T4, T5, T> Join<T> createJoin( final List<Stage<?>> stages, final Function6<T0, T1, T2, T3, T4, T5, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1, final TableIdentifier<T2> t2, final TableIdentifier<T3> t3, final TableIdentifier<T4> t4, final TableIdentifier<T5> t5 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T2> rsMapper2 = rsMapper(stages, 2, t2); final SqlFunction<ResultSet, T3> rsMapper3 = rsMapper(stages, 3, t3); final SqlFunction<ResultSet, T4> rsMapper4 = rsMapper(stages, 4, t4); final SqlFunction<ResultSet, T5> rsMapper5 = rsMapper(stages, 5, t5); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs), rsMapper5.apply(rs) ); return newJoin(stages, rsMapper); }
@Override public <T0, T1, T2, T3, T4, T5, T6, T> Join<T> createJoin( final List<Stage<?>> stages, final Function7<T0, T1, T2, T3, T4, T5, T6, T> constructor, final TableIdentifier<T0> t0, final TableIdentifier<T1> t1, final TableIdentifier<T2> t2, final TableIdentifier<T3> t3, final TableIdentifier<T4> t4, final TableIdentifier<T5> t5, final TableIdentifier<T6> t6 ) { final SqlFunction<ResultSet, T0> rsMapper0 = rsMapper(stages, 0, t0); final SqlFunction<ResultSet, T1> rsMapper1 = rsMapper(stages, 1, t1); final SqlFunction<ResultSet, T2> rsMapper2 = rsMapper(stages, 2, t2); final SqlFunction<ResultSet, T3> rsMapper3 = rsMapper(stages, 3, t3); final SqlFunction<ResultSet, T4> rsMapper4 = rsMapper(stages, 4, t4); final SqlFunction<ResultSet, T5> rsMapper5 = rsMapper(stages, 5, t5); final SqlFunction<ResultSet, T6> rsMapper6 = rsMapper(stages, 6, t6); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs), rsMapper5.apply(rs), rsMapper6.apply(rs) ); return newJoin(stages, rsMapper); }
@Override public void forEachRemaining(Consumer<? super T> action) { if (state == State.NOT_DETERMINED) { if (!hasNext()) { return; }; } if (state == State.NO_NEXT) { return; } try { do { try { action.accept(mapper.apply(resultSet)); } catch (final SQLException ex) { throw new SpeedmentException(ex); } } while (resultSet.next()); } catch (final SQLException ex) { // Do nothing. } finally { state = State.NO_NEXT; } }
final SqlFunction<ResultSet, T7> rsMapper7= rsMapper(stages, 7, t7); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs), rsMapper5.apply(rs), rsMapper6.apply(rs), rsMapper7.apply(rs) ); return newJoin(stages, rsMapper);
final SqlFunction<ResultSet, T8> rsMapper8 = rsMapper(stages, 8, t8); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs), rsMapper5.apply(rs), rsMapper6.apply(rs), rsMapper7.apply(rs), rsMapper8.apply(rs) ); return newJoin(stages, rsMapper);
final SqlFunction<ResultSet, T9> rsMapper9 = rsMapper(stages, 9, t9); final SqlFunction<ResultSet, T> rsMapper = rs -> constructor.apply( rsMapper0.apply(rs), rsMapper1.apply(rs), rsMapper2.apply(rs), rsMapper3.apply(rs), rsMapper4.apply(rs), rsMapper5.apply(rs), rsMapper6.apply(rs), rsMapper7.apply(rs), rsMapper8.apply(rs), rsMapper9.apply(rs) ); return newJoin(stages, rsMapper);
@Override public T next() { if (state == State.NOT_DETERMINED) { if (!hasNext()) { throwNoSuchElementException(); }; } if (state == State.NO_NEXT) { throwNoSuchElementException(); } state = State.NOT_DETERMINED; try { return mapper.apply(resultSet); } catch (final SQLException ex) { throw new SpeedmentException(ex); } }
final String id = childIdGetter.apply(rsChild); final Optional<T> existing = DocumentDbUtil.typedChildrenOf(table) .filter(childType::isInstance)
streamBuilder.add(rsMapper.apply(rs));
default Function<T, R> unWrap() { return t -> { try { return this.apply(t); } catch (SQLException sqle) { throw new SpeedmentException(sqle); } }; }