56475
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
package jdk.incubator.sql2;
|
|
26 |
|
|
27 |
import java.time.Duration;
|
|
28 |
import java.util.concurrent.CompletionStage;
|
|
29 |
import java.util.function.BiConsumer;
|
|
30 |
import java.util.function.Consumer;
|
|
31 |
import java.util.function.Function;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* A multi-operation is an {@link Operation} that returns one or more results in
|
|
35 |
* addition to the out result defined by the {@link Operation}. Each result is
|
56797
|
36 |
* processed by an Operation. The Operations can be created by calling
|
|
37 |
* rowOperation, rowProcessorOperation, or countOperation if the kind of results
|
|
38 |
* is known. These results are processed in the order the Operations are
|
|
39 |
* submitted. Any results not processed by an explicit Operation is processed by
|
|
40 |
* calling the appropriate handler specified by onRows or onCount. If any result
|
|
41 |
* is an error that error is processed by calling the handler specified by
|
|
42 |
* onError. If the appropriate handler is not specified that result is ignored,
|
|
43 |
* including errors.
|
|
44 |
*
|
56475
|
45 |
* ISSUE: Should this have a collector?
|
|
46 |
*
|
|
47 |
* @param <T> The type of the result of this {@link Operation}
|
|
48 |
*/
|
|
49 |
public interface MultiOperation<T> extends OutOperation<T> {
|
|
50 |
|
|
51 |
/**
|
|
52 |
* Returns a {@link RowOperation} to process a row sequence result. The
|
|
53 |
* {@link Operation}s are executed in the order they are submitted. If a
|
|
54 |
* result is of the wrong type for the next submitted {@link Operation} the
|
56797
|
55 |
* {@link MultiOperation} is completed with {@link IllegalStateException}.
|
56475
|
56 |
*
|
|
57 |
* @return a {@link RowOperation} that is part of this {@link MultiOperation}
|
|
58 |
*/
|
|
59 |
public RowOperation<T> rowOperation();
|
|
60 |
|
|
61 |
/**
|
56797
|
62 |
* Returns a {@link RowPublisherOperation} to process a row sequence result.
|
|
63 |
* The {@link Operation}s are executed in the order they are submitted. If a
|
56475
|
64 |
* result is of the wrong type for the next submitted {@link Operation} the
|
56797
|
65 |
* {@link MultiOperation} is completed with {@link IllegalStateException}.
|
56475
|
66 |
*
|
56797
|
67 |
* @return a {@link RowPublisherOperation} that is part of this
|
|
68 |
* {@link MultiOperation}
|
56475
|
69 |
*/
|
56797
|
70 |
public RowPublisherOperation<T> rowProcessorOperation();
|
56475
|
71 |
|
|
72 |
/**
|
56797
|
73 |
* Returns a {@link RowCountOperation} to process a count result. The
|
|
74 |
* {@link Operation}s are executed in the order they are submitted. If a
|
|
75 |
* result is of the wrong type for the next submitted Operation the
|
|
76 |
* {@link MultiOperation} is completed with {@link IllegalStateException}.
|
56475
|
77 |
*
|
56797
|
78 |
* @return a {@link RowCountOperation} that is part of this
|
|
79 |
* {@link MultiOperation}
|
56475
|
80 |
*/
|
56797
|
81 |
public RowCountOperation<T> rowCountOperation();
|
56475
|
82 |
|
|
83 |
/**
|
56797
|
84 |
* Provides a handler for trailing count results. The provided handler is
|
|
85 |
* called for each count result not processed by RowCountOperation. When
|
|
86 |
* called the first argument is the number of results that preceeded the
|
|
87 |
* current result. The second argument is a {@link RowCountOperation} that
|
|
88 |
* will process the current result. This {@link RowCountOperation} has not
|
|
89 |
* been configured in any way nor has it been submitted. The handler
|
|
90 |
* configures the {@link RowCountOperation} and submits it. The count result
|
|
91 |
* is processed when the {@link RowCountOperation} is submitted. If the
|
|
92 |
* {@link RowCountOperation} is not submitted when the handler returns the
|
|
93 |
* count result is ignored.
|
|
94 |
*
|
56475
|
95 |
* If this method is not called any trailing count results are ignored.
|
|
96 |
*
|
|
97 |
* @param handler not null
|
|
98 |
* @return this MultiOperation
|
|
99 |
* @throws IllegalStateException if this method was called previously
|
|
100 |
*/
|
56797
|
101 |
public MultiOperation<T> onCount(BiConsumer<Integer, RowCountOperation<T>> handler);
|
56475
|
102 |
|
|
103 |
/**
|
56797
|
104 |
* Provides a handler for trailing row sequence results. The provided handler
|
|
105 |
* is called for each row sequence result not processed by a RowOperation.
|
|
106 |
* When called the first argument is the number of results that preceeded the
|
|
107 |
* current result. The second argument is a {@link RowOperation} that will
|
|
108 |
* process the current result. This {@link RowOperation} has not been
|
|
109 |
* configured in any way nor has it been submitted. The handler configures the
|
|
110 |
* {@link RowOperation} and submits it. The row sequence result is processed
|
|
111 |
* when the {@link RowOperation} is submitted. If the {@link RowOperation} is
|
|
112 |
* not submitted when the handler returns, the row sequence result is ignored.
|
|
113 |
*
|
56475
|
114 |
* If this method is not called any trailing row sequence results are ignored.
|
56797
|
115 |
*
|
|
116 |
* ISSUE: Should there be a version of this method that provides
|
|
117 |
* RowProcessorOperations? If so only one of that method or this one can be
|
|
118 |
* called.
|
56475
|
119 |
*
|
|
120 |
* @param handler
|
|
121 |
* @return This MultiOperation
|
|
122 |
* @throws IllegalStateException if this method was called previously
|
|
123 |
*/
|
|
124 |
public MultiOperation<T> onRows(BiConsumer<Integer, RowOperation<T>> handler);
|
56797
|
125 |
|
56475
|
126 |
/**
|
56797
|
127 |
* Provides an error handler for this {@link Operation}. The provided handler
|
|
128 |
* is called for each error that occurs. When called the first argument is the
|
56475
|
129 |
* number of results, including errors, that preceeded the current error. The
|
|
130 |
* second argument is a {@link Throwable} corresponding to the error. When the
|
56797
|
131 |
* handler returns processing of the MultiOperation results continues. Only
|
|
132 |
* one onError method may be called.
|
|
133 |
*
|
56475
|
134 |
* @param handler a BiConsumer that handles an error
|
|
135 |
* @return this MultiOperation
|
56797
|
136 |
* @throws IllegalStateException if this method or
|
|
137 |
* {@link MultiOperation#onError(java.util.function.Consumer)} was called
|
|
138 |
* previously
|
56475
|
139 |
*/
|
|
140 |
public MultiOperation<T> onError(BiConsumer<Integer, Throwable> handler);
|
|
141 |
// Covariant overrides
|
|
142 |
|
|
143 |
/**
|
|
144 |
* This handler is called if the execution fails completely. If the execution
|
|
145 |
* returns any individual results, even if any or all of those results are
|
|
146 |
* errors, this handler is not called.
|
56797
|
147 |
*
|
56475
|
148 |
* @param handler
|
56797
|
149 |
* @return
|
56475
|
150 |
*/
|
|
151 |
@Override
|
|
152 |
public MultiOperation<T> onError(Consumer<Throwable> handler);
|
56797
|
153 |
|
56475
|
154 |
@Override
|
56797
|
155 |
public MultiOperation<T> apply(Function<Result.OutColumn, ? extends T> processor);
|
56475
|
156 |
|
|
157 |
@Override
|
|
158 |
public MultiOperation<T> outParameter(String id, SqlType type);
|
|
159 |
|
|
160 |
@Override
|
|
161 |
public MultiOperation<T> set(String id, Object value, SqlType type);
|
|
162 |
|
|
163 |
@Override
|
|
164 |
public MultiOperation<T> set(String id, Object value);
|
|
165 |
|
|
166 |
@Override
|
|
167 |
public MultiOperation<T> set(String id, CompletionStage<?> source, SqlType type);
|
|
168 |
|
|
169 |
@Override
|
|
170 |
public MultiOperation<T> set(String id, CompletionStage<?> source);
|
|
171 |
|
|
172 |
@Override
|
|
173 |
public MultiOperation<T> timeout(Duration minTime);
|
|
174 |
|
|
175 |
}
|