telosys-tools-bricks / telosys-cli

Telosys CLI - Command Line Interface
https://www.telosys.org/
GNU Lesser General Public License v3.0
166 stars 23 forks source link

How to generate entity classes with MySQL request? #21

Open MarErm27 opened 4 years ago

MarErm27 commented 4 years ago

Hello, here is a MySQL script below. Can Telesys-cli create classes with Hibernate annotations based on this script? How to launch it during the build of the Java Maven project?

CREATE TABLE IF NOT EXISTS orders (
    order_id INT PRIMARY KEY,
    order_number VARCHAR(128),
    order_data  VARCHAR(4096),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)ENGINE=INNODB;

CREATE TABLE IF NOT EXISTS invoices (
    invoice_id INT PRIMARY KEY,
        order_id INT UNIQUE,
    INDEX ord_id (order_id),
        FOREIGN KEY (order_id)
        REFERENCES orders(order_id)
                ON DELETE CASCADE,    
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)ENGINE=INNODB;
l-gu commented 4 years ago

Telosys can do that from the database tables created by this script but not from the script itself (you need a database to create a "db model"). See this wiki page for "Db Model" creation : https://github.com/telosys-tools-bricks/telosys-cli/wiki/Guide-Step-2-DB-Model Once the "db model" is created just use JPA templates to generate the annotated entities (and more if you want : API, screens, JUnit tests, etc)

Telosys has been thought to replace the developer, therefore it positions itself before the compilation/build phase. Moreover Telosys is usable to generate any kind of languages (not only Java). So, there's no Maven plugin.

MarErm27 commented 4 years ago

Can I add Telosys-cli as a library from my project and to configure it from Java code? Can I find it in Maven?

l-gu commented 4 years ago

Telosys is not published on Maven central but you can just add the JAR "telosys-cli-3.X.X-xxx.jar" in you project libs. It's a "fat jar" and it contains everything you need (including Telosys-API).

MarErm27 commented 4 years ago

I was wondering if I can ask for an example that uses this "jar" to automatically create the dm model and classes from MySQL?

l-gu commented 4 years ago

The best example is probably the "new db model" command in Telosys-CLI itself. See https://github.com/telosys-tools-bricks/telosys-cli/blob/master/src/main/java/org/telosys/tools/cli/commands/NewDbModelCommand.java

MarErm27 commented 4 years ago

I added the jar file to the libraries folder image

and added this class image

How to get the missing dependencies? And what do I do next? Call the newDatabaseModel(Integer id) method? What is id?

How do I specify that I need the entities to appear at com.qbwc.db.entities package?