[#8619] Let Query subtypes extends RowCountQuery, which extends Publisher<Integer>

This commit is contained in:
Lukas Eder 2019-05-13 12:39:47 +02:00
parent b1d992e33b
commit 62c42944d3
3 changed files with 223 additions and 0 deletions

View File

@ -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<Integer>
, Flow.Publisher<Integer>
{
}

View File

@ -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<Q extends RowCountQuery> extends AbstractDelegatingQuery<Q> implements RowCountQuery {
/**
* Generated UID
*/
private static final long serialVersionUID = 6710523592699040547L;
AbstractDelegatingRowCountQuery(Q delegate) {
super(delegate);
}
@Override
public final void subscribe(Flow.Subscriber<? super Integer> subscriber) {
getDelegate().subscribe(subscriber);
}
@Override
public final void subscribe(org.reactivestreams.Subscriber<? super Integer> subscriber) {
getDelegate().subscribe(subscriber);
}
}

View File

@ -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<? super Integer> 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<? super Integer> subscriber) {
subscribe(new FlowToReactiveStreamsSubscriberBridge<Integer>(subscriber));
}
}