You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2022/01/13 01:37:39 UTC

[ignite-3] branch ignite-16244 created (now 423be6b)

This is an automated email from the ASF dual-hosted git repository.

vkulichenko pushed a change to branch ignite-16244
in repository https://gitbox.apache.org/repos/asf/ignite-3.git.


      at 423be6b  IGNITE-16244

This branch includes the following new commits:

     new 26b5db1  IGNITE-16244
     new 423be6b  IGNITE-16244

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[ignite-3] 01/02: IGNITE-16244

Posted by vk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vkulichenko pushed a commit to branch ignite-16244
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 26b5db15e27d9186c490f398877480e9673b92c8
Author: Valentin Kulichenko <va...@gmail.com>
AuthorDate: Wed Jan 12 14:22:36 2022 -0800

    IGNITE-16244
---
 .../ignite/example/sql/jdbc/SqlJdbcExample.java    | 342 +++++++++------------
 .../ignite/example/table/KeyValueViewExample.java  | 148 ++++-----
 .../example/table/KeyValueViewPojoExample.java     | 154 ++++++++++
 .../ignite/example/table/RecordViewExample.java    | 146 ++++-----
 .../example/table/RecordViewPojoExample.java       | 155 ++++++++++
 5 files changed, 564 insertions(+), 381 deletions(-)

