Coder Social home page Coder Social logo

data-class-generator's Introduction

Data Class Generator

Generate Java data class files.

Examples

Prepare database.

$ docker container run -p 3306:3306  --rm -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=sample mysql:5.7.19
mysql> create table products(id char(36) not null primary key, name varchar(100) not null, description text, unit_price integer, created datetime not null, updated datetime not null);
mysql> create table orders(id char(36) not null primary key, order_date date not null, ship_date date);
mysql> create table order_details(order_id char(36) not null, product_id char(36) not null, quantity integer not null, unit_price bigint not null, primary key (order_id, product_id), foreign key (order_id) references orders (id) on delete cascade, foreign key (product_id) references products (id));

Run this application.

$ ./mvnw clean spring-boot:run -Dgenerator.data-class-type=lombok -Dgenerator.target-schema=sample -Dgenerator.java-package=com.example.foo.model -Dspring.profiles.active=mysql

It will generate java files as follows.

generated-data-classes/com/example/foo/model/Product.java

package com.example.foo.model;

import java.io.Serializable;
import java.sql.Timestamp;
import lombok.Builder;
import lombok.Data;

/**
 * class for the products database table.
 *
 */
@Data
@Builder
public class Product implements Serializable {

        private static final long serialVersionUID = 1L;

        private String id;

        private String name;

        private String description;

        private int unitPrice;

        private Timestamp created;

        private Timestamp updated;

}

generated-data-classes/com/example/foo/model/Order.java

package com.example.foo.model;

import java.io.Serializable;
import java.sql.Date;
import lombok.Builder;
import lombok.Data;

/**
 * class for the orders database table.
 *
 */
@Data
@Builder
public class Order implements Serializable {

        private static final long serialVersionUID = 1L;

        private String id;

        private Date orderDate;

        private Date shipDate;

}

generated-data-classes/com/example/foo/model/OrderDetail.java

package com.example.foo.model;

import java.io.Serializable;
import lombok.Builder;
import lombok.Data;

/**
 * class for the order_details database table.
 *
 */
@Data
@Builder
public class OrderDetail implements Serializable {

        private static final long serialVersionUID = 1L;

        private String orderId;

        private String productId;

        private int quantity;

        private long unitPrice;

}

data-class-generator's People

Contributors

marcie001 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.