33import static com .openblocks .sdk .exception .PluginCommonError .QUERY_EXECUTION_ERROR ;
44import static com .openblocks .sdk .util .ExceptionUtils .ofPluginError ;
55import static com .openblocks .sdk .util .ExceptionUtils .ofPluginException ;
6+ import static com .openblocks .sdk .util .ExceptionUtils .propagateError ;
67
78import java .util .Map ;
89
@@ -27,8 +28,9 @@ public interface QueryExecutor<ConnectionConfig extends DatasourceConnectionConf
2728 extends ExtensionPoint {
2829
2930 /**
30- * should not override this method!
31+ * should use {@link #buildQueryExecutionContextMono} instead
3132 */
33+ @ Deprecated (forRemoval = true )
3234 @ SuppressWarnings ("unchecked" )
3335 default QueryContext doBuildQueryExecutionContext (DatasourceConnectionConfig datasourceConnectionConfig , Map <String , Object > queryConfig ,
3436 Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext ) {
@@ -46,6 +48,32 @@ default QueryContext doBuildQueryExecutionContext(DatasourceConnectionConfig dat
4648 }
4749 }
4850
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+
4977 /**
5078 * should not override this method!
5179 */
@@ -97,6 +125,10 @@ default Map<String, Object> sanitizeQueryConfig(Map<String, Object> queryConfig)
97125 return queryConfig ;
98126 }
99127
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 )
100132 QueryContext buildQueryExecutionContext (ConnectionConfig datasourceConfig , Map <String , Object > queryConfig ,
101133 Map <String , Object > requestParams , QueryVisitorContext queryVisitorContext );
102134
0 commit comments