├── hands-on ├── 4-sdk │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── static │ │ │ │ │ ├── js │ │ │ │ │ │ ├── base.js │ │ │ │ │ │ ├── codemirror-5.39.0 │ │ │ │ │ │ │ └── show-hint.css │ │ │ │ │ │ └── script.js │ │ │ │ │ ├── img │ │ │ │ │ │ ├── dhd.png │ │ │ │ │ │ ├── ico.jpg │ │ │ │ │ │ ├── banner.jpg │ │ │ │ │ │ ├── bodybg.png │ │ │ │ │ │ ├── pixel.gif │ │ │ │ │ │ ├── planet.jpg │ │ │ │ │ │ ├── space.jpeg │ │ │ │ │ │ ├── stargate.png │ │ │ │ │ │ ├── subnavbg.png │ │ │ │ │ │ ├── logo-header.png │ │ │ │ │ │ ├── logo_solr.png │ │ │ │ │ │ ├── logo_spark.png │ │ │ │ │ │ ├── datatable │ │ │ │ │ │ │ ├── sort_asc.png │ │ │ │ │ │ │ ├── sort_both.png │ │ │ │ │ │ │ ├── sort_desc.png │ │ │ │ │ │ │ ├── sort_asc_disabled.png │ │ │ │ │ │ │ └── sort_desc_disabled.png │ │ │ │ │ │ ├── glyphicons-halflings.png │ │ │ │ │ │ ├── glyphicons-halflings-white.png │ │ │ │ │ │ ├── BiodegradableUglyGallinule-size_restricted.gif │ │ │ │ │ │ └── chevrons │ │ │ │ │ │ │ ├── 24.svg │ │ │ │ │ │ │ ├── 38.svg │ │ │ │ │ │ │ ├── 35.svg │ │ │ │ │ │ │ ├── 36.svg │ │ │ │ │ │ │ ├── 23.svg │ │ │ │ │ │ │ ├── 20.svg │ │ │ │ │ │ │ ├── 25.svg │ │ │ │ │ │ │ ├── 27.svg │ │ │ │ │ │ │ ├── 37.svg │ │ │ │ │ │ │ ├── 17.svg │ │ │ │ │ │ │ ├── 15.svg │ │ │ │ │ │ │ ├── 8.svg │ │ │ │ │ │ │ ├── 11.svg │ │ │ │ │ │ │ ├── 22.svg │ │ │ │ │ │ │ ├── 4.svg │ │ │ │ │ │ │ ├── 31.svg │ │ │ │ │ │ │ ├── 1.svg │ │ │ │ │ │ │ ├── 001.svg │ │ │ │ │ │ │ ├── 13.svg │ │ │ │ │ │ │ ├── 28.svg │ │ │ │ │ │ │ ├── 16.svg │ │ │ │ │ │ │ ├── 21.svg │ │ │ │ │ │ │ ├── 39.svg │ │ │ │ │ │ │ ├── 29.svg │ │ │ │ │ │ │ ├── 33.svg │ │ │ │ │ │ │ ├── 7.svg │ │ │ │ │ │ │ ├── 26.svg │ │ │ │ │ │ │ ├── 10.svg │ │ │ │ │ │ │ ├── 32.svg │ │ │ │ │ │ │ ├── 6.svg │ │ │ │ │ │ │ ├── 18.svg │ │ │ │ │ │ │ ├── 2.svg │ │ │ │ │ │ │ ├── 14.svg │ │ │ │ │ │ │ ├── 9.svg │ │ │ │ │ │ │ ├── 34.svg │ │ │ │ │ │ │ ├── 5.svg │ │ │ │ │ │ │ ├── 19.svg │ │ │ │ │ │ │ ├── 12.svg │ │ │ │ │ │ │ ├── 3.svg │ │ │ │ │ │ │ └── 30.svg │ │ │ │ │ ├── sounds │ │ │ │ │ │ └── teaser.mp3 │ │ │ │ │ └── font │ │ │ │ │ │ ├── FontAwesome.otf │ │ │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ │ │ ├── fontawesome-webfont.svgz │ │ │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ │ │ └── fontawesome-webfontd41d.eot │ │ │ │ ├── banner.txt │ │ │ │ ├── views │ │ │ │ │ ├── view-messages.html │ │ │ │ │ ├── view-error │ │ │ │ │ │ ├── 404.html │ │ │ │ │ │ └── 500.html │ │ │ │ │ ├── view-header.html │ │ │ │ │ ├── view-navbar.html │ │ │ │ │ └── view-modals.html │ │ │ │ ├── i18n │ │ │ │ │ └── messages.properties │ │ │ │ └── application.yml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── datastax │ │ │ │ └── demo │ │ │ │ └── stargate │ │ │ │ ├── StargateDemoApplication.java │ │ │ │ ├── chevrons │ │ │ │ ├── ChevronRepository.java │ │ │ │ ├── ChevronPrimaryKey.java │ │ │ │ ├── Chevron.java │ │ │ │ └── ChevronRestController.java │ │ │ │ ├── destinations │ │ │ │ ├── DestinationRepository.java │ │ │ │ ├── Destination.java │ │ │ │ └── DestinationPrimaryKey.java │ │ │ │ ├── web │ │ │ │ ├── HomeBean.java │ │ │ │ └── HomeController.java │ │ │ │ └── conf │ │ │ │ └── WebConfiguration.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── datastax │ │ │ └── demo │ │ │ └── stargate │ │ │ ├── Ex1_UseCqlSessionTest.java │ │ │ ├── Ex3_UseSpringDataDestinationTest.java │ │ │ ├── Ex4_SdkDevopsApi.java │ │ │ ├── Ex5_SdkRestApi.java │ │ │ ├── Ex2_UseSpringDataChevronTest.java │ │ │ └── Ex6_SdkDocApi.java │ └── pom.xml ├── 3-quarkus │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── resources │ │ │ │ │ ├── robots.txt │ │ │ │ │ ├── assets │ │ │ │ │ ├── index.js │ │ │ │ │ └── logo.png │ │ │ │ │ ├── favicon.ico │ │ │ │ │ ├── favicon.png │ │ │ │ │ ├── e90b6873f455f0560c2a2eeae2dbc955.png │ │ │ │ │ ├── css │ │ │ │ │ ├── README.md │ │ │ │ │ ├── spinner.css │ │ │ │ │ └── base.css │ │ │ │ │ ├── manifest.json │ │ │ │ │ └── index.html │ │ │ ├── application.properties.template │ │ │ └── application.properties │ │ ├── docker │ │ │ ├── Dockerfile.native │ │ │ └── Dockerfile.jvm │ │ └── java │ │ │ └── com │ │ │ └── datastaxdev │ │ │ ├── cql │ │ │ └── AstraDemoCQL.java │ │ │ └── todo │ │ │ ├── api │ │ │ └── Todo.java │ │ │ └── AstraTODO.java │ │ └── test │ │ └── java │ │ └── com │ │ └── datastaxdev │ │ └── E24_QuarkusAstraConnectivity.java ├── 1-cassandra-drivers │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── cassandra_logo.png │ │ │ ├── logback.xml │ │ │ ├── custom_astra.conf │ │ │ └── custom_application.conf │ │ │ └── java │ │ │ └── com │ │ │ └── datastax │ │ │ └── samples │ │ │ ├── objectmapping │ │ │ ├── CommentDaoMapper.java │ │ │ ├── CommentByVideo.java │ │ │ ├── CommentByUser.java │ │ │ ├── CommentDao.java │ │ │ ├── Comment.java │ │ │ └── CommentDaoQueryProvider.java │ │ │ ├── dto │ │ │ ├── VideoFormatDto.java │ │ │ ├── UserDto.java │ │ │ ├── FileDto.java │ │ │ └── VideoDto.java │ │ │ ├── E07_DropKeyspace.java │ │ │ ├── E02_CreateKeyspace.java │ │ │ ├── E04_ConfigurationFile.java │ │ │ ├── E06_DropSchema.java │ │ │ ├── E09_ConnectToAstraConfFile.java │ │ │ ├── E01_ClusterShowMetaData.java │ │ │ ├── E05_ProgrammaticConfiguration.java │ │ │ ├── E03_CreateSchema.java │ │ │ ├── codec │ │ │ ├── BytesArrayTypeCodec.java │ │ │ ├── UdtVideoFormatCodec.java │ │ │ └── JsonJacksonTypeCodec.java │ │ │ ├── E08_ConnectToAstraProgrammatic.java │ │ │ ├── schema │ │ │ └── SchemaConstants.java │ │ │ ├── E12_Paging.java │ │ │ └── E19_LightweightTransactions.java │ └── pom.xml ├── 2-spring-data │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── META-INF │ │ │ │ │ └── additional-spring-configuration-metadata.json │ │ │ │ ├── application.conf │ │ │ │ ├── application.properties │ │ │ │ ├── logback.xml │ │ │ │ └── banner.txt │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── datastax │ │ │ │ └── workshop │ │ │ │ ├── hello │ │ │ │ └── HelloWorldRestController.java │ │ │ │ ├── TodobackendSpringdataApplication.java │ │ │ │ ├── todo │ │ │ │ ├── TodoRepositoryCassandra.java │ │ │ │ ├── Todo.java │ │ │ │ ├── TodoRepositorySimpleCassandra.java │ │ │ │ ├── TodoEntity.java │ │ │ │ └── TodoRestController.java │ │ │ │ └── conf │ │ │ │ └── SpringDataConfig.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── datastax │ │ │ └── workshop │ │ │ ├── TodobackendSpringdataApplicationTests.java │ │ │ ├── E22_SpringDataAstraConnectivity.java │ │ │ └── E23_CreateSchemaInAstraTest.java │ └── pom.xml └── docker-compose.yaml ├── img ├── scb.png ├── splash.png ├── astra-token.png ├── db-pending.png ├── new_keyspace.png ├── quarkus_ui.png ├── badge-javazone.png ├── new_keyspace2.png ├── new_keyspace3.png ├── astra-create-db.gif ├── db-cqlconsole-1.png ├── db-cqlconsole-2.png └── astra-create-token.gif └── .gitignore /hands-on/4-sdk/src/main/resources/static/js/base.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /img/scb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/scb.png -------------------------------------------------------------------------------- /img/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/splash.png -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: /api 3 | 4 | -------------------------------------------------------------------------------- /img/astra-token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/astra-token.png -------------------------------------------------------------------------------- /img/db-pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/db-pending.png -------------------------------------------------------------------------------- /img/new_keyspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/new_keyspace.png -------------------------------------------------------------------------------- /img/quarkus_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/quarkus_ui.png -------------------------------------------------------------------------------- /img/badge-javazone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/badge-javazone.png -------------------------------------------------------------------------------- /img/new_keyspace2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/new_keyspace2.png -------------------------------------------------------------------------------- /img/new_keyspace3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/new_keyspace3.png -------------------------------------------------------------------------------- /img/astra-create-db.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/astra-create-db.gif -------------------------------------------------------------------------------- /img/db-cqlconsole-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/db-cqlconsole-1.png -------------------------------------------------------------------------------- /img/db-cqlconsole-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/db-cqlconsole-2.png -------------------------------------------------------------------------------- /img/astra-create-token.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/img/astra-create-token.gif -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/assets/index.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.png'; 2 | export const Logo = logo; 3 | 4 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/dhd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/dhd.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/ico.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/ico.jpg -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/banner.jpg -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/bodybg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/bodybg.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/pixel.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/pixel.gif -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/planet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/planet.jpg -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/space.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/space.jpeg -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/stargate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/stargate.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/subnavbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/subnavbg.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/logo-header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/logo-header.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/logo_solr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/logo_solr.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/logo_spark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/logo_spark.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/sounds/teaser.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/sounds/teaser.mp3 -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/FontAwesome.otf -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/resources/cassandra_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/1-cassandra-drivers/src/main/resources/cassandra_logo.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/datatable/sort_asc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/datatable/sort_asc.png -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/3-quarkus/src/main/resources/META-INF/resources/favicon.ico -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/3-quarkus/src/main/resources/META-INF/resources/favicon.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.eot -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.svgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.svgz -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfont.woff -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/datatable/sort_both.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/datatable/sort_both.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/datatable/sort_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/datatable/sort_desc.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/3-quarkus/src/main/resources/META-INF/resources/assets/logo.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfontd41d.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/font/fontawesome-webfontd41d.eot -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/datatable/sort_asc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/datatable/sort_asc_disabled.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/datatable/sort_desc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/datatable/sort_desc_disabled.png -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/BiodegradableUglyGallinule-size_restricted.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/4-sdk/src/main/resources/static/img/BiodegradableUglyGallinule-size_restricted.gif -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/e90b6873f455f0560c2a2eeae2dbc955.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/datastaxdevs/conference-2021-javazone/main/hands-on/3-quarkus/src/main/resources/META-INF/resources/e90b6873f455f0560c2a2eeae2dbc955.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse conf file 2 | .settings 3 | .classpath 4 | .project 5 | .cache 6 | 7 | # idea conf files 8 | .idea 9 | *.ipr 10 | *.iws 11 | *.iml 12 | 13 | # building 14 | target 15 | build 16 | tmp 17 | dist 18 | 19 | # misc 20 | .DS_Store 21 | 22 | .factorypath 23 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "datastax.astra.secure-connect-bundle", 5 | "type": "java.lang.String", 6 | "description": "An absolute path to the Astra secure connect bundle to use." 7 | } 8 | ] 9 | } -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/css/README.md: -------------------------------------------------------------------------------- 1 | The following files in this directory were taken from TodoMVC project: 2 | 3 | - base.css 4 | - index.css 5 | 6 | https://github.com/tastejs/todomvc 7 | 8 | Following files are taken from http://tobiasahlin.com/spinkit/ 9 | 10 | - spinner.css 11 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/application.properties.template: -------------------------------------------------------------------------------- 1 | # Configuration file 2 | # key = value 3 | quarkus.cassandra.cloud.secure-connect-bundle=/home/tato/Downloads/secure-connect-serverlessdb.zip 4 | # Authentication 5 | quarkus.cassandra.auth.username=token 6 | quarkus.cassandra.auth.password=AstraCS:REPLACE_ME:REPLACE_ME 7 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Sample App", 3 | "name": "Sample app", 4 | "icons": [ 5 | { 6 | "src": "favicon.png", 7 | "type": "image/png" 8 | } 9 | ], 10 | "start_url": "./index.html", 11 | "display": "standalone", 12 | "theme_color": "#000000", 13 | "background_color": "#ffffff" 14 | } 15 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | datastax-java-driver { 2 | basic { 3 | request { 4 | timeout = 8 seconds 5 | consistency = LOCAL_QUORUM 6 | page-size = 5000 7 | } 8 | } 9 | advanced { 10 | connection { 11 | init-query-timeout = 10 seconds 12 | set-keyspace-timeout = 10 seconds 13 | } 14 | control-connection.timeout = 10 seconds 15 | } 16 | } -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/hello/HelloWorldRestController.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.hello; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HelloWorldRestController { 8 | 9 | @RequestMapping("/") 10 | public String hello() { 11 | return "Hello World !"; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/StargateDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class StargateDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(StargateDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/TodobackendSpringdataApplication.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TodobackendSpringdataApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TodobackendSpringdataApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/todo/TodoRepositoryCassandra.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.todo; 2 | 3 | import java.util.UUID; 4 | 5 | import org.springframework.data.cassandra.repository.CassandraRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | /** 9 | * For Basic operations you can leverage on Interface only repository 10 | */ 11 | @Repository 12 | public interface TodoRepositoryCassandra extends CassandraRepository { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/24.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/38.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %magenta(%-5level) %cyan(%-45logger) : %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/35.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/test/java/com/datastaxdev/E24_QuarkusAstraConnectivity.java: -------------------------------------------------------------------------------- 1 | package com.datastaxdev; 2 | 3 | import io.quarkus.test.junit.QuarkusTest; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import static io.restassured.RestAssured.given; 7 | import static org.hamcrest.CoreMatchers.is; 8 | 9 | @QuarkusTest 10 | public class E24_QuarkusAstraConnectivity { 11 | 12 | @Test 13 | public void testHelloEndpoint() { 14 | given() 15 | .when().get("/hello") 16 | .then() 17 | .statusCode(200); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/36.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.cassandra.schema-action=CREATE_IF_NOT_EXISTS 2 | spring.data.cassandra.request.timeout=10s 3 | spring.data.cassandra.connection.connect-timeout=10s 4 | spring.data.cassandra.connection.init-query-timeout=10s 5 | 6 | # -- Keys to be filled 7 | spring.data.cassandra.keyspace-name=spring_data 8 | spring.data.cassandra.username=change_me 9 | spring.data.cassandra.password=change_me 10 | 11 | datastax.astra.secure-connect-bundle=/Users/cedricklunven/Downloads/secure-connect-javazone.zip 12 | # -- 13 | 14 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/23.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/20.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} %magenta(%-5level) %cyan(%-45logger) : %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/chevrons/ChevronRepository.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.chevrons; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.cassandra.repository.CassandraRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface ChevronRepository extends CassandraRepository { 10 | 11 | 12 | /** 13 | * By Convention Spring Data Cassandra will do 14 | * SELECT * FROM chevrons WHERE area='' 15 | */ 16 | List findByKeyArea(String area); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/destinations/DestinationRepository.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.destinations; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.cassandra.repository.CassandraRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | @Repository 9 | public interface DestinationRepository 10 | extends CassandraRepository { 11 | 12 | /** 13 | * By Convention Spring Data Cassandra will do 14 | * SELECT * FROM destinations WHERE galaxy='' 15 | */ 16 | List findByKeyGalaxy(String area); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _________ __ __ 2 | / _____// |______ _______ _________ _/ |_ ____ 3 | \_____ \\ __\__ \\_ __ \/ ___\__ \\ __\/ __ \ 4 | / \| | / __ \| | \/ /_/ > __ \| | \ ___/ 5 | /_______ /|__| (____ /__| \___ (____ /__| \___ > 6 | \/ \/ /_____/ \/ \/ 7 | ________ 8 | \______ \ ____ _____ ____ 9 | | | \_/ __ \ / \ / _ \ 10 | | ` \ ___/| Y Y ( <_> ) 11 | /_______ /\___ >__|_| /\____/ 12 | \/ \/ \/ 13 | 14 | DataStax Developer Advocate team 15 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-messages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 |
8 |
9 | 10 | --- 11 |
12 |
13 |
 
