Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

7/7/2017

Reading time:3 min

jtruelove/exovert

by John Doe

README.md Is a tool that is designed to help free developers up to focus on developing services and not building the boiler plate glue code often involved with accessing a DB, creating POJOs, building CRUD interfaces. It also helps in creating REST server and client classes, or creating Java classes with setters, getters, equals/hashCode/toString, builder and Json annotations.The tool is focused around using Cassandra for storage and Vert.x as the primary service framework. More DB options could be added based on demand at a later time.Currently tool has two generators - CrudGenerator and RestGeneratorCrudGenerator works by reading your schema from the DB then generating the entity classes (ie Table and UDT objects), then building a DAL for them, then the REST interface.CrudGenerator Supportentity classesDALCRUD REST interface, including list APIsSimple Servermetrics support (coming soon)cache support (coming later)RestGenerator works by reading the specification file from the command line and generates either server or client or type classes depending on the command line option.RestGenerator SupportREST API classes for GET, POST and DELETEValidations for API inputsRequest and Response classes for REST APIsJava classes with setters, getters, equals/hashCode/toString, builder and Json annotationsOption to generate Immutable or Mutable classesRequest and Response classes for REST clientsREST client builder with service endpoint, timeouts, retries (coming later)Getting StartedGet the command line tool.<dependency> <groupId>com.cyngn.vertx</groupId> <artifactId>exovert</artifactId> <version>0.2.0</version></dependency>Running CrudCreator$ build/bin/CrudCreatorOption Description------ ------------c, --create create the basic service infrastructure-d, --db the db host to connect to--help shows this message-k, --keyspace the keyspace to read from-n, --namespace the namespace to create java classes in-o, --out the output dir to place files in-p, --preview output all the java files to the console, don't create files-r, --rest generate the REST API for the schemeExample Preview Runjava -jar exovert-0.1.0-fat.jar --preview -k test_keyspace -db localhost -n com.testExample Runjava -jar exovert-0.1.0-fat.jar --create -k test_keyspace -db localhost -n com.test -o src/java/generatedExample Cassandra SchemeAs an example ChronoServer Cassandra Schema// schema scriptCREATE TYPE IF NOT EXISTS chrono.url_package ( method varchar, urls set<varchar>);CREATE TABLE IF NOT EXISTS chrono.test_batch ( name varchar, url_packages list<frozen<url_package>>, created timestamp, PRIMARY KEY (name));CREATE TYPE IF NOT EXISTS chrono.measurement ( url varchar, time_in_milli bigint);CREATE TABLE IF NOT EXISTS chrono.payload ( unit varchar, size bigint, data varchar, PRIMARY KEY (unit, size));CREATE TABLE IF NOT EXISTS chrono.upload_data ( test_batch varchar, unit varchar, size bigint, data varchar, created timestamp, PRIMARY KEY (test_batch, unit, size, created));CREATE TABLE IF NOT EXISTS chrono.report ( batch_name varchar, mode varchar, device_id varchar, mobile_carrier varchar, mobile_rssi varchar, wifi_state varchar, wifi_rssi varchar, gps_coordinates varchar, tag varchar, mobile_network_class varchar, mobile_network_type varchar, client_ip varchar, created timestamp, measurements list<frozen<measurement>>, PRIMARY KEY (batch_name, device_id, created));CRUD Generated Code Examplesee CRUD_README.md for the output code sample.Running RestGenerator$ build/bin/RestCreator--client create the client files on disk-f, --spec specification file (default: api.json)--help shows this message-o, --out the output dir in which to place files (default: build/generated-src)-p, --preview output all the java files to the console, don't create files--server create the server files on disk--types create the type files on disk Example Preview Run to create serverbuild/bin/RestGenerator --preview --server --spec api.jsonFor sample api json file, look at samplesExample Run to create serverbuild/bin/RestGenerator --server --spec api.json --out build/generated-srcREST Generated Code ExampleExamples are at REST_README.mdThanksEspecially to the Java Poet Creators for making such a great and easy to use code generation library.

Illustration Image

README.md

Build Status

Is a tool that is designed to help free developers up to focus on developing services and not building the boiler plate glue code often involved with accessing a DB, creating POJOs, building CRUD interfaces. It also helps in creating REST server and client classes, or creating Java classes with setters, getters, equals/hashCode/toString, builder and Json annotations.

