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
|
|
36 |
* processed by an Operation. The Operations can be created by calling rowOperation,
|
|
37 |
* rowProcessorOperation, or countOperation if the kind of results is known. These
|
|
38 |
* results are processed in the order the Operations are submitted. Any results
|
|
39 |
* not processed by an explicit Operation is processed by calling the appropriate
|
|
40 |
* handler specified by onRows or onCount. If any result is an error that error
|
|
41 |
* is processed by calling the handler specified by onError. If the appropriate
|
|
42 |
* handler is not specified that result is ignored, including errors.
|
|
43 |
*
|
|
44 |
* ISSUE: Should this have a collector?
|
|
45 |
*
|
|
46 |
* @param <T> The type of the result of this {@link Operation}
|
|
47 |
*/
|
|
48 |
public interface MultiOperation<T> extends OutOperation<T> {
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Returns a {@link RowOperation} to process a row sequence result. The
|
|
52 |
* {@link Operation}s are executed in the order they are submitted. If a
|
|
53 |
* result is of the wrong type for the next submitted {@link Operation} the
|
|
54 |
* {@link MultiOperation} is completed with
|
|
55 |
* {@link IllegalStateException}.
|
|
56 |
*
|
|
57 |
* @return a {@link RowOperation} that is part of this {@link MultiOperation}
|
|
58 |
*/
|
|
59 |
public RowOperation<T> rowOperation();
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Returns a {@link RowProcessorOperation} to process a row sequence result. The
|
|
63 |
* {@link Operation}s are executed in the order they are submitted. If a
|
|
64 |
* result is of the wrong type for the next submitted {@link Operation} the
|
|
65 |
* {@link MultiOperation} is completed with
|
|
66 |
* {@link IllegalStateException}.
|
|
67 |
*
|
|
68 |
* @return a {@link RowProcessorOperation} that is part of this {@link MultiOperation}
|
|
69 |
*/
|
|
70 |
public RowProcessorOperation<T> rowProcessorOperation();
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Returns a {@link CountOperation} to process a count result. The {@link Operation}s
|
|
74 |
* are executed in the order they are submitted. If a result is of the wrong
|
|
75 |
* type for the next submitted Operation the {@link MultiOperation} is completed
|
|
76 |
* with {@link IllegalStateException}.
|
|
77 |
*
|
|
78 |
* @return a {@link CountOperation} that is part of this {@link MultiOperation}
|
|
79 |
*/
|
|
80 |
public CountOperation<T> countOperation();
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Provides a handler for trailing count results. The provided handler is called for
|
|
84 |
* each count result not processed by CountOperation. When called the first argument is the number of results
|
|
85 |
* that preceeded the current result. The second argument is a
|
|
86 |
* {@link CountOperation} that will process the current result. This
|
|
87 |
* {@link CountOperation} has not been configured in any way nor has it been
|
|
88 |
* submitted. The handler configures the {@link CountOperation} and submits
|
|
89 |
* it. The count result is processed when the {@link CountOperation} is
|
|
90 |
* submitted. If the {@link CountOperation} is not submitted when the handler
|
|
91 |
* returns the count result is ignored.
|
|
92 |
*
|
|
93 |
* If this method is not called any trailing count results are ignored.
|
|
94 |
*
|
|
95 |
* @param handler not null
|
|
96 |
* @return this MultiOperation
|
|
97 |
* @throws IllegalStateException if this method was called previously
|
|
98 |
*/
|
|
99 |
public MultiOperation<T> onCount(BiConsumer<Integer, CountOperation<T>> handler);
|
|
100 |
|
|
101 |
/**
|
|
102 |
* Provides a handler for trailing row sequence results. The provided handler is called
|
|
103 |
* for each row sequence result not processed by a RowOperation. When called the first argument is the number
|
|
104 |
* of results that preceeded the current result. The second argument is a
|
|
105 |
* {@link RowOperation} that will process the current result. This
|
|
106 |
* {@link RowOperation} has not been configured in any way nor has it been
|
|
107 |
* submitted. The handler configures the {@link RowOperation} and submits it.
|
|
108 |
* The row sequence result is processed when the {@link RowOperation} is
|
|
109 |
* submitted. If the {@link RowOperation} is not submitted when the handler
|
|
110 |
* returns, the row sequence result is ignored.
|
|
111 |
*
|
|
112 |
* If this method is not called any trailing row sequence results are ignored.
|
|
113 |
*
|
|
114 |
* ISSUE: Should there be a version of this method that provides
|
|
115 |
* RowProcessorOperations? If so only one of that method or this one can be called.
|
|
116 |
*
|
|
117 |
* @param handler
|
|
118 |
* @return This MultiOperation
|
|
119 |
* @throws IllegalStateException if this method was called previously
|
|
120 |
*/
|
|
121 |
public MultiOperation<T> onRows(BiConsumer<Integer, RowOperation<T>> handler);
|
|
122 |
|
|
123 |
/**
|
|
124 |
* Provides an error handler for this {@link Operation}. The provided handler
|
|
125 |
* is called for each error that occurs. When called the first argument is the
|
|
126 |
* number of results, including errors, that preceeded the current error. The
|
|
127 |
* second argument is a {@link Throwable} corresponding to the error. When the
|
|
128 |
* handler returns processing of the MultiOperation results continues.
|
|
129 |
* Only one onError method may be called.
|
|
130 |
*
|
|
131 |
* @param handler a BiConsumer that handles an error
|
|
132 |
* @return this MultiOperation
|
|
133 |
* @throws IllegalStateException if this method was called previously
|
|
134 |
*/
|
|
135 |
public MultiOperation<T> onError(BiConsumer<Integer, Throwable> handler);
|
|
136 |
// Covariant overrides
|
|
137 |
|
|
138 |
/**
|
|
139 |
* This handler is called if the execution fails completely. If the execution
|
|
140 |
* returns any individual results, even if any or all of those results are
|
|
141 |
* errors, this handler is not called.
|
|
142 |
*
|
|
143 |
* @param handler
|
|
144 |
* @return
|
|
145 |
*/
|
|
146 |
@Override
|
|
147 |
public MultiOperation<T> onError(Consumer<Throwable> handler);
|
|
148 |
|
|
149 |
@Override
|
|
150 |
public MultiOperation<T> apply(Function<Result.OutParameterMap, ? extends T> processor);
|
|
151 |
|
|
152 |
@Override
|
|
153 |
public MultiOperation<T> outParameter(String id, SqlType type);
|
|
154 |
|
|
155 |
@Override
|
|
156 |
public MultiOperation<T> set(String id, Object value, SqlType type);
|
|
157 |
|
|
158 |
@Override
|
|
159 |
public MultiOperation<T> set(String id, Object value);
|
|
160 |
|
|
161 |
@Override
|
|
162 |
public MultiOperation<T> set(String id, CompletionStage<?> source, SqlType type);
|
|
163 |
|
|
164 |
@Override
|
|
165 |
public MultiOperation<T> set(String id, CompletionStage<?> source);
|
|
166 |
|
|
167 |
@Override
|
|
168 |
public MultiOperation<T> timeout(Duration minTime);
|
|
169 |
|
|
170 |
}
|