14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/25.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/27.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/37.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/i18n/messages.properties: -------------------------------------------------------------------------------- 1 | # ----------------- # 2 | # NAVBARS # 3 | # ----------------- # 4 | navbar.title=Stargate, gate to the star 5 | 6 | # Navbar of home page 7 | navbar.main.home=Stargate 8 | navbar.main.settings=Settings 9 | navbar.main.back=Back 10 | navbar.main.nearearth=Earth Catalog 11 | navbar.main.swagger=SwaggerUI 12 | navbar.main.about=About 13 | 14 | # 500 Page 15 | error.table.key=Session Key 16 | error.table.value=Value 17 | 500.title=An Error occured 18 | 500.subtitle=Please go back to home 19 | 500.back=Get back to home 20 | 21 | # 404 Page 22 | 404.title=Page not Found 23 | 404.subtitle=This page has not been found 24 | 404.back=Get back to home 25 | 26 | 27 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/17.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/15.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/CommentDaoMapper.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import com.datastax.oss.driver.api.core.CqlSession; 4 | import com.datastax.oss.driver.api.mapper.MapperBuilder; 5 | import com.datastax.oss.driver.api.mapper.annotations.DaoFactory; 6 | import com.datastax.oss.driver.api.mapper.annotations.Mapper; 7 | 8 | /** 9 | * Definition of operation for mapping. 10 | */ 11 | @Mapper 12 | public interface CommentDaoMapper { 13 | 14 | @DaoFactory 15 | CommentDao commentDao(); 16 | 17 | static MapperBuilder builder(CqlSession session) { 18 | return new CommentDaoMapperBuilder(session); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/8.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/11.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/22.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/4.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/31.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/docker/Dockerfile.native: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode 3 | # 4 | # Before building the docker image run: 5 | # 6 | # mvn package -Pnative -Dquarkus.native.container-build=true 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.native -t quarkus/my-artifactId . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/my-artifactId 15 | # 16 | ### 17 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1 18 | WORKDIR /work/ 19 | COPY --chown=1001:root target/*-runner /work/application 20 | 21 | EXPOSE 8080 22 | USER 1001 23 | 24 | CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/001.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/13.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/28.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/conf/SpringDataConfig.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.conf; 2 | 3 | import java.io.File; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.autoconfigure.cassandra.CqlSessionBuilderCustomizer; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | public class SpringDataConfig { 12 | 13 | @Value("${datastax.astra.secure-connect-bundle}") 14 | private File cloudSecureBundle; 15 | 16 | @Bean 17 | public CqlSessionBuilderCustomizer sessionBuilderCustomizer() { 18 | return builder -> builder.withCloudSecureConnectBundle(cloudSecureBundle.toPath()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/16.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/21.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/39.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/29.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/33.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/7.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.BLUE} ________ __ __ __ .__ 2 | ${AnsiColor.BLUE} \______ \ _______ __/ \ / \ | __ _____| |__ ____ ______ 3 | ${AnsiColor.BLUE} | | \_/ __ \ \/ /\ \/\/ / |/ / / ___/ | \ / _ \\____ \ 4 | ${AnsiColor.BLUE} | ` \ ___/\ / \ /| < \___ \| Y ( <_> ) |_> > 5 | ${AnsiColor.BLUE} /_______ /\___ >\_/ \__/\ / |__|_ \/____ >___| /\____/| __/ 6 | ${AnsiColor.BLUE} \/ \/ \/ \/ \/ \/ |__| 7 | 8 | ${AnsiColor.CYAN} Implement a todoList with Spring Data Cassandra and Spring Boot 9 | 10 | ${AnsiColor.GREEN} You are using BRANCH PART5 11 | ${AnsiColor.GREEN} The application will start at ${AnsiColor.RED}http://localhost:8080${AnsiColor.BLACK} 12 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/26.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/js/codemirror-5.39.0/show-hint.css: -------------------------------------------------------------------------------- 1 | .CodeMirror-hints { 2 | position: absolute; 3 | z-index: 10; 4 | overflow: hidden; 5 | list-style: none; 6 | 7 | margin: 0; 8 | padding: 2px; 9 | 10 | -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); 11 | -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); 12 | box-shadow: 2px 3px 5px rgba(0,0,0,.2); 13 | border-radius: 3px; 14 | border: 1px solid silver; 15 | 16 | background: white; 17 | font-size: 90%; 18 | font-family: monospace; 19 | 20 | max-height: 20em; 21 | overflow-y: auto; 22 | } 23 | 24 | .CodeMirror-hint { 25 | margin: 0; 26 | padding: 0 4px; 27 | border-radius: 2px; 28 | white-space: pre; 29 | color: black; 30 | cursor: pointer; 31 | } 32 | 33 | li.CodeMirror-hint-active { 34 | background: #08f; 35 | color: white; 36 | } 37 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/resources/custom_astra.conf: -------------------------------------------------------------------------------- 1 | datastax-java-driver { 2 | 3 | basic { 4 | session-keyspace = javazone 5 | request { 6 | timeout = 8 seconds 7 | consistency = LOCAL_QUORUM 8 | page-size = 5000 9 | } 10 | cloud { 11 | secure-connect-bundle = /Users/cedricklunven/Downloads/secure-connect-javazone.zip 12 | } 13 | } 14 | 15 | advanced { 16 | connection { 17 | init-query-timeout = 10 seconds 18 | set-keyspace-timeout = 10 seconds 19 | } 20 | control-connection.timeout = 10 seconds 21 | auth-provider { 22 | class = PlainTextAuthProvider 23 | username = "change_me" 24 | password = "change_me+KTipmev1nPiYQuXbpMpW1wuN.ywz1.UtKRnnJQzgLRZu4cExSGc2xHIQHREzpeB,pugXl,vlSXStTpNxjhPBnl0yZjXJRyFIg2ZJ-K8SZZWHIcdH0SzS" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/10.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/destinations/Destination.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.destinations; 2 | 3 | import org.springframework.data.cassandra.core.mapping.PrimaryKey; 4 | import org.springframework.data.cassandra.core.mapping.Table; 5 | 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @Table(value = "destinations") 14 | public class Destination { 15 | 16 | @PrimaryKey 17 | private DestinationPrimaryKey key; 18 | 19 | private int chevron1; 20 | 21 | private int chevron2; 22 | 23 | private int chevron3; 24 | 25 | private int chevron4; 26 | 27 | private int chevron5; 28 | 29 | private int chevron6; 30 | 31 | private String description; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/test/java/com/datastax/workshop/TodobackendSpringdataApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import com.datastax.workshop.todo.TodoEntity; 9 | import com.datastax.workshop.todo.TodoRepositoryCassandra; 10 | 11 | @SpringBootTest 12 | class TodobackendSpringdataApplicationTests { 13 | 14 | @Autowired 15 | private TodoRepositoryCassandra repo; 16 | 17 | @Test 18 | void shoud_save_task_when_save() { 19 | // Given 20 | TodoEntity te = new TodoEntity("Sample task1", 1); 21 | // When 22 | repo.save(te); 23 | // then 24 | Assertions.assertTrue(repo.existsById(te.getUid())); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/32.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/resources/custom_application.conf: -------------------------------------------------------------------------------- 1 | datastax-java-driver { 2 | 3 | # Core settings 4 | basic { 5 | contact-points = [ "127.0.0.1:9042"] 6 | session-name = my_sample_session 7 | session-keyspace = killrvideo 8 | config-reload-interval = 5 minutes 9 | 10 | request { 11 | timeout = 3 seconds 12 | consistency = LOCAL_QUORUM 13 | page-size = 5000 14 | } 15 | load-balancing-policy { 16 | class = DefaultLoadBalancingPolicy 17 | local-datacenter = dc1 18 | } 19 | } 20 | 21 | # Dedicated Profiles 22 | profiles { 23 | oltp { 24 | basic.request.timeout = 100 milliseconds 25 | basic.request.consistency = ONE 26 | } 27 | olap { 28 | basic.request.timeout = 5 seconds 29 | basic.request.consistency = QUORUM 30 | } 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/6.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/18.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/2.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/chevrons/ChevronPrimaryKey.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.chevrons; 2 | 3 | import org.springframework.data.cassandra.core.cql.Ordering; 4 | import org.springframework.data.cassandra.core.cql.PrimaryKeyType; 5 | import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass; 6 | import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | 12 | @Data 13 | @PrimaryKeyClass 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class ChevronPrimaryKey { 17 | 18 | @PrimaryKeyColumn(name = "area", 19 | type = PrimaryKeyType.PARTITIONED, 20 | ordinal = 0) 21 | private String area; 22 | 23 | @PrimaryKeyColumn(name = "code", 24 | type = PrimaryKeyType.CLUSTERED, 25 | ordinal = 1, ordering = Ordering.ASCENDING) 26 | private int code; 27 | } 28 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/chevrons/Chevron.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.chevrons; 2 | 3 | import org.springframework.data.cassandra.core.mapping.CassandraType; 4 | import org.springframework.data.cassandra.core.mapping.Column; 5 | import org.springframework.data.cassandra.core.mapping.PrimaryKey; 6 | import org.springframework.data.cassandra.core.mapping.Table; 7 | import org.springframework.data.cassandra.core.mapping.CassandraType.Name; 8 | 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @Table(value = "chevrons") 17 | public class Chevron { 18 | 19 | @PrimaryKey 20 | private ChevronPrimaryKey key; 21 | 22 | @Column("name") 23 | @CassandraType(type = Name.TEXT) 24 | private String name; 25 | 26 | @Column("picture") 27 | @CassandraType(type = Name.TEXT) 28 | private String picture; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/java/com/datastaxdev/cql/AstraDemoCQL.java: -------------------------------------------------------------------------------- 1 | package com.datastaxdev.cql; 2 | 3 | import javax.inject.Inject; 4 | import javax.ws.rs.GET; 5 | import javax.ws.rs.Path; 6 | import javax.ws.rs.Produces; 7 | import javax.ws.rs.core.MediaType; 8 | 9 | import com.datastax.oss.driver.api.core.cql.ResultSet; 10 | import com.datastax.oss.driver.api.core.cql.Row; 11 | import com.datastax.oss.quarkus.runtime.api.session.QuarkusCqlSession; 12 | import io.smallrye.common.annotation.Blocking; 13 | 14 | @Path("/hello") 15 | public class AstraDemoCQL { 16 | 17 | @Inject 18 | QuarkusCqlSession cqlSession; 19 | 20 | @GET 21 | @Produces(MediaType.TEXT_PLAIN) 22 | @Blocking 23 | public String hello() { 24 | ResultSet rs = this.cqlSession 25 | .execute("SELECT data_center FROM system.local"); 26 | 27 | Row row = rs.one(); 28 | String version = row.getFormattedContents(); 29 | return "hello" + " " + version; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/destinations/DestinationPrimaryKey.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.destinations; 2 | 3 | import org.springframework.data.cassandra.core.cql.Ordering; 4 | import org.springframework.data.cassandra.core.cql.PrimaryKeyType; 5 | import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass; 6 | import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | 12 | @Data 13 | @PrimaryKeyClass 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class DestinationPrimaryKey { 17 | 18 | @PrimaryKeyColumn(name = "galaxy", 19 | type = PrimaryKeyType.PARTITIONED, 20 | ordinal = 0) 21 | private String galaxy; 22 | 23 | @PrimaryKeyColumn(name = "name", 24 | type = PrimaryKeyType.CLUSTERED, 25 | ordinal = 1, ordering = Ordering.ASCENDING) 26 | private String name; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/14.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/9.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex1_UseCqlSessionTest.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import com.datastax.oss.driver.api.core.CqlSession; 8 | 9 | @SpringBootTest 10 | public class Ex1_UseCqlSessionTest { 11 | 12 | @Autowired 13 | private CqlSession cqlSession; 14 | 15 | @Test 16 | public void listChevronsTest() { 17 | System.out.println("Here are the chevrons:"); 18 | cqlSession.execute("select * from stargate.chevrons") 19 | .all().stream().forEach(row -> { 20 | System.out.println("+" 21 | + " code=" + row.getInt("code") 22 | + ", name='" + row.getString("name") + "'"); 23 | }); 24 | 25 | System.out.println("\u001B[0m [OK] \u001B[32m - Test Successfully you ROCK !\n\n"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/dto/VideoFormatDto.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.dto; 2 | 3 | /** 4 | * CREATE TYPE IF NOT EXISTS video_format ( 5 | * width int, 6 | * height int, 7 | * frames list 8 | * ); 9 | */ 10 | public class VideoFormatDto { 11 | 12 | private int width = 0; 13 | 14 | private int height = 0; 15 | 16 | public VideoFormatDto() {} 17 | 18 | public VideoFormatDto(int w, int h) { 19 | this.width = w; 20 | this.height = h; 21 | } 22 | 23 | public int getWidth() { 24 | return width; 25 | } 26 | 27 | public void setWidth(int width) { 28 | this.width = width; 29 | } 30 | 31 | public int getHeight() { 32 | return height; 33 | } 34 | 35 | public void setHeight(int height) { 36 | this.height = height; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "VideoFormatDto [width=" + width + ", height=" + height; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/34.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/java/com/datastaxdev/todo/api/Todo.java: -------------------------------------------------------------------------------- 1 | package com.datastaxdev.todo.api; 2 | 3 | import io.quarkus.runtime.annotations.RegisterForReflection; 4 | 5 | @RegisterForReflection 6 | public class Todo { 7 | private String id; 8 | private String title; 9 | private boolean completed; 10 | 11 | public Todo() { 12 | } 13 | 14 | public Todo(String id, String title, boolean completed) { 15 | this.id = id; 16 | this.title = title; 17 | this.completed = completed; 18 | } 19 | 20 | public String getId() { 21 | return this.id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public String getTitle() { 29 | return this.title; 30 | } 31 | 32 | public void setTitle(String title) { 33 | this.title = title; 34 | } 35 | 36 | public boolean isCompleted() { 37 | return this.completed; 38 | } 39 | 40 | public void setCompleted(boolean completed) { 41 | this.completed = completed; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/5.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/css/spinner.css: -------------------------------------------------------------------------------- 1 | .spinner { 2 | width: 30px; 3 | height: 30px; 4 | background-color: red; 5 | 6 | margin: 100px auto; 7 | -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out; 8 | animation: sk-rotateplane 1.2s infinite ease-in-out; 9 | } 10 | 11 | @-webkit-keyframes sk-rotateplane { 12 | 0% { -webkit-transform: perspective(120px) } 13 | 50% { -webkit-transform: perspective(120px) rotateY(180deg) } 14 | 100% { -webkit-transform: perspective(120px) rotateY(180deg) rotateX(180deg) } 15 | } 16 | 17 | @keyframes sk-rotateplane { 18 | 0% { 19 | transform: perspective(120px) rotateX(0deg) rotateY(0deg); 20 | -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg) 21 | } 50% { 22 | transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg); 23 | -webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg) 24 | } 100% { 25 | transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg); 26 | -webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg); 27 | } 28 | } -------------------------------------------------------------------------------- /hands-on/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | 4 | cassandra-seed: 5 | image: cassandra:4.0.1 6 | ports: 7 | - 7000:7000 8 | - 7001:7001 9 | - 7199:7199 10 | - 9042:9042 11 | - 9160:9160 12 | mem_limit: 2G 13 | environment: 14 | - HEAP_NEWSIZE=128M 15 | - MAX_HEAP_SIZE=1024M 16 | - CASSANDRA_SEEDS=cassandra-seed 17 | - CASSANDRA_CLUSTER_NAME=javazone 18 | - CASSANDRA_DC=dc1 19 | - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch 20 | 21 | #cassandra-node: 22 | # image: cassandra:4.0.1 23 | # depends_on: 24 | # - cassandra-seed 25 | # command: /bin/bash -c "echo 'Waiting for seed node' && sleep 30 && /usr/local/bin//docker-entrypoint.sh cassandra -f" 26 | # mem_limit: 2G 27 | # environment: 28 | # - HEAP_NEWSIZE=128M 29 | # - MAX_HEAP_SIZE=1024M 30 | # - CASSANDRA_SEEDS=cassandra-seed 31 | # - CASSANDRA_CLUSTER_NAME=javazone 32 | # - CASSANDRA_DC=dc1 33 | # - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch 34 | 35 | 36 | # CQLSH 37 | # docker exec -it `docker ps | grep cassandra:4.0.1 | cut -b 1-12` cqlsh 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: ${PORT:8080} 3 | 4 | logging: 5 | level: 6 | root: WARN 7 | com.datastax.demo: INFO 8 | com.datastax.astra: INFO 9 | com.datastax.stargate: INFO 10 | com.datastax.oss: ERROR 11 | org.junit.vintage: ERROR 12 | 13 | spring: 14 | messages: 15 | basename: i18n/messages 16 | thymeleaf: 17 | mode: XHTML 18 | prefix: classpath:views/view- 19 | suffix: .html 20 | jackson: 21 | default-property-inclusion: non-null 22 | 23 | springdoc: 24 | api-docs: 25 | enabled: true 26 | groups: 27 | enabled: true 28 | swagger-ui: 29 | path: /swagger-ui.html 30 | display-request-duration: true 31 | groups-order: DESC 32 | show-actuator: false 33 | group-configs: 34 | - group: Rest Controllers (Spring MVC) 35 | packages-to-scan: com.datastax.demo.stargate 36 | 37 | # Properties exopected by the starter 38 | astra: 39 | 40 | # Credentials to DB 41 | client-id: 42 | client-secret: 43 | application-token: 44 | 45 | # Select an instance 46 | cloud-region: 47 | database-id: 48 | keyspace: stargate -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/19.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/12.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex3_UseSpringDataDestinationTest.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import com.datastax.demo.stargate.destinations.Destination; 8 | import com.datastax.demo.stargate.destinations.DestinationPrimaryKey; 9 | import com.datastax.demo.stargate.destinations.DestinationRepository; 10 | 11 | @SpringBootTest 12 | public class Ex3_UseSpringDataDestinationTest { 13 | 14 | @Autowired 15 | private DestinationRepository destinationRepository; 16 | 17 | @Test 18 | public void findDestination() { 19 | System.out.println("Here are the chevrons:"); 20 | Destination d = destinationRepository.findById(new DestinationPrimaryKey("Milky Way", "Chulak")).get(); 21 | System.out.println("[" + d.getChevron1() + 22 | " - " + d.getChevron2() + 23 | " - " + d.getChevron3() + 24 | " - " + d.getChevron4() + 25 | " - " + d.getChevron5() + 26 | " - " + d.getChevron6() + "]"); 27 | System.out.println("\u001B[0m[OK] \u001B[32m - Test #2.1 Successful - you ROCK !\n\n"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/CommentByVideo.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import java.util.UUID; 4 | 5 | import com.datastax.oss.driver.api.mapper.annotations.CqlName; 6 | import com.datastax.oss.driver.api.mapper.annotations.Entity; 7 | import com.datastax.oss.driver.api.mapper.annotations.PartitionKey; 8 | import com.datastax.samples.schema.SchemaConstants; 9 | 10 | /** 11 | * Specialization for VIDEO. 12 | * 13 | * @author DataStax Developer Advocates team. 14 | */ 15 | @Entity 16 | @CqlName(SchemaConstants.COMMENT_BY_VIDEO_TABLENAME) 17 | public class CommentByVideo extends Comment { 18 | 19 | /** Serial. */ 20 | private static final long serialVersionUID = -6738790629520080307L; 21 | 22 | public CommentByVideo() { 23 | } 24 | 25 | public CommentByVideo(Comment c) { 26 | this.commentid = c.getCommentid(); 27 | this.userid = c.getUserid(); 28 | this.videoid = c.getVideoid(); 29 | this.comment = c.getComment(); 30 | } 31 | 32 | /** 33 | * Getter for attribute 'videoid'. 34 | * 35 | * @return 36 | * current value of 'videoid' 37 | */ 38 | @PartitionKey 39 | public UUID getVideoid() { 40 | return videoid; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/todo/Todo.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.todo; 2 | 3 | import java.util.UUID; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | import lombok.Data; 8 | 9 | @Data 10 | public class Todo { 11 | 12 | private String url; 13 | private UUID uuid; 14 | private String title; 15 | private boolean completed = false; 16 | private int order = 0; 17 | 18 | public Todo() {} 19 | 20 | public Todo(String title, int order) { 21 | this.uuid = UUID.randomUUID(); 22 | this.title = title; 23 | this.order = order; 24 | } 25 | 26 | public Todo(String title, int order, boolean completed) { 27 | this(title, order); 28 | this.completed = completed; 29 | } 30 | 31 | public Todo setUrl(HttpServletRequest req) { 32 | if (url == null) { 33 | String reqUrl = req.getRequestURL().toString(); 34 | url = reqUrl.contains("gitpod") ? reqUrl.replaceAll("http", "https") : reqUrl; 35 | url += uuid; 36 | } 37 | return this; 38 | } 39 | 40 | public Todo setUrl(String myUrl) { 41 | if (url == null) { 42 | url = myUrl.contains("gitpod") ? myUrl.replaceAll("http", "https") : myUrl; 43 | } 44 | return this; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex4_SdkDevopsApi.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import com.datastax.astra.sdk.AstraClient; 8 | import com.datastax.astra.sdk.databases.domain.DatabaseFilter; 9 | import com.datastax.astra.sdk.databases.domain.DatabaseFilter.Include; 10 | 11 | @SpringBootTest 12 | public class Ex4_SdkDevopsApi { 13 | 14 | @Autowired 15 | private AstraClient astraClient; 16 | 17 | @Test 18 | public void listAvailableDatabases() { 19 | astraClient.apiDevopsDatabases() 20 | .searchDatabases(DatabaseFilter 21 | .builder() 22 | .include(Include.ACTIVE) 23 | .build()) 24 | .forEach(db -> { 25 | System.out.println("Database '" + db.getInfo().getName() + "'"); 26 | System.out.println("+ id=" + db.getId()); 27 | System.out.println("+ region=" + db.getInfo().getRegion()); 28 | System.out.println("+ keyspace=" + db.getInfo().getKeyspace()); 29 | System.out.println(""); 30 | }); 31 | } 32 | 33 | 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-error/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |

