From 719e91e509a73d02c015df311f0c8ddb117ba04e Mon Sep 17 00:00:00 2001 From: Umit UNAL Date: Mon, 9 Mar 2020 10:18:57 +0300 Subject: [PATCH 01/46] Hazelcast 4.0 client migration is done. --- pom.xml | 4 ++-- src/main/java/com/hazelcast/cloud/Client.java | 17 ++++++++--------- .../java/com/hazelcast/cloud/ClientWithSsl.java | 16 ++++++++-------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 1ee0d50..8432a16 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ com.hazelcast - hazelcast-enterprise-client - 3.12.6 + hazelcast-all + 4.0 diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 72efcf4..268dc88 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -2,14 +2,15 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.client.spi.impl.discovery.HazelcastCloudDiscovery; -import com.hazelcast.client.spi.properties.ClientProperty; -import com.hazelcast.config.GroupConfig; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import java.util.Random; +import static com.hazelcast.client.impl.spi.impl.discovery.HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY; +import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; +import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; + /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. * After successful connection, it puts random entries into the map. @@ -20,11 +21,9 @@ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); - config.setGroupConfig(new GroupConfig("YOUR_CLUSTER_NAME", "YOUR_CLUSTER_PASSWORD")); - config.setProperty("hazelcast.client.statistics.enabled", "true"); - config.setProperty(ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); - config.setProperty(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); - + config.setProperty(STATISTICS_ENABLED.getName(), "true"); + config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); + config.setProperty(CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 2002518..0e1f354 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -2,16 +2,17 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.client.spi.impl.discovery.HazelcastCloudDiscovery; -import com.hazelcast.client.spi.properties.ClientProperty; -import com.hazelcast.config.GroupConfig; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; +import com.hazelcast.map.IMap; import java.util.Properties; import java.util.Random; +import static com.hazelcast.client.impl.spi.impl.discovery.HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY; +import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; +import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; + /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. * After successful connection, it puts random entries into the map. @@ -29,10 +30,9 @@ public static void main(String[] args) throws Exception { props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); - config.setGroupConfig(new GroupConfig("YOUR_CLUSTER_NAME", "YOUR_CLUSTER_PASSWORD")); - config.setProperty("hazelcast.client.statistics.enabled", "true"); - config.setProperty(ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); - config.setProperty(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); + config.setProperty(STATISTICS_ENABLED.getName(), "true"); + config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); + config.setProperty(CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); From 903d5e39bb03eb33819dd9ebb53ad4f9a26e8ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Sand=C4=B1kc=C4=B1?= Date: Wed, 8 Apr 2020 14:36:50 +0300 Subject: [PATCH 02/46] ClusterName added. Client changed to enterprise. --- pom.xml | 2 +- src/main/java/com/hazelcast/cloud/Client.java | 1 + src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8432a16..53cd2f8 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.hazelcast - hazelcast-all + hazelcast-enterprise-all 4.0 diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 268dc88..32fbca6 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -24,6 +24,7 @@ public static void main(String[] args) { config.setProperty(STATISTICS_ENABLED.getName(), "true"); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty(CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); + config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 0e1f354..e418728 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -33,7 +33,8 @@ public static void main(String[] args) throws Exception { config.setProperty(STATISTICS_ENABLED.getName(), "true"); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty(CLOUD_URL_BASE_PROPERTY.getName(), "YOUR_DISCOVERY_URL"); - + config.setClusterName("YOUR_CLUSTER_NAME"); + HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); From 473db89751456b2015530fb712178655f8fdc706 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Tue, 24 Nov 2020 13:51:13 +0200 Subject: [PATCH 03/46] Added 4.1 sample code --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53cd2f8..d2087bc 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise-all - 4.0 + 4.1 From 349fc62ed9389efc9f9d935fb68a7a154fd33b4f Mon Sep 17 00:00:00 2001 From: sdreger Date: Fri, 21 May 2021 11:52:35 +0300 Subject: [PATCH 04/46] HZC-521 - Regular printing of progress (#10) * HZC-521 - Regular printing of progress * HZC-521 - Use int instead of byte for the iteration counter (cherry picked from commit 5f6589f25660d3cf62a008c8980173e1efab344f) --- src/main/java/com/hazelcast/cloud/Client.java | 4 +++- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 32fbca6..806aabc 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -32,11 +32,13 @@ public static void main(String[] args) { IMap map = client.getMap("map"); Random random = new Random(); + int iterationCounter = 0; while (true) { int randomKey = random.nextInt(100_000); map.put("key-" + randomKey, "value-" + randomKey); map.get("key-" + random.nextInt(100_000)); - if (randomKey % 10 == 0) { + if (++iterationCounter == 10) { + iterationCounter = 0; System.out.println("Current map size: " + map.size()); } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index e418728..7db889f 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -42,11 +42,13 @@ public static void main(String[] args) throws Exception { IMap map = client.getMap("map"); Random random = new Random(); + int iterationCounter = 0; while (true) { int randomKey = random.nextInt(100_000); map.put("key-" + randomKey, "value-" + randomKey); map.get("key-" + random.nextInt(100_000)); - if (randomKey % 10 == 0) { + if (++iterationCounter == 10) { + iterationCounter = 0; System.out.println("Current map size: " + map.size()); } } From 181dabd52057304f60861500bea98a7409a4de7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20BABAL?= Date: Wed, 7 Jul 2021 22:12:54 +0300 Subject: [PATCH 05/46] Hazelcast 5.0-SNAPSHOT --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d2087bc..7859c4a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,8 +11,8 @@ com.hazelcast - hazelcast-enterprise-all - 4.1 + hazelcast + 5.0-SNAPSHOT From 3cd3897c6bf9c2c1c13f6523eeaeff98f919c08b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Sand=C4=B1kc=C4=B1?= Date: Wed, 11 Aug 2021 09:59:31 +0300 Subject: [PATCH 06/46] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7859c4a..3fb25ad 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast - 5.0-SNAPSHOT + 5.0-BETA-1 From 5c72e8e27f2eec9783e7141693ba5d22977dd915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Sand=C4=B1kc=C4=B1?= Date: Mon, 16 Aug 2021 11:29:58 +0300 Subject: [PATCH 07/46] 5.0-BETA-2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3fb25ad..9c36717 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast - 5.0-BETA-1 + 5.0-BETA-2 From c33139cad55bcacffb5b7b48d276cf8ff4528fb5 Mon Sep 17 00:00:00 2001 From: kubamarchwicki Date: Mon, 13 Sep 2021 23:28:32 +0200 Subject: [PATCH 08/46] Use hazelcase-enterprise jar --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c36717..5c753cb 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.hazelcast - hazelcast + hazelcast-enterprise 5.0-BETA-2 From e85e542d36c3fb440d0935b972aa157f58215691 Mon Sep 17 00:00:00 2001 From: Sergey Dreger Date: Wed, 17 Nov 2021 12:24:23 +0200 Subject: [PATCH 09/46] HZC-2013: Add SQL section to the 5.0 client sample --- src/main/java/com/hazelcast/cloud/Client.java | 71 +++++++++++++++++- .../com/hazelcast/cloud/ClientWithSsl.java | 74 ++++++++++++++++++- 2 files changed, 142 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 9f3bca1..c30b43a 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -6,13 +6,14 @@ import com.hazelcast.client.config.ClientConfig; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.map.IMap; +import com.hazelcast.sql.SqlResult; +import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. - * After successful connection, it puts random entries into the map. *

* See: https://docs.cloud.hazelcast.com/docs/java-client */ @@ -27,6 +28,20 @@ public static void main(String[] args) { HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); + + // the 'mapExample' is an example with an infinite loop inside, so if you'd like to try other examples, + // don't forget to comment out the following line + mapExample(client); + + //sqlExample(client); + } + + /** + * This example shows how to work with Hazelcast maps. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void mapExample(HazelcastInstance client) { System.out.println("Now the map named 'map' will be filled with random entries."); IMap map = client.getMap("map"); @@ -42,4 +57,58 @@ public static void main(String[] args) { } } } + + /** + * This example shows how to work with Hazelcast SQL queries. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void sqlExample(HazelcastInstance client) { + IMap cities = client.getMap("cities"); + + System.out.println("Putting some data..."); + cities.put("Australia", "Canberra"); + cities.put("Croatia", "Zagreb"); + cities.put("Czech Republic", "Prague"); + cities.put("England", "London"); + cities.put("Turkey", "Ankara"); + cities.put("United States", "Washington, DC"); + + System.out.println("Creating a mapping..."); + // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps + try (SqlResult ignored = client.getSql().execute( + "CREATE MAPPING cities TYPE IMap OPTIONS (" + + "'keyFormat' = 'java'," + + "'keyJavaClass' = 'java.lang.String'," + + "'valueFormat' = 'java'," + + "'valueJavaClass' = 'java.lang.String')")) { + System.out.println("The mapping has been created successfully."); + } + + System.out.println("--------------------"); + System.out.println("Retrieving all the data via SQL..."); + try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { + + for (SqlRow row : result) { + String country = row.getObject(0); + String city = row.getObject(1); + System.out.printf("%s - %s\n", country, city); + } + } + + System.out.println("--------------------"); + System.out.println("Retrieving a city name via SQL..."); + try (SqlResult result = client.getSql() + .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { + + for (SqlRow row : result) { + String country = row.getObject("__key"); + String city = row.getObject("this"); + System.out.printf("Country name: %s; City name: %s\n", country, city); + } + } + System.out.println("--------------------"); + System.exit(0); + } + } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index b63e761..499fd9c 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -8,13 +8,14 @@ import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.map.IMap; +import com.hazelcast.sql.SqlResult; +import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. - * After successful connection, it puts random entries into the map. *

* See: https://docs.cloud.hazelcast.com/docs/java-client */ @@ -25,7 +26,8 @@ public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("javax.net.ssl.keyStore", classLoader.getResource("client.keystore").toURI().getPath()); props.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SSL_PASSWORD"); - props.setProperty("javax.net.ssl.trustStore", classLoader.getResource("client.truststore").toURI().getPath()); + props.setProperty("javax.net.ssl.trustStore", + classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); @@ -37,6 +39,20 @@ public static void main(String[] args) throws Exception { HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); + + // the 'mapExample' is an example with an infinite loop inside, so if you'd like to try other examples, + // don't forget to comment out the following line + mapExample(client); + + //sqlExample(client); + } + + /** + * This example shows how to work with Hazelcast maps. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void mapExample(HazelcastInstance client) { System.out.println("Now the map named 'map' will be filled with random entries."); IMap map = client.getMap("map"); @@ -52,4 +68,58 @@ public static void main(String[] args) throws Exception { } } } + + /** + * This example shows how to work with Hazelcast SQL queries. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void sqlExample(HazelcastInstance client) { + IMap cities = client.getMap("cities"); + + System.out.println("Putting some data..."); + cities.put("Australia", "Canberra"); + cities.put("Croatia", "Zagreb"); + cities.put("Czech Republic", "Prague"); + cities.put("England", "London"); + cities.put("Turkey", "Ankara"); + cities.put("United States", "Washington, DC"); + + System.out.println("Creating a mapping..."); + // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps + try (SqlResult ignored = client.getSql().execute( + "CREATE MAPPING cities TYPE IMap OPTIONS (" + + "'keyFormat' = 'java'," + + "'keyJavaClass' = 'java.lang.String'," + + "'valueFormat' = 'java'," + + "'valueJavaClass' = 'java.lang.String')")) { + System.out.println("The mapping has been created successfully."); + } + + System.out.println("--------------------"); + System.out.println("Retrieving all the data via SQL..."); + try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { + + for (SqlRow row : result) { + String country = row.getObject(0); + String city = row.getObject(1); + System.out.printf("%s - %s\n", country, city); + } + } + + System.out.println("--------------------"); + System.out.println("Retrieving a city name via SQL..."); + try (SqlResult result = client.getSql() + .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { + + for (SqlRow row : result) { + String country = row.getObject("__key"); + String city = row.getObject("this"); + System.out.printf("Country name: %s; City name: %s\n", country, city); + } + } + System.out.println("--------------------"); + System.exit(0); + } + } From 8a978d984640ea863ea3d095c01f422a1eadb1b5 Mon Sep 17 00:00:00 2001 From: Sergey Dreger Date: Thu, 18 Nov 2021 11:59:13 +0200 Subject: [PATCH 10/46] HZC-2013: Replace 'put' statements with 'INSERT' statements --- src/main/java/com/hazelcast/cloud/Client.java | 23 +++++++++++-------- .../com/hazelcast/cloud/ClientWithSsl.java | 23 +++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index c30b43a..367a2c6 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -64,15 +64,6 @@ private static void mapExample(HazelcastInstance client) { * @param client - a {@link HazelcastInstance} client. */ private static void sqlExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - - System.out.println("Putting some data..."); - cities.put("Australia", "Canberra"); - cities.put("Croatia", "Zagreb"); - cities.put("Czech Republic", "Prague"); - cities.put("England", "London"); - cities.put("Turkey", "Ankara"); - cities.put("United States", "Washington, DC"); System.out.println("Creating a mapping..."); // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps @@ -85,6 +76,20 @@ private static void sqlExample(HazelcastInstance client) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); + System.out.println("Inserting data via SQL..."); + + String insertQuery = "INSERT INTO cities VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = client.getSql().execute(insertQuery)) { + System.out.println("The data has been inserted successfully."); + } + System.out.println("--------------------"); System.out.println("Retrieving all the data via SQL..."); try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 499fd9c..4a870b1 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -75,15 +75,6 @@ private static void mapExample(HazelcastInstance client) { * @param client - a {@link HazelcastInstance} client. */ private static void sqlExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - - System.out.println("Putting some data..."); - cities.put("Australia", "Canberra"); - cities.put("Croatia", "Zagreb"); - cities.put("Czech Republic", "Prague"); - cities.put("England", "London"); - cities.put("Turkey", "Ankara"); - cities.put("United States", "Washington, DC"); System.out.println("Creating a mapping..."); // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps @@ -96,6 +87,20 @@ private static void sqlExample(HazelcastInstance client) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); + System.out.println("Inserting data via SQL..."); + + String insertQuery = "INSERT INTO cities VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = client.getSql().execute(insertQuery)) { + System.out.println("The data has been inserted successfully."); + } + System.out.println("--------------------"); System.out.println("Retrieving all the data via SQL..."); try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { From f100ab186af2ecb0def3f9d5708f24dd564ebb7c Mon Sep 17 00:00:00 2001 From: Ivan Shevtsov Date: Thu, 2 Dec 2021 15:27:34 +0300 Subject: [PATCH 11/46] Feature/hzc 2039 sql with json (#20) * HZX-2039 sample with json serialization and SQL queries * move additional examples with JSON serialization into main Client class * added javadocs and duplicated example in ClientWithSsl * removed compact serialization in cities --- pom.xml | 2 +- src/main/java/com/hazelcast/cloud/Client.java | 138 ++++++++++++++++++ .../com/hazelcast/cloud/ClientWithSsl.java | 138 ++++++++++++++++++ .../java/com/hazelcast/cloud/model/City.java | 41 ++++++ .../cloud/model/CityJsonSerializer.java | 16 ++ .../com/hazelcast/cloud/model/Country.java | 30 ++++ .../cloud/model/CountryJsonSerializer.java | 15 ++ 7 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hazelcast/cloud/model/City.java create mode 100644 src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java create mode 100644 src/main/java/com/hazelcast/cloud/model/Country.java create mode 100644 src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java diff --git a/pom.xml b/pom.xml index 5c753cb..e82d925 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.0-BETA-2 + 5.0 diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 367a2c6..7e2336e 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -4,13 +4,18 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.cloud.model.CityJsonSerializer; +import com.hazelcast.cloud.model.CountryJsonSerializer; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; +import static com.hazelcast.cloud.model.City.newCity; +import static com.hazelcast.cloud.model.Country.newCountry; /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. @@ -34,6 +39,8 @@ public static void main(String[] args) { mapExample(client); //sqlExample(client); + + //jsonSerializationExample(client); } /** @@ -116,4 +123,135 @@ private static void sqlExample(HazelcastInstance client) { System.exit(0); } + /** + * This example shows how to work with Hazelcast SQL queries via Maps that contains + * JSON serialized values. + * - Select single json element data from a Map + * - Select data from Map with filtering + * - Join data from 2 Maps and select json elements + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void jsonSerializationExample(HazelcastInstance client) { + createMappingForCountries(client); + + populateCountriesWithMap(client); + selectAllCountries(client); + + populateCities(client); + createMappingForCities(client); + + selectCitiesByCountry(client, "AU"); + + selectCountriesAndCities(client); + + System.out.println("--------------------"); + System.exit(0); + } + + private static void createMappingForCountries(HazelcastInstance client) { + //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + String mappingSql = "" + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.String'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult rs = client.getSql().execute(mappingSql)) { + rs.updateCount(); + System.out.println("Mapping for countries has been created"); + } + } + + private static void populateCountriesWithMap(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("Populate Countries with map - values as JSON"); + IMap countries = client.getMap("country"); + countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); + countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); + countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); + countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("US", "Czech Republic"))); + } + + private static void selectAllCountries(HazelcastInstance client) { + String sql = "SELECT c.country from country c"; + System.out.println("--------------------"); + System.out.println("Select all countries with sql = " + sql); + try (SqlResult result = client.getSql().execute(sql)) { + result.forEach(row -> System.out.println("country=" + row.getObject("country"))); + } + } + + private static void populateCities(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("--------------------"); + System.out.println("Populate cities"); + IMap cities = client.getMap("city"); + cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); + cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); + cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); + cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + } + + + private static void createMappingForCities(HazelcastInstance client) { + //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + String mappingSql = "" + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population BIGINT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.Integer'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult rs = client.getSql().execute(mappingSql)) { + rs.updateCount(); + System.out.println("Mapping for cities has been created"); + } + } + + private static void selectCitiesByCountry(HazelcastInstance client, String country) { + String sql = "SELECT city, population FROM city where country=?"; + System.out.println("--------------------"); + System.out.println("Select city and population with sql = " + sql); + try (SqlResult result = client.getSql().execute(sql, country)) { + result.forEach(row -> + System.out.printf("city=%s, population=%s%n", row.getObject("city"), row.getObject("population")) + ); + } + } + + private static void selectCountriesAndCities(HazelcastInstance client) { + String sql = "" + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; + + System.out.println("--------------------"); + System.out.println("Select country and city data in query that joins tables"); + System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); + + try (SqlResult result = client.getSql().execute(sql)) { + result.forEach(row -> { + System.out.printf("%4s | %15s | %20s | %15s |%n", + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") + ); + }); + } + } + } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 4a870b1..b45ae74 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -5,14 +5,19 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.cloud.model.CityJsonSerializer; +import com.hazelcast.cloud.model.CountryJsonSerializer; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; +import static com.hazelcast.cloud.model.City.newCity; +import static com.hazelcast.cloud.model.Country.newCountry; /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. @@ -45,6 +50,8 @@ public static void main(String[] args) throws Exception { mapExample(client); //sqlExample(client); + + //jsonSerializationExample(client); } /** @@ -127,4 +134,135 @@ private static void sqlExample(HazelcastInstance client) { System.exit(0); } + /** + * This example shows how to work with Hazelcast SQL queries via Maps that contains + * JSON serialized values. + * - Select single json element data from a Map + * - Select data from Map with filtering + * - Join data from 2 Maps and select json elements + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void jsonSerializationExample(HazelcastInstance client) { + createMappingForCountries(client); + + populateCountriesWithMap(client); + selectAllCountries(client); + + populateCities(client); + createMappingForCities(client); + + selectCitiesByCountry(client, "AU"); + + selectCountriesAndCities(client); + + System.out.println("--------------------"); + System.exit(0); + } + + private static void createMappingForCountries(HazelcastInstance client) { + //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + String mappingSql = "" + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.String'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult rs = client.getSql().execute(mappingSql)) { + rs.updateCount(); + System.out.println("Mapping for countries has been created"); + } + } + + private static void populateCountriesWithMap(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("Populate Countries with map - values as JSON"); + IMap countries = client.getMap("country"); + countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); + countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); + countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); + countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("US", "Czech Republic"))); + } + + private static void selectAllCountries(HazelcastInstance client) { + String sql = "SELECT c.country from country c"; + System.out.println("--------------------"); + System.out.println("Select all countries with sql = " + sql); + try (SqlResult result = client.getSql().execute(sql)) { + result.forEach(row -> System.out.println("country=" + row.getObject("country"))); + } + } + + private static void populateCities(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("--------------------"); + System.out.println("Populate cities"); + IMap cities = client.getMap("city"); + cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); + cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); + cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); + cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + } + + + private static void createMappingForCities(HazelcastInstance client) { + //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + String mappingSql = "" + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population BIGINT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.Integer'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult rs = client.getSql().execute(mappingSql)) { + rs.updateCount(); + System.out.println("Mapping for cities has been created"); + } + } + + private static void selectCitiesByCountry(HazelcastInstance client, String country) { + String sql = "SELECT city, population FROM city where country=?"; + System.out.println("--------------------"); + System.out.println("Select city and population with sql = " + sql); + try (SqlResult result = client.getSql().execute(sql, country)) { + result.forEach(row -> + System.out.printf("city=%s, population=%s%n", row.getObject("city"), row.getObject("population")) + ); + } + } + + private static void selectCountriesAndCities(HazelcastInstance client) { + String sql = "" + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; + + System.out.println("--------------------"); + System.out.println("Select country and city data in query that joins tables"); + System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); + + try (SqlResult result = client.getSql().execute(sql)) { + result.forEach(row -> { + System.out.printf("%4s | %15s | %20s | %15s |%n", + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") + ); + }); + } + } + } diff --git a/src/main/java/com/hazelcast/cloud/model/City.java b/src/main/java/com/hazelcast/cloud/model/City.java new file mode 100644 index 0000000..e47f13f --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/model/City.java @@ -0,0 +1,41 @@ +package com.hazelcast.cloud.model; + +public class City { + + private String country; + private String city; + private int population; + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public int getPopulation() { + return population; + } + + public void setPopulation(int population) { + this.population = population; + } + + public static City newCity(String country, String cityName, int population) { + City city = new City(); + city.country = country; + city.city = cityName; + city.population = population; + return city; + } + +} diff --git a/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java b/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java new file mode 100644 index 0000000..5c571ac --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java @@ -0,0 +1,16 @@ +package com.hazelcast.cloud.model; + +import com.hazelcast.core.HazelcastJsonValue; +import com.hazelcast.org.json.JSONObject; + +public class CityJsonSerializer { + + public static HazelcastJsonValue cityAsJson(City city) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("country", city.getCountry()); + jsonObject.put("city", city.getCity()); + jsonObject.put("population", city.getPopulation()); + return new HazelcastJsonValue(jsonObject.toString()); + } + +} diff --git a/src/main/java/com/hazelcast/cloud/model/Country.java b/src/main/java/com/hazelcast/cloud/model/Country.java new file mode 100644 index 0000000..2840530 --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/model/Country.java @@ -0,0 +1,30 @@ +package com.hazelcast.cloud.model; + +public class Country { + + private String isoCode; + private String country; + + public String getIsoCode() { + return isoCode; + } + + public void setIsoCode(String isoCode) { + this.isoCode = isoCode; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public static Country newCountry(String isoCode, String countryName) { + Country country = new Country(); + country.isoCode = isoCode; + country.country = countryName; + return country; + } +} diff --git a/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java b/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java new file mode 100644 index 0000000..bc7915d --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java @@ -0,0 +1,15 @@ +package com.hazelcast.cloud.model; + +import com.hazelcast.core.HazelcastJsonValue; +import com.hazelcast.org.json.JSONObject; + +public class CountryJsonSerializer { + + public static HazelcastJsonValue countryAsJson(Country country) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("isoCode", country.getIsoCode()); + jsonObject.put("country", country.getCountry()); + return new HazelcastJsonValue(jsonObject.toString()); + } + +} From b55e59695d4d5c260665b51efc14dc683b53ed99 Mon Sep 17 00:00:00 2001 From: Sergey Dreger Date: Fri, 3 Dec 2021 12:13:16 +0200 Subject: [PATCH 12/46] HZC-2039: Code style cleanup for 5.0 --- src/main/java/com/hazelcast/cloud/Client.java | 101 +++++++++++------- .../com/hazelcast/cloud/ClientWithSsl.java | 101 +++++++++++------- 2 files changed, 124 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 7e2336e..7e09753 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -74,30 +74,39 @@ private static void sqlExample(HazelcastInstance client) { System.out.println("Creating a mapping..."); // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps - try (SqlResult ignored = client.getSql().execute( - "CREATE MAPPING cities TYPE IMap OPTIONS (" + - "'keyFormat' = 'java'," + - "'keyJavaClass' = 'java.lang.String'," + - "'valueFormat' = 'java'," + - "'valueJavaClass' = 'java.lang.String')")) { + final String mappingQuery = "" + + "CREATE OR REPLACE MAPPING cities TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.String'," + + " 'valueFormat' = 'java'," + + " 'valueJavaClass' = 'java.lang.String'" + + " )"; + try (SqlResult ignored = client.getSql().execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); + System.out.println("Deleting data via SQL..."); + try (SqlResult ignored = client.getSql().execute("DELETE FROM cities")) { + System.out.println("The data has been deleted successfully."); + } System.out.println("--------------------"); + System.out.println("Inserting data via SQL..."); - - String insertQuery = "INSERT INTO cities VALUES" + - "('Australia','Canberra')," + - "('Croatia','Zagreb')," + - "('Czech Republic','Prague')," + - "('England','London')," + - "('Turkey','Ankara')," + - "('United States','Washington, DC');"; + String insertQuery = "" + + "INSERT INTO cities VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; try (SqlResult ignored = client.getSql().execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } - System.out.println("--------------------"); + System.out.println("Retrieving all the data via SQL..."); try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { @@ -107,8 +116,8 @@ private static void sqlExample(HazelcastInstance client) { System.out.printf("%s - %s\n", country, city); } } - System.out.println("--------------------"); + System.out.println("Retrieving a city name via SQL..."); try (SqlResult result = client.getSql() .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { @@ -136,27 +145,30 @@ private static void jsonSerializationExample(HazelcastInstance client) { createMappingForCountries(client); populateCountriesWithMap(client); + selectAllCountries(client); - populateCities(client); createMappingForCities(client); + populateCities(client); + selectCitiesByCountry(client, "AU"); selectCountriesAndCities(client); - System.out.println("--------------------"); System.exit(0); } private static void createMappingForCountries(HazelcastInstance client) { //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + System.out.println("Creating mapping for countries..."); + String mappingSql = "" + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR)" - + " TYPE IMap" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + " OPTIONS (" + " 'keyFormat' = 'java'," + " 'keyJavaClass' = 'java.lang.String'," @@ -167,41 +179,36 @@ private static void createMappingForCountries(HazelcastInstance client) { rs.updateCount(); System.out.println("Mapping for countries has been created"); } + System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populate Countries with map - values as JSON"); + System.out.println("Populating 'countries' map with JSON values..."); + IMap countries = client.getMap("country"); countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); - countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("US", "Czech Republic"))); + countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("CZ", "Czech Republic"))); + + System.out.println("The 'countries' map has been populated."); + System.out.println("--------------------"); } private static void selectAllCountries(HazelcastInstance client) { String sql = "SELECT c.country from country c"; - System.out.println("--------------------"); System.out.println("Select all countries with sql = " + sql); try (SqlResult result = client.getSql().execute(sql)) { - result.forEach(row -> System.out.println("country=" + row.getObject("country"))); + result.forEach(row -> System.out.println("country = " + row.getObject("country"))); } - } - - private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map System.out.println("--------------------"); - System.out.println("Populate cities"); - IMap cities = client.getMap("city"); - cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); - cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); - cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); - cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); } - private static void createMappingForCities(HazelcastInstance client) { //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + System.out.println("Creating mapping for cities..."); + String mappingSql = "" + "CREATE OR REPLACE MAPPING city(" + " __key INT ," @@ -219,6 +226,21 @@ private static void createMappingForCities(HazelcastInstance client) { rs.updateCount(); System.out.println("Mapping for cities has been created"); } + System.out.println("--------------------"); + } + + private static void populateCities(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("Populating 'city' map with JSON values..."); + + IMap cities = client.getMap("city"); + cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); + cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); + cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); + cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + + System.out.println("The 'city' map has been populated."); + System.out.println("--------------------"); } private static void selectCitiesByCountry(HazelcastInstance client, String country) { @@ -227,9 +249,10 @@ private static void selectCitiesByCountry(HazelcastInstance client, String count System.out.println("Select city and population with sql = " + sql); try (SqlResult result = client.getSql().execute(sql, country)) { result.forEach(row -> - System.out.printf("city=%s, population=%s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } + System.out.println("--------------------"); } private static void selectCountriesAndCities(HazelcastInstance client) { @@ -238,7 +261,6 @@ private static void selectCountriesAndCities(HazelcastInstance client) { + " FROM country c" + " JOIN city t ON c.isoCode = t.country"; - System.out.println("--------------------"); System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); @@ -252,6 +274,7 @@ private static void selectCountriesAndCities(HazelcastInstance client) { ); }); } + System.out.println("--------------------"); } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index b45ae74..074f7ac 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -85,30 +85,39 @@ private static void sqlExample(HazelcastInstance client) { System.out.println("Creating a mapping..."); // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps - try (SqlResult ignored = client.getSql().execute( - "CREATE MAPPING cities TYPE IMap OPTIONS (" + - "'keyFormat' = 'java'," + - "'keyJavaClass' = 'java.lang.String'," + - "'valueFormat' = 'java'," + - "'valueJavaClass' = 'java.lang.String')")) { + final String mappingQuery = "" + + "CREATE OR REPLACE MAPPING cities TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'java'," + + " 'keyJavaClass' = 'java.lang.String'," + + " 'valueFormat' = 'java'," + + " 'valueJavaClass' = 'java.lang.String'" + + " )"; + try (SqlResult ignored = client.getSql().execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); + System.out.println("Deleting data via SQL..."); + try (SqlResult ignored = client.getSql().execute("DELETE FROM cities")) { + System.out.println("The data has been deleted successfully."); + } System.out.println("--------------------"); - System.out.println("Inserting data via SQL..."); - String insertQuery = "INSERT INTO cities VALUES" + - "('Australia','Canberra')," + - "('Croatia','Zagreb')," + - "('Czech Republic','Prague')," + - "('England','London')," + - "('Turkey','Ankara')," + - "('United States','Washington, DC');"; + System.out.println("Inserting data via SQL..."); + String insertQuery = "" + + "INSERT INTO cities VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; try (SqlResult ignored = client.getSql().execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } - System.out.println("--------------------"); + System.out.println("Retrieving all the data via SQL..."); try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { @@ -118,8 +127,8 @@ private static void sqlExample(HazelcastInstance client) { System.out.printf("%s - %s\n", country, city); } } - System.out.println("--------------------"); + System.out.println("Retrieving a city name via SQL..."); try (SqlResult result = client.getSql() .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { @@ -147,27 +156,30 @@ private static void jsonSerializationExample(HazelcastInstance client) { createMappingForCountries(client); populateCountriesWithMap(client); + selectAllCountries(client); - populateCities(client); createMappingForCities(client); + populateCities(client); + selectCitiesByCountry(client, "AU"); selectCountriesAndCities(client); - System.out.println("--------------------"); System.exit(0); } private static void createMappingForCountries(HazelcastInstance client) { //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + System.out.println("Creating mapping for countries..."); + String mappingSql = "" + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR)" - + " TYPE IMap" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + " OPTIONS (" + " 'keyFormat' = 'java'," + " 'keyJavaClass' = 'java.lang.String'," @@ -178,41 +190,36 @@ private static void createMappingForCountries(HazelcastInstance client) { rs.updateCount(); System.out.println("Mapping for countries has been created"); } + System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populate Countries with map - values as JSON"); + System.out.println("Populating 'countries' map with JSON values..."); + IMap countries = client.getMap("country"); countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); - countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("US", "Czech Republic"))); + countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("CZ", "Czech Republic"))); + + System.out.println("The 'countries' map has been populated."); + System.out.println("--------------------"); } private static void selectAllCountries(HazelcastInstance client) { String sql = "SELECT c.country from country c"; - System.out.println("--------------------"); System.out.println("Select all countries with sql = " + sql); try (SqlResult result = client.getSql().execute(sql)) { - result.forEach(row -> System.out.println("country=" + row.getObject("country"))); + result.forEach(row -> System.out.println("country = " + row.getObject("country"))); } - } - - private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map System.out.println("--------------------"); - System.out.println("Populate cities"); - IMap cities = client.getMap("city"); - cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); - cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); - cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); - cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); } - private static void createMappingForCities(HazelcastInstance client) { //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + System.out.println("Creating mapping for cities..."); + String mappingSql = "" + "CREATE OR REPLACE MAPPING city(" + " __key INT ," @@ -230,6 +237,21 @@ private static void createMappingForCities(HazelcastInstance client) { rs.updateCount(); System.out.println("Mapping for cities has been created"); } + System.out.println("--------------------"); + } + + private static void populateCities(HazelcastInstance client) { + // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + System.out.println("Populating 'city' map with JSON values..."); + + IMap cities = client.getMap("city"); + cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); + cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); + cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); + cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + + System.out.println("The 'city' map has been populated."); + System.out.println("--------------------"); } private static void selectCitiesByCountry(HazelcastInstance client, String country) { @@ -238,9 +260,10 @@ private static void selectCitiesByCountry(HazelcastInstance client, String count System.out.println("Select city and population with sql = " + sql); try (SqlResult result = client.getSql().execute(sql, country)) { result.forEach(row -> - System.out.printf("city=%s, population=%s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } + System.out.println("--------------------"); } private static void selectCountriesAndCities(HazelcastInstance client) { @@ -249,7 +272,6 @@ private static void selectCountriesAndCities(HazelcastInstance client) { + " FROM country c" + " JOIN city t ON c.isoCode = t.country"; - System.out.println("--------------------"); System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); @@ -263,6 +285,7 @@ private static void selectCountriesAndCities(HazelcastInstance client) { ); }); } + System.out.println("--------------------"); } } From 8ec8d311cafb31f210b7be9fd6b5fb39c003ae73 Mon Sep 17 00:00:00 2001 From: Huseyin BABAL Date: Wed, 16 Feb 2022 12:41:38 +0300 Subject: [PATCH 13/46] 5.1-SNAPSHOT added --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e82d925..e4ff6da 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.0 + 5.1-SNAPSHOT From 923981374cd2c446fc62a265d53f35415caa3011 Mon Sep 17 00:00:00 2001 From: Ivan Shevtsov Date: Thu, 10 Mar 2022 16:57:36 +0300 Subject: [PATCH 14/46] use release version of artifact (#29) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4ff6da..12e98b7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.1-SNAPSHOT + 5.1 From f6b5fc8d0a242dc2f5af281e7f8186d1f3c18c1d Mon Sep 17 00:00:00 2001 From: Ivan Shevtsov Date: Fri, 11 Mar 2022 10:04:05 +0300 Subject: [PATCH 15/46] enable redo operation for 5_1 (#26) --- src/main/java/com/hazelcast/cloud/Client.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 7e09753..c5cdbae 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -26,6 +26,7 @@ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); + config.getNetworkConfig().setRedoOperation(true); config.setProperty(STATISTICS_ENABLED.getName(), "true"); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); From 4472730b1865c98112dbb114a3990f2f21baffe2 Mon Sep 17 00:00:00 2001 From: Metin Dumandag Date: Fri, 11 Mar 2022 10:07:26 +0300 Subject: [PATCH 16/46] Remove usage of deprecated property (#22) We have deprecated the `STATISTICS` properties, as in 4.0, we have introduced `MetricsConfig`, which enables metrics collection by default. So, there is no need to set this deprecated property anymore. Co-authored-by: Ivan Shevtsov --- src/main/java/com/hazelcast/cloud/Client.java | 2 -- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index c5cdbae..83d4d34 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -13,7 +13,6 @@ import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; -import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; import static com.hazelcast.cloud.model.City.newCity; import static com.hazelcast.cloud.model.Country.newCountry; @@ -27,7 +26,6 @@ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); config.getNetworkConfig().setRedoOperation(true); - config.setProperty(STATISTICS_ENABLED.getName(), "true"); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 074f7ac..f476ba3 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -15,7 +15,6 @@ import com.hazelcast.sql.SqlRow; import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; -import static com.hazelcast.client.properties.ClientProperty.STATISTICS_ENABLED; import static com.hazelcast.cloud.model.City.newCity; import static com.hazelcast.cloud.model.Country.newCountry; @@ -36,7 +35,6 @@ public static void main(String[] args) throws Exception { props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); - config.setProperty(STATISTICS_ENABLED.getName(), "true"); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); From 98bd175b9e1ef11a4bdee20b14125d3921007484 Mon Sep 17 00:00:00 2001 From: ivanshevtsov Date: Fri, 11 Mar 2022 09:09:11 +0200 Subject: [PATCH 17/46] set setRedoOperation true for ssl client sample --- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index f476ba3..195c890 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -34,6 +34,7 @@ public static void main(String[] args) throws Exception { classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); + config.getNetworkConfig().setRedoOperation(true); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); From 6159c38e5376ef618b05ad7307091f5d43bd6a29 Mon Sep 17 00:00:00 2001 From: Krzysiek Przygudzki Date: Thu, 10 Mar 2022 16:03:50 +0100 Subject: [PATCH 18/46] HZC-847 Use ClientCloudConfig to pass cluster discovery token --- src/main/java/com/hazelcast/cloud/Client.java | 5 +++-- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 83d4d34..5dac73d 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -12,7 +12,6 @@ import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; -import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.cloud.model.City.newCity; import static com.hazelcast.cloud.model.Country.newCountry; @@ -26,7 +25,9 @@ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); config.getNetworkConfig().setRedoOperation(true); - config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); + config.getNetworkConfig().getCloudConfig() + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 195c890..3c14656 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -14,7 +14,6 @@ import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; -import static com.hazelcast.client.properties.ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN; import static com.hazelcast.cloud.model.City.newCity; import static com.hazelcast.cloud.model.Country.newCountry; @@ -36,7 +35,9 @@ public static void main(String[] args) throws Exception { ClientConfig config = new ClientConfig(); config.getNetworkConfig().setRedoOperation(true); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); - config.setProperty(HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), "YOUR_CLUSTER_DISCOVERY_TOKEN"); + config.getNetworkConfig().getCloudConfig() + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); From 5d6746f04320bbb8cb440354fc67adc1d5277cfd Mon Sep 17 00:00:00 2001 From: Metin Dumandag Date: Mon, 25 Jul 2022 13:24:34 +0300 Subject: [PATCH 19/46] Update the Java code samples (#34) * Update the Java code samples This PR updates the code sample according to the decision made with the documentation and the APIs team, to provide consistent code samples across all clients. Instead of populating a map with random entries all the time, the default code sample to run now populates a map with HJV entries so that it can be queryable. The part that queries the map will be handled by the documentation team in their tutorials. This PR also contains some small changes to the code sample like getting rid of unnecessary abstractions, fixing the formatting, making create mapping statements more friendly to non-java developers, etc. * address review comments * address review comments * add non-stop map example --- src/main/java/com/hazelcast/cloud/Client.java | 278 ++++++++++-------- .../com/hazelcast/cloud/ClientWithSsl.java | 276 +++++++++-------- .../java/com/hazelcast/cloud/model/City.java | 45 +-- .../cloud/model/CityJsonSerializer.java | 16 - .../com/hazelcast/cloud/model/Country.java | 35 +-- .../cloud/model/CountryJsonSerializer.java | 15 - 6 files changed, 335 insertions(+), 330 deletions(-) delete mode 100644 src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java delete mode 100644 src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 5dac73d..faeacc1 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -1,46 +1,46 @@ package com.hazelcast.cloud; -import java.util.Random; - import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.cloud.model.CityJsonSerializer; -import com.hazelcast.cloud.model.CountryJsonSerializer; +import com.hazelcast.cloud.model.City; +import com.hazelcast.cloud.model.Country; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; +import com.hazelcast.sql.SqlService; -import static com.hazelcast.cloud.model.City.newCity; -import static com.hazelcast.cloud.model.Country.newCountry; +import java.util.Random; /** - * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. + * This is boilerplate application that configures client to connect Hazelcast + * Cloud cluster. *

- * See: https://docs.cloud.hazelcast.com/docs/java-client + * See: https://docs.hazelcast.com/cloud/java-client */ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); - config.getNetworkConfig().setRedoOperation(true); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); - // the 'mapExample' is an example with an infinite loop inside, so if you'd like to try other examples, - // don't forget to comment out the following line mapExample(client); //sqlExample(client); //jsonSerializationExample(client); + + //nonStopMapExample(client); + + client.shutdown(); } /** @@ -49,20 +49,20 @@ public static void main(String[] args) { * @param client - a {@link HazelcastInstance} client. */ private static void mapExample(HazelcastInstance client) { - System.out.println("Now the map named 'map' will be filled with random entries."); + IMap cities = client.getMap("cities"); + cities.put("1", City.asJson("United Kingdom", "London", 9_540_576)); + cities.put("2", City.asJson("United Kingdom", "Manchester", 2_770_434)); + cities.put("3", City.asJson("United States", "New York", 19_223_191)); + cities.put("4", City.asJson("United States", "Los Angeles", 3_985_520)); + cities.put("5", City.asJson("Turkey", "Ankara", 5_309_690)); + cities.put("6", City.asJson("Turkey", "Istanbul", 15_636_243)); + cities.put("7", City.asJson("Brazil", "Sao Paulo", 22_429_800)); + cities.put("8", City.asJson("Brazil", "Rio de Janeiro", 13_634_274)); + + int mapSize = cities.size(); + System.out.printf("'cities' map now contains %d entries.\n", mapSize); - IMap map = client.getMap("map"); - Random random = new Random(); - int iterationCounter = 0; - while (true) { - int randomKey = random.nextInt(100_000); - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } - } + System.out.println("--------------------"); } /** @@ -71,44 +71,62 @@ private static void mapExample(HazelcastInstance client) { * @param client - a {@link HazelcastInstance} client. */ private static void sqlExample(HazelcastInstance client) { + SqlService sqlService = client.getSql(); + + createMappingForCapitals(sqlService); + clearCapitals(sqlService); + + populateCapitals(sqlService); + + selectAllCapitals(sqlService); + + selectCapitalNames(sqlService); + } + + private static void createMappingForCapitals(SqlService sqlService) { System.out.println("Creating a mapping..."); - // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps - final String mappingQuery = "" - + "CREATE OR REPLACE MAPPING cities TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.String'," - + " 'valueFormat' = 'java'," - + " 'valueJavaClass' = 'java.lang.String'" - + " )"; - try (SqlResult ignored = client.getSql().execute(mappingQuery)) { + // See: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps + + String mappingQuery = "" + + "CREATE OR REPLACE MAPPING capitals TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'varchar'" + + " )"; + try (SqlResult ignored = sqlService.execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } System.out.println("--------------------"); + } + private static void clearCapitals(SqlService sqlService) { System.out.println("Deleting data via SQL..."); - try (SqlResult ignored = client.getSql().execute("DELETE FROM cities")) { + try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { System.out.println("The data has been deleted successfully."); } System.out.println("--------------------"); - + } + + private static void populateCapitals(SqlService sqlService) { System.out.println("Inserting data via SQL..."); String insertQuery = "" - + "INSERT INTO cities VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; - try (SqlResult ignored = client.getSql().execute(insertQuery)) { + + "INSERT INTO capitals VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = sqlService.execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } System.out.println("--------------------"); + } + private static void selectAllCapitals(SqlService sqlService) { System.out.println("Retrieving all the data via SQL..."); - try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { + try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { for (SqlRow row : result) { String country = row.getObject(0); @@ -117,164 +135,186 @@ private static void sqlExample(HazelcastInstance client) { } } System.out.println("--------------------"); + } - System.out.println("Retrieving a city name via SQL..."); - try (SqlResult result = client.getSql() - .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { + private static void selectCapitalNames(SqlService sqlService) { + System.out.println("Retrieving the capital name via SQL..."); + try (SqlResult result = sqlService + .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { for (SqlRow row : result) { String country = row.getObject("__key"); String city = row.getObject("this"); - System.out.printf("Country name: %s; City name: %s\n", country, city); + System.out.printf("Country name: %s; Capital name: %s\n", country, city); } } System.out.println("--------------------"); - System.exit(0); } /** - * This example shows how to work with Hazelcast SQL queries via Maps that contains - * JSON serialized values. - * - Select single json element data from a Map - * - Select data from Map with filtering - * - Join data from 2 Maps and select json elements + * This example shows how to work with Hazelcast SQL queries via Maps that + * contains JSON serialized values. + * + *

    + *
  • Select single json element data from a Map
  • + *
  • Select data from Map with filtering
  • + *
  • Join data from two Maps and select json elements
  • + *
* * @param client - a {@link HazelcastInstance} client. */ private static void jsonSerializationExample(HazelcastInstance client) { - createMappingForCountries(client); + SqlService sqlService = client.getSql(); + + createMappingForCountries(sqlService); populateCountriesWithMap(client); - selectAllCountries(client); + selectAllCountries(sqlService); - createMappingForCities(client); + createMappingForCities(sqlService); populateCities(client); - selectCitiesByCountry(client, "AU"); - - selectCountriesAndCities(client); + selectCitiesByCountry(sqlService, "AU"); - System.exit(0); + selectCountriesAndCities(sqlService); } - private static void createMappingForCountries(HazelcastInstance client) { - //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + private static void createMappingForCountries(SqlService sqlService) { + //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects System.out.println("Creating mapping for countries..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.String'," - + " 'valueFormat' = 'json-flat'" - + " )"; - - try (SqlResult rs = client.getSql().execute(mappingSql)) { - rs.updateCount(); + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for countries has been created"); } System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map System.out.println("Populating 'countries' map with JSON values..."); IMap countries = client.getMap("country"); - countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); - countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); - countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); - countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("CZ", "Czech Republic"))); + countries.put("AU", Country.asJson("AU", "Australia")); + countries.put("EN", Country.asJson("EN", "England")); + countries.put("US", Country.asJson("US", "United States")); + countries.put("CZ", Country.asJson("CZ", "Czech Republic")); System.out.println("The 'countries' map has been populated."); System.out.println("--------------------"); } - private static void selectAllCountries(HazelcastInstance client) { + private static void selectAllCountries(SqlService sqlService) { String sql = "SELECT c.country from country c"; System.out.println("Select all countries with sql = " + sql); - try (SqlResult result = client.getSql().execute(sql)) { + try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> System.out.println("country = " + row.getObject("country"))); } System.out.println("--------------------"); } - private static void createMappingForCities(HazelcastInstance client) { - //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + private static void createMappingForCities(SqlService sqlService) { + //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects System.out.println("Creating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population BIGINT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.Integer'," - + " 'valueFormat' = 'json-flat'" - + " )"; - - try (SqlResult rs = client.getSql().execute(mappingSql)) { - rs.updateCount(); + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population BIGINT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for cities has been created"); } System.out.println("--------------------"); } private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map System.out.println("Populating 'city' map with JSON values..."); IMap cities = client.getMap("city"); - cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); - cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); - cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); - cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + cities.put(1, City.asJson("AU", "Canberra", 467_194)); + cities.put(2, City.asJson("CZ", "Prague", 1_318_085)); + cities.put(3, City.asJson("EN", "London", 9_540_576)); + cities.put(4, City.asJson("US", "Washington, DC", 7_887_965)); System.out.println("The 'city' map has been populated."); System.out.println("--------------------"); } - private static void selectCitiesByCountry(HazelcastInstance client, String country) { + private static void selectCitiesByCountry(SqlService sqlService, String country) { String sql = "SELECT city, population FROM city where country=?"; System.out.println("--------------------"); System.out.println("Select city and population with sql = " + sql); - try (SqlResult result = client.getSql().execute(sql, country)) { + try (SqlResult result = sqlService.execute(sql, country)) { result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } System.out.println("--------------------"); } - private static void selectCountriesAndCities(HazelcastInstance client) { + private static void selectCountriesAndCities(SqlService sqlService) { String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); - try (SqlResult result = client.getSql().execute(sql)) { + try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> { System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") ); }); } System.out.println("--------------------"); } + /** + * This example shows how to work with Hazelcast maps, where the map is + * updated continuously. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void nonStopMapExample(HazelcastInstance client) { + System.out.println("Now the map named 'map' will be filled with random entries."); + + IMap map = client.getMap("map"); + Random random = new Random(); + int iterationCounter = 0; + while (true) { + int randomKey = random.nextInt(100_000); + map.put("key-" + randomKey, "value-" + randomKey); + map.get("key-" + random.nextInt(100_000)); + if (++iterationCounter == 10) { + iterationCounter = 0; + System.out.println("Current map size: " + map.size()); + } + } + } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 3c14656..470e029 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -5,22 +5,21 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; -import com.hazelcast.cloud.model.CityJsonSerializer; -import com.hazelcast.cloud.model.CountryJsonSerializer; +import com.hazelcast.cloud.model.City; +import com.hazelcast.cloud.model.Country; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; - -import static com.hazelcast.cloud.model.City.newCity; -import static com.hazelcast.cloud.model.Country.newCountry; +import com.hazelcast.sql.SqlService; /** - * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. + * This is boilerplate application that configures client to connect Hazelcast + * Cloud cluster. *

- * See: https://docs.cloud.hazelcast.com/docs/java-client + * See: https://docs.hazelcast.com/cloud/java-client */ public class ClientWithSsl { @@ -30,14 +29,13 @@ public static void main(String[] args) throws Exception { props.setProperty("javax.net.ssl.keyStore", classLoader.getResource("client.keystore").toURI().getPath()); props.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SSL_PASSWORD"); props.setProperty("javax.net.ssl.trustStore", - classLoader.getResource("client.truststore").toURI().getPath()); + classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); - config.getNetworkConfig().setRedoOperation(true); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); @@ -45,13 +43,15 @@ public static void main(String[] args) throws Exception { System.out.println("Connection Successful!"); - // the 'mapExample' is an example with an infinite loop inside, so if you'd like to try other examples, - // don't forget to comment out the following line mapExample(client); //sqlExample(client); //jsonSerializationExample(client); + + //nonStopMapExample(client); + + client.shutdown(); } /** @@ -60,20 +60,20 @@ public static void main(String[] args) throws Exception { * @param client - a {@link HazelcastInstance} client. */ private static void mapExample(HazelcastInstance client) { - System.out.println("Now the map named 'map' will be filled with random entries."); + IMap cities = client.getMap("cities"); + cities.put("1", City.asJson("United Kingdom", "London", 9_540_576)); + cities.put("2", City.asJson("United Kingdom", "Manchester", 2_770_434)); + cities.put("3", City.asJson("United States", "New York", 19_223_191)); + cities.put("4", City.asJson("United States", "Los Angeles", 3_985_520)); + cities.put("5", City.asJson("Turkey", "Ankara", 5_309_690)); + cities.put("6", City.asJson("Turkey", "Istanbul", 15_636_243)); + cities.put("7", City.asJson("Brazil", "Sao Paulo", 22_429_800)); + cities.put("8", City.asJson("Brazil", "Rio de Janeiro", 13_634_274)); + + int mapSize = cities.size(); + System.out.printf("'cities' map now contains %d entries.\n", mapSize); - IMap map = client.getMap("map"); - Random random = new Random(); - int iterationCounter = 0; - while (true) { - int randomKey = random.nextInt(100_000); - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } - } + System.out.println("--------------------"); } /** @@ -82,44 +82,62 @@ private static void mapExample(HazelcastInstance client) { * @param client - a {@link HazelcastInstance} client. */ private static void sqlExample(HazelcastInstance client) { + SqlService sqlService = client.getSql(); + + createMappingForCapitals(sqlService); + + clearCapitals(sqlService); + populateCapitals(sqlService); + + selectAllCapitals(sqlService); + + selectCapitalNames(sqlService); + } + + private static void createMappingForCapitals(SqlService sqlService) { System.out.println("Creating a mapping..."); - // See: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps - final String mappingQuery = "" - + "CREATE OR REPLACE MAPPING cities TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.String'," - + " 'valueFormat' = 'java'," - + " 'valueJavaClass' = 'java.lang.String'" - + " )"; - try (SqlResult ignored = client.getSql().execute(mappingQuery)) { + // See: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps + + String mappingQuery = "" + + "CREATE OR REPLACE MAPPING capitals TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'varchar'" + + " )"; + try (SqlResult ignored = sqlService.execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } System.out.println("--------------------"); + } + private static void clearCapitals(SqlService sqlService) { System.out.println("Deleting data via SQL..."); - try (SqlResult ignored = client.getSql().execute("DELETE FROM cities")) { + try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { System.out.println("The data has been deleted successfully."); } System.out.println("--------------------"); + } + private static void populateCapitals(SqlService sqlService) { System.out.println("Inserting data via SQL..."); String insertQuery = "" - + "INSERT INTO cities VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; - try (SqlResult ignored = client.getSql().execute(insertQuery)) { + + "INSERT INTO capitals VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = sqlService.execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } System.out.println("--------------------"); + } + private static void selectAllCapitals(SqlService sqlService) { System.out.println("Retrieving all the data via SQL..."); - try (SqlResult result = client.getSql().execute("SELECT * FROM cities")) { + try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { for (SqlRow row : result) { String country = row.getObject(0); @@ -128,164 +146,186 @@ private static void sqlExample(HazelcastInstance client) { } } System.out.println("--------------------"); + } - System.out.println("Retrieving a city name via SQL..."); - try (SqlResult result = client.getSql() - .execute("SELECT __key, this FROM cities WHERE __key = ?", "United States")) { + private static void selectCapitalNames(SqlService sqlService) { + System.out.println("Retrieving the capital name via SQL..."); + try (SqlResult result = sqlService + .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { for (SqlRow row : result) { String country = row.getObject("__key"); String city = row.getObject("this"); - System.out.printf("Country name: %s; City name: %s\n", country, city); + System.out.printf("Country name: %s; Capital name: %s\n", country, city); } } System.out.println("--------------------"); - System.exit(0); } /** - * This example shows how to work with Hazelcast SQL queries via Maps that contains - * JSON serialized values. - * - Select single json element data from a Map - * - Select data from Map with filtering - * - Join data from 2 Maps and select json elements + * This example shows how to work with Hazelcast SQL queries via Maps that + * contains JSON serialized values. + * + *

    + *
  • Select single json element data from a Map
  • + *
  • Select data from Map with filtering
  • + *
  • Join data from two Maps and select json elements
  • + *
* * @param client - a {@link HazelcastInstance} client. */ private static void jsonSerializationExample(HazelcastInstance client) { - createMappingForCountries(client); + SqlService sqlService = client.getSql(); + + createMappingForCountries(sqlService); populateCountriesWithMap(client); - selectAllCountries(client); + selectAllCountries(sqlService); - createMappingForCities(client); + createMappingForCities(sqlService); populateCities(client); - selectCitiesByCountry(client, "AU"); - - selectCountriesAndCities(client); + selectCitiesByCountry(sqlService, "AU"); - System.exit(0); + selectCountriesAndCities(sqlService); } - private static void createMappingForCountries(HazelcastInstance client) { - //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + private static void createMappingForCountries(SqlService sqlService) { + //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects System.out.println("Creating mapping for countries..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.String'," - + " 'valueFormat' = 'json-flat'" - + " )"; - - try (SqlResult rs = client.getSql().execute(mappingSql)) { - rs.updateCount(); + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for countries has been created"); } System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map System.out.println("Populating 'countries' map with JSON values..."); IMap countries = client.getMap("country"); - countries.put("AU", CountryJsonSerializer.countryAsJson(newCountry("AU", "Australia"))); - countries.put("EN", CountryJsonSerializer.countryAsJson(newCountry("EN", "England"))); - countries.put("US", CountryJsonSerializer.countryAsJson(newCountry("US", "United States"))); - countries.put("CZ", CountryJsonSerializer.countryAsJson(newCountry("CZ", "Czech Republic"))); + countries.put("AU", Country.asJson("AU", "Australia")); + countries.put("EN", Country.asJson("EN", "England")); + countries.put("US", Country.asJson("US", "United States")); + countries.put("CZ", Country.asJson("CZ", "Czech Republic")); System.out.println("The 'countries' map has been populated."); System.out.println("--------------------"); } - private static void selectAllCountries(HazelcastInstance client) { + private static void selectAllCountries(SqlService sqlService) { String sql = "SELECT c.country from country c"; System.out.println("Select all countries with sql = " + sql); - try (SqlResult result = client.getSql().execute(sql)) { + try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> System.out.println("country = " + row.getObject("country"))); } System.out.println("--------------------"); } - private static void createMappingForCities(HazelcastInstance client) { - //see: https://docs.hazelcast.com/hazelcast/5.0/sql/mapping-to-maps#json-objects + private static void createMappingForCities(SqlService sqlService) { + //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects System.out.println("Creating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population BIGINT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'java'," - + " 'keyJavaClass' = 'java.lang.Integer'," - + " 'valueFormat' = 'json-flat'" - + " )"; - - try (SqlResult rs = client.getSql().execute(mappingSql)) { - rs.updateCount(); + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population BIGINT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'json-flat'" + + " )"; + + try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for cities has been created"); } System.out.println("--------------------"); } private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.0/data-structures/creating-a-map#writing-json-to-a-map + // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map System.out.println("Populating 'city' map with JSON values..."); IMap cities = client.getMap("city"); - cities.put(1, CityJsonSerializer.cityAsJson(newCity("AU", "Canberra", 354644))); - cities.put(2, CityJsonSerializer.cityAsJson(newCity("CZ", "Prague", 1227332))); - cities.put(3, CityJsonSerializer.cityAsJson(newCity("EN", "London", 8174100))); - cities.put(4, CityJsonSerializer.cityAsJson(newCity("US", "Washington, DC", 601723))); + cities.put(1, City.asJson("AU", "Canberra", 467_194)); + cities.put(2, City.asJson("CZ", "Prague", 1_318_085)); + cities.put(3, City.asJson("EN", "London", 9_540_576)); + cities.put(4, City.asJson("US", "Washington, DC", 7_887_965)); System.out.println("The 'city' map has been populated."); System.out.println("--------------------"); } - private static void selectCitiesByCountry(HazelcastInstance client, String country) { + private static void selectCitiesByCountry(SqlService sqlService, String country) { String sql = "SELECT city, population FROM city where country=?"; System.out.println("--------------------"); System.out.println("Select city and population with sql = " + sql); - try (SqlResult result = client.getSql().execute(sql, country)) { + try (SqlResult result = sqlService.execute(sql, country)) { result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } System.out.println("--------------------"); } - private static void selectCountriesAndCities(HazelcastInstance client) { + private static void selectCountriesAndCities(SqlService sqlService) { String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); - try (SqlResult result = client.getSql().execute(sql)) { + try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> { System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") ); }); } System.out.println("--------------------"); } + /** + * This example shows how to work with Hazelcast maps, where the map is + * updated continuously. + * + * @param client - a {@link HazelcastInstance} client. + */ + private static void nonStopMapExample(HazelcastInstance client) { + System.out.println("Now the map named 'map' will be filled with random entries."); + + IMap map = client.getMap("map"); + Random random = new Random(); + int iterationCounter = 0; + while (true) { + int randomKey = random.nextInt(100_000); + map.put("key-" + randomKey, "value-" + randomKey); + map.get("key-" + random.nextInt(100_000)); + if (++iterationCounter == 10) { + iterationCounter = 0; + System.out.println("Current map size: " + map.size()); + } + } + } } diff --git a/src/main/java/com/hazelcast/cloud/model/City.java b/src/main/java/com/hazelcast/cloud/model/City.java index e47f13f..7b18e51 100644 --- a/src/main/java/com/hazelcast/cloud/model/City.java +++ b/src/main/java/com/hazelcast/cloud/model/City.java @@ -1,41 +1,14 @@ package com.hazelcast.cloud.model; -public class City { +import com.hazelcast.core.HazelcastJsonValue; +import com.hazelcast.org.json.JSONObject; - private String country; - private String city; - private int population; - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; +public final class City { + public static HazelcastJsonValue asJson(String country, String city, int population) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("country", country); + jsonObject.put("city", city); + jsonObject.put("population", population); + return new HazelcastJsonValue(jsonObject.toString()); } - - public int getPopulation() { - return population; - } - - public void setPopulation(int population) { - this.population = population; - } - - public static City newCity(String country, String cityName, int population) { - City city = new City(); - city.country = country; - city.city = cityName; - city.population = population; - return city; - } - } diff --git a/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java b/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java deleted file mode 100644 index 5c571ac..0000000 --- a/src/main/java/com/hazelcast/cloud/model/CityJsonSerializer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hazelcast.cloud.model; - -import com.hazelcast.core.HazelcastJsonValue; -import com.hazelcast.org.json.JSONObject; - -public class CityJsonSerializer { - - public static HazelcastJsonValue cityAsJson(City city) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("country", city.getCountry()); - jsonObject.put("city", city.getCity()); - jsonObject.put("population", city.getPopulation()); - return new HazelcastJsonValue(jsonObject.toString()); - } - -} diff --git a/src/main/java/com/hazelcast/cloud/model/Country.java b/src/main/java/com/hazelcast/cloud/model/Country.java index 2840530..469bc85 100644 --- a/src/main/java/com/hazelcast/cloud/model/Country.java +++ b/src/main/java/com/hazelcast/cloud/model/Country.java @@ -1,30 +1,13 @@ package com.hazelcast.cloud.model; -public class Country { - - private String isoCode; - private String country; - - public String getIsoCode() { - return isoCode; - } - - public void setIsoCode(String isoCode) { - this.isoCode = isoCode; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public static Country newCountry(String isoCode, String countryName) { - Country country = new Country(); - country.isoCode = isoCode; - country.country = countryName; - return country; +import com.hazelcast.core.HazelcastJsonValue; +import com.hazelcast.org.json.JSONObject; + +public final class Country { + public static HazelcastJsonValue asJson(String isoCode, String country) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("isoCode", isoCode); + jsonObject.put("country", country); + return new HazelcastJsonValue(jsonObject.toString()); } } diff --git a/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java b/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java deleted file mode 100644 index bc7915d..0000000 --- a/src/main/java/com/hazelcast/cloud/model/CountryJsonSerializer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hazelcast.cloud.model; - -import com.hazelcast.core.HazelcastJsonValue; -import com.hazelcast.org.json.JSONObject; - -public class CountryJsonSerializer { - - public static HazelcastJsonValue countryAsJson(Country country) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("isoCode", country.getIsoCode()); - jsonObject.put("country", country.getCountry()); - return new HazelcastJsonValue(jsonObject.toString()); - } - -} From 8b945c84c8cc990a2c1195b6404ffdfc0aca6258 Mon Sep 17 00:00:00 2001 From: Metin Dumandag Date: Wed, 27 Jul 2022 14:41:46 +0300 Subject: [PATCH 20/46] Terminate the JVM after the code sample (#37) It seems that the exec plugin has some problems cleaning up the daemon threads. Adding an explicit exit at the end of the code samples solves this problem. The former code was producing an error like below when run with mvn. ``` [WARNING] thread Thread[ForkJoinPool.commonPool-worker-3,5,com.hazelcast.cloud.ClientWithSsl] was interrupted but is still alive after waiting at least 15000msecs [WARNING] thread Thread[ForkJoinPool.commonPool-worker-3,5,com.hazelcast.cloud.ClientWithSsl] will linger despite being asked to die via interruption [WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied. ``` --- src/main/java/com/hazelcast/cloud/Client.java | 2 ++ src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index faeacc1..92c54eb 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -41,6 +41,8 @@ public static void main(String[] args) { //nonStopMapExample(client); client.shutdown(); + + System.exit(0); } /** diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 470e029..fc7fa29 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -52,6 +52,8 @@ public static void main(String[] args) throws Exception { //nonStopMapExample(client); client.shutdown(); + + System.exit(0); } /** From bf10f08370321fd4e53bdb248bde05bd546bead0 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 11 Aug 2022 13:08:14 +0200 Subject: [PATCH 21/46] Use hazelcast-cloud-maven-plugin (#36) --- pom.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pom.xml b/pom.xml index 12e98b7..52365f6 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,17 @@ + + com.hazelcast.cloud + hazelcast-cloud-maven-plugin + 0.0.1 + + YOUR_DISCOVERY_URL + YOUR_CLUSTER_NAME + + + + org.apache.maven.plugins maven-compiler-plugin From 97b21657b6b7af14e26278fae6d0d540b53c58ab Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 2 Sep 2022 20:34:27 +0200 Subject: [PATCH 22/46] Use hazelcast-cloud-maven-plugin:0.0.2 (#39) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 52365f6..1e43fe0 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ com.hazelcast.cloud hazelcast-cloud-maven-plugin - 0.0.1 + 0.0.2 YOUR_DISCOVERY_URL YOUR_CLUSTER_NAME From 05a8b10e3aa1ee2c1b5ba4ce9da77a46ec3b52e1 Mon Sep 17 00:00:00 2001 From: Sergey Shakhov Date: Mon, 10 Oct 2022 14:26:20 +0200 Subject: [PATCH 23/46] HZC-3384: Update samples with compact serialization (#40) --- pom.xml | 16 +- src/main/java/com/hazelcast/cloud/Client.java | 167 ++++++++++-------- .../com/hazelcast/cloud/ClientWithSsl.java | 165 +++++++++-------- .../java/com/hazelcast/cloud/model/City.java | 18 +- .../com/hazelcast/cloud/model/Country.java | 15 +- 5 files changed, 212 insertions(+), 169 deletions(-) diff --git a/pom.xml b/pom.xml index 1e43fe0..9540e8f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,13 @@ com.hazelcast hazelcast-enterprise - 5.1 + 5.2-BETA-1 + + + org.projectlombok + lombok + 1.18.24 + true @@ -32,9 +38,17 @@ org.apache.maven.plugins maven-compiler-plugin + 3.10.1 1.8 1.8 + + + org.projectlombok + lombok + 1.18.24 + + diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 92c54eb..541a75e 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -1,18 +1,17 @@ package com.hazelcast.cloud; +import java.util.Random; + import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; import com.hazelcast.cloud.model.City; import com.hazelcast.cloud.model.Country; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import com.hazelcast.sql.SqlService; -import java.util.Random; - /** * This is boilerplate application that configures client to connect Hazelcast * Cloud cluster. @@ -24,8 +23,8 @@ public class Client { public static void main(String[] args) { ClientConfig config = new ClientConfig(); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); @@ -36,7 +35,7 @@ public static void main(String[] args) { //sqlExample(client); - //jsonSerializationExample(client); + //compactSerializationExample(client); //nonStopMapExample(client); @@ -51,15 +50,15 @@ public static void main(String[] args) { * @param client - a {@link HazelcastInstance} client. */ private static void mapExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - cities.put("1", City.asJson("United Kingdom", "London", 9_540_576)); - cities.put("2", City.asJson("United Kingdom", "Manchester", 2_770_434)); - cities.put("3", City.asJson("United States", "New York", 19_223_191)); - cities.put("4", City.asJson("United States", "Los Angeles", 3_985_520)); - cities.put("5", City.asJson("Turkey", "Ankara", 5_309_690)); - cities.put("6", City.asJson("Turkey", "Istanbul", 15_636_243)); - cities.put("7", City.asJson("Brazil", "Sao Paulo", 22_429_800)); - cities.put("8", City.asJson("Brazil", "Rio de Janeiro", 13_634_274)); + IMap cities = client.getMap("cities"); + cities.put("1", new City("United Kingdom", "London", 9_540_576)); + cities.put("2", new City("United Kingdom", "Manchester", 2_770_434)); + cities.put("3", new City("United States", "New York", 19_223_191)); + cities.put("4", new City("United States", "Los Angeles", 3_985_520)); + cities.put("5", new City("Turkey", "Ankara", 5_309_690)); + cities.put("6", new City("Turkey", "Istanbul", 15_636_243)); + cities.put("7", new City("Brazil", "Sao Paulo", 22_429_800)); + cities.put("8", new City("Brazil", "Rio de Janeiro", 13_634_274)); int mapSize = cities.size(); System.out.printf("'cities' map now contains %d entries.\n", mapSize); @@ -87,47 +86,54 @@ private static void sqlExample(HazelcastInstance client) { } private static void createMappingForCapitals(SqlService sqlService) { + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#creating-a-mapping-to-a-map System.out.println("Creating a mapping..."); - // See: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps String mappingQuery = "" - + "CREATE OR REPLACE MAPPING capitals TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'varchar'" - + " )"; + + "CREATE OR REPLACE MAPPING capitals TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'varchar'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); } private static void clearCapitals(SqlService sqlService) { System.out.println("Deleting data via SQL..."); + try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { System.out.println("The data has been deleted successfully."); } + System.out.println("--------------------"); } private static void populateCapitals(SqlService sqlService) { System.out.println("Inserting data via SQL..."); + String insertQuery = "" - + "INSERT INTO capitals VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; + + "INSERT INTO capitals VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = sqlService.execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } + System.out.println("--------------------"); } private static void selectAllCapitals(SqlService sqlService) { System.out.println("Retrieving all the data via SQL..."); + try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { for (SqlRow row : result) { @@ -136,13 +142,15 @@ private static void selectAllCapitals(SqlService sqlService) { System.out.printf("%s - %s\n", country, city); } } + System.out.println("--------------------"); } private static void selectCapitalNames(SqlService sqlService) { System.out.println("Retrieving the capital name via SQL..."); + try (SqlResult result = sqlService - .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { + .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { for (SqlRow row : result) { String country = row.getObject("__key"); @@ -150,22 +158,23 @@ private static void selectCapitalNames(SqlService sqlService) { System.out.printf("Country name: %s; Capital name: %s\n", country, city); } } + System.out.println("--------------------"); } /** * This example shows how to work with Hazelcast SQL queries via Maps that - * contains JSON serialized values. + * contains compact serialized values. * *
    - *
  • Select single json element data from a Map
  • + *
  • Select single element from a Map
  • *
  • Select data from Map with filtering
  • - *
  • Join data from two Maps and select json elements
  • + *
  • Join data from two Maps
  • *
* * @param client - a {@link HazelcastInstance} client. */ - private static void jsonSerializationExample(HazelcastInstance client) { + private static void compactSerializationExample(HazelcastInstance client) { SqlService sqlService = client.getSql(); createMappingForCountries(sqlService); @@ -184,35 +193,37 @@ private static void jsonSerializationExample(HazelcastInstance client) { } private static void createMappingForCountries(SqlService sqlService) { - //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects System.out.println("Creating mapping for countries..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'json-flat'" - + " )"; + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'country'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for countries has been created"); } + System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populating 'countries' map with JSON values..."); + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map + System.out.println("Populating 'countries' map..."); - IMap countries = client.getMap("country"); - countries.put("AU", Country.asJson("AU", "Australia")); - countries.put("EN", Country.asJson("EN", "England")); - countries.put("US", Country.asJson("US", "United States")); - countries.put("CZ", Country.asJson("CZ", "Czech Republic")); + IMap countries = client.getMap("country"); + countries.put("AU", new Country("AU", "Australia")); + countries.put("EN", new Country("EN", "England")); + countries.put("US", new Country("US", "United States")); + countries.put("CZ", new Country("CZ", "Czech Republic")); System.out.println("The 'countries' map has been populated."); System.out.println("--------------------"); @@ -228,20 +239,21 @@ private static void selectAllCountries(SqlService sqlService) { } private static void createMappingForCities(SqlService sqlService) { - //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects System.out.println("Creating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population BIGINT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'int'," - + " 'valueFormat' = 'json-flat'" - + " )"; + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population INT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'city'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for cities has been created"); @@ -250,14 +262,14 @@ private static void createMappingForCities(SqlService sqlService) { } private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populating 'city' map with JSON values..."); + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map + System.out.println("Populating 'city' map"); - IMap cities = client.getMap("city"); - cities.put(1, City.asJson("AU", "Canberra", 467_194)); - cities.put(2, City.asJson("CZ", "Prague", 1_318_085)); - cities.put(3, City.asJson("EN", "London", 9_540_576)); - cities.put(4, City.asJson("US", "Washington, DC", 7_887_965)); + IMap cities = client.getMap("city"); + cities.put(1, new City("AU", "Canberra", 467_194)); + cities.put(2, new City("CZ", "Prague", 1_318_085)); + cities.put(3, new City("EN", "London", 9_540_576)); + cities.put(4, new City("US", "Washington, DC", 7_887_965)); System.out.println("The 'city' map has been populated."); System.out.println("--------------------"); @@ -266,20 +278,22 @@ private static void populateCities(HazelcastInstance client) { private static void selectCitiesByCountry(SqlService sqlService, String country) { String sql = "SELECT city, population FROM city where country=?"; System.out.println("--------------------"); + System.out.println("Select city and population with sql = " + sql); try (SqlResult result = sqlService.execute(sql, country)) { result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } + System.out.println("--------------------"); } private static void selectCountriesAndCities(SqlService sqlService) { String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); @@ -287,13 +301,14 @@ private static void selectCountriesAndCities(SqlService sqlService) { try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> { System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") ); }); } + System.out.println("--------------------"); } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index fc7fa29..66a52d2 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -9,7 +9,6 @@ import com.hazelcast.cloud.model.Country; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.HazelcastJsonValue; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; @@ -29,13 +28,13 @@ public static void main(String[] args) throws Exception { props.setProperty("javax.net.ssl.keyStore", classLoader.getResource("client.keystore").toURI().getPath()); props.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SSL_PASSWORD"); props.setProperty("javax.net.ssl.trustStore", - classLoader.getResource("client.truststore").toURI().getPath()); + classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); @@ -47,7 +46,7 @@ public static void main(String[] args) throws Exception { //sqlExample(client); - //jsonSerializationExample(client); + //compactSerializationExample(client); //nonStopMapExample(client); @@ -62,15 +61,15 @@ public static void main(String[] args) throws Exception { * @param client - a {@link HazelcastInstance} client. */ private static void mapExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - cities.put("1", City.asJson("United Kingdom", "London", 9_540_576)); - cities.put("2", City.asJson("United Kingdom", "Manchester", 2_770_434)); - cities.put("3", City.asJson("United States", "New York", 19_223_191)); - cities.put("4", City.asJson("United States", "Los Angeles", 3_985_520)); - cities.put("5", City.asJson("Turkey", "Ankara", 5_309_690)); - cities.put("6", City.asJson("Turkey", "Istanbul", 15_636_243)); - cities.put("7", City.asJson("Brazil", "Sao Paulo", 22_429_800)); - cities.put("8", City.asJson("Brazil", "Rio de Janeiro", 13_634_274)); + IMap cities = client.getMap("cities"); + cities.put("1", new City("United Kingdom", "London", 9_540_576)); + cities.put("2", new City("United Kingdom", "Manchester", 2_770_434)); + cities.put("3", new City("United States", "New York", 19_223_191)); + cities.put("4", new City("United States", "Los Angeles", 3_985_520)); + cities.put("5", new City("Turkey", "Ankara", 5_309_690)); + cities.put("6", new City("Turkey", "Istanbul", 15_636_243)); + cities.put("7", new City("Brazil", "Sao Paulo", 22_429_800)); + cities.put("8", new City("Brazil", "Rio de Janeiro", 13_634_274)); int mapSize = cities.size(); System.out.printf("'cities' map now contains %d entries.\n", mapSize); @@ -98,47 +97,54 @@ private static void sqlExample(HazelcastInstance client) { } private static void createMappingForCapitals(SqlService sqlService) { + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#creating-a-mapping-to-a-map System.out.println("Creating a mapping..."); - // See: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps String mappingQuery = "" - + "CREATE OR REPLACE MAPPING capitals TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'varchar'" - + " )"; + + "CREATE OR REPLACE MAPPING capitals TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'varchar'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingQuery)) { System.out.println("The mapping has been created successfully."); } + System.out.println("--------------------"); } private static void clearCapitals(SqlService sqlService) { System.out.println("Deleting data via SQL..."); + try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { System.out.println("The data has been deleted successfully."); } + System.out.println("--------------------"); } private static void populateCapitals(SqlService sqlService) { System.out.println("Inserting data via SQL..."); + String insertQuery = "" - + "INSERT INTO capitals VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; + + "INSERT INTO capitals VALUES" + + "('Australia','Canberra')," + + "('Croatia','Zagreb')," + + "('Czech Republic','Prague')," + + "('England','London')," + + "('Turkey','Ankara')," + + "('United States','Washington, DC');"; + try (SqlResult ignored = sqlService.execute(insertQuery)) { System.out.println("The data has been inserted successfully."); } + System.out.println("--------------------"); } private static void selectAllCapitals(SqlService sqlService) { System.out.println("Retrieving all the data via SQL..."); + try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { for (SqlRow row : result) { @@ -147,13 +153,15 @@ private static void selectAllCapitals(SqlService sqlService) { System.out.printf("%s - %s\n", country, city); } } + System.out.println("--------------------"); } private static void selectCapitalNames(SqlService sqlService) { System.out.println("Retrieving the capital name via SQL..."); + try (SqlResult result = sqlService - .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { + .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { for (SqlRow row : result) { String country = row.getObject("__key"); @@ -161,22 +169,23 @@ private static void selectCapitalNames(SqlService sqlService) { System.out.printf("Country name: %s; Capital name: %s\n", country, city); } } + System.out.println("--------------------"); } /** * This example shows how to work with Hazelcast SQL queries via Maps that - * contains JSON serialized values. + * contains compact serialized values. * *
    - *
  • Select single json element data from a Map
  • + *
  • Select single element from a Map
  • *
  • Select data from Map with filtering
  • - *
  • Join data from two Maps and select json elements
  • + *
  • Join data from two Maps
  • *
* * @param client - a {@link HazelcastInstance} client. */ - private static void jsonSerializationExample(HazelcastInstance client) { + private static void compactSerializationExample(HazelcastInstance client) { SqlService sqlService = client.getSql(); createMappingForCountries(sqlService); @@ -195,35 +204,37 @@ private static void jsonSerializationExample(HazelcastInstance client) { } private static void createMappingForCountries(SqlService sqlService) { - //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects System.out.println("Creating mapping for countries..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'json-flat'" - + " )"; + + "CREATE OR REPLACE MAPPING country(" + + " __key VARCHAR," + + " isoCode VARCHAR," + + " country VARCHAR" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'varchar'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'country'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for countries has been created"); } + System.out.println("--------------------"); } private static void populateCountriesWithMap(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populating 'countries' map with JSON values..."); + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map + System.out.println("Populating 'countries' map..."); - IMap countries = client.getMap("country"); - countries.put("AU", Country.asJson("AU", "Australia")); - countries.put("EN", Country.asJson("EN", "England")); - countries.put("US", Country.asJson("US", "United States")); - countries.put("CZ", Country.asJson("CZ", "Czech Republic")); + IMap countries = client.getMap("country"); + countries.put("AU", new Country("AU", "Australia")); + countries.put("EN", new Country("EN", "England")); + countries.put("US", new Country("US", "United States")); + countries.put("CZ", new Country("CZ", "Czech Republic")); System.out.println("The 'countries' map has been populated."); System.out.println("--------------------"); @@ -239,20 +250,21 @@ private static void selectAllCountries(SqlService sqlService) { } private static void createMappingForCities(SqlService sqlService) { - //see: https://docs.hazelcast.com/hazelcast/5.1/sql/mapping-to-maps#json-objects + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects System.out.println("Creating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population BIGINT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'int'," - + " 'valueFormat' = 'json-flat'" - + " )"; + + "CREATE OR REPLACE MAPPING city(" + + " __key INT ," + + " country VARCHAR ," + + " city VARCHAR," + + " population INT)" + + " TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'city'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { System.out.println("Mapping for cities has been created"); @@ -261,14 +273,14 @@ private static void createMappingForCities(SqlService sqlService) { } private static void populateCities(HazelcastInstance client) { - // see: https://docs.hazelcast.com/hazelcast/5.1/data-structures/creating-a-map#writing-json-to-a-map - System.out.println("Populating 'city' map with JSON values..."); + // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map + System.out.println("Populating 'city' map"); - IMap cities = client.getMap("city"); - cities.put(1, City.asJson("AU", "Canberra", 467_194)); - cities.put(2, City.asJson("CZ", "Prague", 1_318_085)); - cities.put(3, City.asJson("EN", "London", 9_540_576)); - cities.put(4, City.asJson("US", "Washington, DC", 7_887_965)); + IMap cities = client.getMap("city"); + cities.put(1, new City("AU", "Canberra", 467_194)); + cities.put(2, new City("CZ", "Prague", 1_318_085)); + cities.put(3, new City("EN", "London", 9_540_576)); + cities.put(4, new City("US", "Washington, DC", 7_887_965)); System.out.println("The 'city' map has been populated."); System.out.println("--------------------"); @@ -277,20 +289,22 @@ private static void populateCities(HazelcastInstance client) { private static void selectCitiesByCountry(SqlService sqlService, String country) { String sql = "SELECT city, population FROM city where country=?"; System.out.println("--------------------"); + System.out.println("Select city and population with sql = " + sql); try (SqlResult result = sqlService.execute(sql, country)) { result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) + System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) ); } + System.out.println("--------------------"); } private static void selectCountriesAndCities(SqlService sqlService) { String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + + "SELECT c.isoCode, c.country, t.city, t.population" + + " FROM country c" + + " JOIN city t ON c.isoCode = t.country"; System.out.println("Select country and city data in query that joins tables"); System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); @@ -298,13 +312,14 @@ private static void selectCountriesAndCities(SqlService sqlService) { try (SqlResult result = sqlService.execute(sql)) { result.forEach(row -> { System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + row.getObject("isoCode"), + row.getObject("country"), + row.getObject("city"), + row.getObject("population") ); }); } + System.out.println("--------------------"); } diff --git a/src/main/java/com/hazelcast/cloud/model/City.java b/src/main/java/com/hazelcast/cloud/model/City.java index 7b18e51..d64ee13 100644 --- a/src/main/java/com/hazelcast/cloud/model/City.java +++ b/src/main/java/com/hazelcast/cloud/model/City.java @@ -1,14 +1,14 @@ package com.hazelcast.cloud.model; -import com.hazelcast.core.HazelcastJsonValue; -import com.hazelcast.org.json.JSONObject; +import lombok.AllArgsConstructor; +import lombok.Data; +@Data +@AllArgsConstructor public final class City { - public static HazelcastJsonValue asJson(String country, String city, int population) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("country", country); - jsonObject.put("city", city); - jsonObject.put("population", population); - return new HazelcastJsonValue(jsonObject.toString()); - } + private String country; + + private String city; + + private int population; } diff --git a/src/main/java/com/hazelcast/cloud/model/Country.java b/src/main/java/com/hazelcast/cloud/model/Country.java index 469bc85..b0371d5 100644 --- a/src/main/java/com/hazelcast/cloud/model/Country.java +++ b/src/main/java/com/hazelcast/cloud/model/Country.java @@ -1,13 +1,12 @@ package com.hazelcast.cloud.model; -import com.hazelcast.core.HazelcastJsonValue; -import com.hazelcast.org.json.JSONObject; +import lombok.AllArgsConstructor; +import lombok.Data; +@Data +@AllArgsConstructor public final class Country { - public static HazelcastJsonValue asJson(String isoCode, String country) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("isoCode", isoCode); - jsonObject.put("country", country); - return new HazelcastJsonValue(jsonObject.toString()); - } + private String isoCode; + + private String country; } From 6fb295c21d3667ae09d612de2b7a8bc29788ce96 Mon Sep 17 00:00:00 2001 From: Sergey Shakhov Date: Wed, 9 Nov 2022 10:46:39 +0100 Subject: [PATCH 24/46] 5.2 Jet job example (#42) --- src/main/java/com/hazelcast/cloud/Client.java | 36 +++++++++++++++++++ .../com/hazelcast/cloud/ClientWithSsl.java | 36 +++++++++++++++++++ .../cloud/jobs/UpperCaseFunction.java | 10 ++++++ 3 files changed, 82 insertions(+) create mode 100644 src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 541a75e..af871cd 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -4,9 +4,15 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.cloud.jobs.UpperCaseFunction; import com.hazelcast.cloud.model.City; import com.hazelcast.cloud.model.Country; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.jet.config.JobConfig; +import com.hazelcast.jet.pipeline.BatchSource; +import com.hazelcast.jet.pipeline.Pipeline; +import com.hazelcast.jet.pipeline.Sinks; +import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; @@ -39,6 +45,8 @@ public static void main(String[] args) { //nonStopMapExample(client); + //jetJobExample(client); + client.shutdown(); System.exit(0); @@ -334,4 +342,32 @@ private static void nonStopMapExample(HazelcastInstance client) { } } } + + /** + * This example shows how to submit simple Jet job which uses logger as a sink. + * You will be able to see the results of job execution in the Hazelcast cluster logs. + * + * @param client- a {@link HazelcastInstance} client. + */ + private static void jetJobExample(HazelcastInstance client) { + // See: https://docs.hazelcast.com/hazelcast/5.2/pipelines/submitting-jobs + System.out.println("Submitting Jet job"); + + BatchSource items = TestSources.items( + "United States", "Turkey", "United Kingdom", "Poland", "Ukraine" + ); + + Pipeline pipeline = Pipeline.create() + .readFrom(items) + .map(new UpperCaseFunction()) + .writeTo(Sinks.logger()) + .getPipeline(); + + JobConfig jobConfig = new JobConfig() + .addClass(UpperCaseFunction.class); + + client.getJet().newJob(pipeline, jobConfig); + + System.out.println("Jet job submitted"); + } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 66a52d2..11937bd 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -5,10 +5,16 @@ import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; +import com.hazelcast.cloud.jobs.UpperCaseFunction; import com.hazelcast.cloud.model.City; import com.hazelcast.cloud.model.Country; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.jet.config.JobConfig; +import com.hazelcast.jet.pipeline.BatchSource; +import com.hazelcast.jet.pipeline.Pipeline; +import com.hazelcast.jet.pipeline.Sinks; +import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; @@ -50,6 +56,8 @@ public static void main(String[] args) throws Exception { //nonStopMapExample(client); + //jetJobExample(client); + client.shutdown(); System.exit(0); @@ -345,4 +353,32 @@ private static void nonStopMapExample(HazelcastInstance client) { } } } + + /** + * This example shows how to submit simple Jet job which uses logger as a sink. + * You will be able to see the results of job execution in the Hazelcast cluster logs. + * + * @param client- a {@link HazelcastInstance} client. + */ + private static void jetJobExample(HazelcastInstance client) { + // See: https://docs.hazelcast.com/hazelcast/5.2/pipelines/submitting-jobs + System.out.println("Submitting Jet job"); + + BatchSource items = TestSources.items( + "United States", "Turkey", "United Kingdom", "Poland", "Ukraine" + ); + + Pipeline pipeline = Pipeline.create() + .readFrom(items) + .map(new UpperCaseFunction()) + .writeTo(Sinks.logger()) + .getPipeline(); + + JobConfig jobConfig = new JobConfig() + .addClass(UpperCaseFunction.class); + + client.getJet().newJob(pipeline, jobConfig); + + System.out.println("Jet job submitted"); + } } diff --git a/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java b/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java new file mode 100644 index 0000000..c856f91 --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java @@ -0,0 +1,10 @@ +package com.hazelcast.cloud.jobs; + +import com.hazelcast.function.FunctionEx; + +public class UpperCaseFunction implements FunctionEx { + @Override + public String applyEx(String s) { + return s.toUpperCase(); + } +} From ad1253ea8f859472c9486196f60afeabd50a89f9 Mon Sep 17 00:00:00 2001 From: sergeyshakhov Date: Wed, 9 Nov 2022 10:56:37 +0100 Subject: [PATCH 25/46] Update hazelcast-enterprise version to 5.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9540e8f..726fd4e 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.2-BETA-1 + 5.2.0 org.projectlombok From 849362edde925459bc34e23d532067fbaae198b0 Mon Sep 17 00:00:00 2001 From: sergeyshakhov Date: Wed, 30 Nov 2022 17:40:29 +0100 Subject: [PATCH 26/46] Update hazelcast-cloud-maven-plugin version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 726fd4e..805258e 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ com.hazelcast.cloud hazelcast-cloud-maven-plugin - 0.0.2 + 0.0.5 YOUR_DISCOVERY_URL YOUR_CLUSTER_NAME From d11b95d8146b471d2e9ca99633fbaaaf298719b0 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Thu, 12 Jan 2023 15:00:15 +0200 Subject: [PATCH 27/46] HZC-3930: add Catch and finally blocks (#44) --- src/main/java/com/hazelcast/cloud/Client.java | 37 ++++++++++--------- .../com/hazelcast/cloud/ClientWithSsl.java | 35 ++++++++++-------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index af871cd..5a33b45 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -19,8 +19,7 @@ import com.hazelcast.sql.SqlService; /** - * This is boilerplate application that configures client to connect Hazelcast - * Cloud cluster. + * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. *

* See: https://docs.hazelcast.com/cloud/java-client */ @@ -34,22 +33,25 @@ public static void main(String[] args) { config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); - System.out.println("Connection Successful!"); + try { + mapExample(client); - mapExample(client); - - //sqlExample(client); + //sqlExample(client); - //compactSerializationExample(client); + //compactSerializationExample(client); - //nonStopMapExample(client); + //nonStopMapExample(client); - //jetJobExample(client); + //jetJobExample(client); - client.shutdown(); - - System.exit(0); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + client.shutdown(); + } } /** @@ -171,8 +173,7 @@ private static void selectCapitalNames(SqlService sqlService) { } /** - * This example shows how to work with Hazelcast SQL queries via Maps that - * contains compact serialized values. + * This example shows how to work with Hazelcast SQL queries via Maps that contains compact serialized values. * *

    *
  • Select single element from a Map
  • @@ -321,8 +322,7 @@ private static void selectCountriesAndCities(SqlService sqlService) { } /** - * This example shows how to work with Hazelcast maps, where the map is - * updated continuously. + * This example shows how to work with Hazelcast maps, where the map is updated continuously. * * @param client - a {@link HazelcastInstance} client. */ @@ -344,8 +344,8 @@ private static void nonStopMapExample(HazelcastInstance client) { } /** - * This example shows how to submit simple Jet job which uses logger as a sink. - * You will be able to see the results of job execution in the Hazelcast cluster logs. + * This example shows how to submit simple Jet job which uses logger as a sink. You will be able to see the results + * of job execution in the Hazelcast cluster logs. * * @param client- a {@link HazelcastInstance} client. */ @@ -370,4 +370,5 @@ private static void jetJobExample(HazelcastInstance client) { System.out.println("Jet job submitted"); } + } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 11937bd..f2251d6 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -21,8 +21,7 @@ import com.hazelcast.sql.SqlService; /** - * This is boilerplate application that configures client to connect Hazelcast - * Cloud cluster. + * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. *

    * See: https://docs.hazelcast.com/cloud/java-client */ @@ -45,22 +44,27 @@ public static void main(String[] args) throws Exception { config.setClusterName("YOUR_CLUSTER_NAME"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); - System.out.println("Connection Successful!"); - mapExample(client); + try { - //sqlExample(client); + mapExample(client); - //compactSerializationExample(client); + //sqlExample(client); - //nonStopMapExample(client); + //compactSerializationExample(client); - //jetJobExample(client); + //nonStopMapExample(client); - client.shutdown(); + //jetJobExample(client); - System.exit(0); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + client.shutdown(); + } } /** @@ -182,8 +186,7 @@ private static void selectCapitalNames(SqlService sqlService) { } /** - * This example shows how to work with Hazelcast SQL queries via Maps that - * contains compact serialized values. + * This example shows how to work with Hazelcast SQL queries via Maps that contains compact serialized values. * *

      *
    • Select single element from a Map
    • @@ -332,8 +335,7 @@ private static void selectCountriesAndCities(SqlService sqlService) { } /** - * This example shows how to work with Hazelcast maps, where the map is - * updated continuously. + * This example shows how to work with Hazelcast maps, where the map is updated continuously. * * @param client - a {@link HazelcastInstance} client. */ @@ -355,8 +357,8 @@ private static void nonStopMapExample(HazelcastInstance client) { } /** - * This example shows how to submit simple Jet job which uses logger as a sink. - * You will be able to see the results of job execution in the Hazelcast cluster logs. + * This example shows how to submit simple Jet job which uses logger as a sink. You will be able to see the results + * of job execution in the Hazelcast cluster logs. * * @param client- a {@link HazelcastInstance} client. */ @@ -381,4 +383,5 @@ private static void jetJobExample(HazelcastInstance client) { System.out.println("Jet job submitted"); } + } From a5154b1ddf5424bc05eaa41c2b02d7f1b899fe47 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Thu, 12 Jan 2023 15:06:06 +0200 Subject: [PATCH 28/46] add catch block --- src/main/java/com/hazelcast/cloud/Client.java | 11 +++++++++-- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 5a33b45..58dd24d 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -14,6 +14,7 @@ import com.hazelcast.jet.pipeline.Sinks; import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; +import com.hazelcast.spi.exception.TargetDisconnectedException; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import com.hazelcast.sql.SqlService; @@ -334,8 +335,14 @@ private static void nonStopMapExample(HazelcastInstance client) { int iterationCounter = 0; while (true) { int randomKey = random.nextInt(100_000); - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); + try { + map.put("key-" + randomKey, "value-" + randomKey); + map.get("key-" + random.nextInt(100_000)); + } + catch (IllegalStateException | TargetDisconnectedException ex) { + //rolling update (cluster can be in passive state) e.g. update custom classes + ex.printStackTrace(); + } if (++iterationCounter == 10) { iterationCounter = 0; System.out.println("Current map size: " + map.size()); diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index f2251d6..f708ce9 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -16,6 +16,7 @@ import com.hazelcast.jet.pipeline.Sinks; import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; +import com.hazelcast.spi.exception.TargetDisconnectedException; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import com.hazelcast.sql.SqlService; @@ -347,8 +348,14 @@ private static void nonStopMapExample(HazelcastInstance client) { int iterationCounter = 0; while (true) { int randomKey = random.nextInt(100_000); - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); + try { + map.put("key-" + randomKey, "value-" + randomKey); + map.get("key-" + random.nextInt(100_000)); + } + catch (IllegalStateException | TargetDisconnectedException ex) { + //rolling update (cluster can be in passive state) e.g. update custom classes + ex.printStackTrace(); + } if (++iterationCounter == 10) { iterationCounter = 0; System.out.println("Current map size: " + map.size()); From 6341dbabed50028606522cc46e27800ed4f18ef7 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Fri, 13 Jan 2023 13:45:38 +0200 Subject: [PATCH 29/46] fix example --- src/main/java/com/hazelcast/cloud/Client.java | 8 ++++---- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 58dd24d..c643e07 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -338,15 +338,15 @@ private static void nonStopMapExample(HazelcastInstance client) { try { map.put("key-" + randomKey, "value-" + randomKey); map.get("key-" + random.nextInt(100_000)); + if (++iterationCounter == 10) { + iterationCounter = 0; + System.out.println("Current map size: " + map.size()); + } } catch (IllegalStateException | TargetDisconnectedException ex) { //rolling update (cluster can be in passive state) e.g. update custom classes ex.printStackTrace(); } - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index f708ce9..8b9f9c5 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -351,15 +351,15 @@ private static void nonStopMapExample(HazelcastInstance client) { try { map.put("key-" + randomKey, "value-" + randomKey); map.get("key-" + random.nextInt(100_000)); + if (++iterationCounter == 10) { + iterationCounter = 0; + System.out.println("Current map size: " + map.size()); + } } catch (IllegalStateException | TargetDisconnectedException ex) { //rolling update (cluster can be in passive state) e.g. update custom classes ex.printStackTrace(); } - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } } } From d72266ce7377ec49523bee30f9211b68eb37ce8f Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Thu, 19 Jan 2023 13:41:05 +0200 Subject: [PATCH 30/46] 3.1.0 exec-maven-plugin --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 805258e..7bac0a2 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 + 3.1.0 client From 4707e6158b21e77e7b0c119e83ba34ccf3df44e8 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Fri, 3 Feb 2023 10:18:55 +0200 Subject: [PATCH 31/46] Remove lombook --- pom.xml | 6 ---- .../java/com/hazelcast/cloud/model/City.java | 31 ++++++++++++++----- .../com/hazelcast/cloud/model/Country.java | 24 +++++++++----- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 7bac0a2..52e394c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,12 +14,6 @@ hazelcast-enterprise 5.2.0 - - org.projectlombok - lombok - 1.18.24 - true - diff --git a/src/main/java/com/hazelcast/cloud/model/City.java b/src/main/java/com/hazelcast/cloud/model/City.java index d64ee13..541001a 100644 --- a/src/main/java/com/hazelcast/cloud/model/City.java +++ b/src/main/java/com/hazelcast/cloud/model/City.java @@ -1,14 +1,29 @@ package com.hazelcast.cloud.model; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor public final class City { - private String country; - private String city; + private final String country; + + private final String city; + + private final int population; + + public City(String country, String city, int population) { + this.country = country; + this.city = city; + this.population = population; + } + + public String getCountry() { + return country; + } + + public String getCity() { + return city; + } + + public int getPopulation() { + return population; + } - private int population; } diff --git a/src/main/java/com/hazelcast/cloud/model/Country.java b/src/main/java/com/hazelcast/cloud/model/Country.java index b0371d5..886a53a 100644 --- a/src/main/java/com/hazelcast/cloud/model/Country.java +++ b/src/main/java/com/hazelcast/cloud/model/Country.java @@ -1,12 +1,22 @@ package com.hazelcast.cloud.model; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor public final class Country { - private String isoCode; - private String country; + private final String isoCode; + + private final String country; + + public Country(String isoCode, String country) { + this.isoCode = isoCode; + this.country = country; + } + + public String getIsoCode() { + return isoCode; + } + + public String getCountry() { + return country; + } + } From 5de8b005a2d56a9b3fefdbf794d5840f2b0e447d Mon Sep 17 00:00:00 2001 From: Emre Yigit Date: Wed, 19 Apr 2023 15:05:00 +0300 Subject: [PATCH 32/46] Forward port of 5.2 to 5.3 [API-1977] (#50) * Simplified the example. [API-1977] (#45) * Simplified the example. * Exmaples changed to city to be synced with docs. * Update src/main/java/com/hazelcast/cloud/ClientWithSsl.java Co-authored-by: Metin Dumandag * Review changes. * Add license headers. * Fix syntax. * Non ssl sample aligned with ssl one. --------- Co-authored-by: Metin Dumandag * Update Hazelcast version to 5.2.3 (#47) * Add MC Jobs tip to sample client (#48) --------- Co-authored-by: Metin Dumandag Co-authored-by: Eugene Abramchuk --- pom.xml | 2 +- src/main/java/com/hazelcast/cloud/Client.java | 382 ++++------------- .../com/hazelcast/cloud/ClientWithSsl.java | 402 +++++------------- .../cloud/jobs/UpperCaseFunction.java | 16 + .../java/com/hazelcast/cloud/model/City.java | 16 + .../hazelcast/cloud/model/CitySerializer.java | 47 ++ .../com/hazelcast/cloud/model/Country.java | 22 - 7 files changed, 264 insertions(+), 623 deletions(-) create mode 100644 src/main/java/com/hazelcast/cloud/model/CitySerializer.java delete mode 100644 src/main/java/com/hazelcast/cloud/model/Country.java diff --git a/pom.xml b/pom.xml index 52e394c..8435dde 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.2.0 + 5.2.3 diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index c643e07..497acdb 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -1,12 +1,25 @@ -package com.hazelcast.cloud; +/* + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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. + */ -import java.util.Random; +package com.hazelcast.cloud; import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; import com.hazelcast.cloud.jobs.UpperCaseFunction; import com.hazelcast.cloud.model.City; -import com.hazelcast.cloud.model.Country; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.jet.config.JobConfig; import com.hazelcast.jet.pipeline.BatchSource; @@ -14,7 +27,6 @@ import com.hazelcast.jet.pipeline.Sinks; import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; -import com.hazelcast.spi.exception.TargetDisconnectedException; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import com.hazelcast.sql.SqlService; @@ -22,7 +34,7 @@ /** * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. *

      - * See: https://docs.hazelcast.com/cloud/java-client + * See: https://docs.hazelcast.com/cloud/get-started */ public class Client { @@ -36,16 +48,10 @@ public static void main(String[] args) { HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); try { - mapExample(client); - - //sqlExample(client); - - //compactSerializationExample(client); - - //nonStopMapExample(client); - - //jetJobExample(client); - + createMapping(client.getSql()); + insertCities(client); + fetchCities(client.getSql()); + jetJobExample(client); } catch (Exception ex) { ex.printStackTrace(); @@ -55,299 +61,84 @@ public static void main(String[] args) { } } - /** - * This example shows how to work with Hazelcast maps. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void mapExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - cities.put("1", new City("United Kingdom", "London", 9_540_576)); - cities.put("2", new City("United Kingdom", "Manchester", 2_770_434)); - cities.put("3", new City("United States", "New York", 19_223_191)); - cities.put("4", new City("United States", "Los Angeles", 3_985_520)); - cities.put("5", new City("Turkey", "Ankara", 5_309_690)); - cities.put("6", new City("Turkey", "Istanbul", 15_636_243)); - cities.put("7", new City("Brazil", "Sao Paulo", 22_429_800)); - cities.put("8", new City("Brazil", "Rio de Janeiro", 13_634_274)); - - int mapSize = cities.size(); - System.out.printf("'cities' map now contains %d entries.\n", mapSize); - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast SQL queries. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void sqlExample(HazelcastInstance client) { - SqlService sqlService = client.getSql(); - - createMappingForCapitals(sqlService); - - clearCapitals(sqlService); - - populateCapitals(sqlService); - - selectAllCapitals(sqlService); - - selectCapitalNames(sqlService); - } - - private static void createMappingForCapitals(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#creating-a-mapping-to-a-map - System.out.println("Creating a mapping..."); - - String mappingQuery = "" - + "CREATE OR REPLACE MAPPING capitals TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'varchar'" - + " )"; - try (SqlResult ignored = sqlService.execute(mappingQuery)) { - System.out.println("The mapping has been created successfully."); - } - - System.out.println("--------------------"); - } - - private static void clearCapitals(SqlService sqlService) { - System.out.println("Deleting data via SQL..."); - - try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { - System.out.println("The data has been deleted successfully."); - } - - System.out.println("--------------------"); - } - - private static void populateCapitals(SqlService sqlService) { - System.out.println("Inserting data via SQL..."); - - String insertQuery = "" - + "INSERT INTO capitals VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; - - try (SqlResult ignored = sqlService.execute(insertQuery)) { - System.out.println("The data has been inserted successfully."); - } - - System.out.println("--------------------"); - } - - private static void selectAllCapitals(SqlService sqlService) { - System.out.println("Retrieving all the data via SQL..."); - - try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { - - for (SqlRow row : result) { - String country = row.getObject(0); - String city = row.getObject(1); - System.out.printf("%s - %s\n", country, city); - } - } - - System.out.println("--------------------"); - } - - private static void selectCapitalNames(SqlService sqlService) { - System.out.println("Retrieving the capital name via SQL..."); - - try (SqlResult result = sqlService - .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { - - for (SqlRow row : result) { - String country = row.getObject("__key"); - String city = row.getObject("this"); - System.out.printf("Country name: %s; Capital name: %s\n", country, city); - } - } - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast SQL queries via Maps that contains compact serialized values. - * - *

        - *
      • Select single element from a Map
      • - *
      • Select data from Map with filtering
      • - *
      • Join data from two Maps
      • - *
      - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void compactSerializationExample(HazelcastInstance client) { - SqlService sqlService = client.getSql(); - - createMappingForCountries(sqlService); - - populateCountriesWithMap(client); - - selectAllCountries(sqlService); - - createMappingForCities(sqlService); - - populateCities(client); - - selectCitiesByCountry(sqlService, "AU"); - - selectCountriesAndCities(sqlService); - } - - private static void createMappingForCountries(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects - System.out.println("Creating mapping for countries..."); + private static void createMapping(SqlService sqlService) { + // See: https://docs.hazelcast.com/hazelcast/latest/sql/mapping-to-maps#compact-objects + System.out.print("\nCreating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'compact'," - + " 'valueCompactTypeName' = 'country'" - + " )"; + + "CREATE OR REPLACE MAPPING cities(" + + " __key INT," + + " country VARCHAR," + + " city VARCHAR," + + " population INT" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'city'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { - System.out.println("Mapping for countries has been created"); + System.out.print("OK."); + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } - - System.out.println("--------------------"); } - private static void populateCountriesWithMap(HazelcastInstance client) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map - System.out.println("Populating 'countries' map..."); - - IMap countries = client.getMap("country"); - countries.put("AU", new Country("AU", "Australia")); - countries.put("EN", new Country("EN", "England")); - countries.put("US", new Country("US", "United States")); - countries.put("CZ", new Country("CZ", "Czech Republic")); + private static void insertCities(HazelcastInstance client) { + System.out.print("\nInserting cities into 'cities' map..."); - System.out.println("The 'countries' map has been populated."); - System.out.println("--------------------"); - } + String insertQuery = "INSERT INTO cities " + + "(__key, city, country, population) VALUES" + + "(1, 'London', 'United Kingdom', 9540576)," + + "(2, 'Manchester', 'United Kingdom', 2770434)," + + "(3, 'New York', 'United States', 19223191)," + + "(4, 'Los Angeles', 'United States', 3985520)," + + "(5, 'Istanbul', 'Türkiye', 15636243)," + + "(6, 'Ankara', 'Türkiye', 5309690)," + + "(7, 'Sao Paulo ', 'Brazil', 22429800)"; - private static void selectAllCountries(SqlService sqlService) { - String sql = "SELECT c.country from country c"; - System.out.println("Select all countries with sql = " + sql); - try (SqlResult result = sqlService.execute(sql)) { - result.forEach(row -> System.out.println("country = " + row.getObject("country"))); - } - System.out.println("--------------------"); - } - - private static void createMappingForCities(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects - System.out.println("Creating mapping for cities..."); - - String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population INT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'int'," - + " 'valueFormat' = 'compact'," - + " 'valueCompactTypeName' = 'city'" - + " )"; - - try (SqlResult ignored = sqlService.execute(mappingSql)) { - System.out.println("Mapping for cities has been created"); + try { + SqlResult result = client.getSql().execute(insertQuery); + System.out.print("Insert...OK..."); + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } - System.out.println("--------------------"); - } - - private static void populateCities(HazelcastInstance client) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map - System.out.println("Populating 'city' map"); - IMap cities = client.getMap("city"); - cities.put(1, new City("AU", "Canberra", 467_194)); - cities.put(2, new City("CZ", "Prague", 1_318_085)); - cities.put(3, new City("EN", "London", 9_540_576)); - cities.put(4, new City("US", "Washington, DC", 7_887_965)); + // Let's also add a city as object. + IMap map = client.getMap("cities"); - System.out.println("The 'city' map has been populated."); - System.out.println("--------------------"); + City c = new City("Brazil", "Rio de Janeiro", 13634274); + System.out.print("\nPutting a city into 'cities' map..."); + map.put(8, c); + System.out.print("OK."); } - private static void selectCitiesByCountry(SqlService sqlService, String country) { - String sql = "SELECT city, population FROM city where country=?"; - System.out.println("--------------------"); - - System.out.println("Select city and population with sql = " + sql); - try (SqlResult result = sqlService.execute(sql, country)) { - result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) - ); - } - - System.out.println("--------------------"); - } + private static void fetchCities(SqlService sqlService) { - private static void selectCountriesAndCities(SqlService sqlService) { - String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + System.out.print("\nFetching cities via SQL..."); - System.out.println("Select country and city data in query that joins tables"); - System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); + try (SqlResult result = sqlService.execute("SELECT __key, this FROM cities")) { + System.out.print("OK.\n"); + System.out.println("--Results of 'SELECT __key, this FROM cities'"); - try (SqlResult result = sqlService.execute(sql)) { - result.forEach(row -> { - System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + System.out.printf("%4s | %20s | %20s | %15s |%n", "id", "country", "city", "population"); + for (SqlRow row : result) { + int id = row.getObject("__key"); + City c = row.getObject("this"); + System.out.printf("%4s | %20s | %20s | %15s |%n", + id, + c.getCountry(), + c.getCity(), + c.getPopulation() ); - }); - } - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast maps, where the map is updated continuously. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void nonStopMapExample(HazelcastInstance client) { - System.out.println("Now the map named 'map' will be filled with random entries."); - - IMap map = client.getMap("map"); - Random random = new Random(); - int iterationCounter = 0; - while (true) { - int randomKey = random.nextInt(100_000); - try { - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } - } - catch (IllegalStateException | TargetDisconnectedException ex) { - //rolling update (cluster can be in passive state) e.g. update custom classes - ex.printStackTrace(); } + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } + + System.out.println("\n!! Hint !! You can execute your SQL queries on your Viridian cluster over the management center." + + "\n 1. Go to 'Management Center' of your Hazelcast Viridian cluster. \n 2. Open the 'SQL Browser'. \n 3. Try to execute 'SELECT * FROM cities'.\n"); } /** @@ -361,21 +152,20 @@ private static void jetJobExample(HazelcastInstance client) { System.out.println("Submitting Jet job"); BatchSource items = TestSources.items( - "United States", "Turkey", "United Kingdom", "Poland", "Ukraine" + "United States", "Türkiye", "United Kingdom", "Poland", "Ukraine" ); Pipeline pipeline = Pipeline.create() - .readFrom(items) - .map(new UpperCaseFunction()) - .writeTo(Sinks.logger()) - .getPipeline(); + .readFrom(items) + .map(new UpperCaseFunction()) + .writeTo(Sinks.logger()) // Results will be visible on the server logs. + .getPipeline(); JobConfig jobConfig = new JobConfig() - .addClass(UpperCaseFunction.class); + .addClass(UpperCaseFunction.class); client.getJet().newJob(pipeline, jobConfig); - System.out.println("Jet job submitted"); + System.out.println("Jet job submitted. \nYou can see the results in the logs. Go to your Viridian cluster, and click the 'Logs'."); } - } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 8b9f9c5..49ef4e7 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -1,13 +1,28 @@ +/* + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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 com.hazelcast.cloud; import java.util.Properties; -import java.util.Random; import com.hazelcast.client.HazelcastClient; import com.hazelcast.client.config.ClientConfig; import com.hazelcast.cloud.jobs.UpperCaseFunction; import com.hazelcast.cloud.model.City; -import com.hazelcast.cloud.model.Country; +import com.hazelcast.cloud.model.CitySerializer; import com.hazelcast.config.SSLConfig; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.jet.config.JobConfig; @@ -16,351 +31,131 @@ import com.hazelcast.jet.pipeline.Sinks; import com.hazelcast.jet.pipeline.test.TestSources; import com.hazelcast.map.IMap; -import com.hazelcast.spi.exception.TargetDisconnectedException; import com.hazelcast.sql.SqlResult; import com.hazelcast.sql.SqlRow; import com.hazelcast.sql.SqlService; /** - * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. + * This is boilerplate application that configures client to connect Hazelcast Viridian cluster. *

      - * See: https://docs.hazelcast.com/cloud/java-client + * See: https://docs.hazelcast.com/cloud/get-started */ public class ClientWithSsl { public static void main(String[] args) throws Exception { + // Configure the client. ClassLoader classLoader = ClientWithSsl.class.getClassLoader(); Properties props = new Properties(); props.setProperty("javax.net.ssl.keyStore", classLoader.getResource("client.keystore").toURI().getPath()); props.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SSL_PASSWORD"); props.setProperty("javax.net.ssl.trustStore", - classLoader.getResource("client.truststore").toURI().getPath()); + classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); + // Register serializer of the City. + config.getSerializationConfig().getCompactSerializationConfig().addSerializer(new CitySerializer()); + + System.out.println("Connect Hazelcast Viridian with TLS"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); try { - - mapExample(client); - - //sqlExample(client); - - //compactSerializationExample(client); - - //nonStopMapExample(client); - - //jetJobExample(client); - - } - catch (Exception ex) { + createMapping(client.getSql()); + insertCities(client); + fetchCities(client.getSql()); + jetJobExample(client); + } catch (Exception ex) { ex.printStackTrace(); - } - finally { + } finally { client.shutdown(); } } - /** - * This example shows how to work with Hazelcast maps. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void mapExample(HazelcastInstance client) { - IMap cities = client.getMap("cities"); - cities.put("1", new City("United Kingdom", "London", 9_540_576)); - cities.put("2", new City("United Kingdom", "Manchester", 2_770_434)); - cities.put("3", new City("United States", "New York", 19_223_191)); - cities.put("4", new City("United States", "Los Angeles", 3_985_520)); - cities.put("5", new City("Turkey", "Ankara", 5_309_690)); - cities.put("6", new City("Turkey", "Istanbul", 15_636_243)); - cities.put("7", new City("Brazil", "Sao Paulo", 22_429_800)); - cities.put("8", new City("Brazil", "Rio de Janeiro", 13_634_274)); - - int mapSize = cities.size(); - System.out.printf("'cities' map now contains %d entries.\n", mapSize); - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast SQL queries. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void sqlExample(HazelcastInstance client) { - SqlService sqlService = client.getSql(); - - createMappingForCapitals(sqlService); - - clearCapitals(sqlService); - - populateCapitals(sqlService); - - selectAllCapitals(sqlService); - - selectCapitalNames(sqlService); - } - - private static void createMappingForCapitals(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#creating-a-mapping-to-a-map - System.out.println("Creating a mapping..."); - - String mappingQuery = "" - + "CREATE OR REPLACE MAPPING capitals TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'varchar'" - + " )"; - try (SqlResult ignored = sqlService.execute(mappingQuery)) { - System.out.println("The mapping has been created successfully."); - } - - System.out.println("--------------------"); - } - - private static void clearCapitals(SqlService sqlService) { - System.out.println("Deleting data via SQL..."); - - try (SqlResult ignored = sqlService.execute("DELETE FROM capitals")) { - System.out.println("The data has been deleted successfully."); - } - - System.out.println("--------------------"); - } - - private static void populateCapitals(SqlService sqlService) { - System.out.println("Inserting data via SQL..."); - - String insertQuery = "" - + "INSERT INTO capitals VALUES" - + "('Australia','Canberra')," - + "('Croatia','Zagreb')," - + "('Czech Republic','Prague')," - + "('England','London')," - + "('Turkey','Ankara')," - + "('United States','Washington, DC');"; - - try (SqlResult ignored = sqlService.execute(insertQuery)) { - System.out.println("The data has been inserted successfully."); - } - - System.out.println("--------------------"); - } - - private static void selectAllCapitals(SqlService sqlService) { - System.out.println("Retrieving all the data via SQL..."); - - try (SqlResult result = sqlService.execute("SELECT * FROM capitals")) { - - for (SqlRow row : result) { - String country = row.getObject(0); - String city = row.getObject(1); - System.out.printf("%s - %s\n", country, city); - } - } - - System.out.println("--------------------"); - } - - private static void selectCapitalNames(SqlService sqlService) { - System.out.println("Retrieving the capital name via SQL..."); - - try (SqlResult result = sqlService - .execute("SELECT __key, this FROM capitals WHERE __key = ?", "United States")) { - - for (SqlRow row : result) { - String country = row.getObject("__key"); - String city = row.getObject("this"); - System.out.printf("Country name: %s; Capital name: %s\n", country, city); - } - } - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast SQL queries via Maps that contains compact serialized values. - * - *

        - *
      • Select single element from a Map
      • - *
      • Select data from Map with filtering
      • - *
      • Join data from two Maps
      • - *
      - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void compactSerializationExample(HazelcastInstance client) { - SqlService sqlService = client.getSql(); - - createMappingForCountries(sqlService); - - populateCountriesWithMap(client); - - selectAllCountries(sqlService); - - createMappingForCities(sqlService); - - populateCities(client); - - selectCitiesByCountry(sqlService, "AU"); - - selectCountriesAndCities(sqlService); - } - - private static void createMappingForCountries(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects - System.out.println("Creating mapping for countries..."); + private static void createMapping(SqlService sqlService) { + // See: https://docs.hazelcast.com/hazelcast/latest/sql/mapping-to-maps#compact-objects + System.out.print("\nCreating mapping for cities..."); String mappingSql = "" - + "CREATE OR REPLACE MAPPING country(" - + " __key VARCHAR," - + " isoCode VARCHAR," - + " country VARCHAR" - + ") TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'varchar'," - + " 'valueFormat' = 'compact'," - + " 'valueCompactTypeName' = 'country'" - + " )"; + + "CREATE OR REPLACE MAPPING cities(" + + " __key INT," + + " country VARCHAR," + + " city VARCHAR," + + " population INT" + + ") TYPE IMap" + + " OPTIONS (" + + " 'keyFormat' = 'int'," + + " 'valueFormat' = 'compact'," + + " 'valueCompactTypeName' = 'city'" + + " )"; try (SqlResult ignored = sqlService.execute(mappingSql)) { - System.out.println("Mapping for countries has been created"); + System.out.print("OK."); + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } - - System.out.println("--------------------"); } - private static void populateCountriesWithMap(HazelcastInstance client) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map - System.out.println("Populating 'countries' map..."); + private static void insertCities(HazelcastInstance client) { + System.out.print("\nInserting cities into 'cities' map..."); - IMap countries = client.getMap("country"); - countries.put("AU", new Country("AU", "Australia")); - countries.put("EN", new Country("EN", "England")); - countries.put("US", new Country("US", "United States")); - countries.put("CZ", new Country("CZ", "Czech Republic")); + String insertQuery = "INSERT INTO cities " + + "(__key, city, country, population) VALUES" + + "(1, 'London', 'United Kingdom', 9540576)," + + "(2, 'Manchester', 'United Kingdom', 2770434)," + + "(3, 'New York', 'United States', 19223191)," + + "(4, 'Los Angeles', 'United States', 3985520)," + + "(5, 'Istanbul', 'Türkiye', 15636243)," + + "(6, 'Ankara', 'Türkiye', 5309690)," + + "(7, 'Sao Paulo ', 'Brazil', 22429800)"; - System.out.println("The 'countries' map has been populated."); - System.out.println("--------------------"); - } - - private static void selectAllCountries(SqlService sqlService) { - String sql = "SELECT c.country from country c"; - System.out.println("Select all countries with sql = " + sql); - try (SqlResult result = sqlService.execute(sql)) { - result.forEach(row -> System.out.println("country = " + row.getObject("country"))); - } - System.out.println("--------------------"); - } - - private static void createMappingForCities(SqlService sqlService) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/sql/mapping-to-maps#compact-objects - System.out.println("Creating mapping for cities..."); - - String mappingSql = "" - + "CREATE OR REPLACE MAPPING city(" - + " __key INT ," - + " country VARCHAR ," - + " city VARCHAR," - + " population INT)" - + " TYPE IMap" - + " OPTIONS (" - + " 'keyFormat' = 'int'," - + " 'valueFormat' = 'compact'," - + " 'valueCompactTypeName' = 'city'" - + " )"; - - try (SqlResult ignored = sqlService.execute(mappingSql)) { - System.out.println("Mapping for cities has been created"); + try { + SqlResult result = client.getSql().execute(insertQuery); + System.out.print("Insert...OK."); + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } - System.out.println("--------------------"); - } - - private static void populateCities(HazelcastInstance client) { - // See: https://docs.hazelcast.com/hazelcast/5.2-snapshot/data-structures/creating-a-map - System.out.println("Populating 'city' map"); - IMap cities = client.getMap("city"); - cities.put(1, new City("AU", "Canberra", 467_194)); - cities.put(2, new City("CZ", "Prague", 1_318_085)); - cities.put(3, new City("EN", "London", 9_540_576)); - cities.put(4, new City("US", "Washington, DC", 7_887_965)); + // Let's also add a city as object. + IMap map = client.getMap("cities"); - System.out.println("The 'city' map has been populated."); - System.out.println("--------------------"); + City c = new City("Brazil", "Rio de Janeiro", 13634274); + System.out.print("\nPutting a city into 'cities' map..."); + map.put(8, c); + System.out.print("OK."); } - private static void selectCitiesByCountry(SqlService sqlService, String country) { - String sql = "SELECT city, population FROM city where country=?"; - System.out.println("--------------------"); - - System.out.println("Select city and population with sql = " + sql); - try (SqlResult result = sqlService.execute(sql, country)) { - result.forEach(row -> - System.out.printf("city = %s, population = %s%n", row.getObject("city"), row.getObject("population")) - ); - } - - System.out.println("--------------------"); - } + private static void fetchCities(SqlService sqlService) { - private static void selectCountriesAndCities(SqlService sqlService) { - String sql = "" - + "SELECT c.isoCode, c.country, t.city, t.population" - + " FROM country c" - + " JOIN city t ON c.isoCode = t.country"; + System.out.print("\nFetching cities via SQL..."); - System.out.println("Select country and city data in query that joins tables"); - System.out.printf("%4s | %15s | %20s | %15s |%n", "iso", "country", "city", "population"); + try (SqlResult result = sqlService.execute("SELECT __key, this FROM cities")) { + System.out.print("OK.\n"); + System.out.println("--Results of 'SELECT __key, this FROM cities'"); - try (SqlResult result = sqlService.execute(sql)) { - result.forEach(row -> { - System.out.printf("%4s | %15s | %20s | %15s |%n", - row.getObject("isoCode"), - row.getObject("country"), - row.getObject("city"), - row.getObject("population") + System.out.printf("%4s | %20s | %20s | %15s |%n", "id", "country", "city", "population"); + for (SqlRow row : result) { + int id = row.getObject("__key"); + City c = row.getObject("this"); + System.out.printf("%4s | %20s | %20s | %15s |%n", + id, + c.getCountry(), + c.getCity(), + c.getPopulation() ); - }); - } - - System.out.println("--------------------"); - } - - /** - * This example shows how to work with Hazelcast maps, where the map is updated continuously. - * - * @param client - a {@link HazelcastInstance} client. - */ - private static void nonStopMapExample(HazelcastInstance client) { - System.out.println("Now the map named 'map' will be filled with random entries."); - - IMap map = client.getMap("map"); - Random random = new Random(); - int iterationCounter = 0; - while (true) { - int randomKey = random.nextInt(100_000); - try { - map.put("key-" + randomKey, "value-" + randomKey); - map.get("key-" + random.nextInt(100_000)); - if (++iterationCounter == 10) { - iterationCounter = 0; - System.out.println("Current map size: " + map.size()); - } - } - catch (IllegalStateException | TargetDisconnectedException ex) { - //rolling update (cluster can be in passive state) e.g. update custom classes - ex.printStackTrace(); } + } catch (Exception ex) { + System.out.print("FAILED. " + ex.getMessage()); } + + System.out.println("\n!! Hint !! You can execute your SQL queries on your Viridian cluster over the management center." + + "\n 1. Go to 'Management Center' of your Hazelcast Viridian cluster. \n 2. Open the 'SQL Browser'. \n 3. Try to execute 'SELECT * FROM cities'.\n"); } /** @@ -374,21 +169,20 @@ private static void jetJobExample(HazelcastInstance client) { System.out.println("Submitting Jet job"); BatchSource items = TestSources.items( - "United States", "Turkey", "United Kingdom", "Poland", "Ukraine" + "United States", "Türkiye", "United Kingdom", "Poland", "Ukraine" ); Pipeline pipeline = Pipeline.create() - .readFrom(items) - .map(new UpperCaseFunction()) - .writeTo(Sinks.logger()) - .getPipeline(); + .readFrom(items) + .map(new UpperCaseFunction()) + .writeTo(Sinks.logger()) // Results will be visible on the server logs. + .getPipeline(); JobConfig jobConfig = new JobConfig() - .addClass(UpperCaseFunction.class); + .addClass(UpperCaseFunction.class); client.getJet().newJob(pipeline, jobConfig); - System.out.println("Jet job submitted"); + System.out.println("Jet job submitted. \nYou can see the results in the logs (go to your cluster page in the Viridian console and click the 'Logs' link) or in Management Center - Jobs section (also available through the Viridian cluster page)."); } - } diff --git a/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java b/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java index c856f91..655d737 100644 --- a/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java +++ b/src/main/java/com/hazelcast/cloud/jobs/UpperCaseFunction.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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 com.hazelcast.cloud.jobs; import com.hazelcast.function.FunctionEx; diff --git a/src/main/java/com/hazelcast/cloud/model/City.java b/src/main/java/com/hazelcast/cloud/model/City.java index 541001a..db45dd6 100644 --- a/src/main/java/com/hazelcast/cloud/model/City.java +++ b/src/main/java/com/hazelcast/cloud/model/City.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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 com.hazelcast.cloud.model; public final class City { diff --git a/src/main/java/com/hazelcast/cloud/model/CitySerializer.java b/src/main/java/com/hazelcast/cloud/model/CitySerializer.java new file mode 100644 index 0000000..a789585 --- /dev/null +++ b/src/main/java/com/hazelcast/cloud/model/CitySerializer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. + * + * Licensed 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 com.hazelcast.cloud.model; + +import com.hazelcast.nio.serialization.compact.CompactReader; +import com.hazelcast.nio.serialization.compact.CompactSerializer; +import com.hazelcast.nio.serialization.compact.CompactWriter; + +public class CitySerializer implements CompactSerializer { + @Override + public City read(CompactReader compactReader) { + return new City(compactReader.readString("country"), + compactReader.readString("city"), + compactReader.readInt32("population")); + } + + @Override + public void write(CompactWriter compactWriter, City city) { + compactWriter.writeString("country", city.getCountry()); + compactWriter.writeString("city", city.getCity()); + compactWriter.writeInt32("population", city.getPopulation()); + } + + @Override + public String getTypeName() { + return "city"; + } + + @Override + public Class getCompactClass() { + return City.class; + } +} diff --git a/src/main/java/com/hazelcast/cloud/model/Country.java b/src/main/java/com/hazelcast/cloud/model/Country.java deleted file mode 100644 index 886a53a..0000000 --- a/src/main/java/com/hazelcast/cloud/model/Country.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hazelcast.cloud.model; - -public final class Country { - - private final String isoCode; - - private final String country; - - public Country(String isoCode, String country) { - this.isoCode = isoCode; - this.country = country; - } - - public String getIsoCode() { - return isoCode; - } - - public String getCountry() { - return country; - } - -} From 41b19a055382672d5b1108b9ad3e6b16a7aae930 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Tue, 23 May 2023 14:15:18 +0200 Subject: [PATCH 33/46] HZC-4718: Bump the Hazelcast version to 5.3.0 (#53) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8435dde..604bfd9 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.2.3 + 5.3.0 From 3f8141901e09ed0c56acd6f02764ddc2026a9f1f Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Tue, 23 May 2023 14:16:18 +0200 Subject: [PATCH 34/46] HZC-4719: add 5.3 jdbc dependencies (#54) * HZC-4718: Bump the Hazelcast version to 5.3.0 * HZC-4719: Add the 5.3.0 JDBC dependency --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 604bfd9..adbd15e 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,11 @@ hazelcast-enterprise 5.3.0 + + com.hazelcast + hazelcast-jdbc-enterprise + 5.3.0 + From 4ade44aee11d2e9a45895a68a3e6659801566a10 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Tue, 23 May 2023 15:07:57 +0200 Subject: [PATCH 35/46] HZC-4719: replace the JDBC dependency with an older build --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index adbd15e..5ec9b21 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ com.hazelcast hazelcast-jdbc-enterprise - 5.3.0 + 5.2.1 From f6e04ddbf13c033bdf5268d8c1250f6838e47ded Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Wed, 24 May 2023 12:44:05 +0200 Subject: [PATCH 36/46] Bump jdbc libs to 5.3.0 Following the publishing of the new artifact --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ec9b21..adbd15e 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ com.hazelcast hazelcast-jdbc-enterprise - 5.2.1 + 5.3.0 From 2a585fb5d29d4e51d0fead69bdc44d0b249bc31c Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Wed, 7 Jun 2023 12:25:58 +0300 Subject: [PATCH 37/46] HZC-4733: Re-throw exception --- src/main/java/com/hazelcast/cloud/Client.java | 3 --- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 497acdb..0aeeddc 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -53,9 +53,6 @@ public static void main(String[] args) { fetchCities(client.getSql()); jetJobExample(client); } - catch (Exception ex) { - ex.printStackTrace(); - } finally { client.shutdown(); } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 49ef4e7..73e073f 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -71,8 +71,6 @@ public static void main(String[] args) throws Exception { insertCities(client); fetchCities(client.getSql()); jetJobExample(client); - } catch (Exception ex) { - ex.printStackTrace(); } finally { client.shutdown(); } From 1032e099778e6c77f540dd467809296f01794624 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Fri, 16 Jun 2023 09:52:22 +0200 Subject: [PATCH 38/46] Set platform encoding to UTF-8 (#55) Remove maven warnings and improve stability across all platforms --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index adbd15e..f35772a 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,10 @@ + + UTF-8 + + From 76204c0eb37237ce07320b72b5cfb166790586f3 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Thu, 22 Jun 2023 09:08:16 +0200 Subject: [PATCH 39/46] Client 5.3: Force maven compiler to use UTF-8 (#56) --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index f35772a..968e870 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ 1.8 1.8 + UTF-8 org.projectlombok From 6a5e0c283802bc12c53aa7adb7a9b7e0e528415e Mon Sep 17 00:00:00 2001 From: Sergey Dreger Date: Tue, 11 Jul 2023 16:41:41 +0300 Subject: [PATCH 40/46] HZC-3702: Clean up the 'cities' map before putting the data (#58) --- src/main/java/com/hazelcast/cloud/Client.java | 12 +++++++----- .../java/com/hazelcast/cloud/ClientWithSsl.java | 15 +++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 0aeeddc..9b8cd22 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -52,8 +52,7 @@ public static void main(String[] args) { insertCities(client); fetchCities(client.getSql()); jetJobExample(client); - } - finally { + } finally { client.shutdown(); } } @@ -83,9 +82,13 @@ private static void createMapping(SqlService sqlService) { } private static void insertCities(HazelcastInstance client) { - System.out.print("\nInserting cities into 'cities' map..."); + try { + System.out.print("\nCleaning up the 'cities' map..."); + client.getSql().execute("DELETE FROM cities"); + System.out.print("Cleanup...OK."); + System.out.print("\nInserting cities into 'cities' map..."); - String insertQuery = "INSERT INTO cities " + String insertQuery = "INSERT INTO cities " + "(__key, city, country, population) VALUES" + "(1, 'London', 'United Kingdom', 9540576)," + "(2, 'Manchester', 'United Kingdom', 2770434)," @@ -95,7 +98,6 @@ private static void insertCities(HazelcastInstance client) { + "(6, 'Ankara', 'Türkiye', 5309690)," + "(7, 'Sao Paulo ', 'Brazil', 22429800)"; - try { SqlResult result = client.getSql().execute(insertQuery); System.out.print("Insert...OK..."); } catch (Exception ex) { diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 73e073f..d2b49f6 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -49,13 +49,13 @@ public static void main(String[] args) throws Exception { props.setProperty("javax.net.ssl.keyStore", classLoader.getResource("client.keystore").toURI().getPath()); props.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SSL_PASSWORD"); props.setProperty("javax.net.ssl.trustStore", - classLoader.getResource("client.truststore").toURI().getPath()); + classLoader.getResource("client.truststore").toURI().getPath()); props.setProperty("javax.net.ssl.trustStorePassword", "YOUR_SSL_PASSWORD"); ClientConfig config = new ClientConfig(); config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(true).setProperties(props)); config.getNetworkConfig().getCloudConfig() - .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") - .setEnabled(true); + .setDiscoveryToken("YOUR_CLUSTER_DISCOVERY_TOKEN") + .setEnabled(true); config.setProperty("hazelcast.client.cloud.url", "YOUR_DISCOVERY_URL"); config.setClusterName("YOUR_CLUSTER_NAME"); @@ -101,9 +101,13 @@ private static void createMapping(SqlService sqlService) { } private static void insertCities(HazelcastInstance client) { - System.out.print("\nInserting cities into 'cities' map..."); + try { + System.out.print("\nCleaning up the 'cities' map..."); + client.getSql().execute("DELETE FROM cities"); + System.out.print("Cleanup...OK."); + System.out.print("\nInserting cities into 'cities' map..."); - String insertQuery = "INSERT INTO cities " + String insertQuery = "INSERT INTO cities " + "(__key, city, country, population) VALUES" + "(1, 'London', 'United Kingdom', 9540576)," + "(2, 'Manchester', 'United Kingdom', 2770434)," @@ -113,7 +117,6 @@ private static void insertCities(HazelcastInstance client) { + "(6, 'Ankara', 'Türkiye', 5309690)," + "(7, 'Sao Paulo ', 'Brazil', 22429800)"; - try { SqlResult result = client.getSql().execute(insertQuery); System.out.print("Insert...OK."); } catch (Exception ex) { From 70b354b8685616645cd47907e8051831cdf63cb8 Mon Sep 17 00:00:00 2001 From: Sergey Shakhov Date: Wed, 30 Aug 2023 10:27:25 +0200 Subject: [PATCH 41/46] HZC-5266: Delete mc hint --- src/main/java/com/hazelcast/cloud/Client.java | 9 +++++++-- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 9b8cd22..0600928 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -136,8 +136,13 @@ private static void fetchCities(SqlService sqlService) { System.out.print("FAILED. " + ex.getMessage()); } - System.out.println("\n!! Hint !! You can execute your SQL queries on your Viridian cluster over the management center." + - "\n 1. Go to 'Management Center' of your Hazelcast Viridian cluster. \n 2. Open the 'SQL Browser'. \n 3. Try to execute 'SELECT * FROM cities'.\n"); + System.out.println("\n" + + "!! Hint !! You can execute your SQL queries on your Viridian cluster using the \"SQL Broswer\" UI.\n" + + "1. Start one of the preloaded demos in your Trial Experience.\n" + + "2. This will open the 'SQL Browser'.\n" + + "3. Add a new Tab.\n" + + "4. Try to execute 'SELECT * FROM cities'.\n" + ); } /** diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index d2b49f6..4ca9dc8 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -155,8 +155,13 @@ private static void fetchCities(SqlService sqlService) { System.out.print("FAILED. " + ex.getMessage()); } - System.out.println("\n!! Hint !! You can execute your SQL queries on your Viridian cluster over the management center." + - "\n 1. Go to 'Management Center' of your Hazelcast Viridian cluster. \n 2. Open the 'SQL Browser'. \n 3. Try to execute 'SELECT * FROM cities'.\n"); + System.out.println("\n" + + "!! Hint !! You can execute your SQL queries on your Viridian cluster using the \"SQL Broswer\" UI.\n" + + "1. Start one of the preloaded demos in your Trial Experience.\n" + + "2. This will open the 'SQL Browser'.\n" + + "3. Add a new Tab.\n" + + "4. Try to execute 'SELECT * FROM cities'.\n" + ); } /** From 8b9d6eefc838a8bbef300afb01f31e145f7504c5 Mon Sep 17 00:00:00 2001 From: sergeyshakhov Date: Tue, 5 Dec 2023 17:14:59 +0100 Subject: [PATCH 42/46] HZC-6107: Upgrade to Java 11 --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 968e870..cfdfe5d 100644 --- a/pom.xml +++ b/pom.xml @@ -30,10 +30,10 @@ com.hazelcast.cloud hazelcast-cloud-maven-plugin - 0.0.5 + 0.2.0 YOUR_DISCOVERY_URL - YOUR_CLUSTER_NAME + YOUR_CLUSTER_ID @@ -43,14 +43,14 @@ maven-compiler-plugin 3.10.1 - 1.8 - 1.8 + 11 + 11 UTF-8 org.projectlombok lombok - 1.18.24 + 1.18.30 From 1110bd357e79f46cfc2813eb00ce32650fe8c56e Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Tue, 12 Dec 2023 10:21:22 +0200 Subject: [PATCH 43/46] fix hazelcast version --- pom.xml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index cfdfe5d..071f1eb 100644 --- a/pom.xml +++ b/pom.xml @@ -12,18 +12,13 @@ com.hazelcast hazelcast-enterprise - 5.3.0 - - - com.hazelcast - hazelcast-jdbc-enterprise - 5.3.0 + 5.4.0-SNAPSHOT UTF-8 - + @@ -85,9 +80,12 @@ - hazelcast-ee - Sonatype Repository - https://repository.hazelcast.com/release + Hazelcast Private Release Repository + https://repository.hazelcast.com/release/ + + + Hazelcast Private Snapshot Repository + https://repository.hazelcast.com/snapshot/ From 632da2f84f777ece7cace96f0f80074e4f1f8cfe Mon Sep 17 00:00:00 2001 From: Ivan Shevtsov Date: Thu, 8 Feb 2024 17:37:54 +0300 Subject: [PATCH 44/46] HZC-6539: rename Viridian to Hazelcast Cloud for 5.4 tag (#63) --- src/main/java/com/hazelcast/cloud/Client.java | 4 ++-- src/main/java/com/hazelcast/cloud/ClientWithSsl.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hazelcast/cloud/Client.java b/src/main/java/com/hazelcast/cloud/Client.java index 0600928..754ca6b 100644 --- a/src/main/java/com/hazelcast/cloud/Client.java +++ b/src/main/java/com/hazelcast/cloud/Client.java @@ -137,7 +137,7 @@ private static void fetchCities(SqlService sqlService) { } System.out.println("\n" + - "!! Hint !! You can execute your SQL queries on your Viridian cluster using the \"SQL Broswer\" UI.\n" + + "!! Hint !! You can execute your SQL queries on your Hazelcast Cloud cluster using the \"SQL Broswer\" UI.\n" + "1. Start one of the preloaded demos in your Trial Experience.\n" + "2. This will open the 'SQL Browser'.\n" + "3. Add a new Tab.\n" + @@ -170,6 +170,6 @@ private static void jetJobExample(HazelcastInstance client) { client.getJet().newJob(pipeline, jobConfig); - System.out.println("Jet job submitted. \nYou can see the results in the logs. Go to your Viridian cluster, and click the 'Logs'."); + System.out.println("Jet job submitted. \nYou can see the results in the logs. Go to your Hazelcast Cloud cluster, and click the 'Logs'."); } } diff --git a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java index 4ca9dc8..c018905 100644 --- a/src/main/java/com/hazelcast/cloud/ClientWithSsl.java +++ b/src/main/java/com/hazelcast/cloud/ClientWithSsl.java @@ -36,7 +36,7 @@ import com.hazelcast.sql.SqlService; /** - * This is boilerplate application that configures client to connect Hazelcast Viridian cluster. + * This is boilerplate application that configures client to connect Hazelcast Cloud cluster. *

      * See: https://docs.hazelcast.com/cloud/get-started */ @@ -62,7 +62,7 @@ public static void main(String[] args) throws Exception { // Register serializer of the City. config.getSerializationConfig().getCompactSerializationConfig().addSerializer(new CitySerializer()); - System.out.println("Connect Hazelcast Viridian with TLS"); + System.out.println("Connect Hazelcast Cloud with TLS"); HazelcastInstance client = HazelcastClient.newHazelcastClient(config); System.out.println("Connection Successful!"); @@ -156,7 +156,7 @@ private static void fetchCities(SqlService sqlService) { } System.out.println("\n" + - "!! Hint !! You can execute your SQL queries on your Viridian cluster using the \"SQL Broswer\" UI.\n" + + "!! Hint !! You can execute your SQL queries on your Hazelcast Cloud cluster using the \"SQL Broswer\" UI.\n" + "1. Start one of the preloaded demos in your Trial Experience.\n" + "2. This will open the 'SQL Browser'.\n" + "3. Add a new Tab.\n" + @@ -189,6 +189,6 @@ private static void jetJobExample(HazelcastInstance client) { client.getJet().newJob(pipeline, jobConfig); - System.out.println("Jet job submitted. \nYou can see the results in the logs (go to your cluster page in the Viridian console and click the 'Logs' link) or in Management Center - Jobs section (also available through the Viridian cluster page)."); + System.out.println("Jet job submitted. \nYou can see the results in the logs (go to your cluster page in the Hazelcast Cloud console and click the 'Logs' link) or in Management Center - Jobs section (also available through the Hazelcast Cloud cluster page)."); } } From 18ece2e86106313cbc822f384665b0b22257e551 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Mon, 22 Apr 2024 20:17:45 +0200 Subject: [PATCH 45/46] Update Java to 21, Hazelcast EE jars to 5.4.0 (#65) --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 071f1eb..46bdda7 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.hazelcast hazelcast-enterprise - 5.4.0-SNAPSHOT + 5.4.0 @@ -38,8 +38,8 @@ maven-compiler-plugin 3.10.1 - 11 - 11 + 21 + 21 UTF-8 From 52073319e44606273c81227156c8fb6de964dfa8 Mon Sep 17 00:00:00 2001 From: Eugene Abramchuk Date: Mon, 22 Apr 2024 20:52:45 +0200 Subject: [PATCH 46/46] Lower the compile level to Java 17 to support older Java clients (#66) --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 46bdda7..156d92c 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,8 @@ maven-compiler-plugin 3.10.1 - 21 - 21 + 17 + 17 UTF-8