{"id":27370238,"url":"https://github.com/datastaxdevs/conference-2022-devoxx","last_synced_at":"2025-04-13T08:48:31.503Z","repository":{"id":62027333,"uuid":"545998439","full_name":"datastaxdevs/conference-2022-devoxx","owner":"datastaxdevs","description":"Deep Dive - A Java Developer Journey in to Cassandra","archived":false,"fork":false,"pushed_at":"2022-11-15T00:55:04.000Z","size":23209,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2023-03-04T04:05:48.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datastaxdevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-05T10:47:47.000Z","updated_at":"2023-03-01T21:38:30.000Z","dependencies_parsed_at":"2023-01-21T17:17:58.124Z","dependency_job_id":null,"html_url":"https://github.com/datastaxdevs/conference-2022-devoxx","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastaxdevs%2Fconference-2022-devoxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastaxdevs%2Fconference-2022-devoxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastaxdevs%2Fconference-2022-devoxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datastaxdevs%2Fconference-2022-devoxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datastaxdevs","download_url":"https://codeload.github.com/datastaxdevs/conference-2022-devoxx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688196,"owners_count":21145762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-13T08:48:30.921Z","updated_at":"2025-04-13T08:48:31.491Z","avatar_url":"https://github.com/datastaxdevs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 🧑🏻‍💻 🧑🏾‍💻 A Java developer Journey into Apache Cassandra™ 👩🏿‍💻 👩‍💻\n \n[![License Apache2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/datastaxdevs/conference-2022-devoxx)\n![Java](https://img.shields.io/badge/Java-17%20\u0026%20GraalVM-00CC00?style=flat)\n \nℹ️ **About this Session**\n \n\u003e During this deep-dive session, we will give you everything you need to master this technology: from \u003cb\u003earchitecture\u003c/b\u003e to \u003cb\u003edata modeling\u003c/b\u003e, from \u003cb\u003edrivers to\u003c/b\u003e best practices.\u003c/b\u003e Through practical labs requiring no installation, we will browse and run applications implemented with Spring Boot, Quarkus, and Micronaut in order to see how Apache Cassandra™ can be used in modern java applications.\n \n![](img/splash.png)\n\n⏲️ **Duration :** `3 hours`\n \n🎓 **Level** `Intermediate`\n \n## 📋 Table of content\n \n- [Objectives](#objectives)\n- [Materials](#materials)\n- [**1. Introduction to Cassandra** *(slides)*]()\n- [**2. Environment Setup**](#2-environment-setup)\n - [2.1 - Prerequisites](#21---prerequisites)\n - [2.2 - Start `Gitpod`](#22---start-gitpod)\n - [2.3 - Start Apache Cassandra™ cluster](#23---start-apache-cassandra-cluster)\n - [2.4 - Scale the cluster up](#24---scale-the-cluster-up)\n - [2.5 - Create keyspace](#25---create-keyspace)\n- [**3. Connectivity**](#3-connectivity)\n - [3.1 - Introduction to Drivers *(slides)*](#31---introduction-to-driver)\n - [3.2 - Connect with drivers](#32---connect-with-drivers)\n - [3.3 - Drivers Configuration](#33---drivers-configuration)\n- [**4. Data Distribution** *(slides)*](#4-data-distribution)\n- [**5. Working with CQL**](#5-working-with-cql)\n - [5.1 - Understanding table key *(slides)*](#51---understanding-table-keys)\n - [5.2 - Schema Definition](#52---schema-definition)\n - [5.3 - CRUD Operations](#53---crud-operations)\n - [5.4 - Advanced Data Types](#54---advanced-data-types)\n - [5.5 - Advanced Concepts](#55---advanced-concepts)\n- [**6. Data Modeling**](#6-data-modeling)\n - [6.1 - Data Model Methodology *(slides)*](#61---data-model-methodology)\n - [6.2 - Data Modeling In action](#62---data-modeling-in-action)\n - [6.3 - From SQL to NoSQL Migration  *(slides)*](#63---from-sql-to-nosql-migration)\n- [**7. Working with Spring Framework**](#7-working-with-spring-framework)\n - [7.1 - Spring Data Connection and Configuration](#71---spring-data-connection-and-configuration)\n - [7.2 - `CassandraRepository` and `CrudRepository`](#72---cassandrarepository-and-crudrepository)\n - [7.3 - `CassandraOperations`](#73---cassandraoperations)\n - [7.4 - Spring Boot (mvc, Webflux)](#74---spring-boot-mvc-webflux)\n - [7.5 - Spring Native](#75---spring-native)\n- [**8. Working with Quarkus**](#8-working-with-quarkus)\n - [8.1 - Quarkus extension *(slides)*](#81---quarkus-extension)\n - [8.2 - Application Walkthrough](#82---application-walkthrough)\n - [8.3 - Native Image](#83---native-image)\n- [**9. Working with Micronaut**](#9-working-with-micronaut)\n - [9.1 - Micronaut Philosophy  *(slides)*](#91---micronaut-philosophy)\n - [9.2 - Application Walkthrough](#92---application-walkthrough)\n - [9.3 - Native Image](#93---native-image)\n \n---\n## Objectives\n \n1. 🎯 Discover what the NoSQL Database Apache Cassandra is and what are the relevant **use cases**\n2. 🎯 Understand how Apache Cassandra™ is different from relational database in the philosophy and **data modeling**.\n3. 🎯 Practice on how **Java Applications** connect to the databases, what are the rules and things to know.\n4. 🎯 Learn how to work with Cassandra notions through the drivers, CRUD, Advanced Data Types, Batches, Lightweight transactions\n5. 🎯 Setup a Spring Boot application leverating Cassandra, Spring Data and Spring Boot\n6. 🎯 Setup Quarkus applications leveraging Cassandra\n7. 🎯 Setup Micronaut Boot applications leverating Cassandra\n8. 🎯 Work with GraalVm and native compilation\n \n## Materials\n \nIt doesn't matter if you join the presentation live or you prefer to work at your own pace later, we have you covered. In this repository, you'll find everything you need for this workshop:\n \n- [Slide deck](content/slides.pdf)\n- [Datastax Developers Discord chat](https://bit.ly/cassandra-workshop)\n- [Questions and Answers](https://community.datastax.com/)\n \n## 1. Introduction to Cassandra\n\n_This placeholder mark a moment to pay attention to the speaker_\n![](img/title_introduction-to-cassandra.png)\n\n## 2. Environment Setup\n \n### 2.1 - Prerequisites\n \nInstructions are provided to you to work within `gitpod` cloud IDE. Intention is to easily execute the steps with no installation required. You can of course use your own laptop and those are the tools you will need:\n \n#### 📦 Docker\n\u003e - Use the [reference documentation](https://www.docker.com/products/docker-desktop) to install **Docker Desktop**\n\u003e - Validate your installation with\n\u003e ```bash\n\u003e\n\u003e docker -v\n\u003e docker run hello-world\n\u003e ```\n \n#### 📦 Java Development Kit (JDK) 17+\n\u003e - Use the [reference documentation](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html) to install a \u003e**Java Development Kit**\n\u003e - Validate your installation with\n\u003e\n\u003e ```bash\n\u003e java --version\n\u003e ```\n \n#### 📦 Apache Maven (3.6+)\n\u003e - Use the [reference documentation](https://maven.apache.org/install.html) to install **Apache Maven**\n\u003e - Validate your installation with\n\u003e\n\u003e ```bash\n\u003e mvn -version\n\u003e ```\n \n#### 📦 GraalVM (22.1.r17+)\n\u003e - Use the [reference documentation](https://www.graalvm.org/22.0/docs/getting-started/#install-graalvm) to install **GraalVM**\n\u003e\n\u003e - Validate your installation with\n\u003e\n\u003e ```bash\n\u003e lli --version\n\u003e gu --version\n\u003e ```\n \n### 2.2 - Start `Gitpod`\n \n[Gitpod](https://www.gitpod.io/) is a Free IDE provided as Saas. He leverages [VS Code](https://github.com/gitpod-io/vscode/blob/gp-code/LICENSE.txt?lang=en-US) and comes loaded with all tools needed to develop with multiple languages.\n \n#### `✅.001`- _Right Click_ to open Gitpod in a new browser tab.\n \n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/datastaxdevs/conference-2022-devoxx)\n \n### 2.3 - Start Apache Cassandra™ cluster\n \nOnce gitpod has launched you should find a couple of terminals available. Locate `setup`, you will get this message.\n \n```\n------------------------------------------------------------\n---            Welcome to Devoxx  2022                   ---\n------------------------------------------------------------\n```\n \nℹ️ **Copy-Paste in Gitpod**\n\u003e For the first `copy-paste` within `Gitpod` you are invited to authorize them. Please do so to keep moving in the session.\n \nIn `setup` locate  `docker-compose.yml`. We will run the Cassandra  [official image™](https://hub.docker.com/_/cassandra/).\n \n#### `✅.002`- Open the file and visualize the file, check how `seed` service is isolated from others. Recommendation is one `seed` per rack (2 / 3 `seeds` per ring/dc)\n \n```bash\ngp open /workspace/conference-2022-devoxx/setup/docker-compose.yml\n```\n \n#### `✅.003`- Start first 2 nodes with `docker-compose`\n \n```bash\ncd /workspace/conference-2022-devoxx/setup/\ndocker-compose up -d\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e Creating network \"setup_cassandra\" with the default driver\n\u003e Creating setup_dc1_seed_1 ... done\n\u003e Creating setup_dc1_node_1 ... done\n\u003e ```\n \n#### `✅.004`- Display containers status with `docker`\n \n2 containers will start (services). The second one will wait 30s for the seed to bootstrap.\n \n```bash\ndocker ps\n```\n \n#### `✅.005`- Display containers status with `docker-compose`\n \n```bash\ndocker-compose ps\n```\n \n\u003e 🖥️ Results\n\u003e\n\u003e ```bash\n\u003e     Name                    Command               State                                        Ports\n\u003e --------------------------------------------------------------------------------------------------------------------------------------------\n\u003e setup_dc1_node_1    docker-entrypoint.sh /bin/ ...   Up      7000/tcp, 7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp\n\u003e setup_dc1_seed_1    docker-entrypoint.sh cassa ...   Up      7000/tcp, 7001/tcp, 7199/tcp, 0.0.0.0:9042-\u003e9042/tcp,:::9042-\u003e9042/tcp, 9160/tcp\n\u003e ```\n \n#### `✅.006`- Save `seed` container id\n \nIn order for us to use tools like `cqlsh` and `nodetool` we have to access the container shell. here we save container id to ease future commands.\n \n```bash\nexport dc1_seed_containerid=`docker ps | grep dc1_seed | cut -b 1-12`\necho \"Seed container ID has been saved : $dc1_seed_containerid\"\n```\n \n#### `✅.007`- Display cluster with `nodetool`\n \n```\ndocker exec -it $dc1_seed_containerid nodetool status\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e Datacenter: dc1\n\u003e ===============\n\u003e Status=Up/Down\n\u003e |/ State=Normal/Leaving/Joining/Moving\n\u003e --  Address     Load       Tokens  Owns (effective)  Host \u003e ID                               Rack\n\u003e UN  172.28.0.2  69.05 KiB  16      100.0%8707bea1-ac47-4da0-9e96-5541d3e1431d  rack1\n\u003e UN  172.28.0.3  69.05 KiB  16      100.0%            25f43936-be10-471d-b8ac-7efe93834712  rack1\n\u003e ```\n \nWe expect nodes `states` to be `UN`(Up/Normal).\n \n### 2.4 - Scale the cluster up\n \n#### `✅.008`- Add a third node in the cluster (scale up of the non-seed node).\n \n```bash\ndocker-compose up --scale dc1_node=2 -d\n```\n \nThe command will also restart `dc1_node` unfortunately `docker-compose scale` is deprecated. We did not provide any volume so no harm also as the seed is still present the nodes wi.l synchronize.\n \nTo properly deploy Cassandra in Docker for a multi node configuration you should consider Kubernetes and particularly [k8ssandra.io](k8ssandra.io).\n \n\u003e 🖥️ `Result `\n\u003e ```\n\u003e gitpod /workspace/conference-2022-devoxx/setup (main) $ docker-compose up --scale dc1_node=2 -d\n\u003e [+] Running 3/3\n\u003e ⠿ Container setup-dc1_seed-1  Running                                                                                                                     0.0s\n\u003e ⠿ Container setup-dc1_node-2  Running                                                                                                                     5.3s\n\u003e ⠿ Container setup-dc1_node-1  Started                                                                                                                     5.3s\n\u003e ```\n\u003e.\n \n#### `✅.009`- Check Status\n \nWait about a minute for nodes to have time to properly join the cluster.\n \n```bash\ndocker exec -it $dc1_seed_containerid nodetool status\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e Datacenter: dc1\n\u003e ===============\n\u003e Status=Up/Down\n\u003e |/ State=Normal/Leaving/Joining/Moving\n\u003e --  Address     Load       Tokens  Owns (effective)  Host \u003e ID                               Rack\n\u003e UN  172.28.0.2  69.05 KiB  16      100.0%8707bea1-ac47-4da0-9e96-5541d3e1431d  rack1\n\u003e UN  172.28.0.3  69.05 KiB  16      100.0%            25f43936-be10-471d-b8ac-7efe93834712  rack1\n\u003e UN  172.28.0.4  69.06 KiB  16      76.0%             fe43b0d0-952b-48ec-86e1-d73ace617dc8  rack1\n\u003e ```\n \n### 2.5 - Create keyspace\n \n#### `✅.010`- Open REPL CQLSH\n \nThis tool is available as part of Cassandra installation.  `C.Q.L` stands for _Cassandra Query Language_ and `sh` for shell.\n \n```bash\ndocker exec -it $dc1_seed_containerid cqlsh\n```\n \n#### `✅.011`- Display local node informations\n \nTable `system.local` contains information relative to the current node (here `dc1_seed`).\n \n```sql\nselect cluster_name,data_center,rack,broadcast_address\nfrom system.local;\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e  cluster_name | data_center | rack  | broadcast_address\n\u003e --------------+-------------+-------+-------------------\n\u003e       handson |         dc1 | rack1 |        172.28.0.2\n\u003e\n\u003e (1 rows)\n\u003e ```\n \n#### `✅.012`- Display information for the 2 others nodes\n \nInformation for other nodes are stored in `system.peers`.\n \n```sql\nselect data_center,rack,peer\nfrom system.peers;\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e cqlsh\u003e select data_center,rack,peer from system.peers;\n\u003e\n\u003e data_center | rack  | peer\n\u003e -------------+-------+------------\n\u003e         dc1 | rack1 | 172.28.0.4\n\u003e         dc1 | rack1 | 172.28.0.3\n\u003e\n\u003e (2 rows)\n\u003e ```\n \n#### `✅.013`- Keyspace creation\n \nA Keyspace is a logical grouping of objects. Best practice is to create a keyspace per application.\n \nA single application can work with multiple `keyspaces` within the same session. It can be useful if some data needs to be replicated in different manners (the replication factor is per keyspace).\n \nLet's create the keyspace `devoxx`.\n \n```sql\nCREATE KEYSPACE IF NOT EXISTS devoxx\nWITH REPLICATION = {\n 'class' : 'NetworkTopologyStrategy',\n 'dc1' : 3\n}  AND DURABLE_WRITES = true;\n \nCREATE KEYSPACE IF NOT EXISTS devoxx_drivers\nWITH REPLICATION = {\n 'class' : 'NetworkTopologyStrategy',\n 'dc1' : 3\n}  AND DURABLE_WRITES = true;\n \nCREATE KEYSPACE IF NOT EXISTS devoxx_spring\nWITH REPLICATION = {\n 'class' : 'NetworkTopologyStrategy',\n 'dc1' : 3\n}  AND DURABLE_WRITES = true;\n \nCREATE KEYSPACE IF NOT EXISTS devoxx_quarkus\nWITH REPLICATION = {\n 'class' : 'NetworkTopologyStrategy',\n 'dc1' : 3\n}  AND DURABLE_WRITES = true;\n \nCREATE KEYSPACE IF NOT EXISTS devoxx_micronaut\nWITH REPLICATION = {\n 'class' : 'NetworkTopologyStrategy',\n 'dc1' : 3\n}  AND DURABLE_WRITES = true;\n```\n \n⁉️ `NetworkTopologyStrategy`\n \n\u003e `NetworkTopologyStrategy` will always be used except for tests with a single node. Under those conditions you will use `SimpleReplicationStrategy`.\n\u003e\n\u003e ```sql\n\u003e CREATE KEYSPACE IF NOT EXISTS test_simple_strategy\n\u003e WITH REPLICATION = {\n\u003e   'class' : 'SimpleStrategy',\n\u003e   'replication_factor': '1'\n\u003e } AND DURABLE_WRITES = true;\n\u003e ```\n \n⁉️ `DURABLE_WRITES`\n \n\u003e In Cassandra write path, Data will be written first into memory  (`memtable`). Then data is _flushed_  on disk into immutable files (SSTABLE). This will happen whether by vacation or when a threshold in memory is reached.\n\u003e\n\u003e Using `DURABLE_WRITES = true` is a way to enable `commit log`: before writing into memory data will be persisted in an already open file on disk. It will prevent the loss of data if something goes wrong before data in memory is flushed. `True` is the default value.\n \n#### `✅.014`- List keyspaces\n \n- In Cqlsh:\n```sql\ndescribe keyspaces;\n```\n \n\u003e 🖥️ Result\n\u003e\n\u003e ```\n\u003e devoxx            devoxx_quarkus  system_auth         system_traces       \n\u003e devoxx_drivers    devoxx_spring   system_distributed  system_views        \n\u003e devoxx_micronaut  system          system_schema       system_virtual_schema\n\u003e ```\n \n## 3. Connectivity\n \n### 3.1 - Introduction to Driver\n \n_This placeholder mark a moment to pay attention to the speaker_\n![](img/title_introduction-to-drivers.png)\n \n### 3.2 - Connect with drivers\n \n- Check project `lab-cassandra-drivers` configuration file `pom.xml`\n \n```\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/pom.xml\n```\n \n#### `✅.015`- Run  `E00_TestConnectivityTest`\n \n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E00_ConnectivityTest.java\nmvn test -Dtest=com.datastax.devoxx.E00_ConnectivityTest\n```\n \n### 3.3 - Drivers Configuration\n \n- Check project `lab-cassandra-drivers` configuration file `application.conf`\n \n```\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/main/resources/application.conf\n```\n \n## 4. Data Distribution\n \n_This placeholder mark a moment to pay attention to the speaker_\n![](img/title_data-distribution.png)\n \n## 5. Working with CQL\n \n### 5.1 - Understanding table keys\n \n_This placeholder mark a moment to pay attention to the speaker_\n![](img/title_getting-started-with-table-key.png)\n \n### 5.2 - Schema Definition\n \nWe keep using `cqlsh` to illustrate what have been seen so far\n \n#### `✅.016`- list Keyspaces\n \nCheck that `devoxx` is one of the keyspace\n \n _In shell setup:bash_\n\n```sql\ndescribe KEYSPACES;\n```\n \n#### `✅.017`- Select keyspace `devoxx`\n \n```sql\nuse devoxx;\n```\n \n#### `✅.018`-  List Tables in keyspaces `devoxx`\n \nNo suspense, the schema is empty\n \n```sql\ndesc tables;\n```\n \n#### `✅.019`- Create your first table\n \n```sql\nCREATE TABLE IF NOT EXISTS city_by_country (\n country     text,\n city        text,\n population  int,\n PRIMARY KEY ((country), city)\n);\n```\n \n#### `✅.020`-  `E01_CreateSchemaTest.java`\n \n_In shell tests:bash_\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E01_CreateSchemaTest.java\nmvn test -Dtest=com.datastax.devoxx.E01_CreateSchemaTest\n```\n \n### 5.3 - CRUD Operations\n \n#### `✅.021`- Insert a few rows\n \n```sql\nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Paris', 2187526);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Marseille', 863310);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Lyon', 516092);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Toulouse', 479553);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Nice', 340017);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Nantes', 309346);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Montpellier', 285121);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Strasbourg', 280966);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Bordeaux', 254436);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Lille', 232787);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Rennes', 216815);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Reims', 182460);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Saint-Etienne', 172565);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Toulon', 171953);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Le Havre', 170147);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Grenoble', 158454);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Dijon', 156920);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Angers', 150610);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Saint-Denis', 147931);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Villeurbanne', 147712);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Clermont-Ferrand', 143886);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Le Mans', 142946);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Aix-en-Provence', 142482);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Brest',  140064);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Tours', 135787);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Amiens', 134057);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Limoges', 132175);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Annecy', 126924);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Perpignan', 120158);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('USA','New York', 8000000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('USA','Los Angeles', 4000000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('DE','Berlin', 3350000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('UK','London', 9200000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('AU','Sydney', 4900000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('DE','Nuremberg', 500000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('CA','Toronto', 6200000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('CA','Montreal', 4200000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('JP','Tokyo', 37430000);\n \nINSERT INTO city_by_country(country, city, population)\nVALUES('IN','Mumbai', 20200000);\n```\n \n#### `✅.022`- List records in table\n \n```sql\nselect * from city_by_country;\n```\n \n#### `✅.023`- List french cities\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to display solution\u003c/summary\u003e\n \n```sql\nselect * from city_by_country\nWHERE country='FR';\n```\n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.024`- List cities for country `CA` or `DE` using `IN`\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to display solution\u003c/summary\u003e\n \n```sql\nselect * FROM city_by_country\nWHERE country IN('CA', 'DE');\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.025`- Search for city `Brest` (in France `FR`)\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n \n```sql\nselect * from city_by_country\nWHERE country='FR'\nAND city='Brest';\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.026`- Search for french cities where first letter is `P`\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n\n```sql\nSELECT * FROM city_by_country\nWHERE country='FR'\nAND city\u003e'P';\n```\n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.027`- Update Brest population to `142000` inhabitants\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n \n*with Update statement*\n```sql\nupdate city_by_country\nSET population=142000\nWHERE country='FR'\nAND city='Brest';\n```\n \n*with Insert (as any insert is also an upset)*\n```sql\nINSERT INTO city_by_country(country, city, population)\nVALUES('FR','Brest',  142000);\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.028`- Delete row with city of `Tokyo`\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n \n```sql\nDELETE FROM city_by_country\nWHERE country='JP'\nAND city='Tokyo';\n```\n \n*Check:*\n```sql\nselect * from city_by_country\nWHERE country='JP';\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \nℹ️ **Note**:\n\u003e When you delete a record in Cassandra it is not really deleted on disk, it creates a marker called a  `Tombstone` that needs to be cleaned during an operation called compaction. If you miss some space on disk, deleting here is not a good solution.\n \n#### `✅.029`- Delete rows related to country Canada `(CA)`\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n \n```sql\nDELETE FROM city_by_country\nWHERE country='CA';\n```\n \n*Vérification:*\n```sql\nselect * from city_by_country\nWHERE country='CA';\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \n#### `✅.030`- Delete row for country `AU` and city `Sydney`\n \n\u003cp/\u003e\n\u003cdetails\u003e\n\u003csummary\u003eClick to show solution\u003c/summary\u003e\n \n```sql\nDELETE population\nFROM city_by_country\nWHERE country='AU'\nAND city='Sydney';\n```\n \n*Vérification:*\n```sql\nSELECT * from city_by_country\nWHERE country='AU';\n```\n \n\u003c/details\u003e\n\u003cp/\u003e\n \n⚠️ **Important**\n\u003e ```\n\u003e It is possible to do it, it is not recommended, it will move\n\u003e the load from the client application the coordinator, issue\n\u003e parallel request if you have to do it (N+1 select)\n\u003e ```\n \n#### `✅.031`- Use `GROUP BY` and average function `AVG`\n \n- Show average population grouped by country\n \n```sql\nSELECT country, AVG(CAST(population AS FLOAT)) AS avg_population\nFROM city_by_country\nGROUP BY country;\n```\n \n#### `✅.032`- Use `GROUP BY` and function `COUNT`\n \n- Show number of cities per country\n \n```sql\nSELECT country, count(city) as nb_villes\nFROM city_by_country\nGROUP BY country;\n```\n \n#### `✅.033`- Clean the table\n \nTo avoid creating tombstones we will use `TRUNCATE` instead of `DELETE`.\n \n```sql\nTRUNCATE city_by_country;\n```\n \n### `✅.034`- Execute statements with Java\n \n_In terminal `tests:bash`_\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E02_StatementsTest.java\nmvn test -Dtest=com.datastax.devoxx.E02_StatementsTest\n```\n \n### `✅.035`- Create read update Delete\n \n_In terminal `tests:bash`_\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E03_OperationsCrudTest.java\nmvn test -Dtest=com.datastax.devoxx.E03_OperationsCrudTest\n```\n \n## 5.4 - Advanced Data Types\n \nThere a lot of different simple scalar types in CQL : `VARCHAR`, `ASCII`, `TINYINT`, `SMALLINT`, `INT`, `BIGINT`, `VARINT`, `FLOAT`, `DOUBLE`, `DECIMAL`, `TIME`, `TIMESTAMP`, `DATE`, `DURATION`, `BOOLEAN`, `BLOB`, et `INET`. Here is the [complete list](https://docs.datastax.com/en/cql-oss/3.x/cql/cql_reference/cql_data_types_c.html).\n \n#### `✅.036`- Working with `UUID`\n \n_Back to terminal `setup:bash`_\n\n```sql\ndrop table if exists users;\nCREATE TABLE IF NOT EXISTS users (\n id UUID,\n name TEXT,\n age INT,\n PRIMARY KEY ((id))\n);\n \nINSERT INTO users (id, name, age)\nVALUES (7902a572-e7dc-4428-b056-0571af415df3, 'Joe', 25);\n \nINSERT INTO users (id, name, age)\nVALUES (uuid(), 'Jen', 27);\n \nSELECT * FROM users;\n```\n \n#### `✅.037`- Working with `SET`\n \n```sql\ndrop table if exists movies;\nCREATE TABLE movies (\n id UUID,\n title TEXT,\n year INT,\n duration INT,\n PRIMARY KEY ((id))\n);\n \nINSERT INTO movies (id, title, year, duration)\nVALUES (5069cc15-4300-4595-ae77-381c3af5dc5e,\n'Alice au pays des Merveilles', 2010, 108);\n \nINSERT INTO movies (id, title, year, duration)\nVALUES (uuid(), 'Alice', 1951, 75);\n \nALTER TABLE movies\nADD production SET\u003cTEXT\u003e;\n \nUPDATE movies\nSET production = { 'Walt Disney Pictures',\n                  'Roth Films' }\nWHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;\n \nUPDATE movies\nSET production = production + { 'Team Todd' }\nWHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;\n \nSELECT title, year, production FROM movies;\n```\n \n#### `✅.038`- Working with `LIST`\n \n```sql\nALTER TABLE users\nADD searches LIST\u003cTEXT\u003e;\n \nUPDATE users\nSET searches = [ 'Alice au pays des merveilles' ]\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nUPDATE users\nSET searches = searches + [ 'Comedies' ]\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nUPDATE users\nSET searches = searches + [ 'Alice au pays des merveilles' ]\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nSELECT id, name, searches FROM users;\n \n```\n \n#### `✅.039`- Working with `MAP`\n \n```sql\nALTER TABLE users ADD sessions MAP\u003cTIMEUUID,INT\u003e;\nSELECT name, sessions FROM users;\n \nUPDATE users\nSET sessions = { now(): 32, e22deb70-b65f-11ea-9aac-99396fc4f757: 7 }\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nSELECT name, sessions FROM users;\n \nUPDATE users\nSET sessions[e22deb70-b65f-11ea-9aac-99396fc4f757] = 9\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nSELECT name, sessions FROM users;\n \nALTER TABLE movies\nADD crew MAP\u003cTEXT,FROZEN\u003cLIST\u003cTEXT\u003e\u003e\u003e;\nSELECT title, year, crew FROM movies;\n \nUPDATE movies\nSET crew = {\n 'cast': ['Johnny Depp', 'Mia Wasikowska'],\n 'directed by': ['Tim Burton']\n}\n \nWHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;\nSELECT title, year, crew FROM movies;\n```\n \n#### `✅.040`- Working with `TUPLES`\n \n```sql\nALTER TABLE users ADD full_name TUPLE\u003cTEXT,TEXT,TEXT\u003e;\n \nUPDATE users\nSET full_name = ('Joe', 'The', 'Great')\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nSELECT name, full_name FROM users;\n```\n \n#### `✅.041`- Working with `UDT`\n \n```sql\nCREATE TYPE IF NOT EXISTS ADDRESS (\n   street  TEXT,\n   city    TEXT,\n   state   TEXT,\n   zipcode INT\n);\n \nALTER TABLE users ADD address ADDRESS;\nSELECT name, address FROM users;\n \nUPDATE users\nSET address = { street: '1100 Congress Ave',\n               city: 'Austin',\n               state: 'Texas',\n               zipcode: 78701 }\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nSELECT name, address FROM users\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n \nUPDATE users\nSET address.state = 'TX'\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\nSELECT name,\n      address.street      AS street,\n      address.city        AS city,\n      address.state       AS state,\n      address.zipcode     AS zip\nFROM users\nWHERE id = 7902a572-e7dc-4428-b056-0571af415df3;\n```\n \n#### `✅.042`- Execute List, Set, Map, Udt\n \n_In terminal `tests:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E04_ListSetMapAndUdtTest.java\nmvn test -Dtest=com.datastax.devoxx.E04_ListSetMapAndUdtTest\n```\n \n#### `✅.043`- Working with counters\n \n _In terminal `setup:bash`_\n\n```sql\n-- Create dedicated table\nCREATE TABLE movie_stats (\n id UUID,\n num_ratings COUNTER,\n sum_ratings COUNTER,\n PRIMARY KEY ((id))\n);\n \n-- Insert a record with num_ratings=1  and sum_ratings=7\nUPDATE movie_stats\nSET num_ratings = num_ratings + 1,\n   sum_ratings = sum_ratings + 7\nWHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;\n \n-- num_ratings+=1 et sum_ratings+=7\nUPDATE movie_stats\nSET num_ratings = num_ratings + 1,\n   sum_ratings = sum_ratings + 9\nWHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;\n \nSELECT * FROM movie_stats;\n```\n \n#### `✅.044`- Works with counters in JAVA\n \n  _In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E05_CountersTest.java\nmvn test -Dtest=com.datastax.devoxx.E05_CountersTest\n```\n \n#### `✅.045`- Working with `JSON`\n \n\n_In terminal `setup:bash`_\n\n```sql\nCREATE TYPE IF NOT EXISTS video_format (\n width   int,\n height  int\n);\n \nCREATE TABLE IF NOT EXISTS videos (\nvideoid   uuid,\ntitle     text,\nupload    timestamp,\nemail     text,\nurl       text,\ntags      set \u003ctext\u003e,\nframes    list\u003cint\u003e,\nformats   map \u003ctext,frozen\u003cvideo_format\u003e\u003e,\nPRIMARY KEY (videoid)\n);\n \nINSERT INTO videos(videoid, email, title, upload, url, tags, frames, formats)\nVALUES(uuid(), 'clu@sample.com', 'sample video',\n    toTimeStamp(now()), 'http://google.fr',\n    { 'cassandra','accelerate','2020'},\n    [ 1, 2, 3, 4],\n    { 'mp4':{width:1,height:1},'ogg':{width:1,height:1}});\n \nINSERT INTO videos(videoid, email, title, upload, url)\nVALUES(uuid(), 'clu@sample.com', 'video2', toTimeStamp(now()), 'http://google.fr');\n \nselect videoid, email, title from videos;\n \nINSERT INTO videos JSON '{\n  \"videoid\":\"e466f561-4ea4-4eb7-8dcc-126e0fbfd573\",\n    \"email\":\"clunven@sample.com\",\n    \"title\":\"A video inserted with JSON\",\n    \"upload\":\"2020-02-26 15:09:22 +00:00\",\n    \"url\": \"http://google.fr\",\n    \"frames\": [1,2,3,4],\n    \"tags\":   [ \"cassandra\",\"accelerate\", \"2020\"],\n    \"formats\": {\n       \"mp4\": {\"width\":1,\"height\":1},\n       \"ogg\": {\"width\":1,\"height\":1}\n    }\n}';\n \nselect JSON * from videos\nWHERE videoid=e466f561-4ea4-4eb7-8dcc-126e0fbfd573;\n```\n \n#### `✅.046`- With Java\n \n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E06_JsonTest.java\nmvn test -Dtest=com.datastax.devoxx.E06_JsonTest\n```\n \n### 5.5 - Advanced Concepts\n \n#### `✅.047`- Working with `Batches`\n \n- Single Partition\n \n```sql\nCREATE TABLE shopping_cart (\n cart_id   UUID,\n title     TEXT,\n year      INT,\n price     DECIMAL,\n user      TEXT STATIC,\n total     DECIMAL STATIC,\n PRIMARY KEY ((cart_id), title, year)\n);\n \nBEGIN BATCH\n INSERT INTO shopping_cart\n        (cart_id, title, year, price, user)\n VALUES (b7255608-4a42-4829-9b84-a355e0e5100d,\n        'Alice au pays des merveilles', 2010, 1.99,\n        'joe@datastax.com');\n \n INSERT INTO shopping_cart\n        (cart_id, title, year, price, user)\n VALUES (b7255608-4a42-4829-9b84-a355e0e5100d,\n        'Alice', 1951, 0.99,\n        'joe@datastax.com');\n \n INSERT INTO shopping_cart (cart_id, total)\n VALUES (b7255608-4a42-4829-9b84-a355e0e5100d, 2.98)\n IF NOT EXISTS;\nAPPLY BATCH;\n \nSELECT total, price, title, year\nFROM shopping_cart\nWHERE cart_id = b7255608-4a42-4829-9b84-a355e0e5100d;\n```\n \n#### `✅.048`- Multiple partitions\n \n```sql\nCREATE TABLE  IF NOT EXISTS ratings_by_user (\n email TEXT,\n title TEXT,\n year INT,\n rating INT,\n PRIMARY KEY ((email), title, year)\n);\n \nCREATE TABLE  IF NOT EXISTS ratings_by_movie (\n title TEXT,\n year INT,\n email TEXT,\n rating INT,\n PRIMARY KEY ((title, year), email)\n);\n \nBEGIN BATCH\n INSERT INTO ratings_by_user (email, title, year, rating)\n VALUES ('joe@datastax.com', 'Alice aux pays des merveilles', 2010, 9);\n INSERT INTO ratings_by_movie (email, title, year, rating)\n VALUES ('joe@datastax.com', 'Alice aux pays des merveilles', 2010, 9);\nAPPLY BATCH;\n \nBEGIN BATCH\n UPDATE ratings_by_user SET rating = 10\n WHERE email = 'joe@datastax.com'\n   AND title = 'Alice aux pays des merveilles'\n   AND year  = 2010;\n UPDATE ratings_by_movie SET rating = 10\n WHERE email = 'joe@datastax.com'\n   AND title = 'Alice aux pays des merveilles'\n   AND year  = 2010;\nAPPLY BATCH;\n```\n \n#### `✅.049`- With Java\n \n _In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E07_BatchesTest.java\nmvn test -Dtest=com.datastax.devoxx.E07_BatchesTest\n```\n \n#### `✅.050`- Consistency LEVEL\n \nAs of we do have a single datacenter `dc1`  with 3 nodes like the picture below\n \n![my-pic](img/cluster-docker.png?raw=true)\n \n- Execute the following\n \n```sql\nCONSISTENCY;\n```\n\n```sql\nCONSISTENCY LOCAL_QUORUM;\nTRACING ON;\n SELECT country,city, population\nFROM city_by_country\nWHERE country='DE';\n```\n\n```sql\nCONSISTENCY ONE;\nSELECT country,city, population\nFROM city_by_country\nWHERE country='DE';\nCONSISTENCY LOCAL_QUORUM;\nTRACING OFF;\n```\n \n#### `✅.051`- LightWeight Transactions (LWT)\n \n- Insert only once with `IF NOT EXISTS`\n\n```sql\nCREATE TABLE sample_lwt (\n username TEXT,\n email TEXT,\n name TEXT,\n password TEXT,\n reset_token UUID,\n PRIMARY KEY ((username))\n);\n \nINSERT INTO sample_lwt (username, email, name)\nVALUES ('dragonslayer', 'joe@datastax.com', 'Joe')\nIF NOT EXISTS;\n \nINSERT INTO sample_lwt (username, email, name)\nVALUES ('dragonslayer', 'jen@datastax.com', 'Jen')\nIF NOT EXISTS;\n \nSELECT * FROM sample_lwt\nWHERE username = 'dragonslayer';\n```\n \n#### `✅.052`- Password Reset\n \n```sql\nUPDATE sample_lwt\nUSING TTL 3600\nSET reset_token = 6ef95fd0-9ae0-11ea-a9d2-d777ab7dec9e\nWHERE username = 'devoxx_developer';\n \nSELECT * FROM sample_lwt\nWHERE username = 'devoxx_developer';\n```\n\n```sql\nUPDATE sample_lwt\nSET reset_token = null, password = 'encrypted password'\nWHERE username = 'devoxx_developer'\nIF reset_token = 6ef95fd0-9ae0-11ea-a9d2-d777ab7dec9e;\n\nSELECT * FROM sample_lwt\nWHERE username = 'devoxx_developer';\n```\n\n```sql\nUPDATE sample_lwt\nSET reset_token = null, password = 'malicious password'\nWHERE username = 'devoxx_developer'\nIF reset_token = 6ef95fd0-9ae0-11ea-a9d2-d777ab7dec9e;\n\nSELECT * FROM sample_lwt\nWHERE username = 'devoxx_developer';\n```\n \n#### `✅.053`- Coding LightWeight transactions\n \n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E08_LightweightTransactionsTest.java\nmvn test -Dtest=com.datastax.devoxx.E08_LightweightTransactionsTest\n```\n \n#### `✅.054`- Coding Paging with drivers\n \n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E09_ResultPagingTest.java\nmvn test -Dtest=com.datastax.devoxx.E09_ResultPagingTest\n```\n \n#### `✅.055`- Asynchronous Programming\n \n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E10_AsynchronousProgrammingTest.java\nmvn test -Dtest=com.datastax.devoxx.E10_AsynchronousProgrammingTest\n```\n \n#### `✅.056`- Reactive Programming\n\n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E11_ReactiveProgrammingTest.java\nmvn test -Dtest=com.datastax.devoxx.E11_ReactiveProgrammingTest\n```\n \n#### `✅.057`- Object Mapping\n \n_In terminal `test:bash`_\n\n```\ncd /workspace/conference-2022-devoxx/lab-cassandra-drivers\ngp open /workspace/conference-2022-devoxx/lab-cassandra-drivers/src/test/java/com/datastax/devoxx/E12_ObjectMappingTest.java\nmvn test -Dtest=com.datastax.devoxx.E12_ObjectMappingTest\n```\n \n## 6. Data Modeling\n \n### 6.1 - Data Model Methodology\n \n_This placeholder mark a moment to pay attention to the speaker_\n\n![](img/title_data-modeling-methodology.png)\n \n### 6.2 - Data Modeling in action\n\n\u003e [Datastax Academy by sample](https://www.datastax.com/learn/data-modeling-by-example)\n \n[![Open in KataPod](https://github.com/DataStax-Academy/katapod-shared-assets/blob/main/images/open-in-katapod.png)](https://gitpod.io/#https://github.com/DataStax-Academy/data-modeling-sensor-data/)\n \n### 6.3 - From SQL to NoSQL Migration\n \n_This placeholder mark a moment to pay attention to the speaker_\n![](img/title_migrating-sql-to-nosql.png)\n \n# 7. Working with Spring Framework\n\n![](img/title_spring.png)\n\n## 7.1 - Spring Data Connection and Configuration\n \n#### `✅.058`- Check Setup and keyspace `devoxx_spring`\n \n```sql\ndescribe keyspace devoxx_spring;\nuse devoxx_spring;\n```\n \n- Version Support\n \n\u003e | Drivers       | Spring-Data      | Spring Boot      |\n\u003e | ------------- | ---------------- | ---------------- |\n\u003e | Drivers `3.x` | `2.2` and before | `2.2` and before |\n\u003e | Drivers `4.x` | `3.x` and after  | `2.3` and before |\n\u003e | Drivers `4.x` | `4.x` and after  | `3.x` and before |\n \n```xml\n\u003cdependency\u003e\n \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n \u003cartifactId\u003espring-boot-starter-data-cassandra\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\nmvn clean compile\n```\n\n```bash\ngp open /workspace/conference-2022-devoxx/lab-spring/src/main/resources/application.yml\n```\n \n_application.yml_\n \n```yaml\nspring:\n  cassandra:\n    schema-action: create-if-not-exists\n    keyspace-name: devoxx_spring\n    contact-points: 127.0.0.1:9042\n    local-datacenter: dc1\n    request:\n      timeout: 5s\n      consistency: LOCAL_QUORUM\n      page-size: 5000\n    connection:\n      connect-timeout: 10s\n      init-query-timeout: 10s\n    controlconnection:\n      timeout: 10s\n```\n \n#### `✅.059`- Validate configuration\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\ngp open /workspace/conference-2022-devoxx/lab-spring/src/test/java/com/datastax/todo/E01_SpringDataInitTest.java\nmvn test -Dtest=com.datastax.todo.E01_SpringDataInitTest\n```\n \n## 7.2 - `CassandraRepository` and `CrudRepository\n \n```sql\ndescribe table todos;\n```\n \n#### `✅.060`- Using spring data  `CrudRepository`\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\ngp open /workspace/conference-2022-devoxx/lab-spring/src/test/java/com/datastax/todo/E02_SpringDataRepositoryTest.java\nmvn test -Dtest=com.datastax.todo.E02_SpringDataRepositoryTest\n```\n \n```sql\nuse devoxx_spring;\nSELECT * FROM todos;\n```\n \n## 7.3 - `CassandraOperations`\n \n#### `✅.061`- Using spring data  `CassandraOperations`\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\ngp open /workspace/conference-2022-devoxx/lab-spring/src/test/java/com/datastax/todo/E03_SpringDataCassandraOperationsTest.java\nmvn test -Dtest=com.datastax.todo.E03_SpringDataCassandraOperationsTest\n```\n \n## 7.4 - Spring Boot (mvc, Webflux)\n \n#### `✅.062`- Start application with  `spring-boot` plugin\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\nmvn spring-boot:run\n```\n \n![](img/spring_api_local.png?raw=true)\n \n```bash\ngp url 8080\n```\n \n- Show list of todos `todos`\n \n```\ngp preview \"$(gp url 8080)/api/v1/todos/\"\n```\n \n![](img/spring_api_gitpod.png?raw=true)\n \n```\nhttp://localhost:8080/api/v1/todos/\n```\n \n#### `✅.063`- Integration Test\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-spring\ngp open /workspace/conference-2022-devoxx/lab-spring/src/test/java/com/datastax/todo/E04_SpringControllerTest.java\nmvn test -Dtest=com.datastax.todo.E04_SpringControllerTest\n```\n \n### 7.5 - Spring Native\n \n#### `✅.064`- Compile Native version\n \n```\nmvn clean package -Pnative\n```\n \n#### `✅.065`- Run Native version\n \n```\n./target/lab-spring\n```\n \n# 8. Working with Quarkus\n\n![](img/title_quarkus.png)\n \n## 8.1 - Quarkus extension\n \n[Quarkus](https://quarkus.io/) is a framework to build microservice on Java Platform. Purpose is to execute a maximum of actions at build time and package only what is needed. Main objectives are:\n \n- Producing a native image with about a few megabytes only\n- Producing a native image that can start in a few millis\n \nA [Quarkus extension](https://quarkus.io/guides/writing-extensions) eases applications configuration and integration with third parties. The Datastax team created an extension for Cassandra [available here](https://github.com/datastax/cassandra-quarkus). Here are the underlying featuresL\n \n- Reactive support of `Mutiny` (reactive layer in Quarkus)\n- Integration with `vertx` and Quarkus event loop\n- Declare Mappers in `Arc`, the dependency injection layer in Quarkus.\n- Provide hints for the creation native image _aux petits oignons._\n \n`cassandra-quarkus-client` is available on central maven[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.datastax.oss.quarkus/cassandra-quarkus-client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.datastax.oss.quarkus/cassandra-quarkus-client)\n \n \n```xml\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.datastax.oss.quarkus\u003c/groupId\u003e\n \u003cartifactId\u003ecassandra-quarkus-client\u003c/artifactId\u003e\n \u003cversion\u003e${latest}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n \nDocumentation for Cassandra support in Quarkus can be found [here](https://quarkus.io/guides/cassandra)\n \n## 8.2 - Application Walkthrough\n \n#### `✅.066`- Check Setup and keyspace `devoxx_spring`\n \n```sql\ndescribe keyspace devoxx_quarkus\nuse devoxx_quarkus;\n```\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn clean compile\n```\n \n#### `✅.067`- Validate configuration\n \n```bash\ngp open /workspace/conference-2022-devoxx/lab-quarkus/src/main/resources/application.properties\n```\n \n```\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn test -Dtest=com.datastax.workshop.E01_QuarkusInit\n```\n \n#### `✅.068` - Using `CqlSession` with `Quarkus`\n \n```\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn test -Dtest=com.datastax.workshop.E02_QuarkusCql\n```\n \n#### `✅.069` - Using `Quarkus` object mapping `ARC`  with Quarkus\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn test -Dtest=com.datastax.workshop.E03_QuarkusObjectMapping\n```\n \n#### `✅.070` - Start `Quarkus` application\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn quarkus:dev -DskipTests\n```\n \n```bash\ngp preview \"$(gp url 8081)/q/dev\"\n```\n \n```\nhttp://localhost:8081/q/dev/\n```\n_Dashboard_\n![](img/quarkus-dashboard.png?raw=true)\n \n- Multiple plugins are provided out of the box like `swagger-ui` to test our API in a browser\n \n```bash\ngp preview \"$(gp url 8081)/q/swagger-ui\"\n```\n \n```\nhttp://localhost:8081/q/swagger-ui\n```\n \n![](img/quarkus-swagger.png?raw=true)\n \n \n#### `✅.071` - Integration Test with `Quarkus`\n \nStop the application using `q`. Launch integration tests\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-quarkus\nmvn test -Dtest=com.datastax.workshop.E04_QuarkusController\n```\n \n### 8.3 - Native Image\n \n#### `✅.072` - Build native image with  `Quarkus`\n \n```\nmvn clean package -Pnative\n```\n \n#### `✅.073` - Run the Quarkus native image\n \n```\n.target/lab-quarkus-0.0.1-SNAPSHOT-runner\n```\n \nCheck health status.\n\n```bash\ngp preview \"$(gp url 8081)/q/health\"\ngp preview \"$(gp url 8081)/api/v1/clun/todos\"\n\n```\n \n# 9. Working with Micronaut\n \n![](img/title_micronaut.png)\n\n## 9.1 - Micronaut Philosophy\n \n## 9.2 - Application Walkthrough\n \n#### `✅.073` - list Keyspaces `devoxx_micronaut` should be there\n \n```bash\ndescribe keyspaces\n```\n \n\u003e 🖥️ `output`\n\u003e\n\u003e ```\n\u003e devoxx            devoxx_quarkus  system_auth         system_traces       \n\u003e devoxx_drivers    devoxx_spring   system_distributed  system_views        \n\u003edevoxx_micronaut  system          system_schema       system_virtual_schema\n\u003e```\n \n \n#### `✅.074` - Compile project\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn clean compile\n```\n \n#### `✅.075` - Testing project\n \n```\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn test -Dtest=com.datastaxdev.E01_MicronautInitTest\n```\n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO]  T E S T S\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO] Running com.datastaxdev.E01_MicronautInitTest\n\u003e 12:57:12.946 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 12:57:13.067 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 12:57:13.067 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e com.datastax.oss.driver.internal.core.session.DefaultSession@37854b34\n\u003e 12:57:13.108 [main] INFO  c.datastaxdev.E01_MicronautInitTest - Creating your CqlSession to Cassandra...\n\u003e 12:57:13.111 [main] INFO  c.datastaxdev.E01_MicronautInitTest - + [OK] Your are connected to keyspace ks_micronaut\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.677 s - in com.datastaxdev.E01_MicronautInitTest\n\u003e [INFO]\n\u003e [INFO] Results:\n\u003e [INFO]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0\n\u003e [INFO]\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] BUILD SUCCESS\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] Total time:  11.262 s\n\u003e [INFO] Finished at: 2022-10-04T12:57:15Z\n\u003e [INFO] ------------------------------------------------------------------------\n \n \n#### `✅.076` - Use CqlSession\n \n```\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn test -Dtest=com.datastaxdev.E02_MicronautCqlTest\n```\n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO]  T E S T S\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO] Running com.datastaxdev.E02_MicronautCqlTest\n\u003e 13:00:21.370 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 13:00:21.482 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 13:00:21.482 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e 13:00:22.372 [main] INFO  com.datastaxdev.E02_MicronautCqlTest - Creating the schema...\n\u003e 13:00:22.456 [main] INFO  com.datastaxdev.E02_MicronautCqlTest - + [OK]\n\u003e 13:00:22.457 [main] INFO  com.datastaxdev.E02_MicronautCqlTest - Inserting Data\n\u003e 13:00:22.552 [main] INFO  com.datastaxdev.E02_MicronautCqlTest - + [OK]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.28 s - in com.datastaxdev.E02_MicronautCqlTest\n\u003e [INFO]\n\u003e [INFO] Results:\n\u003e [INFO]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0\n\u003e [INFO]\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] BUILD SUCCESS\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] Total time:  11.441 s\n\u003e [INFO] Finished at: 2022-10-04T13:00:24Z\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e ```\n \n## 4.2 - Configuration\n \n#### `✅.077` - Object Mapping\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn test -Dtest=com.datastaxdev.E03_MicronautObjectMappingTest\n```\n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO]  T E S T S\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO] Running com.datastaxdev.E03_MicronautObjectMappingTest\n\u003e 13:02:03.705 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 13:02:03.810 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 13:02:03.810 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e 13:02:04.038 [main] INFO  c.d.E03_MicronautObjectMappingTest - Inserting Data\n\u003e 13:02:04.135 [main] INFO  c.d.E03_MicronautObjectMappingTest - + [OK]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 7.494 s - in com.datastaxdev.E03_MicronautObjectMappingTest\n\u003e [INFO]\n\u003e [INFO] Results:\n\u003e [INFO]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0\n\u003e [INFO]\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] BUILD SUCCESS\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] Total time:  10.433 s\n\u003e [INFO] Finished at: 2022-10-04T13:02:06Z\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e ```\n \n#### `✅.078` - Integration Tests\n \n- Run integration tests with the following.\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn test -Dtest=com.datastaxdev.E04_MicronautControllerTest\n```\n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO]  T E S T S\n\u003e [INFO] -------------------------------------------------------\n\u003e [INFO] Running com.datastaxdev.E04_MicronautControllerTest\n\u003e 13:10:03.322 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 13:10:03.431 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 13:10:03.431 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e 13:10:04.828 [main] INFO  c.d.E04_MicronautControllerTest - 12 task retrieved\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.811 s - in com.datastaxdev.E04_MicronautControllerTest\n\u003e [INFO]\n\u003e [INFO] Results:\n\u003e [INFO]\n\u003e [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0\n\u003e [INFO]\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] BUILD SUCCESS\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e [INFO] Total time:  12.778 s\n\u003e [INFO] Finished at: 2022-10-04T13:10:07Z\n\u003e [INFO] ------------------------------------------------------------------------\n\u003e ```\n \n## 4.3 - Micronaut Application\n \n#### `✅.079` - Start the application\n \n```bash\ncd /workspace/conference-2022-devoxx/lab-micronaut/\nmvn mn:run -DskipTests\n```\n \n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e  __  __ _                                  _  \n\u003e |  \\/  (_) ___ _ __ ___  _ __   __ _ _   _| |_\n\u003e | |\\/| | |/ __| '__/ _ \\| '_ \\ / _` | | | | __|\n\u003e | |  | | | (__| | | (_) | | | | (_| | |_| | |_\n\u003e |_|  |_|_|\\___|_|  \\___/|_| |_|\\__,_|\\__,_|\\__|\n\u003e   Micronaut (v3.7.1)\n\u003e\n\u003e 13:06:15.990 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 13:06:16.096 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 13:06:16.096 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e\n\u003e ```\n \n#### `✅.080` - Show the Apis\n \n- Open the application API on port `8082`\n \n```bash\ngp preview \"$(gp url 8082)/api/v1/clun/todos/\"\n```\n \n![out](img/micronaut-output.png)\n \n## 4.4 - Native Image\n \n#### `✅.081` - Build native image\n \n\u003e **[Documentation](https://docs.micronaut.io/latest/guide/index.html#graal)**\n\n \n- Compile with proper packaging\n \n```\nmvn package -Dpackaging=native-image -Pgraalvm -DskipTests\n```\n \n- Then\n \n```\nnative-image --no-server -cp ./target/lab-micronaut-0.1.0-SNAPSHOT.jar com.datastaxdev.TodoApplication target/todo-micronaut\n```\n \n#### `✅.082` - Run native image\n \n```\n./target/todo-micronaut\n```\n \n\u003e 🖥️ `OUTPUT`\n\u003e ```\n\u003e  __  __ _                                  _  \n\u003e |  \\/  (_) ___ _ __ ___  _ __   __ _ _   _| |_\n\u003e | |\\/| | |/ __| '__/ _ \\| '_ \\ / _` | | | | __|\n\u003e | |  | | | (__| | | (_) | | | | (_| | |_| | |_\n\u003e |_|  |_|_|\\___|_|  \\___/|_| |_|\\__,_|\\__,_|\\__|\n\u003e  Micronaut (v3.7.1)\n\u003e\n\u003e 20:20:16.205 [main] INFO  c.datastaxdev.TodoApplicationStartup - Startup Initialization\n\u003e 20:20:16.208 [main] INFO  c.datastaxdev.TodoApplicationStartup - + Table TodoItems created if needed.\n\u003e 20:20:16.208 [main] INFO  c.datastaxdev.TodoApplicationStartup - [OK]\n\u003e```\n \n- Show the API\n \n```\ngp preview \"$(gp url 8082)/api/v1/clun/todos/\"\n```\n \n```\nhttp://localhost:8082/api/v1/clun/todos/\n```\n \n \n----\n# The End\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatastaxdevs%2Fconference-2022-devoxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatastaxdevs%2Fconference-2022-devoxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatastaxdevs%2Fconference-2022-devoxx/lists"}