diff --git a/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java b/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
index ab382cd..9a1aab3 100644
--- a/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
@@ -17,19 +17,7 @@
 
 package org.apache.ignite.example.sql.jdbc;
 
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgnitionManager;
-import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
-import org.apache.ignite.schema.SchemaBuilders;
-import org.apache.ignite.schema.definition.ColumnType;
-import org.apache.ignite.schema.definition.TableDefinition;
+import java.sql.*;
 
 /**
  * This example demonstrates the usage of the Apache Ignite JDBC driver.
@@ -54,236 +42,182 @@ public class SqlJdbcExample {
     public static void main(String[] args) throws Exception {
         //--------------------------------------------------------------------------------------
         //
-        // Starting a server node.
-        //
-        // NOTE: An embedded server node is only needed to invoke the 'createTable' API.
-        //       In the future releases, this API will be available on the client,
-        //       eliminating the need to start an embedded server node in this example.
+        // Creating a JDBC connection to connect to the cluster.
         //
         //--------------------------------------------------------------------------------------
 
-        System.out.println("Starting a server node... Logging to file: example-node.log");
-
-        System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+        System.out.println("\nConnecting to server...");
 
-        try (Ignite ignite = IgnitionManager.start(
-                "example-node",
-                Files.readString(Path.of("config", "ignite-config.json")),
-                Path.of("work")
-        )) {
+        try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
             //--------------------------------------------------------------------------------------
             //
-            // Creating 'CITIES' table. The API call below is the equivalent of the following DDL:
+            // Creating tables.
+            //
+            //--------------------------------------------------------------------------------------
+
+            try (Statement stmt = conn.createStatement()) {
+                stmt.executeUpdate(
+                    "CREATE TABLE CITIES (" +
+                    "    ID   INT PRIMARY KEY," +
+                    "    NAME VARCHAR" +
+                    ")"
+                );
+
+                stmt.executeUpdate(
+                    "CREATE TABLE ACCOUNTS (" +
+                    "    ACCOUNT_ID INT PRIMARY KEY," +
+                    "    CITY_ID    INT," +
+                    "    FIRST_NAME VARCHAR," +
+                    "    LAST_NAME  VARCHAR," +
+                    "    BALANCE    DOUBLE" +
+                    ")"
+                );
+            }
+
+            //--------------------------------------------------------------------------------------
             //
-            //     CREATE TABLE cities (
-            //         ID   INT PRIMARY KEY,
-            //         NAME VARCHAR
-            //     )
+            // Populating 'CITIES' table.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nCreating 'CITIES' table...");
+            System.out.println("\nPopulating 'CITIES' table...");
 
-            TableDefinition citiesTableDef = SchemaBuilders.tableBuilder("PUBLIC", "CITIES")
-                    .columns(
-                            SchemaBuilders.column("ID", ColumnType.INT32).build(),
-                            SchemaBuilders.column("NAME", ColumnType.string()).asNullable(true).build()
-                    )
-                    .withPrimaryKey("ID")
-                    .build();
+            try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO CITIES (ID, NAME) VALUES (?, ?)")) {
+                stmt.setInt(1, 1);
+                stmt.setString(2, "Forest Hill");
+                stmt.executeUpdate();
 
-            ignite.tables().createTable(citiesTableDef.canonicalName(), tableChange ->
-                    SchemaConfigurationConverter.convert(citiesTableDef, tableChange)
-                            .changeReplicas(1)
-                            .changePartitions(10)
-            );
+                stmt.setInt(1, 2);
+                stmt.setString(2, "Denver");
+                stmt.executeUpdate();
+
+                stmt.setInt(1, 3);
+                stmt.setString(2, "St. Petersburg");
+                stmt.executeUpdate();
+            }
 
             //--------------------------------------------------------------------------------------
             //
-            // Creating 'ACCOUNTS' table. The API call below is the equivalent of the following DDL:
-            //
-            //     CREATE TABLE ACCOUNTS (
-            //         ACCOUNT_ID INT PRIMARY KEY,
-            //         CITY_ID    INT,
-            //         FIRST_NAME VARCHAR,
-            //         LAST_NAME  VARCHAR,
-            //         BALANCE    DOUBLE
-            //     )
+            // Populating 'ACCOUNTS' table.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nCreating 'ACCOUNTS' table...");
-
-            TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "ACCOUNTS")
-                    .columns(
-                            SchemaBuilders.column("ACCOUNT_ID", ColumnType.INT32).build(),
-                            SchemaBuilders.column("CITY_ID", ColumnType.INT32).build(),
-                            SchemaBuilders.column("FIRST_NAME", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("LAST_NAME", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("BALANCE", ColumnType.DOUBLE).asNullable(true).build()
-                    )
-                    .withPrimaryKey("ACCOUNT_ID")
-                    .build();
-
-            ignite.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
-                    SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
-                            .changeReplicas(1)
-                            .changePartitions(10)
-            );
+            System.out.println("\nPopulating 'ACCOUNTS' table...");
+
+            try (PreparedStatement stmt = conn.prepareStatement(
+                "INSERT INTO ACCOUNTS (ACCOUNT_ID, CITY_ID, FIRST_NAME, LAST_NAME, BALANCE) values (?, ?, ?, ?, ?)")) {
+                stmt.setInt(1, 1);
+                stmt.setInt(2, 1);
+                stmt.setString(3, "John");
+                stmt.setString(4, "Doe");
+                stmt.setDouble(5, 1000.0d);
+                stmt.executeUpdate();
+
+                stmt.setInt(1, 2);
+                stmt.setInt(2, 1);
+                stmt.setString(3, "Jane");
+                stmt.setString(4, "Roe");
+                stmt.setDouble(5, 2000.0d);
+                stmt.executeUpdate();
+
+                stmt.setInt(1, 3);
+                stmt.setInt(2, 2);
+                stmt.setString(3, "Mary");
+                stmt.setString(4, "Major");
+                stmt.setDouble(5, 1500.0d);
+                stmt.executeUpdate();
+
+                stmt.setInt(1, 4);
+                stmt.setInt(2, 3);
+                stmt.setString(3, "Richard");
+                stmt.setString(4, "Miles");
+                stmt.setDouble(5, 1450.0d);
+                stmt.executeUpdate();
+            }
 
             //--------------------------------------------------------------------------------------
             //
-            // Creating a JDBC connection to connect to the cluster.
+            // Requesting information about all account owners.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nConnecting to server...");
-
-            try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
-
-                //--------------------------------------------------------------------------------------
-                //
-                // Populating 'CITIES' table.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nPopulating 'CITIES' table...");
-
-                try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO CITIES (ID, NAME) VALUES (?, ?)")) {
-                    stmt.setInt(1, 1);
-                    stmt.setString(2, "Forest Hill");
-                    stmt.executeUpdate();
-
-                    stmt.setInt(1, 2);
-                    stmt.setString(2, "Denver");
-                    stmt.executeUpdate();
-
-                    stmt.setInt(1, 3);
-                    stmt.setString(2, "St. Petersburg");
-                    stmt.executeUpdate();
+            System.out.println("\nAll accounts:");
+
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery(
+                    "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a "
+                        + "INNER JOIN CITIES c on c.ID = a.CITY_ID ORDER BY a.ACCOUNT_ID")) {
+                    while (rs.next()) {
+                        System.out.println("    "
+                            + rs.getString(1) + ", "
+                            + rs.getString(2) + ", "
+                            + rs.getString(3));
+                    }
                 }
+            }
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Populating 'ACCOUNTS' table.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nPopulating 'ACCOUNTS' table...");
-
-                try (PreparedStatement stmt = conn.prepareStatement(
-                        "INSERT INTO ACCOUNTS (ACCOUNT_ID, CITY_ID, FIRST_NAME, LAST_NAME, BALANCE) values (?, ?, ?, ?, ?)")) {
-                    stmt.setInt(1, 1);
-                    stmt.setInt(2, 1);
-                    stmt.setString(3, "John");
-                    stmt.setString(4, "Doe");
-                    stmt.setDouble(5, 1000.0d);
-                    stmt.executeUpdate();
-
-                    stmt.setInt(1, 2);
-                    stmt.setInt(2, 1);
-                    stmt.setString(3, "Jane");
-                    stmt.setString(4, "Roe");
-                    stmt.setDouble(5, 2000.0d);
-                    stmt.executeUpdate();
-
-                    stmt.setInt(1, 3);
-                    stmt.setInt(2, 2);
-                    stmt.setString(3, "Mary");
-                    stmt.setString(4, "Major");
-                    stmt.setDouble(5, 1500.0d);
-                    stmt.executeUpdate();
-
-                    stmt.setInt(1, 4);
-                    stmt.setInt(2, 3);
-                    stmt.setString(3, "Richard");
-                    stmt.setString(4, "Miles");
-                    stmt.setDouble(5, 1450.0d);
-                    stmt.executeUpdate();
-                }
+            //--------------------------------------------------------------------------------------
+            //
+            // Requesting accounts with balances lower than 1,500.
+            //
+            //--------------------------------------------------------------------------------------
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Requesting information about all account owners.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nAll accounts:");
-
-                try (Statement stmt = conn.createStatement()) {
-                    try (ResultSet rs = stmt.executeQuery(
-                            "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a "
-                                    + "INNER JOIN CITIES c on c.ID = a.CITY_ID ORDER BY a.ACCOUNT_ID")) {
-                        while (rs.next()) {
-                            System.out.println("    "
-                                    + rs.getString(1) + ", "
-                                    + rs.getString(2) + ", "
-                                    + rs.getString(3));
-                        }
+            System.out.println("\nAccounts with balance lower than 1,500:");
+
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery(
+                    "SELECT a.FIRST_NAME, a.LAST_NAME, a.BALANCE FROM ACCOUNTS a WHERE a.BALANCE < 1500.0 "
+                        + "ORDER BY a.ACCOUNT_ID")) {
+                    while (rs.next()) {
+                        System.out.println("    "
+                            + rs.getString(1) + ", "
+                            + rs.getString(2) + ", "
+                            + rs.getDouble(3));
                     }
                 }
+            }
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Requesting accounts with balances lower than 1,500.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nAccounts with balance lower than 1,500:");
-
-                try (Statement stmt = conn.createStatement()) {
-                    try (ResultSet rs = stmt.executeQuery(
-                            "SELECT a.FIRST_NAME, a.LAST_NAME, a.BALANCE FROM ACCOUNTS a WHERE a.BALANCE < 1500.0 "
-                                    + "ORDER BY a.ACCOUNT_ID")) {
-                        while (rs.next()) {
-                            System.out.println("    "
-                                    + rs.getString(1) + ", "
-                                    + rs.getString(2) + ", "
-                                    + rs.getDouble(3));
-                        }
-                    }
-                }
+            //--------------------------------------------------------------------------------------
+            //
+            // Deleting one of the accounts.
+            //
+            //--------------------------------------------------------------------------------------
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Deleting one of the accounts.
-                //
-                //--------------------------------------------------------------------------------------
+            System.out.println("\nDeleting one of the accounts...");
 
-                System.out.println("\nDeleting one of the accounts...");
+            try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM ACCOUNTS WHERE ACCOUNT_ID = ?")) {
+                stmt.setInt(1, 1);
+                stmt.executeUpdate();
+            }
 
-                try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM ACCOUNTS WHERE ACCOUNT_ID = ?")) {
-                    stmt.setInt(1, 1);
-                    stmt.executeUpdate();
-                }
+            //--------------------------------------------------------------------------------------
+            //
+            // Requesting information about all account owners once again
+            // to verify that the account was actually deleted.
+            //
+            //--------------------------------------------------------------------------------------
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Requesting information about all account owners once again
-                // to verify that the account was actually deleted.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nAll accounts:");
-
-                try (Statement stmt = conn.createStatement()) {
-                    try (ResultSet rs = stmt.executeQuery(
-                            "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a "
-                                    + "INNER JOIN CITIES c on c.ID = a.CITY_ID ORDER BY a.ACCOUNT_ID")) {
-                        while (rs.next()) {
-                            System.out.println("    "
-                                    + rs.getString(1) + ", "
-                                    + rs.getString(2) + ", "
-                                    + rs.getString(3));
-                        }
+            System.out.println("\nAll accounts:");
+
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery(
+                    "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a "
+                            + "INNER JOIN CITIES c on c.ID = a.CITY_ID ORDER BY a.ACCOUNT_ID")) {
+                    while (rs.next()) {
+                        System.out.println("    "
+                            + rs.getString(1) + ", "
+                            + rs.getString(2) + ", "
+                            + rs.getString(3));
                     }
                 }
             }
 
-            System.out.println("\nDropping tables and stopping the server...");
+            System.out.println("\nDropping the tables...");
 
-            ignite.tables().dropTable(citiesTableDef.canonicalName());
-            ignite.tables().dropTable(accountsTableDef.canonicalName());
+            try (Statement stmt = conn.createStatement()) {
+                stmt.executeUpdate("DROP TABLE ACCOUNTS");
+                stmt.executeUpdate("DROP TABLE CITIES");
+            }
         }
     }
 }
diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
index 0943ae5..3ba05ef 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
@@ -17,18 +17,14 @@
 
 package org.apache.ignite.example.table;
 
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgnitionManager;
 import org.apache.ignite.client.IgniteClient;
-import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
-import org.apache.ignite.schema.SchemaBuilders;
-import org.apache.ignite.schema.definition.ColumnType;
-import org.apache.ignite.schema.definition.TableDefinition;
 import org.apache.ignite.table.KeyValueView;
 import org.apache.ignite.table.Tuple;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
 /**
  * This example demonstrates the usage of the {@link KeyValueView} API.
  *
@@ -52,112 +48,86 @@ public class KeyValueViewExample {
     public static void main(String[] args) throws Exception {
         //--------------------------------------------------------------------------------------
         //
-        // Starting a server node.
-        //
-        // NOTE: An embedded server node is only needed to invoke the 'createTable' API.
-        //       In the future releases, this API will be available on the client,
-        //       eliminating the need to start an embedded server node in this example.
+        // Creating 'accounts' table.
         //
         //--------------------------------------------------------------------------------------
 
-        System.out.println("Starting a server node... Logging to file: example-node.log");
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate(
+                "CREATE TABLE accounts (" +
+                "    accountNumber INT PRIMARY KEY," +
+                "    firstName     VARCHAR," +
+                "    lastName      VARCHAR," +
+                "    balance       DOUBLE" +
+                ")"
+            );
+        }
+
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating a client to connect to the cluster.
+        //
+        //--------------------------------------------------------------------------------------
 
-        System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+        System.out.println("\nConnecting to server...");
 
-        try (Ignite server = IgnitionManager.start(
-                "example-node",
-                Files.readString(Path.of("config", "ignite-config.json")),
-                Path.of("work")
-        )) {
+        try (IgniteClient client = IgniteClient.builder()
+            .addresses("127.0.0.1:10800")
+            .build()
+        ) {
             //--------------------------------------------------------------------------------------
             //
-            // Creating 'accounts' table. The API call below is the equivalent of the following DDL:
-            //
-            //     CREATE TABLE accounts (
-            //         accountNumber INT PRIMARY KEY,
-            //         firstName     VARCHAR,
-            //         lastName      VARCHAR,
-            //         balance       DOUBLE
-            //     )
+            // Creating a key-value view for the 'accounts' table.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nCreating 'accounts' table...");
-
-            TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "accounts")
-                    .columns(
-                            SchemaBuilders.column("accountNumber", ColumnType.INT32).build(),
-                            SchemaBuilders.column("firstName", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("lastName", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable(true).build()
-                    )
-                    .withPrimaryKey("accountNumber")
-                    .build();
-
-            server.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
-                    SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
-                            .changeReplicas(1)
-                            .changePartitions(10)
-            );
+            KeyValueView<Tuple, Tuple> kvView = client.tables().table("PUBLIC.accounts").keyValueView();
 
             //--------------------------------------------------------------------------------------
             //
-            // Creating a client to connect to the cluster.
+            // Performing the 'put' operation.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nConnecting to server...");
-
-            try (IgniteClient client = IgniteClient.builder()
-                    .addresses("127.0.0.1:10800")
-                    .build()
-            ) {
-                //--------------------------------------------------------------------------------------
-                //
-                // Creating a key-value view for the 'accounts' table.
-                //
-                //--------------------------------------------------------------------------------------
-
-                KeyValueView<Tuple, Tuple> kvView = client.tables().table("PUBLIC.accounts").keyValueView();
-
-                //--------------------------------------------------------------------------------------
-                //
-                // Performing the 'put' operation.
-                //
-                //--------------------------------------------------------------------------------------
-
-                System.out.println("\nInserting a key-value pair into the 'accounts' table...");
+            System.out.println("\nInserting a key-value pair into the 'accounts' table...");
 
-                Tuple key = Tuple.create()
-                        .set("accountNumber", 123456);
+            Tuple key = Tuple.create()
+                .set("accountNumber", 123456);
 
-                Tuple value = Tuple.create()
-                        .set("firstName", "Val")
-                        .set("lastName", "Kulichenko")
-                        .set("balance", 100.00d);
+            Tuple value = Tuple.create()
+                .set("firstName", "Val")
+                .set("lastName", "Kulichenko")
+                .set("balance", 100.00d);
 
-                kvView.put(null, key, value);
+            kvView.put(null, key, value);
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Performing the 'get' operation.
-                //
-                //--------------------------------------------------------------------------------------
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'get' operation.
+            //
+            //--------------------------------------------------------------------------------------
 
-                System.out.println("\nRetrieving a value using KeyValueView API...");
+            System.out.println("\nRetrieving a value using KeyValueView API...");
 
-                value = kvView.get(null, key);
+            value = kvView.get(null, key);
 
-                System.out.println(
-                        "\nRetrieved value:\n"
-                                + "    Account Number: " + key.intValue("accountNumber") + '\n'
-                                + "    Owner: " + value.stringValue("firstName") + " " + value.stringValue("lastName") + '\n'
-                                + "    Balance: $" + value.doubleValue("balance"));
-            }
+            System.out.println(
+                "\nRetrieved value:\n" +
+                "    Account Number: " + key.intValue("accountNumber") + '\n' +
+                "    Owner: " + value.stringValue("firstName") + " " + value.stringValue("lastName") + '\n' +
+                "    Balance: $" + value.doubleValue("balance"));
+        }
 
-            System.out.println("\nDropping the table and stopping the server...");
+        System.out.println("\nDropping the table...");
 
-            server.tables().dropTable(accountsTableDef.canonicalName());
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate("DROP TABLE accounts");
         }
     }
 }
diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
new file mode 100644
index 0000000..f5c1200
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
@@ -0,0 +1,154 @@
+/*
+ * 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.example.table;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.table.KeyValueView;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+/**
+ * This example demonstrates the usage of the {@link KeyValueView} API.
+ *
+ * <p>To run the example, do the following:
+ * <ol>
+ *     <li>Import the examples project into you IDE.</li>
+ *     <li>
+ *         Start a server node using the CLI tool:<br>
+ *         {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json my-first-node}
+ *     </li>
+ *     <li>Run the example in the IDE.</li>
+ * </ol>
+ */
+public class KeyValueViewPojoExample {
+    /**
+     * Main method of the example.
+     *
+     * @param args The command line arguments.
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating 'accounts' table.
+        //
+        //--------------------------------------------------------------------------------------
+
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate(
+                "CREATE TABLE accounts (" +
+                "    accountNumber INT PRIMARY KEY," +
+                "    firstName     VARCHAR," +
+                "    lastName      VARCHAR," +
+                "    balance       DOUBLE" +
+                ")"
+            );
+        }
+
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating a client to connect to the cluster.
+        //
+        //--------------------------------------------------------------------------------------
+
+        System.out.println("\nConnecting to server...");
+
+        try (IgniteClient client = IgniteClient.builder()
+            .addresses("127.0.0.1:10800")
+            .build()
+        ) {
+            class AccountKey {
+                final int accountNumber;
+
+                public AccountKey(int accountNumber) {
+                    this.accountNumber = accountNumber;
+                }
+            }
+
+            class Account {
+                final String firstName;
+                final String lastName;
+                final double balance;
+
+                public Account(String firstName, String lastName, double balance) {
+                    this.firstName = firstName;
+                    this.lastName = lastName;
+                    this.balance = balance;
+                }
+            }
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Creating a key-value view for the 'accounts' table.
+            //
+            //--------------------------------------------------------------------------------------
+
+            KeyValueView<AccountKey, Account> kvView = client.tables()
+                .table("PUBLIC.accounts")
+                .keyValueView(AccountKey.class, Account.class);
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'put' operation.
+            //
+            //--------------------------------------------------------------------------------------
+
+            System.out.println("\nInserting a key-value pair into the 'accounts' table...");
+
+            AccountKey key = new AccountKey(123456);
+
+            Account value = new Account(
+                "Val",
+                "Kulichenko",
+                100.00d
+            );
+
+            kvView.put(null, key, value);
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'get' operation.
+            //
+            //--------------------------------------------------------------------------------------
+
+            System.out.println("\nRetrieving a value using KeyValueView API...");
+
+            value = kvView.get(null, key);
+
+            System.out.println(
+                "\nRetrieved value:\n" +
+                "    Account Number: " + key.accountNumber + '\n' +
+                "    Owner: " + value.firstName + " " + value.lastName + '\n' +
+                "    Balance: $" + value.balance);
+        }
+
+        System.out.println("\nDropping the table...");
+
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate("DROP TABLE accounts");
+        }
+    }
+}
diff --git a/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java b/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
index a1d11fb..f14730c 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
@@ -17,18 +17,14 @@
 
 package org.apache.ignite.example.table;
 
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgnitionManager;
 import org.apache.ignite.client.IgniteClient;
-import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
-import org.apache.ignite.schema.SchemaBuilders;
-import org.apache.ignite.schema.definition.ColumnType;
-import org.apache.ignite.schema.definition.TableDefinition;
 import org.apache.ignite.table.RecordView;
 import org.apache.ignite.table.Tuple;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
 /**
  * This example demonstrates the usage of the {@link RecordView} API.
  *
@@ -52,112 +48,86 @@ public class RecordViewExample {
     public static void main(String[] args) throws Exception {
         //--------------------------------------------------------------------------------------
         //
-        // Starting a server node.
-        //
-        // NOTE: An embedded server node is only needed to invoke the 'createTable' API.
-        //       In the future releases, this API will be available on the client,
-        //       eliminating the need to start an embedded server node in this example.
+        // Creating 'accounts' table.
         //
         //--------------------------------------------------------------------------------------
 
-        System.out.println("Starting a server node... Logging to file: example-node.log");
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate(
+                "CREATE TABLE accounts (" +
+                "    accountNumber INT PRIMARY KEY," +
+                "    firstName     VARCHAR," +
+                "    lastName      VARCHAR," +
+                "    balance       DOUBLE" +
+                ")"
+            );
+        }
 
-        System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating a client to connect to the cluster.
+        //
+        //--------------------------------------------------------------------------------------
+
+        System.out.println("\nConnecting to server...");
 
-        try (Ignite server = IgnitionManager.start(
-                "example-node",
-                Files.readString(Path.of("config", "ignite-config.json")),
-                Path.of("work")
-        )) {
+        try (IgniteClient client = IgniteClient.builder()
+            .addresses("127.0.0.1:10800")
+            .build()
+        ) {
             //--------------------------------------------------------------------------------------
             //
-            // Creating 'accounts' table. The API call below is the equivalent of the following DDL:
-            //
-            //     CREATE TABLE accounts (
-            //         accountNumber INT PRIMARY KEY,
-            //         firstName     VARCHAR,
-            //         lastName      VARCHAR,
-            //         balance       DOUBLE
-            //     )
+            // Creating a record view for the 'accounts' table.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nCreating 'accounts' table...");
-
-            TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "accounts")
-                    .columns(
-                            SchemaBuilders.column("accountNumber", ColumnType.INT32).build(),
-                            SchemaBuilders.column("firstName", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("lastName", ColumnType.string()).asNullable(true).build(),
-                            SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable(true).build()
-                    )
-                    .withPrimaryKey("accountNumber")
-                    .build();
-
-            server.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
-                    SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
-                            .changeReplicas(1)
-                            .changePartitions(10)
-            );
+            RecordView<Tuple> accounts = client.tables().table("PUBLIC.accounts").recordView();
 
             //--------------------------------------------------------------------------------------
             //
-            // Creating a client to connect to the cluster.
+            // Performing the 'insert' operation.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nConnecting to server...");
+            System.out.println("\nInserting a record into the 'accounts' table...");
 
-            try (IgniteClient client = IgniteClient.builder()
-                    .addresses("127.0.0.1:10800")
-                    .build()
-            ) {
-                //--------------------------------------------------------------------------------------
-                //
-                // Creating a record view for the 'accounts' table.
-                //
-                //--------------------------------------------------------------------------------------
-
-                RecordView<Tuple> accounts = client.tables().table("PUBLIC.accounts").recordView();
-
-                //--------------------------------------------------------------------------------------
-                //
-                // Performing the 'insert' operation.
-                //
-                //--------------------------------------------------------------------------------------
+            Tuple newAccountTuple = Tuple.create()
+                .set("accountNumber", 123456)
+                .set("firstName", "Val")
+                .set("lastName", "Kulichenko")
+                .set("balance", 100.00d);
 
-                System.out.println("\nInserting a record into the 'accounts' table...");
+            accounts.insert(null, newAccountTuple);
 
-                Tuple newAccountTuple = Tuple.create()
-                        .set("accountNumber", 123456)
-                        .set("firstName", "Val")
-                        .set("lastName", "Kulichenko")
-                        .set("balance", 100.00d);
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'get' operation.
+            //
+            //--------------------------------------------------------------------------------------
 
-                accounts.insert(null, newAccountTuple);
+            System.out.println("\nRetrieving a record using RecordView API...");
 
-                //--------------------------------------------------------------------------------------
-                //
-                // Performing the 'get' operation.
-                //
-                //--------------------------------------------------------------------------------------
+            Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
 
-                System.out.println("\nRetrieving a record using RecordView API...");
+            Tuple accountTuple = accounts.get(null, accountNumberTuple);
 
-                Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
+            System.out.println(
+                "\nRetrieved record:\n" +
+                "    Account Number: " + accountTuple.intValue("accountNumber") + '\n' +
+                "    Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' +
+                "    Balance: $" + accountTuple.doubleValue("balance"));
 
-                Tuple accountTuple = accounts.get(null, accountNumberTuple);
+            System.out.println("\nDropping the table...");
 
-                System.out.println(
-                        "\nRetrieved record:\n"
-                                + "    Account Number: " + accountTuple.intValue("accountNumber") + '\n'
-                                + "    Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n'
-                                + "    Balance: $" + accountTuple.doubleValue("balance"));
+            try (
+                Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+                Statement stmt = conn.createStatement()
+            ) {
+                stmt.executeUpdate("DROP TABLE accounts");
             }
-
-            System.out.println("\nDropping the table and stopping the server...");
-
-            server.tables().dropTable(accountsTableDef.canonicalName());
         }
     }
 }
diff --git a/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java b/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
new file mode 100644
index 0000000..0529d3f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
@@ -0,0 +1,155 @@
+/*
+ * 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.example.table;
+
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.table.RecordView;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+/**
+ * This example demonstrates the usage of the {@link RecordView} API.
+ *
+ * <p>To run the example, do the following:
+ * <ol>
+ *     <li>Import the examples project into you IDE.</li>
+ *     <li>
+ *         Start a server node using the CLI tool:<br>
+ *         {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json my-first-node}
+ *     </li>
+ *     <li>Run the example in the IDE.</li>
+ * </ol>
+ */
+public class RecordViewPojoExample {
+    /**
+     * Main method of the example.
+     *
+     * @param args The command line arguments.
+     * @throws Exception If failed.
+     */
+    public static void main(String[] args) throws Exception {
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating 'accounts' table.
+        //
+        //--------------------------------------------------------------------------------------
+
+        try (
+            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+            Statement stmt = conn.createStatement()
+        ) {
+            stmt.executeUpdate(
+                "CREATE TABLE accounts (" +
+                "    accountNumber INT PRIMARY KEY," +
+                "    firstName     VARCHAR," +
+                "    lastName      VARCHAR," +
+                "    balance       DOUBLE" +
+                ")"
+            );
+        }
+
+        //--------------------------------------------------------------------------------------
+        //
+        // Creating a client to connect to the cluster.
+        //
+        //--------------------------------------------------------------------------------------
+
+        System.out.println("\nConnecting to server...");
+
+        try (IgniteClient client = IgniteClient.builder()
+            .addresses("127.0.0.1:10800")
+            .build()
+        ) {
+            class Account {
+                final int accountNumber;
+                final String firstName;
+                final String lastName;
+                final double balance;
+
+                public Account(int accountNumber) {
+                    this.accountNumber = accountNumber;
+
+                    firstName = null;
+                    lastName = null;
+                    balance = 0.0d;
+                }
+
+                public Account(int accountNumber, String firstName, String lastName, double balance) {
+                    this.accountNumber = accountNumber;
+                    this.firstName = firstName;
+                    this.lastName = lastName;
+                    this.balance = balance;
+                }
+            }
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Creating a record view for the 'accounts' table.
+            //
+            //--------------------------------------------------------------------------------------
+
+            RecordView<Account> accounts = client.tables()
+                .table("PUBLIC.accounts")
+                .recordView(Account.class);
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'insert' operation.
+            //
+            //--------------------------------------------------------------------------------------
+
+            System.out.println("\nInserting a record into the 'accounts' table...");
+
+            Account newAccount = new Account(
+                123456,
+                "Val",
+                "Kulichenko",
+                100.00d
+            );
+
+            accounts.insert(null, newAccount);
+
+            //--------------------------------------------------------------------------------------
+            //
+            // Performing the 'get' operation.
+            //
+            //--------------------------------------------------------------------------------------
+
+            System.out.println("\nRetrieving a record using RecordView API...");
+
+            Account account = accounts.get(null, new Account(123456));
+
+            System.out.println(
+                "\nRetrieved record:\n" +
+                "    Account Number: " + account.accountNumber + '\n' +
+                "    Owner: " + account.firstName + " " + account.lastName + '\n' +
+                "    Balance: $" + account.balance);
+
+            System.out.println("\nDropping the table...");
+
+            try (
+                Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+                Statement stmt = conn.createStatement()
+            ) {
+                stmt.executeUpdate("DROP TABLE accounts");
+            }
+        }
+    }
+}

[ignite-3] 02/02: IGNITE-16244

Posted by vk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vkulichenko pushed a commit to branch ignite-16244
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 423be6b31a0bdd01662d06af5d71993cbddd5068
Author: Valentin Kulichenko <va...@gmail.com>
AuthorDate: Wed Jan 12 15:25:51 2022 -0800

    IGNITE-16244
---
 .../example/table/KeyValueViewPojoExample.java     |  6 ++
 .../example/table/RecordViewPojoExample.java       |  6 ++
 .../TransactionsExample.java}                      | 96 ++++++++++------------
 3 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
