This is an automated email from the ASF dual-hosted git repository.
mpochatkin 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 674735d388d IGNITE-28117 Examples not self-contained - missing or
broken setup/teardown causes state leakage (#7738)
674735d388d is described below
commit 674735d388d2201485807a44f51d1679e20ba3d2
Author: Ashish Mishra <[email protected]>
AuthorDate: Thu Mar 12 15:10:50 2026 +0530
IGNITE-28117 Examples not self-contained - missing or broken setup/teardown
causes state leakage (#7738)
---
examples/java/build.gradle | 2 +
.../ignite/example/client/IgniteClientExample.java | 8 +-
.../client/IgniteClientWithConfigExample.java | 8 +-
.../code/deployment/CodeDeploymentExample.java | 8 +-
.../example/compute/ComputeAsyncExample.java | 10 +-
.../example/compute/ComputeBroadcastExample.java | 10 +-
.../compute/ComputeCancellationExample.java | 10 +-
.../example/compute/ComputeColocatedExample.java | 10 +-
.../ignite/example/compute/ComputeExample.java | 8 +-
.../example/compute/ComputeJobPriorityExample.java | 14 +-
.../example/compute/ComputeJobStateExample.java | 8 +-
.../example/compute/ComputeMapReduceExample.java | 10 +-
.../ComputeWithCustomResultMarshallerExample.java | 8 +-
.../example/compute/ComputeWithResultExample.java | 8 +-
.../CustomPojoSerializationExample.java | 2 +-
.../NativeTypeSerializationExample.java | 2 +-
.../PojoAutoSerializationExample.java | 2 +-
.../serialization/TupleSerializationExample.java | 2 +-
.../apache/ignite/example/sql/SqlApiExample.java | 28 ++--
.../ignite/example/sql/jdbc/SqlJdbcExample.java | 20 +--
.../example/storage/StorageEngineExample.java | 163 ++++++++++-----------
.../DistributedComputeWithReceiverExample.java | 2 +-
.../streaming/MultiTableDataStreamerExample.java | 2 +-
.../ignite/example/table/KeyValueViewExample.java | 55 +++----
.../example/table/KeyValueViewPojoExample.java | 55 +++----
.../apache/ignite/example/table/MapperExample.java | 75 ++++++----
.../ignite/example/table/RecordViewExample.java | 55 +++----
.../example/table/RecordViewPojoExample.java | 55 +++----
.../apache/ignite/example/table/TableExample.java | 70 +++++----
.../ignite/example/tx/TransactionsExample.java | 82 ++++++-----
30 files changed, 395 insertions(+), 397 deletions(-)
diff --git a/examples/java/build.gradle b/examples/java/build.gradle
index db7bbf99373..5787998e376 100644
--- a/examples/java/build.gradle
+++ b/examples/java/build.gradle
@@ -34,6 +34,8 @@ tasks.register('deploymentUnitJar', Jar) {
from(sourceSets.main.output.classesDirs) {
include 'org/apache/ignite/example/**/*Job.class'
include 'org/apache/ignite/example/**/*Job$*.class'
+ include 'org/apache/ignite/example/**/*Receiver.class'
+ include 'org/apache/ignite/example/**/*Receiver$*.class'
include 'org/apache/ignite/example/**/Compute*Example.class'
include 'org/apache/ignite/example/**/Compute*Example$*.class'
include 'org/apache/ignite/example/**/Distributed*Example.class'
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientExample.java
b/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientExample.java
index c45135303a8..7f94543a2f1 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientExample.java
@@ -47,7 +47,13 @@ public class IgniteClientExample {
// You can use the client here.
//
//--------------------------------------------------------------------------------------
- client.sql().execute("CREATE TABLE IF NOT EXISTS Person (id int
primary key, name varchar, age int);");
+ try {
+ client.sql().execute("CREATE TABLE Person (id int primary key,
name varchar, age int);");
+ } finally {
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS Person");
+ }
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientWithConfigExample.java
b/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientWithConfigExample.java
index d884b834126..4a09fd9fc73 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientWithConfigExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/client/IgniteClientWithConfigExample.java
@@ -76,7 +76,13 @@ public class IgniteClientWithConfigExample {
// You can use the client here.
//
//--------------------------------------------------------------------------------------
- client.sql().execute("CREATE TABLE IF NOT EXISTS Person (id int
primary key, name varchar, age int);");
+ try {
+ client.sql().execute("CREATE TABLE Person (id int primary key,
name varchar, age int);");
+ } finally {
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS Person");
+ }
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/code/deployment/CodeDeploymentExample.java
b/examples/java/src/main/java/org/apache/ignite/example/code/deployment/CodeDeploymentExample.java
index d4ca3ddd96b..3f3278491d9 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/code/deployment/CodeDeploymentExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/code/deployment/CodeDeploymentExample.java
@@ -50,11 +50,11 @@ public class CodeDeploymentExample {
*/
public static void main(String[] args) throws Exception {
DeployComputeUnit.processDeploymentUnit(args);
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client =
IgniteClient.builder().addresses("127.0.0.1:10800").build()) {
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -63,11 +63,11 @@ public class CodeDeploymentExample {
JobTarget target = JobTarget.anyNode(client.cluster().nodes());
- System.out.println("\nExecuting compute job'" + "'...");
+ System.out.println("Executing compute job'" + "'...");
String result = client.compute().execute(target, job, "Hello from
job");
- System.out.println("\n=== Result ===\n" + result);
+ System.out.println("=== Result ===\n" + result);
} finally {
System.out.println("Cleaning up resources...");
undeployUnit(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION);
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeAsyncExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeAsyncExample.java
index 2acdf8e0694..c3542f55c9c 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeAsyncExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeAsyncExample.java
@@ -65,7 +65,7 @@ public class ComputeAsyncExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -77,7 +77,7 @@ public class ComputeAsyncExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -105,7 +105,7 @@ public class ComputeAsyncExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job for word '" + word
+ "'...");
+ System.out.println("Executing compute job for word '" + word +
"'...");
CompletableFuture<Integer> jobFuture =
client.compute().executeAsync(jobTarget, job, word);
@@ -130,7 +130,7 @@ public class ComputeAsyncExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nTotal number of characters in the words is
'" + sum + "'.");
+ System.out.println("Total number of characters in the words is '"
+ sum + "'.");
} finally {
System.out.println("Cleaning up resources");
@@ -148,7 +148,7 @@ public class ComputeAsyncExample {
public CompletableFuture<Integer> executeAsync(JobExecutionContext
context, String arg) {
assert arg != null;
- System.out.println("\nProcessing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
+ System.out.println("Processing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
return completedFuture(arg.length());
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeBroadcastExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeBroadcastExample.java
index b4ebf9a28e1..00f0691baaa 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeBroadcastExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeBroadcastExample.java
@@ -61,7 +61,7 @@ public class ComputeBroadcastExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -87,7 +87,7 @@ public class ComputeBroadcastExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
JobDescriptor<String, Void> job =
JobDescriptor.builder(HelloMessageJob.class)
.units(new DeploymentUnit(DEPLOYMENT_UNIT_NAME,
DEPLOYMENT_UNIT_VERSION))
@@ -101,11 +101,11 @@ public class ComputeBroadcastExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job...");
+ System.out.println("Executing compute job...");
client.compute().execute(target, job, "John");
- System.out.println("\nCompute job executed...");
+ System.out.println("Compute job executed...");
//--------------------------------------------------------------------------------------
//
@@ -132,7 +132,7 @@ public class ComputeBroadcastExample {
undeployUnit(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION);
// Drop tables
- System.out.println("\nDropping the tables...");
+ System.out.println("Dropping the tables...");
client.sql().executeScript("DROP TABLE IF EXISTS Person");
client.sql().executeScript("DROP TABLE IF EXISTS
PUBLIC.MY_TABLE");
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeCancellationExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeCancellationExample.java
index d9cb7f5af47..08ee7e8387a 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeCancellationExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeCancellationExample.java
@@ -63,7 +63,7 @@ public class ComputeCancellationExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -75,7 +75,7 @@ public class ComputeCancellationExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -100,7 +100,7 @@ public class ComputeCancellationExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job...");
+ System.out.println("Executing compute job...");
CompletableFuture<Void> resultFuture =
client.compute().executeAsync(jobTarget, job, null, cancelHandle.token());
@@ -110,14 +110,14 @@ public class ComputeCancellationExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nCancelling compute job...");
+ System.out.println("Cancelling compute job...");
cancelHandle.cancel();
try {
resultFuture.join();
} catch (CompletionException ex) {
- System.out.println("\nThe compute job was cancelled: " +
ex.getMessage());
+ System.out.println("The compute job was cancelled: " +
ex.getMessage());
}
} finally {
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeColocatedExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeColocatedExample.java
index d72254d74fe..33a1faf22db 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeColocatedExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeColocatedExample.java
@@ -66,7 +66,7 @@ public class ComputeColocatedExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -100,7 +100,7 @@ public class ComputeColocatedExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nCreating account records...");
+ System.out.println("Creating account records...");
for (int i = 0; i < ACCOUNTS_COUNT; i++) {
view.insert(null, account(i));
@@ -112,7 +112,7 @@ public class ComputeColocatedExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME,
DEPLOYMENT_UNIT_VERSION, DeployComputeUnit.getJarPath());
@@ -130,7 +130,7 @@ public class ComputeColocatedExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job for the
accountNumber '" + accountNumber + "'...");
+ System.out.println("Executing compute job for the
accountNumber '" + accountNumber + "'...");
client.compute().execute(jobTarget, job, accountNumber);
} finally {
@@ -139,7 +139,7 @@ public class ComputeColocatedExample {
undeployUnit(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION);
/* Drop table */
- System.out.println("\nDropping the table...");
+ System.out.println("Dropping the table...");
client.sql().executeScript("DROP TABLE IF EXISTS accounts");
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeExample.java
index 08ea0a3ca41..28d14ec3404 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeExample.java
@@ -60,7 +60,7 @@ public class ComputeExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -72,7 +72,7 @@ public class ComputeExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -96,7 +96,7 @@ public class ComputeExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job for word '" + word
+ "'...");
+ System.out.println("Executing compute job for word '" + word +
"'...");
client.compute().execute(jobTarget, job, word);
}
@@ -115,7 +115,7 @@ public class ComputeExample {
/** {@inheritDoc} */
@Override
public CompletableFuture<Void> executeAsync(JobExecutionContext
context, String arg) {
- System.out.println("\nProcessing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
+ System.out.println("Processing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
return completedFuture(null);
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobPriorityExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobPriorityExample.java
index 0e4067d1e68..87a5431927a 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobPriorityExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobPriorityExample.java
@@ -63,7 +63,7 @@ public class ComputeJobPriorityExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client =
IgniteClient.builder().addresses("127.0.0.1:10800").build()) {
//--------------------------------------------------------------------------------------
@@ -72,7 +72,7 @@ public class ComputeJobPriorityExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -98,7 +98,7 @@ public class ComputeJobPriorityExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute jobs for arg '" + i +
"'...");
+ System.out.println("Executing compute jobs for arg '" + i +
"'...");
CompletableFuture<Void> lowPriorityJobFuture =
client.compute().executeAsync(jobTarget, lowPriorityJob, i)
.thenAccept(System.out::println);
@@ -132,7 +132,7 @@ public class ComputeJobPriorityExample {
/** {@inheritDoc} */
@Override
public CompletableFuture<String> executeAsync(JobExecutionContext
context, Integer arg) {
- System.out.println("\nHighPriorityJob started for arg '" + arg +
"' at node '" + context.ignite().name() + "'.");
+ System.out.println("HighPriorityJob started for arg '" + arg + "'
at node '" + context.ignite().name() + "'.");
try {
Thread.sleep(2000);
@@ -142,7 +142,7 @@ public class ComputeJobPriorityExample {
String result = "HighPriorityJob [arg=" + arg + ", res=" + arg *
100 + "]";
- System.out.println("\nHighPriorityJob finished for arg '" + arg +
"' at node '" + context.ignite().name() + "'.");
+ System.out.println("HighPriorityJob finished for arg '" + arg + "'
at node '" + context.ignite().name() + "'.");
return completedFuture(result);
}
@@ -155,7 +155,7 @@ public class ComputeJobPriorityExample {
/** {@inheritDoc} */
@Override
public CompletableFuture<String> executeAsync(JobExecutionContext
context, Integer arg) {
- System.out.println("\nLowPriorityJob started for arg '" + arg + "'
at node '" + context.ignite().name() + "'.");
+ System.out.println("LowPriorityJob started for arg '" + arg + "'
at node '" + context.ignite().name() + "'.");
try {
Thread.sleep(1000);
@@ -165,7 +165,7 @@ public class ComputeJobPriorityExample {
String result = "LowPriorityJob [arg=" + arg + ", res=" + arg * 10
+ "]";
- System.out.println("\nLowPriorityJob finished for arg '" + arg +
"' at node '" + context.ignite().name() + "'.");
+ System.out.println("LowPriorityJob finished for arg '" + arg + "'
at node '" + context.ignite().name() + "'.");
return completedFuture(result);
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobStateExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobStateExample.java
index 145ddb642f1..64d5f8811e0 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobStateExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeJobStateExample.java
@@ -63,7 +63,7 @@ public class ComputeJobStateExample {
//
//---------------------
-----------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -75,7 +75,7 @@ public class ComputeJobStateExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -87,7 +87,7 @@ public class ComputeJobStateExample {
execution.get().stateAsync().thenApply(state -> {
if (state.status() == FAILED) {
- System.out.println("\nJob failed...");
+ System.out.println("Job failed...");
}
return null;
});
@@ -106,7 +106,7 @@ public class ComputeJobStateExample {
/** {@inheritDoc} */
@Override
public CompletableFuture<Void> executeAsync(JobExecutionContext
context, String arg) {
- System.out.println("\nProcessing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
+ System.out.println("Processing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
return completedFuture(null);
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeMapReduceExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeMapReduceExample.java
index 41061b0bce0..8e1743cd509 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeMapReduceExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeMapReduceExample.java
@@ -67,7 +67,7 @@ public class ComputeMapReduceExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client =
IgniteClient.builder().addresses("127.0.0.1:10800").build()) {
//--------------------------------------------------------------------------------------
@@ -76,7 +76,7 @@ public class ComputeMapReduceExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring map reduce task...");
+ System.out.println("Configuring map reduce task...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -90,7 +90,7 @@ public class ComputeMapReduceExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting map reduce task...");
+ System.out.println("Executing map reduce task...");
String phrase = "Count characters using map reduce";
@@ -102,7 +102,7 @@ public class ComputeMapReduceExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nTotal number of characters in the words is
'" + result + "'.");
+ System.out.println("Total number of characters in the words is '"
+ result + "'.");
} finally {
System.out.println("Cleaning up resources");
@@ -159,7 +159,7 @@ public class ComputeMapReduceExample {
public CompletableFuture<Integer> executeAsync(JobExecutionContext
context, String arg) {
assert arg != null;
- System.out.println("\nProcessing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
+ System.out.println("Processing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
return completedFuture(arg.length());
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithCustomResultMarshallerExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithCustomResultMarshallerExample.java
index 3dff5c65739..6901e8bc943 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithCustomResultMarshallerExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithCustomResultMarshallerExample.java
@@ -64,7 +64,7 @@ public class ComputeWithCustomResultMarshallerExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -76,7 +76,7 @@ public class ComputeWithCustomResultMarshallerExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
deployIfNotExist(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION,
DeployComputeUnit.getJarPath());
@@ -99,7 +99,7 @@ public class ComputeWithCustomResultMarshallerExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nExecuting compute job for the word '" +
word + "'...");
+ System.out.println("Executing compute job for the word '" +
word + "'...");
WordInfoResult result = client.compute().execute(jobTarget,
job, word);
@@ -201,7 +201,7 @@ public class ComputeWithCustomResultMarshallerExample {
public CompletableFuture<WordInfoResult>
executeAsync(JobExecutionContext context, String arg) {
assert arg != null;
- System.out.println("\nProcessing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
+ System.out.println("Processing word '" + arg + "' at node '" +
context.ignite().name() + "'.");
WordInfoResult result = new WordInfoResult(arg, arg.length());
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithResultExample.java
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithResultExample.java
index ce80449931e..4e10b438d99 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithResultExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/compute/ComputeWithResultExample.java
@@ -60,7 +60,7 @@ public class ComputeWithResultExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -72,7 +72,7 @@ public class ComputeWithResultExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConfiguring compute job...");
+ System.out.println("Configuring compute job...");
@@ -93,7 +93,7 @@ public class ComputeWithResultExample {
String phrase = "Count characters using callable";
- System.out.println("\nExecuting compute job for the phrase '" +
phrase + "'...");
+ System.out.println("Executing compute job for the phrase '" +
phrase + "'...");
Integer wordCnt = client.compute().execute(jobTarget, job, phrase);
@@ -103,7 +103,7 @@ public class ComputeWithResultExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nTotal number of words in the phrase is '" +
wordCnt + "'.");
+ System.out.println("Total number of words in the phrase is '" +
wordCnt + "'.");
} finally {
System.out.println("Cleaning up resources");
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/serialization/CustomPojoSerializationExample.java
b/examples/java/src/main/java/org/apache/ignite/example/serialization/CustomPojoSerializationExample.java
index ba9fe53be0c..cc3d5b4a2a0 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/serialization/CustomPojoSerializationExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/serialization/CustomPojoSerializationExample.java
@@ -50,7 +50,7 @@ public class CustomPojoSerializationExample {
*/
static void runPojoCustomJsonSerialization(IgniteClient client) {
- System.out.println("\n[POJO custom] Running POJO job with custom JSON
marshallers both on the client and on the server");
+ System.out.println("[POJO custom] Running POJO job with custom JSON
marshallers both on the client and on the server");
JobDescriptor<JsonArg, JsonResult> job =
JobDescriptor.builder(CustomPojoSerializationJob.class)
.argumentMarshaller(new JsonArgMarshaller())
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/serialization/NativeTypeSerializationExample.java
b/examples/java/src/main/java/org/apache/ignite/example/serialization/NativeTypeSerializationExample.java
index 8232eda8a59..364630fac62 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/serialization/NativeTypeSerializationExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/serialization/NativeTypeSerializationExample.java
@@ -30,7 +30,7 @@ class NativeTypeSerializationExample {
/** Using native types: primitives or wrappers, so no marshallers needed,
as Ignite autoserializes native types. */
static void runNativeSerialization(IgniteClient client) {
- System.out.println("\n[Native] Running Integer decrement job...");
+ System.out.println("[Native] Running Integer decrement job...");
JobDescriptor<Integer, Integer> job =
JobDescriptor.builder(IntegerDecrementJob.class)
.units(new DeploymentUnit(DEPLOYMENT_UNIT_NAME,
DEPLOYMENT_UNIT_VERSION))
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/serialization/PojoAutoSerializationExample.java
b/examples/java/src/main/java/org/apache/ignite/example/serialization/PojoAutoSerializationExample.java
index 7af2982ff23..6bf58276f41 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/serialization/PojoAutoSerializationExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/serialization/PojoAutoSerializationExample.java
@@ -33,7 +33,7 @@ public class PojoAutoSerializationExample {
*/
static void runPojoAutoSerialization(IgniteClient client) {
- System.out.println("\n[POJO auto] Running POJO job without custom
marshallers...");
+ System.out.println("[POJO auto] Running POJO job without custom
marshallers...");
JobDescriptor<AutoSerializableArg, AutoSerializableResult> job =
JobDescriptor.builder(PojoAutoSerializationJob.class)
.resultClass(AutoSerializableResult.class) // REQUIRED
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/serialization/TupleSerializationExample.java
b/examples/java/src/main/java/org/apache/ignite/example/serialization/TupleSerializationExample.java
index 72efe0131f1..cdb562f6701 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/serialization/TupleSerializationExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/serialization/TupleSerializationExample.java
@@ -31,7 +31,7 @@ public class TupleSerializationExample {
/** Using tuples, no marshallers needed as tuples are also autoserialized
by Ignite. */
static void runTupleSerialization(IgniteClient client) {
- System.out.println("\n[Tuple] Running tuple transform job...");
+ System.out.println("[Tuple] Running tuple transform job...");
JobDescriptor<Tuple, Tuple> job =
JobDescriptor.builder(TupleTransformJob.class)
.units(new DeploymentUnit(DEPLOYMENT_UNIT_NAME,
DEPLOYMENT_UNIT_VERSION))
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/sql/SqlApiExample.java
b/examples/java/src/main/java/org/apache/ignite/example/sql/SqlApiExample.java
index 60bc65c0e52..38d5250f096 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/sql/SqlApiExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/sql/SqlApiExample.java
@@ -52,7 +52,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
@@ -83,7 +83,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nStarting read-write transaction...");
+ System.out.println("Starting read-write transaction...");
Transaction tx = client.transactions().begin(new
TransactionOptions().readOnly(false));
@@ -94,7 +94,7 @@ public class SqlApiExample {
//--------------------------------------------------------------------------------------
try {
- System.out.println("\nPopulating 'CITIES' table...");
+ System.out.println("Populating 'CITIES' table...");
Statement stmt = client.sql().createStatement("INSERT INTO
CITIES (ID, NAME) VALUES (?, ?)");
long rowsAdded = 0;
@@ -109,7 +109,7 @@ public class SqlApiExample {
rowsAdded += rs.affectedRows();
}
- System.out.println("\nAdded cities: " + rowsAdded);
+ System.out.println("Added cities: " + rowsAdded);
//--------------------------------------------------------------------------------------
//
@@ -117,7 +117,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nPopulating 'ACCOUNTS' table...");
+ System.out.println("Populating 'ACCOUNTS' table...");
rowsAdded = Arrays.stream(client.sql().executeBatch(tx,
"INSERT INTO ACCOUNTS (ACCOUNT_ID, CITY_ID,
FIRST_NAME, LAST_NAME, BALANCE) values (?, ?, ?, ?, ?)",
@@ -127,7 +127,7 @@ public class SqlApiExample {
.add(4, 3, "Richard", "Miles",
1450.0d)))
.sum();
- System.out.println("\nAdded accounts: " + rowsAdded);
+ System.out.println("Added accounts: " + rowsAdded);
//--------------------------------------------------------------------------------------
//
@@ -135,7 +135,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nCommitting transaction...");
+ System.out.println("Committing transaction...");
tx.commit();
} catch (Exception e) {
@@ -150,7 +150,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAll accounts:");
+ System.out.println("All accounts:");
try (ResultSet<SqlRow> rs = client.sql().execute(
"SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a "
@@ -171,7 +171,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAccounts with balance lower than 1,500:");
+ System.out.println("Accounts with balance lower than 1,500:");
Statement statement = client.sql().statementBuilder()
.query("SELECT a.FIRST_NAME as firstName, a.LAST_NAME as
lastName, a.BALANCE FROM ACCOUNTS a "
@@ -209,7 +209,7 @@ public class SqlApiExample {
CompletableFuture<Void> cancelled = cancelHandle.cancelAsync();
cancelled.get(5, TimeUnit.SECONDS);
- System.out.println("\nIs query cancelled: " + cancelled.isDone());
+ System.out.println("Is query cancelled: " + cancelled.isDone());
//--------------------------------------------------------------------------------------
//
@@ -217,10 +217,10 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nDeleting one of the accounts...");
+ System.out.println("Deleting one of the accounts...");
try (ResultSet<SqlRow> rs = client.sql().execute( "DELETE FROM
ACCOUNTS WHERE ACCOUNT_ID = ?", 1)) {
- System.out.println("\n Removed accounts: " +
rs.affectedRows());
+ System.out.println(" Removed accounts: " + rs.affectedRows());
}
//--------------------------------------------------------------------------------------
@@ -230,7 +230,7 @@ public class SqlApiExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAll accounts:");
+ System.out.println("All accounts:");
// Async way.
Statement stmt = client.sql().statementBuilder()
@@ -243,7 +243,7 @@ public class SqlApiExample {
.thenCompose(SqlApiExample::fetchAllRowsInto)
.get();
- System.out.println("\nDropping the tables...");
+ System.out.println("Dropping the tables...");
client.sql().executeScript(
"DROP TABLE ACCOUNTS;"
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
b/examples/java/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
index 6d351553f8f..7477425f942 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
@@ -42,7 +42,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
//--------------------------------------------------------------------------------------
@@ -74,7 +74,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nPopulating 'CITIES' table...");
+ System.out.println("Populating 'CITIES' table...");
try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO
CITIES (ID, NAME) VALUES (?, ?)")) {
stmt.setInt(1, 1);
@@ -96,7 +96,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nPopulating 'ACCOUNTS' table...");
+ System.out.println("Populating 'ACCOUNTS' table...");
try (PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO ACCOUNTS (ACCOUNT_ID, CITY_ID, FIRST_NAME,
LAST_NAME, BALANCE) values (?, ?, ?, ?, ?)")) {
@@ -135,7 +135,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAll accounts:");
+ System.out.println("All accounts:");
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery(
@@ -156,7 +156,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAccounts with balance lower than 1,500:");
+ System.out.println("Accounts with balance lower than 1,500:");
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery(
@@ -177,7 +177,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nDeleting one of the accounts...");
+ System.out.println("Deleting one of the accounts...");
try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM
ACCOUNTS WHERE ACCOUNT_ID = ?")) {
stmt.setInt(1, 1);
@@ -191,7 +191,7 @@ public class SqlJdbcExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nAll accounts:");
+ System.out.println("All accounts:");
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery(
@@ -206,11 +206,11 @@ public class SqlJdbcExample {
}
}
- System.out.println("\nDropping the tables...");
+ System.out.println("Dropping the tables...");
try (Statement stmt = conn.createStatement()) {
- stmt.executeUpdate("DROP TABLE ACCOUNTS");
- stmt.executeUpdate("DROP TABLE CITIES");
+ stmt.executeUpdate("DROP TABLE IF EXISTS ACCOUNTS");
+ stmt.executeUpdate("DROP TABLE IF EXISTS CITIES");
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/storage/StorageEngineExample.java
b/examples/java/src/main/java/org/apache/ignite/example/storage/StorageEngineExample.java
index c0a90856a06..a3081dfeb52 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/storage/StorageEngineExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/storage/StorageEngineExample.java
@@ -51,96 +51,95 @@ class StorageEngineExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nConnecting to server...");
+ System.out.println("Connecting to server...");
try (Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
-
//--------------------------------------------------------------------------------------
- //
- // Creating table.
- //
-
//--------------------------------------------------------------------------------------
-
- try (Statement stmt = conn.createStatement()) {
- stmt.executeUpdate(
- "CREATE ZONE ACCOUNTS_ZONE "
- + " WITH STORAGE_PROFILES='" +
storageProfileName + "'"
- );
- stmt.executeUpdate(
- "CREATE TABLE ACCOUNTS ( "
- + "ACCOUNT_ID INT PRIMARY KEY,"
- + "FIRST_NAME VARCHAR, "
- + "LAST_NAME VARCHAR, "
- + "BALANCE DOUBLE) "
- + "ZONE ACCOUNTS_ZONE"
- );
- }
-
-
//--------------------------------------------------------------------------------------
- //
- // Populating 'ACCOUNTS' table.
- //
-
//--------------------------------------------------------------------------------------
-
- System.out.println("\nPopulating 'ACCOUNTS' table...");
-
- try (PreparedStatement stmt = conn.prepareStatement(
- "INSERT INTO ACCOUNTS (ACCOUNT_ID, FIRST_NAME, LAST_NAME,
BALANCE) values (?, ?, ?, ?)"
- )) {
- stmt.setInt(1, 1);
- stmt.setString(2, "John");
- stmt.setString(3, "Doe");
- stmt.setDouble(4, 1000.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 2);
- stmt.setString(2, "Jane");
- stmt.setString(3, "Roe");
- stmt.setDouble(4, 2000.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 3);
- stmt.setString(2, "Mary");
- stmt.setString(3, "Major");
- stmt.setDouble(4, 1500.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 4);
- stmt.setString(2, "Richard");
- stmt.setString(3, "Miles");
- stmt.setDouble(4, 1450.0d);
- stmt.executeUpdate();
- }
+ try {
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating zone and table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ try (Statement stmt = conn.createStatement()) {
+ stmt.executeUpdate(
+ "CREATE ZONE ACCOUNTS_ZONE "
+ + " WITH STORAGE_PROFILES='" +
storageProfileName + "'"
+ );
+ stmt.executeUpdate(
+ "CREATE TABLE ACCOUNTS ( "
+ + "ACCOUNT_ID INT PRIMARY KEY,"
+ + "FIRST_NAME VARCHAR, "
+ + "LAST_NAME VARCHAR, "
+ + "BALANCE DOUBLE) "
+ + "ZONE ACCOUNTS_ZONE"
+ );
+ }
-
//--------------------------------------------------------------------------------------
- //
- // Requesting information about all account owners.
- //
-
//--------------------------------------------------------------------------------------
+
//--------------------------------------------------------------------------------------
+ //
+ // Populating 'ACCOUNTS' table.
+ //
+
//--------------------------------------------------------------------------------------
- System.out.println("\nAll accounts:");
+ System.out.println("Populating 'ACCOUNTS' table...");
- try (Statement stmt = conn.createStatement()) {
- try (ResultSet rs = stmt.executeQuery(
- "SELECT ACCOUNT_ID, FIRST_NAME, LAST_NAME, BALANCE
FROM ACCOUNTS ORDER BY ACCOUNT_ID"
+ try (PreparedStatement stmt = conn.prepareStatement(
+ "INSERT INTO ACCOUNTS (ACCOUNT_ID, FIRST_NAME,
LAST_NAME, BALANCE) values (?, ?, ?, ?)"
)) {
- while (rs.next()) {
- System.out.println(" "
- + rs.getString(1) + ", "
- + rs.getString(2) + ", "
- + rs.getString(3) + ", "
- + rs.getString(4));
+ stmt.setInt(1, 1);
+ stmt.setString(2, "John");
+ stmt.setString(3, "Doe");
+ stmt.setDouble(4, 1000.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 2);
+ stmt.setString(2, "Jane");
+ stmt.setString(3, "Roe");
+ stmt.setDouble(4, 2000.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 3);
+ stmt.setString(2, "Mary");
+ stmt.setString(3, "Major");
+ stmt.setDouble(4, 1500.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 4);
+ stmt.setString(2, "Richard");
+ stmt.setString(3, "Miles");
+ stmt.setDouble(4, 1450.0d);
+ stmt.executeUpdate();
+ }
+
+
//--------------------------------------------------------------------------------------
+ //
+ // Requesting information about all account owners.
+ //
+
//--------------------------------------------------------------------------------------
+
+ System.out.println("All accounts:");
+
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery(
+ "SELECT ACCOUNT_ID, FIRST_NAME, LAST_NAME, BALANCE
FROM ACCOUNTS ORDER BY ACCOUNT_ID"
+ )) {
+ while (rs.next()) {
+ System.out.println(" "
+ + rs.getString(1) + ", "
+ + rs.getString(2) + ", "
+ + rs.getString(3) + ", "
+ + rs.getString(4));
+ }
}
}
- }
- } finally {
- 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");
- stmt.executeUpdate("DROP ZONE ACCOUNTS_ZONE");
+ } finally {
+ System.out.println("Dropping the table...");
+
+ try (Statement stmt = conn.createStatement()) {
+ stmt.executeUpdate("DROP TABLE IF EXISTS ACCOUNTS");
+ stmt.executeUpdate("DROP ZONE IF EXISTS ACCOUNTS_ZONE");
+ }
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/streaming/DistributedComputeWithReceiverExample.java
b/examples/java/src/main/java/org/apache/ignite/example/streaming/DistributedComputeWithReceiverExample.java
index b83a18085aa..e0fe1738d0c 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/streaming/DistributedComputeWithReceiverExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/streaming/DistributedComputeWithReceiverExample.java
@@ -146,7 +146,7 @@ public class DistributedComputeWithReceiverExample {
System.out.println("Cleaning up resources");
/* Drop table */
- System.out.println("\nDropping the table...");
+ System.out.println("Dropping the table...");
client.sql().executeScript("DROP TABLE IF EXISTS tx_dummy");
} finally {
undeployUnit(DEPLOYMENT_UNIT_NAME, DEPLOYMENT_UNIT_VERSION);
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/streaming/MultiTableDataStreamerExample.java
b/examples/java/src/main/java/org/apache/ignite/example/streaming/MultiTableDataStreamerExample.java
index 7d774889cc8..8acca790520 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/streaming/MultiTableDataStreamerExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/streaming/MultiTableDataStreamerExample.java
@@ -134,7 +134,7 @@ public class MultiTableDataStreamerExample {
streamerFut.join();
// Drop tables
- System.out.println("\nDropping the tables...");
+ System.out.println("Dropping the tables...");
client.sql().executeScript("DROP TABLE IF EXISTS Customers");
client.sql().executeScript("DROP TABLE IF EXISTS Addresses");
} finally {
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
index 75caedf41a6..b7900220171 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
@@ -17,21 +17,18 @@
package org.apache.ignite.example.table;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.table.Tuple;
/**
- * This example demonstrates the usage of the { @link KeyValueView} API.
+ * This example demonstrates the usage of the {@link KeyValueView} API.
*
* <p>Find instructions on how to run the example in the README.md file
located in the "examples" directory root.
*/
public class KeyValueViewExample {
/**
- * Main method of the example.
+ * Runs the KeyValueViewExample.
*
* @param args The command line arguments.
* @throws Exception If failed.
@@ -39,35 +36,30 @@ public class KeyValueViewExample {
public static void main(String[] args) throws Exception {
//--------------------------------------------------------------------------------------
//
- // Creating 'accounts' table.
+ // Creating a client to connect to the cluster.
//
//--------------------------------------------------------------------------------------
- try (
- Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
+ System.out.println("Connecting to server...");
+
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
) {
- stmt.executeUpdate(
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'accounts' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
"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()
- ) {
//--------------------------------------------------------------------------------------
//
// Creating a key-value view for the 'accounts' table.
@@ -82,7 +74,7 @@ public class KeyValueViewExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nInserting a key-value pair into the
'accounts' table...");
+ System.out.println("Inserting a key-value pair into the 'accounts'
table...");
Tuple key = Tuple.create()
.set("accountNumber", 123456);
@@ -100,7 +92,7 @@ public class KeyValueViewExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nRetrieving a value using KeyValueView
API...");
+ System.out.println("Retrieving a value using KeyValueView API...");
value = kvView.get(null, key);
@@ -109,15 +101,10 @@ public class KeyValueViewExample {
+ " Account Number: " +
key.intValue("accountNumber") + '\n'
+ " Owner: " + value.stringValue("firstName") +
" " + value.stringValue("lastName") + '\n'
+ " Balance: $" + value.doubleValue("balance"));
- } finally {
- 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");
- }
+
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS accounts");
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
index d3f842902a3..0b9af03b9de 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/KeyValueViewPojoExample.java
@@ -17,20 +17,17 @@
package org.apache.ignite.example.table;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.table.KeyValueView;
/**
- * This example demonstrates the usage of the { @link KeyValueView} API with
user-defined POJOs.
+ * This example demonstrates the usage of the {@link KeyValueView} API with
user-defined POJOs.
*
* <p>Find instructions on how to run the example in the README.md file
located in the "examples" directory root.
*/
public class KeyValueViewPojoExample {
/**
- * Main method of the example.
+ * Runs the KeyValueViewPojoExample.
*
* @param args The command line arguments.
* @throws Exception If failed.
@@ -38,35 +35,30 @@ public class KeyValueViewPojoExample {
public static void main(String[] args) throws Exception {
//--------------------------------------------------------------------------------------
//
- // Creating 'accounts' table.
+ // Creating a client to connect to the cluster.
//
//--------------------------------------------------------------------------------------
- try (
- Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
+ System.out.println("Connecting to server...");
+
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
) {
- stmt.executeUpdate(
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'accounts' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
"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()
- ) {
//--------------------------------------------------------------------------------------
//
// Creating a key-value view for the 'accounts' table.
@@ -83,7 +75,7 @@ public class KeyValueViewPojoExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nInserting a key-value pair into the
'accounts' table...");
+ System.out.println("Inserting a key-value pair into the 'accounts'
table...");
AccountKey key = new AccountKey(123456);
@@ -101,7 +93,7 @@ public class KeyValueViewPojoExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nRetrieving a value using KeyValueView
API...");
+ System.out.println("Retrieving a value using KeyValueView API...");
value = kvView.get(null, key);
@@ -110,15 +102,10 @@ public class KeyValueViewPojoExample {
+ " Account Number: " + key.accountNumber + '\n'
+ " Owner: " + value.firstName + " " +
value.lastName + '\n'
+ " Balance: $" + value.balance);
- } finally {
- 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");
- }
+
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS accounts");
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java
index b2f0ff81925..34566cb31db 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java
@@ -22,6 +22,11 @@ import org.apache.ignite.table.RecordView;
import org.apache.ignite.table.mapper.Mapper;
import org.apache.ignite.table.mapper.TypeConverter;
+/**
+ * This example demonstrates the usage of the {@link Mapper} API with a custom
{@link TypeConverter}.
+ *
+ * <p>Find instructions on how to run the example in the README.md file
located in the "examples" directory root.
+ */
public class MapperExample {
static class CityIdConverter implements TypeConverter<String, Integer> {
@@ -36,48 +41,60 @@ public class MapperExample {
}
}
+ /**
+ * Runs the MapperExample.
+ *
+ * @param args The command line arguments.
+ * @throws Exception If failed.
+ */
public static void main(String[] args) throws Exception {
-
try (IgniteClient client = IgniteClient.builder()
.addresses("127.0.0.1:10800")
.build()
) {
- try {
- client.sql().executeScript(
- "CREATE TABLE Person ("
- + "id int primary key, "
- + "city varchar, "
- + "name varchar, "
- + "age int, "
- + "company varchar, "
- + "city_id int)"
- );
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'Person' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
+ "CREATE TABLE Person ("
+ + "id int primary key, "
+ + "city varchar, "
+ + "name varchar, "
+ + "age int, "
+ + "company varchar, "
+ + "city_id int)"
+ );
- client.sql().executeScript(
- "INSERT INTO Person (id, city, name, age, company,
city_id) VALUES (1, 'London', 'John Doe', 42, 'Apache', 101)");
- client.sql().executeScript(
- "INSERT INTO Person (id, city, name, age, company,
city_id) VALUES (2, 'New York', 'Jane Doe', 36, 'Apache', 102)");
+ client.sql().execute(
+ "INSERT INTO Person (id, city, name, age, company,
city_id) VALUES (1, 'London', 'John Doe', 42, 'Apache', 101)");
+ client.sql().execute(
+ "INSERT INTO Person (id, city, name, age, company,
city_id) VALUES (2, 'New York', 'Jane Doe', 36, 'Apache', 102)");
- var mapper = Mapper.builder(Person.class)
- .automap()
- .map("cityId", "city_id", new CityIdConverter())
- .build();
+
//--------------------------------------------------------------------------------------
+ //
+ // Demonstrating Mapper API with custom TypeConverter.
+ //
+
//--------------------------------------------------------------------------------------
- RecordView<Person> view = client.tables()
- .table("person")
- .recordView(mapper);
+ var mapper = Mapper.builder(Person.class)
+ .automap()
+ .map("cityId", "city_id", new CityIdConverter())
+ .build();
- Person myPerson = new Person(2, "2", "John Doe", 40, "Apache");
+ RecordView<Person> view = client.tables()
+ .table("person")
+ .recordView(mapper);
- view.upsert(null, myPerson);
- } finally {
+ Person myPerson = new Person(2, "2", "John Doe", 40, "Apache");
- System.out.println("Dropping the table...");
+ view.upsert(null, myPerson);
- client.sql().executeScript(
- "DROP TABLE Person;");
+ System.out.println("Dropping the table...");
- }
+ client.sql().execute("DROP TABLE IF EXISTS Person");
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
index 4c14b22d2d8..fd98f50ec98 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
@@ -17,21 +17,18 @@
package org.apache.ignite.example.table;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.table.RecordView;
import org.apache.ignite.table.Tuple;
/**
- * This example demonstrates the usage of the { @link RecordView} API.
+ * This example demonstrates the usage of the {@link RecordView} API.
*
* <p>Find instructions on how to run the example in the README.md file
located in the "examples" directory root.
*/
public class RecordViewExample {
/**
- * Main method of the example.
+ * Runs the RecordViewExample.
*
* @param args The command line arguments.
* @throws Exception If failed.
@@ -39,35 +36,30 @@ public class RecordViewExample {
public static void main(String[] args) throws Exception {
//--------------------------------------------------------------------------------------
//
- // Creating 'accounts' table.
+ // Creating a client to connect to the cluster.
//
//--------------------------------------------------------------------------------------
- try (
- Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
+ System.out.println("Connecting to server...");
+
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
) {
- stmt.executeUpdate(
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'accounts' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
"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()
- ) {
//--------------------------------------------------------------------------------------
//
// Creating a record view for the 'accounts' table.
@@ -82,7 +74,7 @@ public class RecordViewExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nInserting a record into the 'accounts'
table...");
+ System.out.println("Inserting a record into the 'accounts'
table...");
Tuple newAccountTuple = Tuple.create()
.set("accountNumber", 123456)
@@ -98,7 +90,7 @@ public class RecordViewExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nRetrieving a record using RecordView
API...");
+ System.out.println("Retrieving a record using RecordView API...");
Tuple accountNumberTuple = Tuple.create().set("accountNumber",
123456);
@@ -109,15 +101,10 @@ public class RecordViewExample {
+ " Account Number: " +
accountTuple.intValue("accountNumber") + '\n'
+ " Owner: " +
accountTuple.stringValue("firstName") + " " +
accountTuple.stringValue("lastName") + '\n'
+ " Balance: $" +
accountTuple.doubleValue("balance"));
- } finally {
- 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");
- }
+
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS accounts");
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
index 8e8a3f9f4d2..b14578d6f7f 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/RecordViewPojoExample.java
@@ -17,20 +17,17 @@
package org.apache.ignite.example.table;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.table.RecordView;
/**
- * This example demonstrates the usage of the { @link RecordView} API with
user-defined POJOs.
+ * This example demonstrates the usage of the {@link RecordView} API with
user-defined POJOs.
*
* <p>Find instructions on how to run the example in the README.md file
located in the "examples" directory root.
*/
public class RecordViewPojoExample {
/**
- * Main method of the example.
+ * Runs the RecordViewPojoExample.
*
* @param args The command line arguments.
* @throws Exception If failed.
@@ -38,35 +35,30 @@ public class RecordViewPojoExample {
public static void main(String[] args) throws Exception {
//--------------------------------------------------------------------------------------
//
- // Creating 'accounts' table.
+ // Creating a client to connect to the cluster.
//
//--------------------------------------------------------------------------------------
- try (
- Connection conn =
DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
+ System.out.println("Connecting to server...");
+
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
) {
- stmt.executeUpdate(
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'accounts' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
"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()
- ) {
//--------------------------------------------------------------------------------------
//
// Creating a record view for the 'accounts' table.
@@ -83,7 +75,7 @@ public class RecordViewPojoExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nInserting a record into the 'accounts'
table...");
+ System.out.println("Inserting a record into the 'accounts'
table...");
Account newAccount = new Account(
123456,
@@ -100,7 +92,7 @@ public class RecordViewPojoExample {
//
//--------------------------------------------------------------------------------------
- System.out.println("\nRetrieving a record using RecordView
API...");
+ System.out.println("Retrieving a record using RecordView API...");
Account account = accounts.get(null, new Account(123456));
@@ -109,15 +101,10 @@ public class RecordViewPojoExample {
+ " Account Number: " + account.accountNumber + '\n'
+ " Owner: " + account.firstName + " " +
account.lastName + '\n'
+ " Balance: $" + account.balance);
- } finally {
- 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");
- }
+
+ System.out.println("Dropping the table...");
+
+ client.sql().execute("DROP TABLE IF EXISTS accounts");
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java
b/examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java
index e3c9e74c36d..d9b2488b7b4 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java
@@ -43,52 +43,58 @@ public class TableExample {
.addresses("127.0.0.1:10800")
.build()
) {
- // Create a table to work with later
- client.sql().execute("CREATE TABLE IF NOT EXISTS Person (" +
- "id int primary key," +
- "city_id int," +
- "name varchar," +
- "age int," +
- "company varchar)"
- );
-
// Get the tables API to interact with database tables
IgniteTables tableApi = client.tables();
- // Retrieve a list of all existing tables in the cluster
- //List<Table> existingTables = tableApi.tables();
-
- // Get the first table from the list (for demonstration purposes)
- //Table firstTable = existingTables.get(0);
-
- // Access a specific table by its simple name
- //Table specificTable = tableApi.table("MY_TABLE");
-
// Create a qualified table name by parsing a string (schema.table
format)
QualifiedName qualifiedTableName =
QualifiedName.parse("PUBLIC.Person");
// Alternative way to create qualified name using schema and table
parts
//QualifiedName qualifiedTableName = QualifiedName.of("PUBLIC",
"MY_TABLE");
- // Access a table using the qualified name (includes schema)
- Table myTable = tableApi.table(qualifiedTableName);
+ try {
+ // Create a table to work with later
+ client.sql().execute("CREATE TABLE Person (" +
+ "id int primary key," +
+ "city_id int," +
+ "name varchar," +
+ "age int," +
+ "company varchar)"
+ );
+
+ // Retrieve a list of all existing tables in the cluster
+ //List<Table> existingTables = tableApi.tables();
+
+ // Get the first table from the list (for demonstration
purposes)
+ //Table firstTable = existingTables.get(0);
+
+ // Access a specific table by its simple name
+ //Table specificTable = tableApi.table("MY_TABLE");
+
+ // Access a table using the qualified name (includes schema)
+ Table myTable = tableApi.table(qualifiedTableName);
+
+ RecordView<Tuple> personTableView = myTable.recordView();
- RecordView<Tuple> personTableView = myTable.recordView();
+ Tuple personTuple = Tuple.create()
+ .set("id", 1)
+ .set("city_id", 3)
+ .set("name", "John Doe")
+ .set("age", 32)
+ .set("company", "Apache");
- Tuple personTuple = Tuple.create()
- .set("id", 1)
- .set("city_id", 3)
- .set("name", "John Doe")
- .set("age", 32)
- .set("company", "Apache");
+ personTableView.upsert(null, personTuple);
- personTableView.upsert(null, personTuple);
+ Tuple personIdTuple = Tuple.create()
+ .set("id", 1);
+ Tuple insertedPerson = personTableView.get(null,
personIdTuple);
- Tuple personIdTuple = Tuple.create()
- .set("id", 1);
- Tuple insertedPerson = personTableView.get(null, personIdTuple);
+ System.out.println("Person name: " +
insertedPerson.stringValue("name"));
+ } finally {
+ System.out.println("Dropping the table...");
- System.out.println("Person name: " +
insertedPerson.stringValue("name"));
+ client.sql().execute("DROP TABLE IF EXISTS Person");
+ }
}
}
}
diff --git
a/examples/java/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
b/examples/java/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
index e940902bbba..3f6f16d6b33 100644
---
a/examples/java/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
+++
b/examples/java/src/main/java/org/apache/ignite/example/tx/TransactionsExample.java
@@ -17,10 +17,6 @@
package org.apache.ignite.example.tx;
-import static java.sql.DriverManager.getConnection;
-
-import java.sql.Connection;
-import java.sql.Statement;
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.table.KeyValueView;
@@ -39,40 +35,49 @@ public class TransactionsExample {
* @throws Exception if any error occurs.
*/
public static void main(String[] args) throws Exception {
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating a client to connect to the cluster.
+ //
+
//--------------------------------------------------------------------------------------
+
+ System.out.println("Connecting to server...");
- /* Create 'accounts' table via JDBC */
- try (
- Connection conn =
getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
- ) {
- stmt.executeUpdate(
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()) {
+
+
//--------------------------------------------------------------------------------------
+ //
+ // Creating 'accounts' table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ client.sql().execute(
"CREATE TABLE IF NOT EXISTS 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...");
+
//--------------------------------------------------------------------------------------
+ //
+ // Preparing key-value view.
+ //
+
//--------------------------------------------------------------------------------------
- try (IgniteClient client = IgniteClient.builder()
- .addresses("127.0.0.1:10800")
- .build()) {
-
- /* Prepare key-value view */
KeyValueView<AccountKey, Account> accounts = client.tables()
.table("accounts")
.keyValueView(AccountKey.class, Account.class);
AccountKey key = new AccountKey(123);
- /* Insert initial account */
+ // Insert initial account.
accounts.put(null, key, new Account("John", "Doe", 1000.0d));
System.out.println("Initial balance: " + accounts.get(null,
key).balance);
- /* Using synchronous transactional API to update the balance */
+ // Using synchronous transactional API to update the balance.
client.transactions().runInTransaction(tx -> {
Account acct = accounts.get(tx, key);
acct.balance += 200.0d;
@@ -81,7 +86,7 @@ public class TransactionsExample {
System.out.println("Balance after the sync transaction: " +
accounts.get(null, key).balance);
- /* Using asynchronous transactional API to update the balance */
+ // Using asynchronous transactional API to update the balance.
CompletableFuture<Void> future =
client.transactions().runInTransactionAsync(tx ->
accounts.getAsync(tx, key)
.thenCompose(acct -> {
@@ -92,24 +97,28 @@ public class TransactionsExample {
future.join();
System.out.println("Balance after the async transaction: " +
accounts.get(null, key).balance);
- } finally {
+
//--------------------------------------------------------------------------------------
+ //
+ // Dropping the table.
+ //
+
//--------------------------------------------------------------------------------------
+
+ System.out.println("Dropping the table...");
- /* Drop table */
- System.out.println("\nDropping the table...");
- try (
- Connection conn =
getConnection("jdbc:ignite:thin://127.0.0.1:10800/");
- Statement stmt = conn.createStatement()
- ) {
- stmt.executeUpdate("DROP TABLE IF EXISTS accounts");
- }
+ client.sql().execute("DROP TABLE IF EXISTS accounts");
}
}
- /* POJO class for key */
+ /**
+ * POJO class that represents key.
+ */
static class AccountKey {
int accountNumber;
- /* Default constructor required for deserialization */
+ /**
+ * Default constructor (required for deserialization).
+ */
+ @SuppressWarnings("unused")
AccountKey() {
}
@@ -118,13 +127,18 @@ public class TransactionsExample {
}
}
- /* POJO class for value */
+ /**
+ * POJO class that represents value.
+ */
static class Account {
String firstName;
String lastName;
double balance;
- /* Default constructor required for deserialization */
+ /**
+ * Default constructor (required for deserialization).
+ */
+ @SuppressWarnings("unused")
Account() {
}