This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new c52a70fa8 IGNITE-17038 Improve SQL API (#828)
c52a70fa8 is described below
commit c52a70fa867f1df18c6259e183be00f63460d914
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Thu May 26 17:29:40 2022 +0300
IGNITE-17038 Improve SQL API (#828)
* Merge `AsyncSession` and `ReactiveSession` into `Session`: consistent
with other APIs where sync and async methods reside in a single interface.
* Add missing async/reactive methods (`executeScript`) and missing
parameters (`arguments`).
---
.../main/java/org/apache/ignite/sql/Session.java | 128 +++++++++++++++++++--
.../org/apache/ignite/sql/async/AsyncSession.java | 84 --------------
.../ignite/sql/reactive/ReactiveSession.java | 84 --------------
3 files changed, 119 insertions(+), 177 deletions(-)
diff --git a/modules/api/src/main/java/org/apache/ignite/sql/Session.java
b/modules/api/src/main/java/org/apache/ignite/sql/Session.java
index 5be57da01..af61c455a 100644
--- a/modules/api/src/main/java/org/apache/ignite/sql/Session.java
+++ b/modules/api/src/main/java/org/apache/ignite/sql/Session.java
@@ -17,9 +17,11 @@
package org.apache.ignite.sql;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Flow;
import java.util.concurrent.TimeUnit;
-import org.apache.ignite.sql.async.AsyncSession;
-import org.apache.ignite.sql.reactive.ReactiveSession;
+import org.apache.ignite.sql.async.AsyncResultSet;
+import org.apache.ignite.sql.reactive.ReactiveResultSet;
import org.apache.ignite.tx.Transaction;
import org.jetbrains.annotations.Nullable;
@@ -29,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
* <p>Session is a stateful object and holds setting that intended to be used
as defaults for the new queries.
* Session object is immutable and thread-safe.
*/
-public interface Session extends AsyncSession, ReactiveSession, AutoCloseable {
+public interface Session extends AutoCloseable {
/** Default schema name. */
String DEFAULT_SCHEMA = "PUBLIC";
@@ -57,6 +59,50 @@ public interface Session extends AsyncSession,
ReactiveSession, AutoCloseable {
*/
ResultSet execute(@Nullable Transaction transaction, Statement statement,
@Nullable Object... arguments);
+ /**
+ * Executes SQL query in an asynchronous way.
+ *
+ * @param transaction Transaction to execute the query within or {@code
null}.
+ * @param query SQL query template.
+ * @param arguments Arguments for the template (optional).
+ * @return Operation future.
+ * @throws SqlException If failed.
+ */
+ CompletableFuture<AsyncResultSet> executeAsync(@Nullable Transaction
transaction, String query, @Nullable Object... arguments);
+
+ /**
+ * Executes SQL statement in an asynchronous way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param statement SQL statement to execute.
+ * @param arguments Arguments for the statement.
+ * @return Operation future.
+ * @throws SqlException If failed.
+ */
+ CompletableFuture<AsyncResultSet> executeAsync(@Nullable Transaction
transaction, Statement statement, @Nullable Object... arguments);
+
+ /**
+ * Executes SQL query in a reactive way.
+ *
+ * @param transaction Transaction to execute the query within or {@code
null}.
+ * @param query SQL query template.
+ * @param arguments Arguments for the template (optional).
+ * @return Reactive result.
+ * @throws SqlException If failed.
+ */
+ ReactiveResultSet executeReactive(@Nullable Transaction transaction,
String query, @Nullable Object... arguments);
+
+ /**
+ * Executes SQL query in a reactive way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param statement SQL statement.
+ * @param arguments Arguments for the statement.
+ * @return Reactive result.
+ * @throws SqlException If failed.
+ */
+ ReactiveResultSet executeReactive(@Nullable Transaction transaction,
Statement statement, @Nullable Object... arguments);
+
/**
* Executes batched SQL query. Only DML queries are supported.
*
@@ -75,11 +121,51 @@ public interface Session extends AsyncSession,
ReactiveSession, AutoCloseable {
* @param batch Batch of query arguments.
* @return Number of rows affected by each query in the batch.
*/
- int[] executeBatch(
- @Nullable Transaction transaction,
- Statement dmlStatement,
- BatchedArguments batch
- );
+ int[] executeBatch(@Nullable Transaction transaction, Statement
dmlStatement, BatchedArguments batch);
+
+ /**
+ * Executes batched SQL query in an asynchronous way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param query SQL query template.
+ * @param batch List of batch rows, where each row is a list of statement
arguments.
+ * @return Operation future.
+ * @throws SqlException If failed.
+ */
+ CompletableFuture<int[]> executeBatchAsync(@Nullable Transaction
transaction, String query, BatchedArguments batch);
+
+ /**
+ * Executes batched SQL query in an asynchronous way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param statement SQL statement to execute.
+ * @param batch List of batch rows, where each row is a list of statement
arguments.
+ * @return Operation future.
+ * @throws SqlException If failed.
+ */
+ CompletableFuture<int[]> executeBatchAsync(@Nullable Transaction
transaction, Statement statement, BatchedArguments batch);
+
+ /**
+ * Executes batched SQL query in a reactive way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param query SQL query template.
+ * @param batch List of batch rows, where each row is a list of statement
arguments.
+ * @return Publisher for the number of rows affected by the query.
+ * @throws SqlException If failed.
+ */
+ Flow.Publisher<Integer> executeBatchReactive(@Nullable Transaction
transaction, String query, BatchedArguments batch);
+
+ /**
+ * Executes batched SQL query in a reactive way.
+ *
+ * @param transaction Transaction to execute the statement within or
{@code null}.
+ * @param statement SQL statement to execute.
+ * @param batch List of batch rows, where each row is a list of statement
arguments.
+ * @return Publisher for the number of rows affected by the query.
+ * @throws SqlException If failed.
+ */
+ Flow.Publisher<Integer> executeBatchReactive(@Nullable Transaction
transaction, Statement statement, BatchedArguments batch);
/**
* Executes multi-statement SQL query.
@@ -90,6 +176,16 @@ public interface Session extends AsyncSession,
ReactiveSession, AutoCloseable {
*/
void executeScript(String query, @Nullable Object... arguments);
+ /**
+ * Executes multi-statement SQL query.
+ *
+ * @param query SQL query template.
+ * @param arguments Arguments for the template (optional).
+ * @return Operation future.
+ * @throws SqlException If failed.
+ */
+ CompletableFuture<Void> executeScriptAsync(String query, @Nullable
Object... arguments);
+
/**
* Return default query timeout.
*
@@ -121,11 +217,25 @@ public interface Session extends AsyncSession,
ReactiveSession, AutoCloseable {
@Nullable Object property(String name);
/**
- * Invalidates session, cleanup remote session resources, and stops all
queries that are running within the current session.
+ * Invalidates session, cleans up remote session resources, and stops all
queries that are running within the current session.
*/
@Override
void close();
+ /**
+ * Invalidates session, cleans up remote session resources, and stops all
queries that are running within the current session.
+ *
+ * @return Operation future.
+ */
+ CompletableFuture<Void> closeAsync();
+
+ /**
+ * Invalidates session, cleans up remote session resources, and stops all
queries that are running within the current session.
+ *
+ * @return Publisher.
+ */
+ Flow.Publisher<Void> closeReactive();
+
/**
* Creates a new session builder from current session.
*/
diff --git
a/modules/api/src/main/java/org/apache/ignite/sql/async/AsyncSession.java
b/modules/api/src/main/java/org/apache/ignite/sql/async/AsyncSession.java
deleted file mode 100644
index 53ba478cf..000000000
--- a/modules/api/src/main/java/org/apache/ignite/sql/async/AsyncSession.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-package org.apache.ignite.sql.async;
-
-import java.util.concurrent.CompletableFuture;
-import org.apache.ignite.sql.BatchedArguments;
-import org.apache.ignite.sql.SqlException;
-import org.apache.ignite.sql.Statement;
-import org.apache.ignite.tx.Transaction;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Async Session provides methods for asynchronous query execution.
- *
- * @see org.apache.ignite.sql.Session
- */
-public interface AsyncSession {
- /**
- * Executes SQL query in an asynchronous way.
- *
- * @param transaction Transaction to execute the query within or {@code
null}.
- * @param query SQL query template.
- * @param arguments Arguments for the template (optional).
- * @return Operation future.
- * @throws SqlException If failed.
- */
- CompletableFuture<AsyncResultSet> executeAsync(@Nullable Transaction
transaction, String query,
- @Nullable Object... arguments);
-
- /**
- * Executes SQL statement in an asynchronous way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param statement SQL statement to execute.
- * @return Operation future.
- * @throws SqlException If failed.
- */
- CompletableFuture<AsyncResultSet> executeAsync(@Nullable Transaction
transaction, Statement statement);
-
- /**
- * Executes batched SQL query in an asynchronous way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param query SQL query template.
- * @param batch List of batch rows, where each row is a list of statement
arguments.
- * @return Operation future.
- * @throws SqlException If failed.
- */
- CompletableFuture<Integer> executeBatchAsync(
- @Nullable Transaction transaction,
- String query,
- BatchedArguments batch
- );
-
- /**
- * Executes batched SQL query in an asynchronous way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param statement SQL statement to execute.
- * @param batch List of batch rows, where each row is a list of statement
arguments.
- * @return Operation future.
- * @throws SqlException If failed.
- */
- CompletableFuture<Integer> executeBatchAsync(
- @Nullable Transaction transaction,
- Statement statement,
- BatchedArguments batch
- );
-}
diff --git
a/modules/api/src/main/java/org/apache/ignite/sql/reactive/ReactiveSession.java
b/modules/api/src/main/java/org/apache/ignite/sql/reactive/ReactiveSession.java
deleted file mode 100644
index c81344928..000000000
---
a/modules/api/src/main/java/org/apache/ignite/sql/reactive/ReactiveSession.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-package org.apache.ignite.sql.reactive;
-
-import java.util.concurrent.Flow;
-import org.apache.ignite.sql.BatchedArguments;
-import org.apache.ignite.sql.SqlException;
-import org.apache.ignite.sql.Statement;
-import org.apache.ignite.tx.Transaction;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Reactive Session provides methods for reactive query execution.
- *
- * @see org.apache.ignite.sql.Session
- */
-public interface ReactiveSession {
- /**
- * Executes SQL query in a reactive way.
- *
- * @param transaction Transaction to execute the query within or {@code
null}.
- * @param query SQL query template.
- * @param arguments Arguments for the template (optional).
- * @return Reactive result.
- * @throws SqlException If failed.
- */
- ReactiveResultSet executeReactive(@Nullable Transaction transaction,
String query,
- @Nullable Object... arguments);
-
- /**
- * Executes SQL query in a reactive way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param statement SQL statement.
- * @return Reactive result.
- * @throws SqlException If failed.
- */
- ReactiveResultSet executeReactive(@Nullable Transaction transaction,
Statement statement);
-
- /**
- * Executes batched SQL query in a reactive way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param query SQL query template.
- * @param batch List of batch rows, where each row is a list of statement
arguments.
- * @return Publisher for the number of rows affected by the query.
- * @throws SqlException If failed.
- */
- Flow.Publisher<Integer> executeBatchReactive(
- @Nullable Transaction transaction,
- String query,
- BatchedArguments batch
- );
-
- /**
- * Executes batched SQL query in a reactive way.
- *
- * @param transaction Transaction to execute the statement within or
{@code null}.
- * @param statement SQL statement to execute.
- * @param batch List of batch rows, where each row is a list of statement
arguments.
- * @return Publisher for the number of rows affected by the query.
- * @throws SqlException If failed.
- */
- Flow.Publisher<Integer> executeBatchReactive(
- @Nullable Transaction transaction,
- Statement statement,
- BatchedArguments batch
- );
-}