index f5c1200..7101954 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
@@ -77,6 +77,12 @@ public class KeyValueViewPojoExample {
             .addresses("127.0.0.1:10800")
             .build()
         ) {
+            //--------------------------------------------------------------------------------------
+            //
+            // Defining POJO classes.
+            //
+            //--------------------------------------------------------------------------------------
+
             class AccountKey {
                 final int accountNumber;
 
diff --git a/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java b/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
index 0529d3f..b4af258 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
@@ -77,6 +77,12 @@ public class RecordViewPojoExample {
             .addresses("127.0.0.1:10800")
             .build()
         ) {
+            //--------------------------------------------------------------------------------------
+            //
+            // Defining POJO class.
+            //
+            //--------------------------------------------------------------------------------------
+
             class Account {
                 final int accountNumber;
                 final String firstName;
diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java b/examples/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
similarity index 60%
copy from examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
copy to examples/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
index f5c1200..a500b3c 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
@@ -1,31 +1,16 @@
-/*
- * 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.example.table;
+package org.apache.ignite.example.tx;
 
 import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.table.KeyValueView;
+import org.apache.ignite.tx.IgniteTransactions;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.Statement;
+import java.util.concurrent.CompletableFuture;
 
 /**
- * This example demonstrates the usage of the {@link KeyValueView} API.
+ * This example demonstrates the usage of the {@link IgniteTransactions} API.
  *
  * <p>To run the example, do the following:
  * <ol>
@@ -37,7 +22,7 @@ import java.sql.Statement;
  *     <li>Run the example in the IDE.</li>
  * </ol>
  */
-public class KeyValueViewPojoExample {
+public class TransactionsExample {
     /**
      * Main method of the example.
      *
@@ -77,6 +62,12 @@ public class KeyValueViewPojoExample {
             .addresses("127.0.0.1:10800")
             .build()
         ) {
+            //--------------------------------------------------------------------------------------
+            //
+            // Creating an account.
+            //
+            //--------------------------------------------------------------------------------------
+
             class AccountKey {
                 final int accountNumber;
 
@@ -88,7 +79,7 @@ public class KeyValueViewPojoExample {
             class Account {
                 final String firstName;
                 final String lastName;
-                final double balance;
+                double balance;
 
                 public Account(String firstName, String lastName, double balance) {
                     this.firstName = firstName;
@@ -97,58 +88,59 @@ public class KeyValueViewPojoExample {
                 }
             }
 
-            //--------------------------------------------------------------------------------------
-            //
-            // Creating a key-value view for the 'accounts' table.
-            //
-            //--------------------------------------------------------------------------------------
-
-            KeyValueView<AccountKey, Account> kvView = client.tables()
+            KeyValueView<AccountKey, Account> accounts = client.tables()
                 .table("PUBLIC.accounts")
                 .keyValueView(AccountKey.class, Account.class);
 
+            final AccountKey key = new AccountKey(123);
+
+            accounts.put(null, key, new Account("John", "Doe", 1000.0d));
+
+            System.out.println("\nInitial balance: " + accounts.get(null, key).balance);
+
             //--------------------------------------------------------------------------------------
             //
-            // Performing the 'put' operation.
+            // Using synchronous transactional API to update the balance.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nInserting a key-value pair into the 'accounts' table...");
+            client.transactions().runInTransaction(tx -> {
+                Account account = accounts.get(tx, key);
 
-            AccountKey key = new AccountKey(123456);
+                account.balance += 200.0d;
 
-            Account value = new Account(
-                "Val",
-                "Kulichenko",
-                100.00d
-            );
+                accounts.put(tx, key, account);
+            });
 
-            kvView.put(null, key, value);
+            System.out.println("\nBalance after the sync transaction: " + accounts.get(null, key).balance);
 
             //--------------------------------------------------------------------------------------
             //
-            // Performing the 'get' operation.
+            // Using asynchronous transactional API to update the balance.
             //
             //--------------------------------------------------------------------------------------
 
-            System.out.println("\nRetrieving a value using KeyValueView API...");
+            CompletableFuture<Void> fut = client.transactions().beginAsync().thenCompose(tx ->
+                accounts.getAsync(tx, key).thenCompose(account -> {
+                    account.balance += 300.0d;
 
-            value = kvView.get(null, key);
+                    return accounts.putAsync(tx, key, account);
+                })
+            );
 
-            System.out.println(
-                "\nRetrieved value:\n" +
-                "    Account Number: " + key.accountNumber + '\n' +
-                "    Owner: " + value.firstName + " " + value.lastName + '\n' +
-                "    Balance: $" + value.balance);
-        }
+            // Wait for completion.
+            fut.join();
 
-        System.out.println("\nDropping the table...");
+            System.out.println("\nBalance after the async transaction: " + accounts.get(null, key).balance);
 
-        try (
-            Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
-            Statement stmt = conn.createStatement()
-        ) {
-            stmt.executeUpdate("DROP TABLE accounts");
+            System.out.println("\nDropping the table...");
+
+            try (
+                Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
+                Statement stmt = conn.createStatement()
+            ) {
+                stmt.executeUpdate("DROP TABLE accounts");
+            }
         }
     }
 }