buckelieg.jdbc.StoredProcedureQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbc-fn Show documentation
Show all versions of jdbc-fn Show documentation
Functional style programming with plain JDBC
The newest version!
/*
* Copyright 2016- Anatoly Kutyakov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package buckelieg.jdbc;
import buckelieg.jdbc.fn.TryConsumer;
import buckelieg.jdbc.fn.TryFunction;
import buckelieg.jdbc.fn.TrySupplier;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;
import java.sql.*;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
@NotThreadSafe
@ParametersAreNonnullByDefault
final class StoredProcedureQuery extends SelectQuery implements StoredProcedure {
StoredProcedureQuery(
Map metaCache,
TrySupplier connectionSupplier,
TryConsumer connectionConsumer,
Supplier executorServiceSupplier,
String query, P>... params) {
super(metaCache, connectionSupplier, connectionConsumer, executorServiceSupplier, query, (Object[]) params);
}
@Nonnull
@Override
public Select call(TryFunction mapper, Consumer consumer) {
if (null == mapper) throw new NullPointerException("Mapper must be provided");
if (null == consumer) throw new NullPointerException("Consumer must be provided");
this.finisher = () -> {
if (mapper != null && consumer != null && isPrepared) {
try {
consumer.accept(mapper.apply(ValueGetters.reader(meta, (CallableStatement) statement)));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
};
return this;
}
@Nonnull
@Override
public StoredProcedure timeout(int timeout) {
return (StoredProcedure) super.timeout(timeout);
}
@Nonnull
@Override
public StoredProcedure skipWarnings(boolean skipWarnings) {
return (StoredProcedure) super.skipWarnings(skipWarnings);
}
@Nonnull
@Override
public StoredProcedure print(Consumer printer) {
return (StoredProcedure) super.print(printer);
}
@SuppressWarnings("unchecked")
@Nonnull
@Override
public Stream