3
3
import static com .openblocks .sdk .exception .PluginCommonError .QUERY_EXECUTION_ERROR ;
4
4
import static com .openblocks .sdk .util .ExceptionUtils .ofPluginError ;
5
5
import static com .openblocks .sdk .util .ExceptionUtils .ofPluginException ;
6
+ import static com .openblocks .sdk .util .ExceptionUtils .propagateError ;
6
7
7
8
import java .util .Map ;
8
9
@@ -27,8 +28,9 @@ public interface QueryExecutor<ConnectionConfig extends DatasourceConnectionConf
27
28
extends ExtensionPoint {
28
29
29
30
/**
30
- * should not override this method!
31
+ * should use {@link #buildQueryExecutionContextMono} instead
31
32
*/
33
+ @ Deprecated (forRemoval = true )
32
34
@ SuppressWarnings ("unchecked" )
33
35
default QueryContext doBuildQueryExecutionContext (DatasourceConnectionConfig datasourceConnectionConfig , Map <String , Object > queryConfig ,
34
36
Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext ) {
@@ -46,6 +48,32 @@ default QueryContext doBuildQueryExecutionContext(DatasourceConnectionConfig dat
46
48
}
47
49
}
48
50
51
+ @ SuppressWarnings ("unchecked" )
52
+ default Mono <QueryContext > buildQueryExecutionContextMono (DatasourceConnectionConfig datasourceConnectionConfig ,
53
+ Map <String , Object > queryConfig ,
54
+ Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext ) {
55
+ ConnectionConfig connectionConfig ;
56
+ try {
57
+ connectionConfig = (ConnectionConfig ) datasourceConnectionConfig ;
58
+ } catch (ClassCastException e ) {
59
+ return propagateError (PluginCommonError .INVALID_QUERY_SETTINGS , "INVALID_QUERY_SETTINGS" , e );
60
+ }
61
+
62
+ return doBuildQueryExecutionContextMono (connectionConfig , queryConfig , requestParams , queryVisitorContext );
63
+ }
64
+
65
+ /**
66
+ * We'll call JS to do server-side parsing and mustache {{ }} handling in the future,
67
+ * plugins should override this method to return a Mono<QueryContext>
68
+ */
69
+ @ SuppressWarnings ("unchecked" )
70
+ default Mono <QueryContext > doBuildQueryExecutionContextMono (ConnectionConfig connectionConfig ,
71
+ Map <String , Object > queryConfig ,
72
+ Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext ) {
73
+ return Mono .fromSupplier (() -> buildQueryExecutionContext (connectionConfig , queryConfig , requestParams , queryVisitorContext ))
74
+ .onErrorMap (e -> ExceptionUtils .wrapException (PluginCommonError .INVALID_QUERY_SETTINGS , "QUERY_ARGUMENT_ERROR" , e ));
75
+ }
76
+
49
77
/**
50
78
* should not override this method!
51
79
*/
@@ -97,6 +125,10 @@ default Map<String, Object> sanitizeQueryConfig(Map<String, Object> queryConfig)
97
125
return queryConfig ;
98
126
}
99
127
128
+ /**
129
+ * We'll call JS to do server-side parsing and mustache {{ }} handling in the future, so this blocking call should be removed
130
+ */
131
+ @ Deprecated (forRemoval = true )
100
132
QueryContext buildQueryExecutionContext (ConnectionConfig datasourceConfig , Map <String , Object > queryConfig ,
101
133
Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext );
102
134
0 commit comments