From 62c42944d379db8e9de64098679e0dbc91e55439 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Mon, 13 May 2019 12:39:47 +0200 Subject: [PATCH] [#8619] Let Query subtypes extends RowCountQuery, which extends Publisher --- .../src/main/java/org/jooq/RowCountQuery.java | 55 +++++++++++ .../impl/AbstractDelegatingRowCountQuery.java | 75 +++++++++++++++ .../org/jooq/impl/AbstractRowCountQuery.java | 93 +++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/RowCountQuery.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingRowCountQuery.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/AbstractRowCountQuery.java diff --git a/jOOQ/src/main/java/org/jooq/RowCountQuery.java b/jOOQ/src/main/java/org/jooq/RowCountQuery.java new file mode 100644 index 0000000000..3a8d6e8e04 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/RowCountQuery.java @@ -0,0 +1,55 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq; + +import java.util.concurrent.Flow; + +/** + * Any query that is not a {@link ResultQuery}, and thus possibly produces a row + * count as a result, instead of a {@link Result}. + * + * @author Lukas Eder + */ +public interface RowCountQuery +extends + Query + , org.reactivestreams.Publisher + , Flow.Publisher +{ + +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingRowCountQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingRowCountQuery.java new file mode 100644 index 0000000000..3a364b9d28 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDelegatingRowCountQuery.java @@ -0,0 +1,75 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import java.util.concurrent.Flow; + +import org.jooq.RowCountQuery; + +/** + * @author Lukas Eder + */ +abstract class AbstractDelegatingRowCountQuery extends AbstractDelegatingQuery implements RowCountQuery { + + /** + * Generated UID + */ + private static final long serialVersionUID = 6710523592699040547L; + + AbstractDelegatingRowCountQuery(Q delegate) { + super(delegate); + } + + + + @Override + public final void subscribe(Flow.Subscriber subscriber) { + getDelegate().subscribe(subscriber); + } + + + + + + @Override + public final void subscribe(org.reactivestreams.Subscriber subscriber) { + getDelegate().subscribe(subscriber); + } + + +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRowCountQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRowCountQuery.java new file mode 100644 index 0000000000..1fe98d89a6 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRowCountQuery.java @@ -0,0 +1,93 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import org.jooq.Configuration; +import org.jooq.RowCountQuery; + +/** + * @author Lukas Eder + */ +abstract class AbstractRowCountQuery extends AbstractQuery implements RowCountQuery { + + /** + * Generated UID + */ + private static final long serialVersionUID = 516654856465466162L; + + AbstractRowCountQuery(Configuration configuration) { + super(configuration); + } + + + + @Override + public final void subscribe(org.reactivestreams.Subscriber subscriber) { + subscriber.onSubscribe(new org.reactivestreams.Subscription() { + Integer rows; + + @Override + public void request(long n) { + try { + if (rows == null) + subscriber.onNext(rows = execute()); + } + catch (Throwable t) { + subscriber.onError(t); + } + + subscriber.onComplete(); + } + + @Override + public void cancel() { + } + }); + } + + + + + + @Override + public final void subscribe(java.util.concurrent.Flow.Subscriber subscriber) { + subscribe(new FlowToReactiveStreamsSubscriberBridge(subscriber)); + } + + +}