404

18 |

title

19 |
20 | title 21 |
22 | 23 | 31 | 32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 |
40 |
41 |
42 |
43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/todo/TodoRepositorySimpleCassandra.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.todo; 2 | 3 | import java.util.UUID; 4 | 5 | import org.springframework.data.cassandra.core.CassandraOperations; 6 | import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity; 7 | import org.springframework.data.cassandra.repository.support.MappingCassandraEntityInformation; 8 | import org.springframework.data.cassandra.repository.support.SimpleCassandraRepository; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.datastax.oss.driver.api.core.CqlSession; 12 | 13 | @Repository 14 | public class TodoRepositorySimpleCassandra extends SimpleCassandraRepository { 15 | 16 | protected final CqlSession cqlSession; 17 | 18 | protected final CassandraOperations cassandraTemplate; 19 | 20 | @SuppressWarnings("unchecked") 21 | public TodoRepositorySimpleCassandra(CqlSession cqlSession, CassandraOperations ops) { 22 | super(new MappingCassandraEntityInformation( 23 | (CassandraPersistentEntity) ops.getConverter().getMappingContext() 24 | .getRequiredPersistentEntity(TodoEntity.class), ops.getConverter()), ops); 25 | this.cqlSession = cqlSession; 26 | this.cassandraTemplate = ops; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/3.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/img/chevrons/30.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex5_SdkRestApi.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import com.datastax.astra.sdk.AstraClient; 8 | import com.datastax.demo.stargate.chevrons.Chevron; 9 | import com.datastax.stargate.sdk.rest.domain.RowMapper; 10 | import com.datastax.stargate.sdk.rest.domain.SearchTableQuery; 11 | 12 | @SpringBootTest 13 | public class Ex5_SdkRestApi { 14 | 15 | @Autowired 16 | private AstraClient astraClient; 17 | 18 | @Test 19 | public void listChevrons() { 20 | astraClient.apiStargateData().keyspace("stargate").table("chevrons") 21 | .search(SearchTableQuery.builder().build(), new ChevronRowMapper()) 22 | .getResults().stream() 23 | .map(Chevron::getName) 24 | .forEach(System.out::println); 25 | } 26 | 27 | private static class ChevronRowMapper implements RowMapper { 28 | @Override 29 | public Chevron map(com.datastax.stargate.sdk.rest.domain.Row row) { 30 | Chevron c = new Chevron(); 31 | c.setName(row.getString("name")); 32 | //... 33 | return c; 34 | } 35 | 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/CommentByUser.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import java.util.UUID; 4 | 5 | import com.datastax.oss.driver.api.mapper.annotations.CqlName; 6 | import com.datastax.oss.driver.api.mapper.annotations.Entity; 7 | import com.datastax.oss.driver.api.mapper.annotations.PartitionKey; 8 | import com.datastax.samples.schema.SchemaConstants; 9 | 10 | /** 11 | * Specialization for USER. 12 | * 13 | * @author DataStax Developer Advocates team. 14 | */ 15 | @Entity 16 | @CqlName(SchemaConstants.COMMENT_BY_USER_TABLENAME) 17 | public class CommentByUser extends Comment { 18 | 19 | /** Serial. */ 20 | private static final long serialVersionUID = 1453554109222565840L; 21 | 22 | /** 23 | * Default constructor. 24 | */ 25 | public CommentByUser() {} 26 | 27 | /** 28 | * Copy constructor. 29 | * 30 | * @param c 31 | */ 32 | public CommentByUser(Comment c) { 33 | this.commentid = c.getCommentid(); 34 | this.userid = c.getUserid(); 35 | this.videoid = c.getVideoid(); 36 | this.comment = c.getComment(); 37 | } 38 | 39 | /** 40 | * Getter for attribute 'userid'. 41 | * 42 | * @return 43 | * current value of 'userid' 44 | */ 45 | @PartitionKey 46 | public UUID getUserid() { 47 | return userid; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E07_DropKeyspace.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.datastax.oss.driver.api.core.CqlSession; 9 | import com.datastax.oss.driver.api.querybuilder.SchemaBuilder; 10 | import com.datastax.samples.schema.SchemaConstants; 11 | 12 | /** 13 | * Sample code to create tables, types and objects in a keyspace. 14 | * 15 | * Pre-requisites: 16 | * - Cassandra running locally (127.0.0.1, port 9042) 17 | * - Keyspace killrvideo created {@link E02_CreateKeyspace} 18 | * 19 | * @author Cedrick LUNVEN (@clunven) 20 | */ 21 | public class E07_DropKeyspace implements SchemaConstants { 22 | 23 | /** Logger for the class. */ 24 | private static Logger LOGGER = LoggerFactory.getLogger(E07_DropKeyspace.class); 25 | 26 | /** StandAlone (vs JUNIT) to help you running. */ 27 | public static void main(String[] args) { 28 | try (CqlSession cqlSession = CqlSession.builder() 29 | .addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 30 | .withLocalDatacenter("dc1") 31 | .build()) { 32 | cqlSession.execute(SchemaBuilder.dropKeyspace(KEYSPACE_NAME).ifExists().build()); 33 | LOGGER.info("+ Keyspace '{}' has been dropped (if needed).", KEYSPACE_NAME); 34 | } 35 | LOGGER.info("[OK] Success"); 36 | System.exit(0); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/CommentDao.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import java.util.UUID; 4 | 5 | import com.datastax.oss.driver.api.core.PagingIterable; 6 | import com.datastax.oss.driver.api.mapper.annotations.Dao; 7 | import com.datastax.oss.driver.api.mapper.annotations.Query; 8 | import com.datastax.oss.driver.api.mapper.annotations.QueryProvider; 9 | import com.datastax.samples.schema.SchemaConstants; 10 | 11 | /** 12 | * Implementation of Services to work with Comments in Killrvideo. We work with 13 | * 2 tables 'comments_by_user' and 'comments_by_video'. 14 | */ 15 | @Dao 16 | public interface CommentDao extends SchemaConstants { 17 | 18 | @Query("SELECT * FROM ${keyspaceId}.${tableId} " 19 | + "WHERE " + COMMENT_BY_USER_USERID + " = :userid ") 20 | PagingIterable retrieveUserComments(UUID userid); 21 | 22 | @Query("SELECT * FROM ${keyspaceId}.${tableId} " 23 | + "WHERE " + COMMENT_BY_VIDEO_VIDEOID + " = :videoid ") 24 | PagingIterable retrieveVideoComments(UUID videoid); 25 | 26 | @QueryProvider( 27 | providerClass = CommentDaoQueryProvider.class, 28 | entityHelpers = { CommentByUser.class, CommentByVideo.class}) 29 | void upsert(Comment comment); 30 | 31 | @QueryProvider( 32 | providerClass = CommentDaoQueryProvider.class, 33 | entityHelpers = { CommentByUser.class, CommentByVideo.class}) 34 | void delete(Comment res); 35 | } 36 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E02_CreateKeyspace.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.datastax.samples.schema.SchemaConstants; 7 | import com.datastax.samples.schema.SchemaUtils; 8 | 9 | /** 10 | * Create a keyspace with Simple Strategy and replication factor 1 (for local environment) 11 | * 12 | * Pre-requisites: 13 | * - Cassandra running at (ip=127.0.0.1, port=9042, datacenter=datacenter1) 14 | * 15 | * This code below will execute the following CQL statement: 16 | * -------------------------------------------------------------------- 17 | * CREATE KEYSPACE killrvideo 18 | * WITH replication = 19 | * {'class': 'SimpleStrategy', 20 | * 'replication_factor': '1'} 21 | * AND durable_writes = true; 22 | * --------------------------------------------------------------------- 23 | * 24 | * @author DataStax Developer Advocate Team 25 | * 26 | * Need Help ? Join us on community.datastax.com to ask your questions for free. 27 | */ 28 | public class E02_CreateKeyspace implements SchemaConstants { 29 | 30 | /** Logger for the class. */ 31 | private static Logger LOGGER = LoggerFactory.getLogger(E02_CreateKeyspace.class); 32 | 33 | /** 34 | * StandAlone program relying on main method to easy copy/paste. 35 | */ 36 | public static void main(String[] args) { 37 | LOGGER.info("Creating Keyspace 'killrvideo'"); 38 | SchemaUtils.createKeyspace(); 39 | System.exit(0); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/todo/TodoEntity.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.todo; 2 | 3 | import java.util.UUID; 4 | 5 | import org.springframework.data.cassandra.core.mapping.CassandraType; 6 | import org.springframework.data.cassandra.core.mapping.CassandraType.Name; 7 | import org.springframework.data.cassandra.core.mapping.Column; 8 | import org.springframework.data.cassandra.core.mapping.PrimaryKey; 9 | import org.springframework.data.cassandra.core.mapping.Table; 10 | 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @Table(value = TodoEntity.TABLENAME) 19 | public class TodoEntity { 20 | 21 | public static final String TABLENAME = "todos"; 22 | public static final String COLUMN_UID = "uid"; 23 | public static final String COLUMN_TITLE = "title"; 24 | public static final String COLUMN_COMPLETED = "completed"; 25 | public static final String COLUMN_ORDER = "offset"; 26 | 27 | @PrimaryKey 28 | @Column(COLUMN_UID) 29 | @CassandraType(type = Name.UUID) 30 | private UUID uid; 31 | 32 | @Column(COLUMN_TITLE) 33 | @CassandraType(type = Name.TEXT) 34 | private String title; 35 | 36 | @Column(COLUMN_COMPLETED) 37 | @CassandraType(type = Name.BOOLEAN) 38 | private boolean completed = false; 39 | 40 | @Column(COLUMN_ORDER) 41 | @CassandraType(type = Name.INT) 42 | private int order = 0; 43 | 44 | public TodoEntity(String title, int offset) { 45 | this(UUID.randomUUID(), title, false, offset); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E04_ConfigurationFile.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.io.File; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.datastax.oss.driver.api.core.CqlSession; 9 | import com.datastax.oss.driver.api.core.config.DriverConfigLoader; 10 | import com.datastax.samples.schema.SchemaConstants; 11 | 12 | /** 13 | * Sample code to create tables, types and objects in a keyspace. 14 | * 15 | * Pre-requisites: 16 | * - Cassandra running locally (127.0.0.1, port 9042) 17 | * - Keyspace killrvideo created {@link E02_CreateKeyspace} 18 | * 19 | * @author Cedrick LUNVEN (@clunven) 20 | */ 21 | public class E04_ConfigurationFile implements SchemaConstants { 22 | 23 | /** Logger for the class. */ 24 | private static Logger LOGGER = LoggerFactory.getLogger(E04_ConfigurationFile.class); 25 | 26 | /** StandAlone (vs JUNIT) to help you running. */ 27 | public static void main(String[] args) { 28 | 29 | // Load Configuration from file 30 | String confFilePath = E04_ConfigurationFile.class.getResource("/custom_application.conf").getFile(); 31 | 32 | // Create a Load with this file 33 | DriverConfigLoader loader = DriverConfigLoader.fromFile(new File(confFilePath)); 34 | 35 | // Use it to create the session 36 | try (CqlSession cqlSession = CqlSession.builder().withConfigLoader(loader).build()) { 37 | 38 | // Use session 39 | LOGGER.info("[OK] Connected to Keyspace {}", cqlSession.getKeyspace().get()); 40 | } 41 | LOGGER.info("[OK] Success"); 42 | System.exit(0); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Workshop Spring Stargate 29 | 30 | 31 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E06_DropSchema.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import static com.datastax.samples.schema.SchemaUtils.dropTableIfExists; 4 | import static com.datastax.samples.schema.SchemaUtils.dropTypeIffExists; 5 | 6 | import java.net.InetSocketAddress; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.datastax.oss.driver.api.core.CqlSession; 12 | import com.datastax.samples.schema.SchemaConstants; 13 | 14 | /** 15 | * Sample code to create tables, types and objects in a keyspace. 16 | * 17 | * Pre-requisites: 18 | * - Cassandra running locally (127.0.0.1, port 9042) 19 | * - Keyspace killrvideo created {@link E02_CreateKeyspace} 20 | * 21 | * @author Cedrick LUNVEN (@clunven) 22 | */ 23 | public class E06_DropSchema implements SchemaConstants { 24 | 25 | /** Logger for the class. */ 26 | private static Logger LOGGER = LoggerFactory.getLogger(E06_DropSchema.class); 27 | 28 | /** StandAlone (vs JUNIT) to help you running. */ 29 | public static void main(String[] args) { 30 | 31 | try (CqlSession cqlSession = CqlSession.builder() 32 | .addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 33 | .withLocalDatacenter("dc1") 34 | .withKeyspace(KEYSPACE_NAME) 35 | .build()) { 36 | LOGGER.info("[OK] Connected to Keyspace"); 37 | dropTableIfExists(cqlSession, COMMENT_BY_VIDEO_TABLENAME); 38 | dropTableIfExists(cqlSession, COMMENT_BY_USER_TABLENAME); 39 | dropTableIfExists(cqlSession, VIDEO_VIEWS_TABLENAME); 40 | dropTableIfExists(cqlSession, VIDEO_TABLENAME); 41 | dropTableIfExists(cqlSession, USER_TABLENAME); 42 | dropTypeIffExists(cqlSession, UDT_VIDEO_FORMAT_NAME); 43 | } 44 | LOGGER.info("[OK] Success"); 45 | System.exit(0); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E09_ConnectToAstraConfFile.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.io.File; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.datastax.oss.driver.api.core.CqlSession; 9 | import com.datastax.oss.driver.api.core.config.DriverConfigLoader; 10 | import com.datastax.samples.schema.SchemaConstants; 11 | 12 | /** 13 | * This class shows how to connect to the DataStax Cloud Cassandra As a Service: ASTRA 14 | * 15 | * Pre-requisites: 16 | * =================== 17 | * 18 | * 1. You need an ASTRA intance : go to astra.datastax.com and create an instance there. There is a free tier 19 | * for you to have a 3-node clusters availables forever. You can find more info on: 20 | * 21 | * 2. You need to provide you ASTRA credentials username, password, keyspace 22 | * but also the secure bundle ZIP. To download it please follow the instruction on : 23 | * https://docs.datastax.com/en/developer/java-driver/4.5/manual/cloud/ 24 | * 25 | * 3. You need a java driver version 3.8 26 | */ 27 | public class E09_ConnectToAstraConfFile implements SchemaConstants { 28 | 29 | /** Logger for the class. */ 30 | private static Logger LOGGER = LoggerFactory.getLogger(E09_ConnectToAstraConfFile.class); 31 | 32 | /** StandAlone (vs JUNIT) to help you running. */ 33 | public static void main(String[] args) { 34 | String configFile = E09_ConnectToAstraConfFile.class.getResource("/custom_astra.conf").getFile(); 35 | DriverConfigLoader configLoader = DriverConfigLoader.fromFile(new File(configFile)); 36 | try (CqlSession cqlSession = CqlSession.builder().withConfigLoader(configLoader).build()) { 37 | // Use session 38 | LOGGER.info("[OK] Welcome to ASTRA (conf file). Connected to Keyspace {}", 39 | cqlSession.getKeyspace().get()); 40 | } 41 | LOGGER.info("[OK] Success"); 42 | System.exit(0); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex2_UseSpringDataChevronTest.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import com.datastax.demo.stargate.chevrons.ChevronPrimaryKey; 8 | import com.datastax.demo.stargate.chevrons.ChevronRepository; 9 | 10 | @SpringBootTest 11 | public class Ex2_UseSpringDataChevronTest { 12 | 13 | @Autowired 14 | private ChevronRepository chevronRepo; 15 | 16 | @Test 17 | public void listChevronsTest() { 18 | System.out.println("Here are the chevrons:"); 19 | chevronRepo.findAll().stream().forEachOrdered(chevron -> { 20 | System.out.println("+" 21 | + " code=" + chevron.getKey().getCode() 22 | + ", name='" + chevron.getName() + "'"); 23 | }); 24 | System.out.println("\u001B[0m [OK] \u001B[32m - Test #2.1 Successful - you ROCK !\n\n"); 25 | } 26 | 27 | @Test 28 | public void retrieveAChevronByPrimaryKey() { 29 | System.out.println("Earth !"); 30 | chevronRepo.findById(new ChevronPrimaryKey("Milky Way",1 )) 31 | .ifPresent(chevron -> System.out.println(chevron.getName())); 32 | System.out.println("\u001B[0m [OK] \u001B[32m - Test #2.2 Successful - you ROCK !\n\n"); 33 | } 34 | 35 | @Test 36 | public void listChevronsMilkyWayTest() { 37 | System.out.println("Here are chevrons of the Milky Way"); 38 | chevronRepo.findByKeyArea("Milky Way") 39 | .stream() 40 | .forEachOrdered(chevron -> { 41 | System.out.println("+" 42 | + " code=" + chevron.getKey().getCode() 43 | + ", name='" + chevron.getName() + "'"); 44 | }); 45 | System.out.println("\u001B[0m [OK] \u001B[32m - Test #2.3 Successful - you ROCK !\n\n"); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E01_ClusterShowMetaData.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.datastax.oss.driver.api.core.CqlSession; 9 | import com.datastax.oss.driver.api.core.metadata.Metadata; 10 | import com.datastax.oss.driver.api.core.metadata.Node; 11 | 12 | /** 13 | * Standalone class to log metadata of a running cluster. 14 | * 15 | * We expect you to have a running Cassandra on 127.0.0.1 with default port 9042 16 | */ 17 | public class E01_ClusterShowMetaData { 18 | 19 | /** Logger for the class. */ 20 | private static Logger LOGGER = LoggerFactory.getLogger(E01_ClusterShowMetaData.class); 21 | 22 | /** StandAlone (vs JUNIT) to help you running. */ 23 | public static void main(String[] args) { 24 | LOGGER.info("Starting 'ClusterShowMetaData' sample..."); 25 | 26 | try (CqlSession cqlSession = CqlSession.builder() 27 | .addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 28 | .withLocalDatacenter("dc1") 29 | .build()) { 30 | 31 | LOGGER.info("Connected to cluster with Session '{}'", 32 | cqlSession.getName()); 33 | 34 | LOGGER.info("Protocol Version: {}", 35 | cqlSession.getContext().getProtocolVersion()); 36 | 37 | Metadata metaData = cqlSession.getMetadata(); 38 | 39 | LOGGER.info("Listing available Nodes:"); 40 | for (Node host : metaData.getNodes().values()) { 41 | LOGGER.info("+ [{}]: datacenter='{}' and rack='{}'", 42 | host.getListenAddress().orElse(null), 43 | host.getDatacenter(), 44 | host.getRack()); 45 | } 46 | 47 | LOGGER.info("[OK] Success"); 48 | } 49 | System.exit(0); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Astra • ReactJS • Serverless • Todo Demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
{{thing}}
22 |
23 |

Double-click to edit a todo

24 |

Created by gdborton

25 |

Upgraded and cloudified by huksley

26 |

Modified for Datastax Astra Cassandra service by tjake

27 |
28 | 29 | Fork me on GitHub 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/docker/Dockerfile.jvm: -------------------------------------------------------------------------------- 1 | #### 2 | # This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode 3 | # 4 | # Before building the docker image run: 5 | # 6 | # mvn package 7 | # 8 | # Then, build the image with: 9 | # 10 | # docker build -f src/main/docker/Dockerfile.jvm -t quarkus/my-artifactId-jvm . 11 | # 12 | # Then run the container using: 13 | # 14 | # docker run -i --rm -p 8080:8080 quarkus/my-artifactId-jvm 15 | # 16 | # If you want to include the debug port into your docker image 17 | # you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 18 | # 19 | # Then run the container using : 20 | # 21 | # docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/my-artifactId-jvm 22 | # 23 | ### 24 | FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1 25 | 26 | ARG JAVA_PACKAGE=java-11-openjdk-headless 27 | ARG RUN_JAVA_VERSION=1.3.8 28 | 29 | ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' 30 | 31 | # Install java and the run-java script 32 | # Also set up permissions for user `1001` 33 | RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ 34 | && microdnf update \ 35 | && microdnf clean all \ 36 | && mkdir /deployments \ 37 | && chown 1001 /deployments \ 38 | && chmod "g+rwX" /deployments \ 39 | && chown 1001:root /deployments \ 40 | && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ 41 | && chown 1001 /deployments/run-java.sh \ 42 | && chmod 540 /deployments/run-java.sh \ 43 | && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security 44 | 45 | # Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. 46 | ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" 47 | 48 | COPY target/lib/* /deployments/lib/ 49 | COPY target/*-runner.jar /deployments/app.jar 50 | 51 | EXPOSE 8080 52 | USER 1001 53 | 54 | ENTRYPOINT [ "/deployments/run-java.sh" ] -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/chevrons/ChevronRestController.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.chevrons; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.DELETE; 4 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 5 | import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS; 6 | import static org.springframework.web.bind.annotation.RequestMethod.PATCH; 7 | import static org.springframework.web.bind.annotation.RequestMethod.POST; 8 | import static org.springframework.web.bind.annotation.RequestMethod.PUT; 9 | 10 | import java.util.List; 11 | 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.CrossOrigin; 14 | import org.springframework.web.bind.annotation.GetMapping; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | @RestController 20 | @RequestMapping("/api/chevrons") 21 | @CrossOrigin( 22 | methods = {PUT, POST, GET, OPTIONS, DELETE, PATCH}, 23 | maxAge = 3600, 24 | allowedHeaders = {"x-requested-with", "origin", "content-type", "accept"}, 25 | origins = "*" 26 | ) 27 | public class ChevronRestController { 28 | 29 | private final ChevronRepository repo; 30 | 31 | public ChevronRestController(ChevronRepository chevronRepo) { 32 | this.repo = chevronRepo; 33 | } 34 | 35 | @GetMapping 36 | public List findAll() { 37 | return repo.findAll(); 38 | } 39 | 40 | @GetMapping("/{area}") 41 | public List findByArea(@PathVariable(value = "area") String area) { 42 | return repo.findByKeyArea(area); 43 | } 44 | 45 | @GetMapping("/{area}/{code}") 46 | public ResponseEntity findAChevron(@PathVariable(value = "area") String area, 47 | @PathVariable(value = "code") int code) { 48 | return repo.findById(new ChevronPrimaryKey(area, code)) 49 | .map(ResponseEntity::ok) 50 | .orElse(ResponseEntity.notFound().build()); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E05_ProgrammaticConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.time.Duration; 4 | import java.util.Arrays; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import com.datastax.oss.driver.api.core.CqlSession; 10 | import com.datastax.oss.driver.api.core.config.DefaultDriverOption; 11 | import com.datastax.oss.driver.api.core.config.DriverConfigLoader; 12 | import com.datastax.samples.schema.SchemaConstants; 13 | 14 | /** 15 | * Sample code to create tables, types and objects in a keyspace. 16 | * 17 | * Pre-requisites: 18 | * - Cassandra running locally (127.0.0.1, port 9042) 19 | * - Keyspace killrvideo created {@link E02_CreateKeyspace} 20 | * 21 | * Doc : https://docs.datastax.com/en/developer/java-driver/4.5/manual/core/configuration/ 22 | */ 23 | public class E05_ProgrammaticConfiguration implements SchemaConstants { 24 | 25 | /** Logger for the class. */ 26 | private static Logger LOGGER = LoggerFactory.getLogger(E05_ProgrammaticConfiguration.class); 27 | 28 | /** StandAlone (vs JUNIT) to help you running. */ 29 | public static void main(String[] args) { 30 | 31 | DriverConfigLoader loader = DriverConfigLoader.programmaticBuilder() 32 | .withStringList(DefaultDriverOption.CONTACT_POINTS, Arrays.asList("127.0.0.1:9042")) 33 | .withString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, "dc1") 34 | .withString(DefaultDriverOption.SESSION_KEYSPACE, KEYSPACE_NAME) 35 | .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(5)) 36 | .startProfile("slow") 37 | .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(30)) 38 | .endProfile() 39 | .build(); 40 | 41 | // Use it to create the session 42 | try (CqlSession cqlSession = CqlSession.builder().withConfigLoader(loader).build()) { 43 | 44 | // Use session 45 | LOGGER.info("[OK] Connected to Keyspace {}", cqlSession.getKeyspace().get()); 46 | } 47 | LOGGER.info("[OK] Success"); 48 | System.exit(0); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-navbar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 19 |
20 | 21 |
22 | 46 |
47 | 48 |
49 | 68 |
69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-error/500.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |

500

19 |

title

20 | x 22 | 23 |

24 |

25 |   title 29 | 30 |
31 | 32 | 33 |

34 |

Session DUMP

35 | 36 | 37 | 38 | 40 | 42 | 43 | 44 | 45 | 46 | 47 |
KeyGroup
javax.servlet.context.tempdir/tmp
48 |

49 | 50 | 51 |
52 | 53 | 54 |
55 | 56 | 57 |
58 | 59 | 60 | 61 |
62 |
63 |
64 |
65 |
66 |
67 | 68 | 69 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E03_CreateSchema.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import static com.datastax.samples.schema.SchemaUtils.createTableCommentByUser; 4 | import static com.datastax.samples.schema.SchemaUtils.createTableCommentByVideo; 5 | import static com.datastax.samples.schema.SchemaUtils.createTableUser; 6 | import static com.datastax.samples.schema.SchemaUtils.createTableVideo; 7 | import static com.datastax.samples.schema.SchemaUtils.createTableVideoViews; 8 | import static com.datastax.samples.schema.SchemaUtils.createUdtVideoFormat; 9 | 10 | import java.net.InetSocketAddress; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | /** 16 | * Sample code to create tables, types and objects in a keyspace. 17 | * 18 | * Pre-requisites: 19 | * - Cassandra running locally (127.0.0.1, port 9042) 20 | * - Keyspace killrvideo created {@link SampleCode4x_CONNECT_CreateKeyspace} 21 | */ 22 | import com.datastax.oss.driver.api.core.CqlSession; 23 | import com.datastax.samples.schema.SchemaConstants; 24 | 25 | 26 | /** 27 | * Sample code to create tables, types and objects in a keyspace. 28 | * 29 | * Pre-requisites: 30 | * - Cassandra running locally (127.0.0.1, port 9042) 31 | */ 32 | public class E03_CreateSchema implements SchemaConstants { 33 | 34 | /** Logger for the class. */ 35 | private static Logger LOGGER = LoggerFactory.getLogger(E03_CreateSchema.class); 36 | 37 | /** StandAlone (vs JUNIT) to help you running. */ 38 | public static void main(String[] args) { 39 | LOGGER.info("Starting 'CreateSchema' sample..."); 40 | 41 | try (CqlSession cqlSession = CqlSession.builder() 42 | .addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 43 | .withLocalDatacenter("dc1") 44 | .withKeyspace(KEYSPACE_NAME) 45 | .build()) { 46 | createUdtVideoFormat(cqlSession); 47 | createTableUser(cqlSession); 48 | createTableVideo(cqlSession); 49 | createTableVideoViews(cqlSession); 50 | createTableCommentByVideo(cqlSession); 51 | createTableCommentByUser(cqlSession); 52 | } 53 | LOGGER.info("[OK] Success"); 54 | System.exit(0); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/web/HomeBean.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.web; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import com.datastax.demo.stargate.destinations.Destination; 10 | 11 | /** 12 | * Web bean to be displayed on home page 13 | * 14 | * @author Cedrick LUNVEN (@clunven) 15 | */ 16 | public class HomeBean implements Serializable { 17 | 18 | /** Serial. */ 19 | private static final long serialVersionUID = -4329564412692576275L; 20 | 21 | private Destination destination; 22 | 23 | private Map chevronMap = new HashMap<>(); 24 | 25 | /** List of available planets. */ 26 | private List catalog = new ArrayList<>(); 27 | 28 | /** 29 | * Getter accessor for attribute 'destination'. 30 | * 31 | * @return 32 | * current value of 'destination' 33 | */ 34 | public Destination getDestination() { 35 | return destination; 36 | } 37 | 38 | /** 39 | * Setter accessor for attribute 'destination'. 40 | * @param destination 41 | * new value for 'destination ' 42 | */ 43 | public void setDestination(Destination destination) { 44 | this.destination = destination; 45 | } 46 | 47 | /** 48 | * Getter accessor for attribute 'chevronMap'. 49 | * 50 | * @return 51 | * current value of 'chevronMap' 52 | */ 53 | public Map getChevronMap() { 54 | return chevronMap; 55 | } 56 | 57 | /** 58 | * Setter accessor for attribute 'chevronMap'. 59 | * @param chevronMap 60 | * new value for 'chevronMap ' 61 | */ 62 | public void setChevronMap(Map chevronMap) { 63 | this.chevronMap = chevronMap; 64 | } 65 | 66 | /** 67 | * Getter accessor for attribute 'catalog'. 68 | * 69 | * @return 70 | * current value of 'catalog' 71 | */ 72 | public List getCatalog() { 73 | return catalog; 74 | } 75 | 76 | /** 77 | * Setter accessor for attribute 'catalog'. 78 | * @param catalog 79 | * new value for 'catalog ' 80 | */ 81 | public void setCatalog(List catalog) { 82 | this.catalog = catalog; 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/test/java/com/datastax/demo/stargate/Ex6_SdkDocApi.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | import java.util.UUID; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | 12 | import com.datastax.astra.sdk.AstraClient; 13 | import com.datastax.stargate.sdk.doc.domain.SearchDocumentQuery; 14 | 15 | import lombok.AllArgsConstructor; 16 | import lombok.Data; 17 | import lombok.NoArgsConstructor; 18 | 19 | @SpringBootTest 20 | public class Ex6_SdkDocApi { 21 | 22 | 23 | @Autowired 24 | private AstraClient astraClient; 25 | 26 | @Test 27 | public void listDocument() { 28 | 29 | if (!astraClient.apiStargateDocument() 30 | .namespace("stargate") 31 | .exist()) { 32 | throw new IllegalArgumentException("Make sure you use 'stargate' as namespace"); 33 | } 34 | 35 | if (!astraClient.apiStargateDocument() 36 | .namespace("stargate") 37 | .collection("sampledoc") 38 | .exist()) { 39 | throw new IllegalArgumentException("Make sure you use create a doc in `sampledoc1` step 11a : https://github.com/datastaxdevs/workshop-spring-stargate#11-using-stargate-document-api"); 40 | } 41 | 42 | astraClient.apiStargateDocument() 43 | .namespace("stargate") 44 | .collection("sampledoc") 45 | .search(SearchDocumentQuery.builder().build(), VideoBean.class) 46 | .forEach(doc -> { 47 | System.out.println("Document:"); 48 | System.out.println("+ id=" + doc.getDocumentId()); 49 | System.out.println("+ email= " + doc.getDocument().getEmail()); 50 | System.out.println(""); 51 | }); 52 | } 53 | 54 | @Data 55 | @AllArgsConstructor 56 | @NoArgsConstructor 57 | private static class VideoBean { 58 | private UUID videoid; 59 | private String email; 60 | private String upload; 61 | private String url; 62 | private List frames; 63 | private Set tags; 64 | private Map> formats; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/codec/BytesArrayTypeCodec.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.codec; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.nio.charset.Charset; 5 | import java.nio.charset.StandardCharsets; 6 | 7 | import com.datastax.oss.driver.api.core.ProtocolVersion; 8 | import com.datastax.oss.driver.api.core.type.DataType; 9 | import com.datastax.oss.driver.api.core.type.DataTypes; 10 | import com.datastax.oss.driver.api.core.type.codec.TypeCodec; 11 | import com.datastax.oss.driver.api.core.type.reflect.GenericType; 12 | 13 | /** 14 | * Retrieve a blob as a byte array from Cassandra. 15 | */ 16 | public class BytesArrayTypeCodec implements TypeCodec { 17 | 18 | private Charset charSet = StandardCharsets.UTF_8; 19 | 20 | public BytesArrayTypeCodec(Charset charSet) { 21 | this.charSet = charSet; 22 | } 23 | 24 | /** Default constructor. */ 25 | public BytesArrayTypeCodec() { 26 | this(StandardCharsets.UTF_8); 27 | } 28 | 29 | /** {@inheritDoc} */ 30 | @Override 31 | public GenericType getJavaType() { 32 | return GenericType.of(byte[].class); 33 | } 34 | 35 | /** {@inheritDoc} */ 36 | @Override 37 | public DataType getCqlType() { 38 | return DataTypes.BLOB; 39 | } 40 | 41 | /** {@inheritDoc} */ 42 | @Override 43 | public ByteBuffer encode(byte[] value, ProtocolVersion protocolVersion) { 44 | if (value == null) return null; 45 | ByteBuffer byteBuffer = ByteBuffer.allocate(value.length); 46 | byteBuffer.put(value); 47 | return byteBuffer; 48 | } 49 | 50 | /** {@inheritDoc} */ 51 | @Override 52 | public byte[] decode(ByteBuffer byteBuffer, ProtocolVersion protocolVersion) { 53 | if (byteBuffer == null) return null; 54 | byte[] bytesArray = new byte[byteBuffer.remaining()]; 55 | byteBuffer.get(bytesArray, 0, bytesArray.length); 56 | return bytesArray; 57 | } 58 | 59 | /** {@inheritDoc} */ 60 | @Override 61 | public String format(byte[] value) { 62 | if (value == null) return "NULL"; 63 | return new String(value, charSet); 64 | } 65 | 66 | /** {@inheritDoc} */ 67 | @Override 68 | public byte[] parse(String value) { 69 | return (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) 70 | ? null 71 | : value.getBytes(charSet); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.datastax.oss.driver.api.core.cql.Row; 6 | import com.datastax.samples.schema.SchemaConstants; 7 | 8 | /** 9 | * Sample bean for row. 10 | */ 11 | public class UserDto implements Serializable, SchemaConstants { 12 | 13 | /** Serial. */ 14 | private static final long serialVersionUID = -6767335554891314036L; 15 | 16 | private String email; 17 | 18 | private String firstName; 19 | 20 | private String lastName; 21 | 22 | public UserDto() { 23 | } 24 | 25 | public UserDto(Row tableUsersRow) { 26 | super(); 27 | this.email = tableUsersRow.getString(USER_EMAIL); 28 | this.firstName = tableUsersRow.getString(USER_FIRSTNAME); 29 | this.lastName = tableUsersRow.getString(USER_LASTNAME); 30 | } 31 | 32 | public UserDto(String email, String firstName, String lastName) { 33 | super(); 34 | this.email = email; 35 | this.firstName = firstName; 36 | this.lastName = lastName; 37 | } 38 | 39 | /** 40 | * Getter accessor for attribute 'email'. 41 | * 42 | * @return 43 | * current value of 'email' 44 | */ 45 | public String getEmail() { 46 | return email; 47 | } 48 | 49 | /** 50 | * Setter accessor for attribute 'email'. 51 | * @param email 52 | * new value for 'email ' 53 | */ 54 | public void setEmail(String email) { 55 | this.email = email; 56 | } 57 | 58 | /** 59 | * Getter accessor for attribute 'firstName'. 60 | * 61 | * @return 62 | * current value of 'firstName' 63 | */ 64 | public String getFirstName() { 65 | return firstName; 66 | } 67 | 68 | /** 69 | * Setter accessor for attribute 'firstName'. 70 | * @param firstName 71 | * new value for 'firstName ' 72 | */ 73 | public void setFirstName(String firstName) { 74 | this.firstName = firstName; 75 | } 76 | 77 | /** 78 | * Getter accessor for attribute 'lastName'. 79 | * 80 | * @return 81 | * current value of 'lastName' 82 | */ 83 | public String getLastName() { 84 | return lastName; 85 | } 86 | 87 | /** 88 | * Setter accessor for attribute 'lastName'. 89 | * @param lastName 90 | * new value for 'lastName ' 91 | */ 92 | public void setLastName(String lastName) { 93 | this.lastName = lastName; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/META-INF/resources/css/base.css: -------------------------------------------------------------------------------- 1 | hr { 2 | margin: 20px 0; 3 | border: 0; 4 | border-top: 1px dashed #c5c5c5; 5 | border-bottom: 1px dashed #f7f7f7; 6 | } 7 | 8 | .learn a { 9 | font-weight: normal; 10 | text-decoration: none; 11 | color: #b83f45; 12 | } 13 | 14 | .learn a:hover { 15 | text-decoration: underline; 16 | color: #787e7e; 17 | } 18 | 19 | .learn h3, 20 | .learn h4, 21 | .learn h5 { 22 | margin: 10px 0; 23 | font-weight: 500; 24 | line-height: 1.2; 25 | color: #000; 26 | } 27 | 28 | .learn h3 { 29 | font-size: 24px; 30 | } 31 | 32 | .learn h4 { 33 | font-size: 18px; 34 | } 35 | 36 | .learn h5 { 37 | margin-bottom: 0; 38 | font-size: 14px; 39 | } 40 | 41 | .learn ul { 42 | padding: 0; 43 | margin: 0 0 30px 25px; 44 | } 45 | 46 | .learn li { 47 | line-height: 20px; 48 | } 49 | 50 | .learn p { 51 | font-size: 15px; 52 | font-weight: 300; 53 | line-height: 1.3; 54 | margin-top: 0; 55 | margin-bottom: 0; 56 | } 57 | 58 | #issue-count { 59 | display: none; 60 | } 61 | 62 | .quote { 63 | border: none; 64 | margin: 20px 0 60px 0; 65 | } 66 | 67 | .quote p { 68 | font-style: italic; 69 | } 70 | 71 | .quote p:before { 72 | content: '“'; 73 | font-size: 50px; 74 | opacity: .15; 75 | position: absolute; 76 | top: -20px; 77 | left: 3px; 78 | } 79 | 80 | .quote p:after { 81 | content: '”'; 82 | font-size: 50px; 83 | opacity: .15; 84 | position: absolute; 85 | bottom: -42px; 86 | right: 3px; 87 | } 88 | 89 | .quote footer { 90 | position: absolute; 91 | bottom: -40px; 92 | right: 0; 93 | } 94 | 95 | .quote footer img { 96 | border-radius: 3px; 97 | } 98 | 99 | .quote footer a { 100 | margin-left: 5px; 101 | vertical-align: middle; 102 | } 103 | 104 | .speech-bubble { 105 | position: relative; 106 | padding: 10px; 107 | background: rgba(0, 0, 0, .04); 108 | border-radius: 5px; 109 | } 110 | 111 | .speech-bubble:after { 112 | content: ''; 113 | position: absolute; 114 | top: 100%; 115 | right: 30px; 116 | border: 13px solid transparent; 117 | border-top-color: rgba(0, 0, 0, .04); 118 | } 119 | 120 | .learn-bar > .learn { 121 | position: absolute; 122 | width: 272px; 123 | top: 8px; 124 | left: -300px; 125 | padding: 10px; 126 | border-radius: 5px; 127 | background-color: rgba(255, 255, 255, .6); 128 | transition-property: left; 129 | transition-duration: 500ms; 130 | } 131 | 132 | @media (min-width: 899px) { 133 | .learn-bar { 134 | width: auto; 135 | padding-left: 300px; 136 | } 137 | 138 | .learn-bar > .learn { 139 | left: 8px; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/dto/FileDto.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.dto; 2 | 3 | import java.io.Serializable; 4 | import java.nio.ByteBuffer; 5 | import java.time.Instant; 6 | 7 | /** 8 | * Sample POJO. 9 | */ 10 | public class FileDto implements Serializable { 11 | 12 | /** Serial. */ 13 | private static final long serialVersionUID = 7325306650146053028L; 14 | 15 | private String filename; 16 | 17 | private String extension; 18 | 19 | private Instant updload; 20 | 21 | private ByteBuffer content; 22 | 23 | public FileDto() { 24 | } 25 | 26 | /** 27 | * Getter accessor for attribute 'filename'. 28 | * 29 | * @return 30 | * current value of 'filename' 31 | */ 32 | public String getFilename() { 33 | return filename; 34 | } 35 | 36 | /** 37 | * Setter accessor for attribute 'filename'. 38 | * @param filename 39 | * new value for 'filename ' 40 | */ 41 | public void setFilename(String filename) { 42 | this.filename = filename; 43 | } 44 | 45 | /** 46 | * Getter accessor for attribute 'extension'. 47 | * 48 | * @return 49 | * current value of 'extension' 50 | */ 51 | public String getExtension() { 52 | return extension; 53 | } 54 | 55 | /** 56 | * Setter accessor for attribute 'extension'. 57 | * @param extension 58 | * new value for 'extension ' 59 | */ 60 | public void setExtension(String extension) { 61 | this.extension = extension; 62 | } 63 | 64 | /** 65 | * Getter accessor for attribute 'updload'. 66 | * 67 | * @return 68 | * current value of 'updload' 69 | */ 70 | public Instant getUpload() { 71 | return updload; 72 | } 73 | 74 | /** 75 | * Setter accessor for attribute 'updload'. 76 | * @param updload 77 | * new value for 'updload ' 78 | */ 79 | public void setUpload(Instant updload) { 80 | this.updload = updload; 81 | } 82 | 83 | /** 84 | * Getter accessor for attribute 'content'. 85 | * 86 | * @return 87 | * current value of 'content' 88 | */ 89 | public ByteBuffer getContent() { 90 | return content; 91 | } 92 | 93 | /** 94 | * Setter accessor for attribute 'content'. 95 | * @param content 96 | * new value for 'content ' 97 | */ 98 | public void setContent(ByteBuffer content) { 99 | this.content = content; 100 | } 101 | 102 | 103 | 104 | } 105 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/test/java/com/datastax/workshop/E22_SpringDataAstraConnectivity.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop; 2 | 3 | import java.io.File; 4 | import java.nio.file.Paths; 5 | 6 | import org.junit.jupiter.api.Assertions; 7 | import org.junit.jupiter.api.DisplayName; 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.extension.ExtendWith; 10 | import org.junit.platform.runner.JUnitPlatform; 11 | import org.junit.runner.RunWith; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Value; 15 | import org.springframework.test.context.TestPropertySource; 16 | import org.springframework.test.context.junit.jupiter.SpringExtension; 17 | 18 | import com.datastax.oss.driver.api.core.CqlSession; 19 | 20 | /** 21 | * Connecticity to ASTRA 22 | */ 23 | @SuppressWarnings("deprecation") 24 | @RunWith(JUnitPlatform.class) 25 | @ExtendWith(SpringExtension.class) 26 | @TestPropertySource(locations="/application.properties") 27 | public class E22_SpringDataAstraConnectivity { 28 | 29 | /** Logger for the class. */ 30 | private static Logger LOGGER = LoggerFactory.getLogger(E22_SpringDataAstraConnectivity.class); 31 | 32 | @Value("${spring.data.cassandra.username}") 33 | private String username; 34 | 35 | @Value("${spring.data.cassandra.password}") 36 | private String password; 37 | 38 | @Value("${spring.data.cassandra.keyspace-name}") 39 | private String keyspace; 40 | 41 | @Value("${datastax.astra.secure-connect-bundle}") 42 | private String cloudSecureBundle; 43 | 44 | @Test 45 | @DisplayName("Test connectivity to Astra explicit values") 46 | public void should_connect_to_Astra() { 47 | 48 | // Given interface is properly populated 49 | Assertions.assertTrue(new File(cloudSecureBundle).exists(), 50 | "File '" + cloudSecureBundle + "' has not been found\n" 51 | + "To run this sample you need to download the secure bundle file from ASTRA WebPage\n" 52 | + "More info here:"); 53 | 54 | // When connecting to ASTRA 55 | try (CqlSession cqlSession = CqlSession.builder() 56 | //.addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 57 | .withCloudSecureConnectBundle(Paths.get(cloudSecureBundle)) 58 | .withAuthCredentials(username, password) 59 | .withKeyspace(keyspace) 60 | .build()) { 61 | 62 | // Then connection is successfull 63 | LOGGER.info(" + [OK] - Connection Established to Astra with Keyspace {}", 64 | cqlSession.getKeyspace().get()); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.datastax 7 | javazone-1-cassandra-drivers 8 | 1.0-SNAPSHOT 9 | jar 10 | javazone-1-cassandra-drivers 11 | 12 | 13 | 14 | 15 | 4.13.0 16 | 1.2.3 17 | 18 | 19 | 11 20 | UTF-8 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | com.datastax.oss 29 | java-driver-core 30 | ${cassandra.driver.oss.version} 31 | 32 | 33 | ch.qos.logback 34 | logback-classic 35 | ${logback.version} 36 | 37 | 38 | 39 | 40 | com.datastax.oss 41 | java-driver-query-builder 42 | ${cassandra.driver.oss.version} 43 | 44 | 45 | com.datastax.oss 46 | java-driver-mapper-runtime 47 | ${cassandra.driver.oss.version} 48 | 49 | 50 | 51 | 52 | io.projectreactor 53 | reactor-core 54 | 3.3.3.RELEASE 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-compiler-plugin 65 | 3.8.1 66 | 67 | ${java.version} 68 | ${java.version} 69 | ${java.version} 70 | 71 | 72 | com.datastax.oss 73 | java-driver-mapper-processor 74 | ${cassandra.driver.oss.version} 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.web; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Optional; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.ui.Model; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | 16 | import com.datastax.demo.stargate.chevrons.ChevronRepository; 17 | import com.datastax.demo.stargate.destinations.Destination; 18 | import com.datastax.demo.stargate.destinations.DestinationPrimaryKey; 19 | import com.datastax.demo.stargate.destinations.DestinationRepository; 20 | 21 | /** 22 | * Home Controller, we want to show the gate. 23 | * 24 | * @author Cedrick LUNVEN (@clunven) 25 | * @author Sergi Almar (@sergialmar) 26 | */ 27 | @Controller 28 | public class HomeController { 29 | 30 | /** View name. */ 31 | private static final String HOME_VIEW = "home"; 32 | 33 | /** Reference to the chevron URL. */ 34 | private static Map chevronMap = new HashMap<>(); 35 | 36 | private static List catalog = new ArrayList<>(); 37 | 38 | private static final String GALAXY = "Milky Way"; 39 | 40 | 41 | private final DestinationRepository destinationRepository; 42 | 43 | private final ChevronRepository chevronRepository; 44 | 45 | 46 | public HomeController(DestinationRepository destinationRepository, ChevronRepository chevronRepository) { 47 | this.destinationRepository = destinationRepository; 48 | this.chevronRepository = chevronRepository; 49 | } 50 | 51 | @PostConstruct 52 | public void populateChevonsAndCatalog() { 53 | chevronRepository.findByKeyArea(GALAXY).forEach(chevron -> { 54 | chevronMap.put(chevron.getKey().getCode(), chevron.getName()); 55 | }); 56 | 57 | catalog = destinationRepository.findByKeyGalaxy(GALAXY); 58 | } 59 | 60 | @GetMapping("/") 61 | public String showHome(@RequestParam(name = "planetName", defaultValue = "Chulak") String planetName, 62 | Model model) throws Exception { 63 | 64 | HomeBean hb = new HomeBean(); 65 | hb.setChevronMap(chevronMap); 66 | hb.setCatalog(catalog); 67 | hb.setDestination(new Destination(new DestinationPrimaryKey(GALAXY, planetName), 1, 1, 1, 1, 1, 1, "ok")); 68 | Optional destination = 69 | destinationRepository.findById( 70 | new DestinationPrimaryKey(GALAXY, planetName)); 71 | destination.ifPresent(hb::setDestination); 72 | model.addAttribute("homebean", hb); 73 | return HOME_VIEW; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/codec/UdtVideoFormatCodec.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.codec; 2 | 3 | import java.nio.ByteBuffer; 4 | 5 | import com.datastax.oss.driver.api.core.ProtocolVersion; 6 | import com.datastax.oss.driver.api.core.data.UdtValue; 7 | import com.datastax.oss.driver.api.core.type.DataType; 8 | import com.datastax.oss.driver.api.core.type.UserDefinedType; 9 | import com.datastax.oss.driver.api.core.type.codec.TypeCodec; 10 | import com.datastax.oss.driver.api.core.type.reflect.GenericType; 11 | import com.datastax.samples.dto.VideoFormatDto; 12 | import com.datastax.samples.schema.SchemaConstants; 13 | 14 | /** 15 | * Codec. 16 | */ 17 | public class UdtVideoFormatCodec implements TypeCodec, SchemaConstants { 18 | 19 | final TypeCodec innerCodec; 20 | 21 | final UserDefinedType videoFormatUdt; 22 | 23 | public UdtVideoFormatCodec(TypeCodec innerCodec, Class javaType) { 24 | this.innerCodec = innerCodec; 25 | this.videoFormatUdt = (UserDefinedType) innerCodec.getCqlType(); 26 | } 27 | 28 | /** {@inheritDoc} */ 29 | @Override 30 | public GenericType getJavaType() { 31 | return GenericType.of(VideoFormatDto.class); 32 | } 33 | 34 | /** {@inheritDoc} */ 35 | @Override 36 | public DataType getCqlType() { 37 | return videoFormatUdt; 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | @Override 42 | public ByteBuffer encode(VideoFormatDto value, ProtocolVersion protocolVersion) { 43 | return innerCodec.encode(toUDTValue(value), protocolVersion); 44 | } 45 | 46 | /** {@inheritDoc} */ 47 | @Override 48 | public VideoFormatDto decode(ByteBuffer bytes, ProtocolVersion protocolVersion) { 49 | return toVideoFormatDto(innerCodec.decode(bytes, protocolVersion)); 50 | } 51 | 52 | /** {@inheritDoc} */ 53 | @Override 54 | public String format(VideoFormatDto value) { 55 | return value == null ? "NULL" : innerCodec.format(toUDTValue(value)); 56 | } 57 | 58 | /** {@inheritDoc} */ 59 | @Override 60 | public VideoFormatDto parse(String value) { 61 | return value == null || value.isEmpty() || value.equalsIgnoreCase("NULL") ? 62 | null : toVideoFormatDto(innerCodec.parse(value)); 63 | } 64 | 65 | protected VideoFormatDto toVideoFormatDto(UdtValue value) { 66 | return value == null ? null : new VideoFormatDto( 67 | value.getInt(UDT_VIDEO_FORMAT_WIDTH), 68 | value.getInt(UDT_VIDEO_FORMAT_HEIGHT) 69 | ); 70 | } 71 | 72 | protected UdtValue toUDTValue(VideoFormatDto value) { 73 | return value == null ? null : videoFormatUdt.newValue() 74 | .setInt(UDT_VIDEO_FORMAT_WIDTH, value.getWidth()) 75 | .setInt(UDT_VIDEO_FORMAT_HEIGHT, value.getHeight()); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.1 9 | 10 | 11 | com.datastax.workshop 12 | javazone-2-spring-data 13 | 0.0.1-SNAPSHOT 14 | javazone-2-spring-data 15 | TodoBackend Spring Boot Microservices with Spring Data for Apache Cassandra 16 | 17 | 18 | 11 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-cassandra 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-devtools 36 | runtime 37 | true 38 | 39 | 40 | 41 | org.projectlombok 42 | lombok 43 | true 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | org.junit.vintage 54 | junit-vintage-engine 55 | 56 | 57 | com.vaadin.external.google 58 | android-json 59 | 60 | 61 | 62 | 63 | org.junit.jupiter 64 | junit-jupiter-api 65 | test 66 | 67 | 68 | org.junit.jupiter 69 | junit-jupiter-engine 70 | test 71 | 72 | 73 | org.junit.platform 74 | junit-platform-runner 75 | test 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/java/com/datastax/demo/stargate/conf/WebConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.datastax.demo.stargate.conf; 2 | 3 | import java.util.Locale; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.web.servlet.HandlerInterceptor; 12 | import org.springframework.web.servlet.LocaleResolver; 13 | import org.springframework.web.servlet.ModelAndView; 14 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 15 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 16 | import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; 17 | import org.springframework.web.servlet.i18n.CookieLocaleResolver; 18 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 19 | 20 | import com.datastax.astra.sdk.AstraClient; 21 | 22 | @Configuration 23 | public class WebConfiguration implements WebMvcConfigurer { 24 | 25 | @Autowired 26 | private AstraClient astraClient; 27 | 28 | 29 | 30 | @Override 31 | public void addInterceptors(InterceptorRegistry interceptorRegistry) { 32 | interceptorRegistry.addInterceptor(localeChangeInterceptor()); 33 | interceptorRegistry.addInterceptor(exposeNamespaceInterceptor()); 34 | } 35 | 36 | @Bean 37 | public LocaleResolver localeResolver() { 38 | CookieLocaleResolver localeResolver = new CookieLocaleResolver(); 39 | localeResolver.setDefaultLocale(Locale.ENGLISH); 40 | return localeResolver; 41 | } 42 | 43 | @Bean 44 | public LocaleChangeInterceptor localeChangeInterceptor() { 45 | LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); 46 | localeChangeInterceptor.setParamName("lang"); 47 | return localeChangeInterceptor; 48 | } 49 | 50 | @Bean 51 | public HandlerInterceptor exposeNamespaceInterceptor() { 52 | return new HandlerInterceptor() { 53 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 54 | ModelAndView modelAndView) throws Exception { 55 | astraClient.cqlSession().getKeyspace().ifPresent(namespace -> { 56 | if (modelAndView != null) { 57 | modelAndView.addObject("namespace", namespace.asInternal()); 58 | } 59 | }); 60 | } 61 | }; 62 | } 63 | 64 | @Bean 65 | public SimpleMappingExceptionResolver exposeExtraErrorInfoExceptionResolver() { 66 | return new SimpleMappingExceptionResolver() { 67 | @Override 68 | protected ModelAndView doResolveException(HttpServletRequest req, 69 | HttpServletResponse resp, Object handler, Exception ex) { 70 | 71 | req.setAttribute("msgType", "error"); 72 | req.setAttribute("msgInfo", ex.getMessage()); 73 | return super.doResolveException(req, resp, handler, ex); 74 | } 75 | }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E08_ConnectToAstraProgrammatic.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import java.io.File; 4 | import java.nio.file.Paths; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import com.datastax.oss.driver.api.core.CqlSession; 10 | import com.datastax.samples.schema.SchemaConstants; 11 | 12 | /** 13 | * This class shows how to connect to the DataStax Cloud Cassandra As a Service: ASTRA 14 | * 15 | * Pre-requisites: 16 | * =================== 17 | * 18 | * 1. You need an ASTRA intance : go to astra.datastax.com and create an instance there. There is a free tier 19 | * for you to have a 3-node clusters availables forever. You can find more info on: 20 | * 21 | * 2. You need to provide you ASTRA credentials username, password, keyspace 22 | * but also the secure bundle ZIP. To download it please follow the instruction on : 23 | * https://docs.datastax.com/en/developer/java-driver/4.5/manual/cloud/ 24 | * 25 | * 3. You need a java driver version 3.8 26 | */ 27 | public class E08_ConnectToAstraProgrammatic implements SchemaConstants { 28 | 29 | /** Logger for the class. */ 30 | private static Logger LOGGER = LoggerFactory.getLogger(E08_ConnectToAstraProgrammatic.class); 31 | 32 | /** StandAlone (vs JUNIT) to help you running. */ 33 | public static void main(String[] args) { 34 | 35 | // ---- 36 | // #1. Connecting explicitely using the CqlSessionBuilder 37 | // ---- 38 | 39 | // Those are mandatory to connect to ASTRA 40 | final String ASTRA_ZIP_FILE = "/Users/cedricklunven/Downloads/secure-connect-javazone.zip"; 41 | final String ASTRA_KEYSPACE = "javazone"; 42 | final String ASTRA_CLIENTID = "LorYCpiKoBGtPZvTaXkJYUvf"; 43 | final String ASTRA_CLIENTSECRET = "PDRdeNf8Hb0+KTipmev1nPiYQuXbpMpW1wuN.ywz1.UtKRnnJQzgLRZu4cExSGc2xHIQHREzpeB,pugXl,vlSXStTpNxjhPBnl0yZjXJRyFIg2ZJ-K8SZZWHIcdH0SzS"; 44 | 45 | // Check the cloud zip file 46 | File cloudSecureConnectBundleFile = new File(ASTRA_ZIP_FILE); 47 | if (!cloudSecureConnectBundleFile.exists()) { 48 | throw new IllegalStateException("File '" + ASTRA_ZIP_FILE + "' has not been found\n" 49 | + "To run this sample you need to download the secure bundle file from ASTRA WebPage\n" 50 | + "More info here:"); 51 | } 52 | 53 | // Connect 54 | try (CqlSession cqlSession = CqlSession.builder() 55 | .withCloudSecureConnectBundle(Paths.get(ASTRA_ZIP_FILE)) 56 | .withAuthCredentials(ASTRA_CLIENTID, ASTRA_CLIENTSECRET) 57 | .withKeyspace(ASTRA_KEYSPACE) 58 | .build()) { 59 | LOGGER.info("[OK] Welcome to ASTRA. Connected to Keyspace {}", cqlSession.getKeyspace().get()); 60 | } 61 | LOGGER.info("[OK] Success"); 62 | System.exit(0); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/test/java/com/datastax/workshop/E23_CreateSchemaInAstraTest.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop; 2 | 3 | import java.nio.file.Paths; 4 | 5 | import org.junit.jupiter.api.DisplayName; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtendWith; 8 | import org.junit.platform.runner.JUnitPlatform; 9 | import org.junit.runner.RunWith; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.test.context.TestPropertySource; 14 | import org.springframework.test.context.junit.jupiter.SpringExtension; 15 | 16 | import com.datastax.oss.driver.api.core.CqlSession; 17 | import com.datastax.oss.driver.api.core.cql.SimpleStatement; 18 | import com.datastax.oss.driver.api.core.type.DataTypes; 19 | import com.datastax.oss.driver.api.querybuilder.SchemaBuilder; 20 | import com.datastax.workshop.todo.TodoEntity; 21 | 22 | @SuppressWarnings("deprecation") 23 | @RunWith(JUnitPlatform.class) 24 | @ExtendWith(SpringExtension.class) 25 | @TestPropertySource(locations="/application.properties") 26 | public class E23_CreateSchemaInAstraTest { 27 | 28 | /** Logger for the class. */ 29 | private static Logger LOGGER = LoggerFactory.getLogger(E23_CreateSchemaInAstraTest.class); 30 | 31 | @Value("${spring.data.cassandra.username}") 32 | private String username; 33 | 34 | @Value("${spring.data.cassandra.password}") 35 | private String password; 36 | 37 | @Value("${spring.data.cassandra.keyspace-name}") 38 | private String keyspace; 39 | 40 | @Value("${datastax.astra.secure-connect-bundle}") 41 | private String cloudSecureBundle; 42 | 43 | @Test 44 | @DisplayName("Test to create a table in ASTRA") 45 | public void should_create_expected_table() { 46 | try (CqlSession cqlSession = CqlSession.builder() 47 | //.addContactPoint(new InetSocketAddress("127.0.0.1", 9042)) 48 | .withCloudSecureConnectBundle(Paths.get(cloudSecureBundle)) 49 | .withAuthCredentials(username, password) 50 | .withKeyspace(keyspace) 51 | .build()) { 52 | LOGGER.info("Connection Established to Astra with Keyspace '{}'", 53 | cqlSession.getKeyspace().get()); 54 | SimpleStatement stmtCreateTable = SchemaBuilder 55 | .createTable(TodoEntity.TABLENAME) 56 | .ifNotExists() 57 | .withPartitionKey(TodoEntity.COLUMN_UID, DataTypes.UUID) 58 | .withColumn(TodoEntity.COLUMN_TITLE, DataTypes.TEXT) 59 | .withColumn(TodoEntity.COLUMN_COMPLETED, DataTypes.BOOLEAN) 60 | .withColumn(TodoEntity.COLUMN_ORDER, DataTypes.INT) 61 | .build(); 62 | 63 | // When creating the table 64 | cqlSession.execute(stmtCreateTable); 65 | 66 | // Then table is created 67 | LOGGER.info("Table '{}' has been created (if needed).", TodoEntity.TABLENAME); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright DataStax, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | #quarkus.container-image.build=true 17 | #quarkus.container-image.push=true 18 | quarkus.container-image.registry=docker.io 19 | #quarkus.container-image.build=false 20 | quarkus.profile=dev 21 | #quarkus.container-image.group=ragsns 22 | quarkus.container-image.name=quarkus-cassandra 23 | 24 | quarkus.kubernetes.service-type=load-balancer 25 | 26 | #quarkus.native.resources.includes=** 27 | 28 | 29 | quarkus.cassandra.init.eager-init=true 30 | 31 | # Authentication 32 | quarkus.cassandra.keyspace=quarkus 33 | quarkus.cassandra.cloud.secure-connect-bundle=/Users/cedricklunven/Downloads/secure-connect-javazone.zip 34 | quarkus.cassandra.auth.username=change_me 35 | quarkus.cassandra.auth.password=change_me 36 | 37 | # Health Checks 38 | quarkus.cassandra.health.enabled=true 39 | 40 | # Metrics 41 | # See https://docs.datastax.com/en/developer/java-driver/latest/manual/core/metrics/ 42 | quarkus.cassandra.metrics.enabled=true 43 | quarkus.cassandra.metrics.session.enabled=\ 44 | bytes-sent,\ 45 | bytes-received,\ 46 | connected-nodes,\ 47 | cql-requests,\ 48 | cql-client-timeouts 49 | quarkus.cassandra.metrics.node.enabled=\ 50 | pool.open-connections,\ 51 | pool.in-flight,\ 52 | bytes-sent,\ 53 | bytes-received,\ 54 | cql-messages,\ 55 | errors.request.unsent,\ 56 | errors.request.aborted,\ 57 | errors.request.write-timeouts,\ 58 | errors.request.read-timeouts,\ 59 | errors.request.unavailables,\ 60 | errors.request.others,\ 61 | retries.total,\ 62 | retries.aborted,\ 63 | retries.read-timeout,\ 64 | retries.write-timeout,\ 65 | retries.unavailable,\ 66 | retries.other,\ 67 | ignores.total,\ 68 | ignores.aborted,\ 69 | ignores.read-timeout,\ 70 | ignores.write-timeout,\ 71 | ignores.unavailable,\ 72 | ignores.other,\ 73 | errors.connection.init,\ 74 | errors.connection.auth 75 | 76 | # Request properties 77 | #quarkus.cassandra.request.timeout=PT10S 78 | #quarkus.cassandra.request.consistency-level=LOCAL_QUORUM 79 | #quarkus.cassandra.request.serial-consistency-level=LOCAL_SERIAL 80 | #quarkus.cassandra.request.page-size=5000 81 | #quarkus.cassandra.request.default-idempotence=true 82 | 83 | # Protocol settings 84 | #quarkus.cassandra.protocol.compression=none 85 | 86 | # Startup and Initialization settings 87 | #quarkus.cassandra.init.eager-init=false 88 | #quarkus.cassandra.init.eager-init-timeout=PT10S 89 | #quarkus.cassandra.init.print-eager-init-info=true 90 | #quarkus.cassandra.init.reconnect-on-init=true 91 | #quarkus.cassandra.init.resolve-contact-points=false 92 | #quarkus.cassandra.init.use-quarkus-event-loop=true 93 | 94 | # Logging 95 | #quarkus.log.level=INFO 96 | #quarkus.log.min-level=DEBUG 97 | #quarkus.log.category."com.datastax.oss.quarkus".level=INFO 98 | #quarkus.log.category."com.datastax.oss.driver".level=INFO 99 | #quarkus.log.category."com.datastax.dse.driver".level=INFO 100 | 101 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/codec/JsonJacksonTypeCodec.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.codec; 2 | 3 | import java.io.IOException; 4 | import java.io.Serializable; 5 | import java.nio.ByteBuffer; 6 | 7 | import com.datastax.oss.driver.api.core.ProtocolVersion; 8 | import com.datastax.oss.driver.api.core.type.DataType; 9 | import com.datastax.oss.driver.api.core.type.DataTypes; 10 | import com.datastax.oss.driver.api.core.type.codec.TypeCodec; 11 | import com.datastax.oss.driver.api.core.type.reflect.GenericType; 12 | import com.fasterxml.jackson.core.JsonProcessingException; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | import com.fasterxml.jackson.databind.type.TypeFactory; 15 | 16 | /** 17 | * Convert some PJP into JSON. 18 | * 19 | * @param 20 | */ 21 | public class JsonJacksonTypeCodec implements TypeCodec { 22 | 23 | /** 24 | * Jackson will help us here json <-> POJO 25 | */ 26 | private final ObjectMapper objectMapper = new ObjectMapper(); 27 | 28 | private Class javaType; 29 | 30 | public JsonJacksonTypeCodec(Class classType) { 31 | this.javaType = classType; 32 | } 33 | 34 | /** {@inheritDoc} */ 35 | @Override 36 | public GenericType getJavaType() { 37 | return GenericType.of(javaType); 38 | } 39 | 40 | /** {@inheritDoc} */ 41 | @Override 42 | public DataType getCqlType() { 43 | return DataTypes.TEXT; 44 | } 45 | 46 | /** {@inheritDoc} */ 47 | @Override 48 | public ByteBuffer encode(T value, ProtocolVersion protocolVersion) { 49 | if (value == null) 50 | return null; 51 | try { 52 | return ByteBuffer.wrap(objectMapper.writeValueAsBytes(value)); 53 | } catch (JsonProcessingException e) { 54 | throw new IllegalArgumentException(e.getMessage(), e); 55 | } 56 | } 57 | 58 | /** {@inheritDoc} */ 59 | @Override 60 | @SuppressWarnings("unchecked") 61 | public T decode(ByteBuffer bytes, ProtocolVersion protocolVersion) { 62 | if (bytes == null) 63 | return null; 64 | try { 65 | byte[] b = new byte[bytes.remaining()]; 66 | bytes.duplicate().get(b); 67 | return (T) objectMapper.readValue(b, TypeFactory.defaultInstance().constructType(getJavaType().getType())); 68 | } catch (IOException e) { 69 | throw new IllegalArgumentException(e.getMessage(), e); 70 | } 71 | } 72 | 73 | /** {@inheritDoc} */ 74 | @Override 75 | public String format(T value) { 76 | if (value == null) 77 | return "NULL"; 78 | String json; 79 | try { 80 | json = objectMapper.writeValueAsString(value); 81 | } catch (IOException e) { 82 | throw new IllegalArgumentException(e.getMessage(), e); 83 | } 84 | return '\'' + json.replace("\'", "''") + '\''; 85 | } 86 | 87 | /** {@inheritDoc} */ 88 | @Override 89 | @SuppressWarnings("unchecked") 90 | public T parse(String value) { 91 | if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) 92 | return null; 93 | if (value.charAt(0) != '\'' || value.charAt(value.length() - 1) != '\'') 94 | throw new IllegalArgumentException("JSON strings must be enclosed by single quotes"); 95 | String json = value.substring(1, value.length() - 1).replace("''", "'"); 96 | try { 97 | return (T) objectMapper.readValue(json, TypeFactory.defaultInstance().constructType(getJavaType().getType())); 98 | } catch (IOException e) { 99 | throw new IllegalArgumentException(e.getMessage(), e); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/Comment.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import java.io.Serializable; 4 | import java.util.UUID; 5 | 6 | import com.datastax.oss.driver.api.core.uuid.Uuids; 7 | import com.datastax.oss.driver.api.mapper.annotations.ClusteringColumn; 8 | import com.datastax.oss.driver.api.mapper.annotations.CqlName; 9 | import com.datastax.samples.schema.SchemaConstants; 10 | 11 | /** 12 | * Bean standing for comment on video. 13 | * 14 | * @author DataStax Developer Advocates team. 15 | */ 16 | public class Comment implements Serializable, SchemaConstants { 17 | 18 | /** Serial. */ 19 | private static final long serialVersionUID = 7675521710612951368L; 20 | 21 | @CqlName(COMMENT_BY_USER_USERID) 22 | protected UUID userid; 23 | 24 | @CqlName(COMMENT_BY_USER_VIDEOID) 25 | protected UUID videoid; 26 | 27 | @ClusteringColumn 28 | @CqlName(COMMENT_BY_USER_COMMENTID) 29 | protected UUID commentid; 30 | 31 | @CqlName(COMMENT_BY_USER_COMMENT) 32 | protected String comment; 33 | 34 | /** 35 | * Default constructor. 36 | */ 37 | public Comment() { 38 | } 39 | 40 | /** 41 | * Constructor with parameters. 42 | * 43 | * @param userid 44 | * user unique identifier 45 | * @param videoId 46 | * video unique identifier 47 | * @param comment 48 | * text value for the comment 49 | */ 50 | public Comment(UUID userid, UUID videoId, String comment) { 51 | this.userid = userid; 52 | this.videoid = videoId; 53 | this.comment = comment; 54 | this.commentid = Uuids.timeBased(); 55 | } 56 | 57 | /** 58 | * Default constructor. 59 | */ 60 | public Comment(String comment) { 61 | this.comment = comment; 62 | } 63 | 64 | /** 65 | * Setter for attribute 'userid'. 66 | * @param userid 67 | * new value for 'userid ' 68 | */ 69 | public void setUserid(UUID userid) { 70 | this.userid = userid; 71 | } 72 | 73 | /** 74 | * Setter for attribute 'videoid'. 75 | * @param videoid 76 | * new value for 'videoid ' 77 | */ 78 | public void setVideoid(UUID videoid) { 79 | this.videoid = videoid; 80 | } 81 | 82 | /** 83 | * Getter for attribute 'commentid'. 84 | * 85 | * @return 86 | * current value of 'commentid' 87 | */ 88 | public UUID getCommentid() { 89 | return commentid; 90 | } 91 | 92 | /** 93 | * Setter for attribute 'commentid'. 94 | * @param commentid 95 | * new value for 'commentid ' 96 | */ 97 | public void setCommentid(UUID commentid) { 98 | this.commentid = commentid; 99 | } 100 | 101 | /** 102 | * Getter for attribute 'comment'. 103 | * 104 | * @return 105 | * current value of 'comment' 106 | */ 107 | public String getComment() { 108 | return comment; 109 | } 110 | 111 | /** 112 | * Setter for attribute 'comment'. 113 | * @param comment 114 | * new value for 'comment ' 115 | */ 116 | public void setComment(String comment) { 117 | this.comment = comment; 118 | } 119 | 120 | /** 121 | * Getter for attribute 'userid'. 122 | * 123 | * @return 124 | * current value of 'userid' 125 | */ 126 | public UUID getUserid() { 127 | return userid; 128 | } 129 | 130 | /** 131 | * Getter for attribute 'videoid'. 132 | * 133 | * @return 134 | * current value of 'videoid' 135 | */ 136 | public UUID getVideoid() { 137 | return videoid; 138 | } 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/schema/SchemaConstants.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.schema; 2 | 3 | /** 4 | * Externalization of schema constant. 5 | */ 6 | public interface SchemaConstants { 7 | 8 | String KEYSPACE_NAME = "javazone"; 9 | int KEYSPACE_REPLICATION_FACTOR = 1; 10 | 11 | /** 12 | * Will be used for this table: 13 | * 14 | * CREATE TABLE IF NOT EXISTS users ( 15 | * email text, 16 | * firstname text, 17 | * lastname text, 18 | * PRIMARY KEY (email) 19 | * ); 20 | */ 21 | String USER_TABLENAME = "users"; 22 | String USER_EMAIL = "email"; 23 | String USER_FIRSTNAME = "firstname"; 24 | String USER_LASTNAME = "lastname"; 25 | 26 | /** 27 | * CREATE TYPE IF NOT EXISTS video_format ( 28 | * width int, 29 | * height int 30 | *); 31 | */ 32 | String UDT_VIDEO_FORMAT_NAME = "video_format"; 33 | String UDT_VIDEO_FORMAT_WIDTH = "width"; 34 | String UDT_VIDEO_FORMAT_HEIGHT = "height"; 35 | 36 | /** 37 | * CREATE TABLE IF NOT EXISTS videos ( 38 | * videoid uuid, 39 | * title text, 40 | * upload timestamp, 41 | * email text, 42 | * url text, 43 | * tags set , 44 | * frames list, 45 | * formats map >, 46 | * PRIMARY KEY (videoid) 47 | * ); 48 | **/ 49 | String VIDEO_TABLENAME = "videos"; 50 | String VIDEO_VIDEOID = "videoid"; 51 | String VIDEO_TITLE = "title"; 52 | String VIDEO_UPLOAD = "upload"; 53 | String VIDEO_USER_EMAIL = "email"; 54 | String VIDEO_FRAMES = "frames"; 55 | String VIDEO_URL = "url"; 56 | String VIDEO_TAGS = "tags"; 57 | String VIDEO_FORMAT = "formats"; 58 | 59 | /** 60 | * CREATE TABLE IF NOT EXISTS videos_views ( 61 | * videoid uuid, 62 | * views counter, 63 | * PRIMARY KEY (videoid) 64 | * ); 65 | */ 66 | String VIDEO_VIEWS_TABLENAME = "videos_views"; 67 | String VIDEO_VIEWS_VIDEOID = "videoid"; 68 | String VIDEO_VIEWS_VIEWS = "views"; 69 | 70 | /** 71 | * CREATE TABLE IF NOT EXISTS comments_by_video ( 72 | * videoid uuid, 73 | * commentid timeuuid, 74 | * userid uuid, 75 | * comment text, 76 | * PRIMARY KEY (videoid, commentid) 77 | * ) WITH CLUSTERING ORDER BY (commentid DESC); 78 | * 79 | * 80 | * CREATE TABLE IF NOT EXISTS comments_by_user ( 81 | * userid uuid, 82 | * commentid timeuuid, 83 | * videoid uuid, 84 | * comment text, 85 | * PRIMARY KEY (userid, commentid) 86 | * ) WITH CLUSTERING ORDER BY (commentid DESC); 87 | */ 88 | String COMMENT_BY_VIDEO_TABLENAME = "comments_by_video"; 89 | String COMMENT_BY_VIDEO_VIDEOID = "videoid"; 90 | String COMMENT_BY_VIDEO_COMMENTID = "commentid"; 91 | String COMMENT_BY_VIDEO_USERID = "userid"; 92 | String COMMENT_BY_VIDEO_COMMENT = "comment"; 93 | String COMMENT_BY_USER_TABLENAME = "comments_by_user"; 94 | String COMMENT_BY_USER_VIDEOID = COMMENT_BY_VIDEO_VIDEOID; 95 | String COMMENT_BY_USER_COMMENTID = COMMENT_BY_VIDEO_COMMENTID; 96 | String COMMENT_BY_USER_USERID = COMMENT_BY_VIDEO_USERID; 97 | String COMMENT_BY_USER_COMMENT = COMMENT_BY_VIDEO_COMMENT; 98 | 99 | String FILES_TABLENAME = "files"; 100 | String FILES_FILENAME = "filename"; 101 | String FILES_EXTENSION = "extension"; 102 | String FILES_UPLOAD = "upload"; 103 | String FILES_BINARY = "binary"; 104 | 105 | } 106 | -------------------------------------------------------------------------------- /hands-on/3-quarkus/src/main/java/com/datastaxdev/todo/AstraTODO.java: -------------------------------------------------------------------------------- 1 | package com.datastaxdev.todo; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | import javax.enterprise.context.ApplicationScoped; 7 | import javax.enterprise.event.Observes; 8 | import javax.inject.Inject; 9 | import javax.ws.rs.Consumes; 10 | import javax.ws.rs.DELETE; 11 | import javax.ws.rs.GET; 12 | import javax.ws.rs.POST; 13 | import javax.ws.rs.Path; 14 | import javax.ws.rs.PathParam; 15 | import javax.ws.rs.Produces; 16 | import javax.ws.rs.core.MediaType; 17 | import javax.ws.rs.core.Response; 18 | 19 | import com.datastax.oss.driver.api.core.cql.ResultSet; 20 | import com.datastax.oss.driver.api.core.cql.Row; 21 | import com.datastax.oss.quarkus.runtime.api.session.QuarkusCqlSession; 22 | import com.datastaxdev.todo.api.Todo; 23 | 24 | import io.quarkus.runtime.StartupEvent; 25 | import io.smallrye.common.annotation.Blocking; 26 | 27 | @ApplicationScoped 28 | @Path("/api") 29 | public class AstraTODO { 30 | @Inject 31 | QuarkusCqlSession cqlSession; 32 | 33 | private String keyspaceName = "quarkus"; 34 | private String tableName = "todolist"; 35 | 36 | public boolean onStart(@Observes StartupEvent ev){ 37 | ResultSet rs = this.cqlSession.execute("CREATE TABLE IF NOT EXISTS " + this.keyspaceName+"." + this.tableName + "(list_id text, id text, title text, completed boolean, PRIMARY KEY(list_id, id));"); 38 | System.out.println("**** Table created " + rs.wasApplied() + "****"); 39 | return rs.wasApplied(); 40 | } 41 | 42 | @GET 43 | @Produces(MediaType.APPLICATION_JSON) 44 | @Path("/todo/{list_id}") 45 | @Blocking 46 | public List getTodos(@PathParam("list_id") String list_id) { 47 | ResultSet rs = this.cqlSession 48 | .execute("SELECT * FROM " + this.keyspaceName + "." + this.tableName + " where list_id =?", list_id); 49 | 50 | List rows = rs.all(); 51 | return rows.stream() 52 | .map(x -> new Todo(x.getString("id"), x.getString("title"), x.getBoolean("completed"))) 53 | .collect(Collectors.toList()); 54 | } 55 | 56 | @POST 57 | @Produces(MediaType.APPLICATION_JSON) 58 | @Consumes(MediaType.APPLICATION_JSON) 59 | @Path("/todo/{list_id}") 60 | @Blocking 61 | public Response setTodo(@PathParam("list_id") String list_id, Todo todo) { 62 | ResultSet rs = this.cqlSession 63 | .execute("INSERT INTO " + this.keyspaceName + "." + this.tableName + 64 | "(list_id, id, title, completed) VALUES (?,?,?,?)", 65 | list_id, todo.getId(), todo.getTitle(), todo.isCompleted()); 66 | 67 | boolean successful = rs.wasApplied(); 68 | if (successful) { 69 | return Response.ok().build(); 70 | }else{ 71 | return Response.serverError().build(); 72 | } 73 | 74 | } 75 | 76 | @DELETE 77 | @Produces(MediaType.APPLICATION_JSON) 78 | @Path("/todo/{list_id}/{id}") 79 | @Blocking 80 | public boolean getTodos(@PathParam("list_id") String list_id, @PathParam("id") String id){ 81 | ResultSet rs = this.cqlSession.execute("DELETE FROM " + this.keyspaceName + "." + 82 | this.tableName + " WHERE list_id = ? AND id = ?",list_id, id); 83 | 84 | return rs.wasApplied(); 85 | } 86 | 87 | @POST 88 | @Produces(MediaType.APPLICATION_JSON) 89 | @Path("/todo/{list_id}/{id}") 90 | @Blocking 91 | public boolean completeTodo(@PathParam("list_id") String list_id, @PathParam("id") String id) { 92 | 93 | ResultSet rs = this.cqlSession.execute("INSERT INTO " + this.keyspaceName + 94 | "." + this.tableName + " (id, list_id, completed) VALUES (?, ?, ?)", id, list_id, true); 95 | 96 | return rs.wasApplied(); 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /hands-on/4-sdk/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.5.1 9 | 10 | 11 | com.datastax.samples 12 | javazone-4-sdk 13 | 0.0.1-SNAPSHOT 14 | javazone-4-sdk 15 | Workshop to show Stargate APIs. 16 | 17 | 18 | 11 19 | 1.3.9 20 | 0.1.14 21 | 22 | 2.9.2 23 | 3.0.0 24 | 3.8.1 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-data-cassandra 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-thymeleaf 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-web 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-devtools 49 | true 50 | 51 | 52 | 53 | org.projectlombok 54 | lombok 55 | true 56 | 57 | 58 | 59 | 60 | com.datastax.astra 61 | astra-spring-boot-starter 62 | ${astra-starter.version} 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter-test 70 | test 71 | 72 | 73 | com.vaadin.external.google 74 | android-json 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | org.apache.maven.plugins 86 | maven-surefire-plugin 87 | 2.22.1 88 | 89 | true 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-compiler-plugin 95 | ${maven-plugin-compiler.version} 96 | 97 | 98 | 99 | 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-jar-plugin 104 | 105 | 106 | 107 | com.datastax.demo.stargate.StargateDemoApplication 108 | 109 | 110 | 111 | 112 | 113 | org.springframework.boot 114 | spring-boot-maven-plugin 115 | 116 | 117 | 118 | repackage 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/views/view-modals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 30 |
31 | 32 | 33 | 34 |
35 | 52 |
53 | 54 | 55 | 56 | 57 |
58 |
59 | 96 |
97 | 102 |
103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E12_Paging.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import static com.datastax.samples.schema.SchemaUtils.closeSession; 4 | import static com.datastax.samples.schema.SchemaUtils.connectAstra; 5 | import static com.datastax.samples.schema.SchemaUtils.createTableUser; 6 | import static com.datastax.samples.schema.SchemaUtils.truncateTable; 7 | 8 | import java.nio.ByteBuffer; 9 | import java.time.Duration; 10 | import java.util.Iterator; 11 | 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import com.datastax.oss.driver.api.core.ConsistencyLevel; 16 | import com.datastax.oss.driver.api.core.CqlSession; 17 | import com.datastax.oss.driver.api.core.cql.BatchStatement; 18 | import com.datastax.oss.driver.api.core.cql.BatchStatementBuilder; 19 | import com.datastax.oss.driver.api.core.cql.DefaultBatchType; 20 | import com.datastax.oss.driver.api.core.cql.PreparedStatement; 21 | import com.datastax.oss.driver.api.core.cql.ResultSet; 22 | import com.datastax.oss.driver.api.core.cql.Row; 23 | import com.datastax.oss.driver.api.core.cql.SimpleStatement; 24 | import com.datastax.oss.driver.api.querybuilder.QueryBuilder; 25 | import com.datastax.oss.protocol.internal.util.Bytes; 26 | import com.datastax.samples.schema.SchemaConstants; 27 | 28 | /** 29 | * Yet Another Class /_0_/ *dub 30 | * 31 | * @author Cedrick LUNVEN (@clunven) 32 | */ 33 | public class E12_Paging implements SchemaConstants { 34 | 35 | /** Logger for the class. */ 36 | private static Logger LOGGER = LoggerFactory.getLogger(E12_Paging.class); 37 | 38 | /** StandAlone (vs JUNIT) to help you running. */ 39 | public static void main(String[] args) { 40 | 41 | CqlSession session = null; 42 | try { 43 | 44 | // Initialize Cluster and Session Objects (connected to keyspace) 45 | session = connectAstra(); 46 | 47 | // Create working table User (if needed) 48 | createTableUser(session); 49 | 50 | // Empty tables for tests 51 | truncateTable(session, USER_TABLENAME); 52 | 53 | PreparedStatement stmtCreateUser = 54 | session.prepare(QueryBuilder.insertInto(USER_TABLENAME) 55 | .value(USER_EMAIL, QueryBuilder.bindMarker()) 56 | .value(USER_FIRSTNAME, QueryBuilder.bindMarker()) 57 | .value(USER_LASTNAME, QueryBuilder.bindMarker()) 58 | .build()); 59 | 60 | // Adding 50 records in the table 61 | BatchStatementBuilder bb = BatchStatement.builder(DefaultBatchType.LOGGED); 62 | for (int i = 0; i < 50; i++) { 63 | bb.addStatement(stmtCreateUser.bind("user_" + i + "@sample.com", "user_" + i, "lastname")); 64 | } 65 | session.execute(bb.build()); 66 | LOGGER.info("+ {} users have been created", 50); 67 | 68 | // Paged query 69 | SimpleStatement statement = QueryBuilder.selectFrom(USER_TABLENAME).all().build() 70 | .setPageSize(10) // 10 per pages 71 | .setTimeout(Duration.ofSeconds(1)) // 1s timeout 72 | .setConsistencyLevel(ConsistencyLevel.ONE); 73 | ResultSet page1 = session.execute(statement); 74 | 75 | // Checking 76 | LOGGER.info("+ Page 1 has {} items", page1.getAvailableWithoutFetching()); 77 | Iterator page1Iter = page1.iterator(); 78 | while (0 < page1.getAvailableWithoutFetching()) { 79 | LOGGER.info("Page1: " + page1Iter.next().getString(USER_EMAIL)); 80 | } 81 | 82 | // Notice that items are NOT ordered (it uses the hashed token) 83 | // From this point if you invoke .next() driver will look for page2. 84 | // But we can invoke page2 directly: (useful for delay between calls) 85 | ByteBuffer pagingStateAsBytes = page1.getExecutionInfo().getPagingState(); 86 | 87 | // If you need to to externalize this as a STRING 88 | Bytes.toHexString(pagingStateAsBytes); 89 | // If you need to go back to byteBuffer 90 | // ByteBuffer pagingStateAsBytesBack = Bytes.fromHexString(pageStateAsString); 91 | 92 | statement.setPagingState(pagingStateAsBytes); 93 | ResultSet page2 = session.execute(statement); 94 | LOGGER.info("+ Page 2 has {} items", page2.getAvailableWithoutFetching()); 95 | 96 | } finally { 97 | closeSession(session); 98 | } 99 | System.exit(0); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /hands-on/2-spring-data/src/main/java/com/datastax/workshop/todo/TodoRestController.java: -------------------------------------------------------------------------------- 1 | package com.datastax.workshop.todo; 2 | 3 | import static org.springframework.web.bind.annotation.RequestMethod.DELETE; 4 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 5 | import static org.springframework.web.bind.annotation.RequestMethod.OPTIONS; 6 | import static org.springframework.web.bind.annotation.RequestMethod.PATCH; 7 | import static org.springframework.web.bind.annotation.RequestMethod.POST; 8 | import static org.springframework.web.bind.annotation.RequestMethod.PUT; 9 | 10 | import java.net.URI; 11 | import java.net.URISyntaxException; 12 | import java.util.Optional; 13 | import java.util.UUID; 14 | import java.util.stream.Stream; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | 18 | import org.springframework.http.HttpStatus; 19 | import org.springframework.http.ResponseEntity; 20 | import org.springframework.web.bind.annotation.CrossOrigin; 21 | import org.springframework.web.bind.annotation.DeleteMapping; 22 | import org.springframework.web.bind.annotation.GetMapping; 23 | import org.springframework.web.bind.annotation.PatchMapping; 24 | import org.springframework.web.bind.annotation.PathVariable; 25 | import org.springframework.web.bind.annotation.PostMapping; 26 | import org.springframework.web.bind.annotation.RequestBody; 27 | import org.springframework.web.bind.annotation.RequestMapping; 28 | import org.springframework.web.bind.annotation.RestController; 29 | 30 | @RestController 31 | @CrossOrigin( 32 | methods = {POST, GET, OPTIONS, PUT, DELETE, PATCH}, 33 | maxAge = 3600, 34 | allowedHeaders = {"x-requested-with", "origin", "content-type", "accept"}, 35 | origins = "*" 36 | ) 37 | @RequestMapping("/api/v1/todos/") 38 | public class TodoRestController { 39 | 40 | private TodoRepositoryCassandra repo; 41 | 42 | public TodoRestController(TodoRepositoryCassandra todoRepo) { 43 | this.repo = todoRepo; 44 | } 45 | 46 | @GetMapping 47 | public Stream findAll(HttpServletRequest req) { 48 | return repo.findAll().stream() 49 | .map(TodoRestController::mapAsTodo) 50 | .map(t -> t.setUrl(req)); 51 | } 52 | 53 | @GetMapping("/{uid}") 54 | public ResponseEntity findById(HttpServletRequest req, @PathVariable(value = "uid") String uid) { 55 | Optional e = repo.findById(UUID.fromString(uid)); 56 | if (!e.isPresent()) { 57 | return ResponseEntity.notFound().build(); 58 | } 59 | return ResponseEntity.ok(mapAsTodo(e.get()).setUrl(req.getRequestURL().toString())); 60 | } 61 | 62 | @PostMapping 63 | public ResponseEntity create(HttpServletRequest req, @RequestBody Todo todoReq) 64 | throws URISyntaxException { 65 | TodoEntity te = mapAsTodoEntity(todoReq); 66 | repo.save(te); 67 | todoReq.setUuid(te.getUid()); 68 | todoReq.setUrl(req); 69 | return ResponseEntity.created(new URI(todoReq.getUrl())).body(todoReq); 70 | } 71 | 72 | @PatchMapping("{uid}") 73 | public ResponseEntity update(HttpServletRequest req, @PathVariable(value = "uid") String uid, @RequestBody Todo todoReq) 74 | throws URISyntaxException { 75 | todoReq.setUuid(UUID.fromString(uid)); 76 | todoReq.setUrl(req.getRequestURL().toString()); 77 | repo.save(mapAsTodoEntity(todoReq)); 78 | return ResponseEntity.accepted().body(todoReq); 79 | } 80 | 81 | @DeleteMapping("{uid}") 82 | public ResponseEntity deleteById(@PathVariable(value = "uid") String uid) { 83 | if (!repo.existsById(UUID.fromString(uid))) { 84 | return ResponseEntity.notFound().build(); 85 | } 86 | repo.deleteById(UUID.fromString(uid)); 87 | return new ResponseEntity<>(HttpStatus.NO_CONTENT); 88 | } 89 | 90 | @DeleteMapping 91 | public ResponseEntity deleteAll(HttpServletRequest request) { 92 | repo.deleteAll(); 93 | return new ResponseEntity<>(HttpStatus.NO_CONTENT); 94 | } 95 | 96 | private static Todo mapAsTodo(TodoEntity te) { 97 | Todo todo = new Todo(); 98 | todo.setTitle(te.getTitle()); 99 | todo.setOrder(te.getOrder()); 100 | todo.setUuid(te.getUid()); 101 | todo.setCompleted(te.isCompleted()); 102 | return todo; 103 | } 104 | 105 | private static TodoEntity mapAsTodoEntity(Todo te) { 106 | TodoEntity todo = new TodoEntity(); 107 | if (null != te.getUuid()) { 108 | todo.setUid(te.getUuid()); 109 | } else { 110 | todo.setUid(UUID.randomUUID()); 111 | } 112 | todo.setTitle(te.getTitle()); 113 | todo.setOrder(te.getOrder()); 114 | todo.setCompleted(te.isCompleted()); 115 | return todo; 116 | } 117 | } -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/E19_LightweightTransactions.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples; 2 | 3 | import static com.datastax.samples.schema.SchemaUtils.*; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.datastax.oss.driver.api.core.CqlSession; 9 | import com.datastax.oss.driver.api.core.cql.PreparedStatement; 10 | import com.datastax.oss.driver.api.querybuilder.QueryBuilder; 11 | import com.datastax.samples.schema.SchemaConstants; 12 | 13 | 14 | /** 15 | * CREATE TABLE IF NOT EXISTS users ( 16 | * email text, 17 | * firstname text, 18 | * lastname text, 19 | * PRIMARY KEY (email) 20 | * ); 21 | */ 22 | public class E19_LightweightTransactions implements SchemaConstants { 23 | 24 | /** Logger for the class. */ 25 | private static Logger LOGGER = LoggerFactory.getLogger(E19_LightweightTransactions.class); 26 | 27 | // This will be used as singletons for the sample 28 | private static CqlSession session; 29 | 30 | // Prepare your statements once and execute multiple times 31 | private static PreparedStatement stmtCreateUser; 32 | private static PreparedStatement stmtUpdateUserLwt; 33 | 34 | /** StandAlone (vs JUNIT) to help you running. */ 35 | public static void main(String[] args) { 36 | try { 37 | 38 | // Initialize Cluster and Session Objects (connected to keyspace) 39 | session = connectAstra(); 40 | 41 | // Use PreparedStatement for queries that are executed multiple times in your application 42 | prepareStatements(); 43 | 44 | // Create working table User (if needed) 45 | createTableUser(session); 46 | 47 | // Empty tables for tests 48 | truncateTable(session, USER_TABLENAME); 49 | 50 | // Insert if not exist 51 | boolean first = createUserIfNotExist("clun@sample.com", "Cedric", "Lunven"); 52 | boolean second = createUserIfNotExist("clun@sample.com", "Cedric", "Lunven"); 53 | LOGGER.info("+ Created first time ? {} and second time {}", first, second); 54 | 55 | // Update if condition 56 | boolean applied1 = updateIf("clun@sample.com", "Cedric", "BEST"); 57 | boolean applied2 = updateIf("clun@sample.com", "Cedrick", "Lunven"); 58 | LOGGER.info("+ Applied when correct value ? {} and invalid value {}", applied1, applied2); 59 | 60 | } finally { 61 | closeSession(session); 62 | } 63 | System.exit(0); 64 | } 65 | 66 | /** 67 | * The resultset is applied only if the record is created. If not the resultSet is populated 68 | * with existing data in DB (read) 69 | */ 70 | private static boolean createUserIfNotExist(String email, String firstname, String lastname) { 71 | return session.execute(stmtCreateUser.bind(email, firstname, lastname)).wasApplied(); 72 | } 73 | 74 | /** 75 | * Note: we named the parameters as they are not in the same order in the query. 76 | */ 77 | private static boolean updateIf(String email, String expectedFirstName, String newLastName) { 78 | return session.execute(stmtUpdateUserLwt.bind() 79 | .setString(USER_EMAIL, email) 80 | .setString(USER_FIRSTNAME, expectedFirstName) 81 | .setString(USER_LASTNAME, newLastName)).wasApplied(); 82 | } 83 | 84 | /** 85 | * Documentation 86 | * https://docs.datastax.com/en/developer/java-driver/3.8/manual/statements/prepared/#prepared-statements 87 | */ 88 | private static void prepareStatements() { 89 | 90 | /* 91 | * INSERT INTO users (email, firstname, lastname) 92 | * VALUES(?,?,?) 93 | * IF NOT EXISTS 94 | */ 95 | stmtCreateUser = session.prepare(QueryBuilder.insertInto(USER_TABLENAME) 96 | .value(USER_EMAIL, QueryBuilder.bindMarker()) 97 | .value(USER_FIRSTNAME, QueryBuilder.bindMarker()) 98 | .value(USER_LASTNAME, QueryBuilder.bindMarker()) 99 | .ifNotExists() 100 | .build()); 101 | 102 | /* 103 | * UPDATE users SET lastname=:lastname 104 | * WHERE email=:email 105 | * IF firstname=:firstname 106 | * 107 | * Operators available for LWT Condition: 108 | * =, <, <=, >, >=, != and IN 109 | */ 110 | stmtUpdateUserLwt = session.prepare(QueryBuilder.update(USER_TABLENAME) 111 | .setColumn(USER_LASTNAME, QueryBuilder.bindMarker(USER_LASTNAME)) 112 | .whereColumn(USER_EMAIL).isEqualTo(QueryBuilder.bindMarker(USER_EMAIL)) 113 | .ifColumn(USER_FIRSTNAME).isEqualTo(QueryBuilder.bindMarker(USER_FIRSTNAME)) 114 | .build()); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/objectmapping/CommentDaoQueryProvider.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.objectmapping; 2 | 3 | import java.util.UUID; 4 | 5 | import com.datastax.oss.driver.api.core.CqlSession; 6 | import com.datastax.oss.driver.api.core.PagingIterable; 7 | import com.datastax.oss.driver.api.core.cql.BatchStatement; 8 | import com.datastax.oss.driver.api.core.cql.BoundStatement; 9 | import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder; 10 | import com.datastax.oss.driver.api.core.cql.DefaultBatchType; 11 | import com.datastax.oss.driver.api.core.cql.PreparedStatement; 12 | import com.datastax.oss.driver.api.mapper.MapperContext; 13 | import com.datastax.oss.driver.api.mapper.entity.EntityHelper; 14 | import com.datastax.oss.driver.api.mapper.entity.saving.NullSavingStrategy; 15 | import com.datastax.oss.driver.api.querybuilder.QueryBuilder; 16 | import com.datastax.samples.schema.SchemaConstants; 17 | 18 | /** 19 | * Query implementation for Comment Dse and Mapper. 20 | * 21 | * @author DataStax Developer Advocates team. 22 | */ 23 | @SuppressWarnings("deprecation") 24 | public class CommentDaoQueryProvider implements CommentDao, SchemaConstants { 25 | 26 | private final CqlSession cqlSession; 27 | 28 | private final EntityHelper helperUser; 29 | private final EntityHelper helperVideo; 30 | 31 | private static PreparedStatement selectCommentByVideo; 32 | private static PreparedStatement selectCommentByUser; 33 | 34 | private PreparedStatement psInsertCommentUser; 35 | private PreparedStatement psDeleteCommentUser; 36 | private PreparedStatement psInsertCommentVideo; 37 | private PreparedStatement psDeleteCommentVideo; 38 | 39 | public CommentDaoQueryProvider(MapperContext context, 40 | EntityHelper helperUser, 41 | EntityHelper helperVideo) { 42 | 43 | this.cqlSession = context.getSession(); 44 | this.helperUser = helperUser; 45 | this.helperVideo = helperVideo; 46 | psInsertCommentUser = cqlSession.prepare(helperUser.insert().asCql()); 47 | psDeleteCommentUser = cqlSession.prepare(helperUser.deleteByPrimaryKey().asCql()); 48 | psInsertCommentVideo = cqlSession.prepare(helperVideo.insert().asCql()); 49 | psDeleteCommentVideo = cqlSession.prepare(helperVideo.deleteByPrimaryKey().asCql()); 50 | 51 | selectCommentByVideo = cqlSession.prepare( 52 | QueryBuilder.selectFrom(COMMENT_BY_VIDEO_TABLENAME).all() 53 | .whereColumn(COMMENT_BY_VIDEO_VIDEOID).isEqualTo(QueryBuilder.bindMarker()) 54 | .build()); 55 | selectCommentByUser = cqlSession.prepare( 56 | QueryBuilder.selectFrom(COMMENT_BY_USER_TABLENAME).all() 57 | .whereColumn(COMMENT_BY_USER_USERID).isEqualTo(QueryBuilder.bindMarker()) 58 | .build()); 59 | } 60 | 61 | /** {@inheritDoc} */ 62 | 63 | @Override 64 | public PagingIterable retrieveUserComments(UUID userid) { 65 | return cqlSession.execute(selectCommentByUser.bind(userid)).map(helperUser::get); 66 | } 67 | 68 | /** {@inheritDoc} */ 69 | @Override 70 | public PagingIterable retrieveVideoComments(UUID videoid) { 71 | return cqlSession.execute(selectCommentByVideo.bind(videoid)).map(helperVideo::get); 72 | } 73 | 74 | /** {@inheritDoc} */ 75 | @Override 76 | public void upsert(Comment comment) { 77 | cqlSession.execute(BatchStatement.builder(DefaultBatchType.LOGGED) 78 | .addStatement(bind(psInsertCommentUser, new CommentByUser(comment), helperUser)) 79 | .addStatement(bind(psInsertCommentVideo, new CommentByVideo(comment), helperVideo)) 80 | .build()); 81 | } 82 | 83 | /** {@inheritDoc} */ 84 | @Override 85 | public void delete(Comment comment) { 86 | 87 | CommentByUser cbu = new CommentByUser(); 88 | cbu.setCommentid(comment.getCommentid()); 89 | cbu.setUserid(comment.getUserid()); 90 | 91 | CommentByVideo cbv = new CommentByVideo(); 92 | cbv.setCommentid(comment.getCommentid()); 93 | cbv.setVideoid(comment.getVideoid()); 94 | 95 | cqlSession.execute( 96 | BatchStatement.builder(DefaultBatchType.LOGGED) 97 | .addStatement(bind(psDeleteCommentUser, cbu, helperUser)) 98 | .addStatement(bind(psDeleteCommentVideo, cbv, helperVideo)) 99 | .build()); 100 | } 101 | 102 | public static BoundStatement bind(PreparedStatement preparedStatement, T entity, EntityHelper entityHelper) { 103 | BoundStatementBuilder boundStatement = preparedStatement.boundStatementBuilder(); 104 | entityHelper.set(entity, boundStatement, NullSavingStrategy.DO_NOT_SET); 105 | return boundStatement.build(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /hands-on/1-cassandra-drivers/src/main/java/com/datastax/samples/dto/VideoDto.java: -------------------------------------------------------------------------------- 1 | package com.datastax.samples.dto; 2 | 3 | import java.io.Serializable; 4 | import java.time.Instant; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.HashSet; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Set; 11 | import java.util.UUID; 12 | 13 | import com.fasterxml.jackson.annotation.JsonIgnore; 14 | 15 | /** 16 | * CREATE TABLE IF NOT EXISTS videos ( videoid uuid, title text, upload timestamp, email text, url text, tags set , formats 17 | * map >, PRIMARY KEY (videoid) ); 18 | */ 19 | public class VideoDto implements Serializable { 20 | 21 | /** Serial. */ 22 | private static final long serialVersionUID = -5086632646056781255L; 23 | 24 | private UUID videoid; 25 | 26 | private String title; 27 | 28 | private String email; 29 | 30 | private String url; 31 | 32 | @JsonIgnore 33 | private long upload = Instant.now().toEpochMilli(); 34 | 35 | private Set tags = new HashSet<>(); 36 | 37 | private List frames = new ArrayList<>(); 38 | 39 | private Map formats = new HashMap<>(); 40 | 41 | public VideoDto() {} 42 | 43 | public VideoDto(UUID videoId, String title, String email, String url) { 44 | super(); 45 | this.videoid = videoId; 46 | this.title = title; 47 | this.email = email; 48 | } 49 | 50 | /** 51 | * Getter accessor for attribute 'videoId'. 52 | * 53 | * @return current value of 'videoId' 54 | */ 55 | public UUID getVideoid() { 56 | return videoid; 57 | } 58 | 59 | /** 60 | * Setter accessor for attribute 'videoId'. 61 | * 62 | * @param videoId 63 | * new value for 'videoId ' 64 | */ 65 | public void setVideoid(UUID videoId) { 66 | this.videoid = videoId; 67 | } 68 | 69 | /** 70 | * Getter accessor for attribute 'title'. 71 | * 72 | * @return current value of 'title' 73 | */ 74 | public String getTitle() { 75 | return title; 76 | } 77 | 78 | /** 79 | * Setter accessor for attribute 'title'. 80 | * 81 | * @param title 82 | * new value for 'title ' 83 | */ 84 | public void setTitle(String title) { 85 | this.title = title; 86 | } 87 | 88 | /** 89 | * Getter accessor for attribute 'upload'. 90 | * 91 | * @return current value of 'upload' 92 | */ 93 | public Long getUpload() { 94 | return upload; 95 | } 96 | 97 | /** 98 | * Setter accessor for attribute 'upload'. 99 | * 100 | * @param upload 101 | * new value for 'upload ' 102 | */ 103 | public void setUpload(Long upload) { 104 | this.upload = upload; 105 | } 106 | 107 | /** 108 | * Getter accessor for attribute 'email'. 109 | * 110 | * @return current value of 'email' 111 | */ 112 | public String getEmail() { 113 | return email; 114 | } 115 | 116 | /** 117 | * Setter accessor for attribute 'email'. 118 | * 119 | * @param email 120 | * new value for 'email ' 121 | */ 122 | public void setEmail(String email) { 123 | this.email = email; 124 | } 125 | 126 | /** 127 | * Getter accessor for attribute 'tags'. 128 | * 129 | * @return current value of 'tags' 130 | */ 131 | public Set getTags() { 132 | return tags; 133 | } 134 | 135 | /** 136 | * Setter accessor for attribute 'tags'. 137 | * 138 | * @param tags 139 | * new value for 'tags ' 140 | */ 141 | public void setTags(Set tags) { 142 | this.tags = tags; 143 | } 144 | 145 | /** 146 | * Getter accessor for attribute 'formatsd'. 147 | * 148 | * @return current value of 'formatsd' 149 | */ 150 | public Map getFormats() { 151 | return formats; 152 | } 153 | 154 | /** 155 | * Setter accessor for attribute 'formatsd'. 156 | * 157 | * @param formatsd 158 | * new value for 'formatsd ' 159 | */ 160 | public void setFormats(Map formatsd) { 161 | this.formats = formatsd; 162 | } 163 | 164 | public String getUrl() { 165 | return url; 166 | } 167 | 168 | public void setUrl(String url) { 169 | this.url = url; 170 | } 171 | 172 | /** 173 | * Getter accessor for attribute 'frames'. 174 | * 175 | * @return current value of 'frames' 176 | */ 177 | public List getFrames() { 178 | return frames; 179 | } 180 | 181 | /** 182 | * Setter accessor for attribute 'frames'. 183 | * 184 | * @param frames 185 | * new value for 'frames ' 186 | */ 187 | public void setFrames(List frames) { 188 | this.frames = frames; 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /hands-on/4-sdk/src/main/resources/static/js/script.js: -------------------------------------------------------------------------------- 1 | // SVG: http://stargate.wikia.com/wiki/Glyph 2 | 3 | var sounds = {} 4 | //var path = 'https://cdn.rawgit.com/ManzDev/cursos-assets/gh-pages/css3/audio/'; 5 | var path = 'https://manzdev.github.io/cursos-assets/css3/audio/'; 6 | var title = document.querySelector('.title'); 7 | var listChevrons = document.querySelectorAll('#stargate img'); 8 | 9 | // ChevronClosed sounds 10 | sounds.chevronClosed = { 11 | audio: [new Audio(path + 'chev_usual_1.mp3'), 12 | new Audio(path + 'chev_usual_2.mp3'), 13 | new Audio(path + 'chev_usual_3.mp3'), 14 | new Audio(path + 'chev_usual_4.mp3'), 15 | new Audio(path + 'chev_usual_5.mp3'), 16 | new Audio(path + 'chev_usual_6.mp3'), 17 | new Audio(path + 'chev_usual_7.mp3')] 18 | } 19 | sounds.chevronClosed.play = function(n = -1) { 20 | if (n == -1) 21 | var n = Math.floor(Math.random() * this.audio.length); 22 | this.audio[n].currentTime = 0; 23 | this.audio[n].play(); 24 | } 25 | 26 | // Stargate sounds 27 | sounds.gateRoll = new Audio(path + 'roll.mp3'); 28 | sounds.gateSpin = new Audio(path + 'spin.mp3'); 29 | sounds.fail = new Audio(path + 'fail.mp3'); 30 | sounds.gateClose = new Audio(path + 'eh_usual_close.mp3'); 31 | sounds.gateOpen = new Audio(path + 'eh_usual_open.mp3'); 32 | sounds.gateSpin.loop = true; 33 | sounds.gateSpin.addEventListener('timeupdate', function() { 34 | if (this.currentTime > this.duration - .3) 35 | this.currentTime = 0; 36 | }); 37 | 38 | // WormHole Loop sounds 39 | sounds.wormHole = new Audio(path + 'wormhole.mp3'); 40 | sounds.wormHole.loop = true; 41 | sounds.wormHole.addEventListener('timeupdate', function() { 42 | if (this.currentTime > this.duration - .6) 43 | this.currentTime = 0; 44 | }); 45 | 46 | // Arrows 47 | var arrows = document.querySelectorAll('.arrow'); 48 | [].forEach.call(arrows, function(i) { 49 | i.addEventListener('click', function() { 50 | 51 | if (!this.classList.contains('on')) { 52 | sounds.chevronClosed.play(); 53 | this.classList.add('on'); 54 | 55 | if (stargate.getChevronsOpened() == 8) { 56 | stargate.startMove(); 57 | //stargate.title = title.innerHTML; 58 | //title.innerHTML = ''; 59 | } 60 | 61 | //var n = Math.floor(Math.random() * listChevrons.length); 62 | //title.innerHTML += listChevrons[n].outerHTML; 63 | 64 | if ((stargate.isOpen() == false) && (stargate.isReady() == true)) 65 | setTimeout(function() { 66 | stargate.enableWormHole(); 67 | }, 1000); 68 | } 69 | 70 | }); 71 | }); 72 | 73 | var stargate = { 74 | 75 | CHAPAHAI_OPEN: false, 76 | 77 | isOpen: function() { 78 | return this.CHAPAHAI_OPEN; 79 | }, 80 | 81 | isReady: function() { 82 | return (document.querySelectorAll('.arrow:not(.on)').length === 0); 83 | }, 84 | 85 | getChevronsOpened: function() { 86 | return document.querySelectorAll('.arrow:not(.on)').length; 87 | }, 88 | 89 | // Comienza a mover el Stargate (20 seg máx.) 90 | startMove: function() { 91 | document.querySelector('#stargate').classList.add('on'); 92 | sounds.gateRoll.volume = .5; 93 | sounds.gateRoll.currentTime = 0; 94 | sounds.gateRoll.play(); 95 | 96 | setTimeout(function() { 97 | document.querySelector('#stargate').classList.remove('on'); 98 | 99 | if (stargate.isOpen() == false) { 100 | sounds.fail.play(); 101 | stargate.disableChevrons(); 102 | } 103 | }, 20000); 104 | }, 105 | 106 | stopMove: function() { 107 | document.querySelector('#stargate').classList.remove('on'); 108 | if (!sounds.gateRoll.paused) 109 | sounds.gateRoll.pause() 110 | }, 111 | 112 | // Activa un chevron aleatorio (o el "n" indicado) 113 | enableChevron: function(n = -1) { 114 | var arrowsOff = document.querySelectorAll('.arrow:not(.on)'); 115 | if (n == -1) 116 | var n = Math.floor(Math.random() * arrowsOff.length); 117 | 118 | arrowsOff[n].classList.add('on'); 119 | sounds.chevronClosed.play(); 120 | }, 121 | 122 | disableChevrons: function() { 123 | [].forEach.call(arrows, function(i) { 124 | i.classList.remove('on'); 125 | }); 126 | }, 127 | 128 | enableWormHole: function() { 129 | this.CHAPAHAI_OPEN = true; 130 | this.stopMove(); 131 | sounds.gateOpen.play(); 132 | document.getElementById('cartouche').style.display='block'; 133 | document.querySelector('.wormhole').classList.add('on'); 134 | setTimeout(function() { 135 | sounds.wormHole.play(); 136 | }, 3000); 137 | 138 | setTimeout(function() { 139 | stargate.disableWormHole(); 140 | }, 18000); 141 | }, 142 | 143 | disableWormHole: function() { 144 | this.CHAPAHAI_OPEN = false; 145 | sounds.gateClose.play(); 146 | setTimeout(function() { 147 | document.querySelector('.wormhole').classList.remove('on'); 148 | document.querySelector('.center-menu').classList.add('on'); 149 | sounds.wormHole.pause(); 150 | }, 300); 151 | this.disableChevrons(); 152 | //title.innerHTML = stargate.title; 153 | } 154 | } --------------------------------------------------------------------------------