The tool is focused around using Cassandra for storage and Vert.x as the primary service framework. More DB options could be added based on demand at a later time.

Currently tool has two generators - CrudGenerator and RestGenerator

CrudGenerator works by reading your schema from the DB then generating the entity classes (ie Table and UDT objects), then building a DAL for them, then the REST interface.

CrudGenerator Support

  • entity classes
  • DAL
  • CRUD REST interface, including list APIs
  • Simple Server
  • metrics support (coming soon)
  • cache support (coming later)

RestGenerator works by reading the specification file from the command line and generates either server or client or type classes depending on the command line option.

RestGenerator Support

  • REST API classes for GET, POST and DELETE
  • Validations for API inputs
  • Request and Response classes for REST APIs
  • Java classes with setters, getters, equals/hashCode/toString, builder and Json annotations
  • Option to generate Immutable or Mutable classes
  • Request and Response classes for REST clients
  • REST client builder with service endpoint, timeouts, retries (coming later)

Getting Started

Get the command line tool.

<dependency>
    <groupId>com.cyngn.vertx</groupId>
    <artifactId>exovert</artifactId>
    <version>0.2.0</version>
</dependency>

Running CrudCreator

$ build/bin/CrudCreator
Option           Description
------           -----------
-c, --create     create the basic service infrastructure
-d, --db         the db host to connect to
--help           shows this message
-k, --keyspace   the keyspace to read from
-n, --namespace  the namespace to create java classes in
-o, --out        the output dir to place files in
-p, --preview    output all the java files to the
                   console, don't create files
-r, --rest       generate the REST API for the scheme

Example Preview Run

java -jar exovert-0.1.0-fat.jar --preview -k test_keyspace -db localhost -n com.test

Example Run

java -jar exovert-0.1.0-fat.jar --create -k test_keyspace -db localhost -n com.test -o src/java/generated

Example Cassandra Scheme

As an example ChronoServer Cassandra Schema

// schema script
CREATE TYPE IF NOT EXISTS chrono.url_package (
   method varchar,
   urls set<varchar>
);
CREATE TABLE IF NOT EXISTS chrono.test_batch (
    name varchar,
    url_packages list<frozen<url_package>>,
    created timestamp,
    PRIMARY KEY (name)
);
CREATE TYPE IF NOT EXISTS chrono.measurement (
   url varchar,
   time_in_milli bigint
);
CREATE TABLE IF NOT EXISTS chrono.payload (
    unit varchar,
    size bigint,
    data varchar,
    PRIMARY KEY (unit, size)
);
CREATE TABLE IF NOT EXISTS chrono.upload_data (
	  test_batch varchar,
    unit varchar,
    size bigint,
    data varchar,
    created timestamp,
    PRIMARY KEY (test_batch, unit, size, created)
);
CREATE TABLE IF NOT EXISTS chrono.report (
    batch_name varchar,
    mode varchar,
    device_id varchar,
    mobile_carrier varchar,
    mobile_rssi varchar,
    wifi_state varchar,
    wifi_rssi varchar,
    gps_coordinates varchar,
    tag varchar,
    mobile_network_class varchar,
    mobile_network_type varchar,
    client_ip varchar,
    created timestamp,
    measurements list<frozen<measurement>>,
    PRIMARY KEY (batch_name, device_id, created)
);

CRUD Generated Code Example

see CRUD_README.md for the output code sample.

Running RestGenerator

$ build/bin/RestCreator
--client       create the client files on disk
-f, --spec     specification file (default: api.json)
--help         shows this message
-o, --out      the output dir in which to place files
                 (default: build/generated-src)
-p, --preview  output all the java files to the
                 console, don't create files
--server       create the server files on disk
--types        create the type files on disk  

Example Preview Run to create server

build/bin/RestGenerator --preview --server --spec api.json

For sample api json file, look at samples

Example Run to create server

build/bin/RestGenerator --server --spec api.json --out build/generated-src

REST Generated Code Example

Examples are at REST_README.md

Thanks

Especially to the Java Poet Creators for making such a great and easy to use code generation library.

Related Articles

spring
angular
rest

GitHub - jhipster/jhipster-sample-app-cassandra: This is a sample application created with JHipster, with the Cassandra option

jhipster

3/7/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

rest