From 1ac54a0d5df879b814046a763f5aa52374a1a9d2 Mon Sep 17 00:00:00 2001 From: skidus Date: Tue, 23 Sep 2025 23:00:05 +0700 Subject: [PATCH] docs: Add GEMINI.md for project context Introduces GEMINI.md to provide a comprehensive overview of the ActionModelsGenerator project, including its purpose, core technologies, build instructions, and development conventions. This document serves as essential context for future interactions and development. --- GEMINI.md | 44 ++++++++ src/main/java/com/sdk/generators/GUtils.java | 4 + .../actionmodels}/GenerateAction.java | 0 .../actionmodels}/GenerateBeanAction.java | 0 .../actionmodels}/GeneratorServices.java | 0 .../actionBean.extend.ftl | 0 .../{template => templates}/actionBean.ftl | 0 .../resources/templates/actionDTO.extend.ftl | 18 +++ src/main/resources/templates/actionDTO.ftl | 103 ++++++++++++++++++ 9 files changed, 169 insertions(+) create mode 100644 GEMINI.md create mode 100644 src/main/java/com/sdk/generators/GUtils.java rename src/main/java/com/sdk/{actionbean/generator => generators/actionmodels}/GenerateAction.java (100%) rename src/main/java/com/sdk/{actionbean/generator => generators/actionmodels}/GenerateBeanAction.java (100%) rename src/main/java/com/sdk/{actionbean/generator => generators/actionmodels}/GeneratorServices.java (100%) rename src/main/resources/{template => templates}/actionBean.extend.ftl (100%) rename src/main/resources/{template => templates}/actionBean.ftl (100%) create mode 100644 src/main/resources/templates/actionDTO.extend.ftl create mode 100644 src/main/resources/templates/actionDTO.ftl diff --git a/GEMINI.md b/GEMINI.md new file mode 100644 index 0000000..82bd944 --- /dev/null +++ b/GEMINI.md @@ -0,0 +1,44 @@ +# ActionModelsGenerator + +## Project Overview + +The `ActionModelsGenerator` is an IntelliJ Platform Plugin designed to automate the generation of Java `ActionBean` and Data Transfer Object (DTO) classes from a database schema. This plugin integrates directly into the IntelliJ IDE, allowing developers to select a database table and generate corresponding Java classes based on predefined FreeMarker templates. + +**Key Features:** +* **Database Schema Introspection:** Utilizes IntelliJ's database tools to read table and column metadata. +* **Code Generation:** Generates `ActionBean` and DTO classes using FreeMarker templates. +* **Template-driven:** Customizable code generation via FreeMarker templates (`actionBean.ftl`, `actionBean.extend.ftl`, `actionDTO.ftl`, `actionDTO.extend.ftl`). +* **IDE Integration:** Provides a context menu action ("Generate Action Models") in the Database View for easy access. + +**Core Technologies:** +* **Java:** Primary development language. +* **Kotlin:** Configured in `build.gradle.kts`, indicating potential for Kotlin usage. +* **Gradle (Kotlin DSL):** Build automation system. +* **IntelliJ Platform SDK:** For IDE integration and database interaction. +* **FreeMarker:** Templating engine for code generation. + +## Building and Running + +This project is an IntelliJ Platform Plugin built with Gradle. + +**Build the Plugin:** +To build the plugin, use the following Gradle command: +```bash +./gradlew build +``` +This will produce a `.zip` plugin artifact in the `build/distributions` directory. + +**Run the Plugin in a Development IDE:** +To run a new IntelliJ IDE instance with this plugin installed for development and testing: +```bash +./gradlew runIde +``` +Alternatively, you can use the "Run IDE with Plugin" run configuration provided in the `.run` directory within IntelliJ IDEA. + +## Development Conventions + +* **Language:** Primarily Java, with Kotlin support configured. +* **Build System:** Gradle with Kotlin DSL (`.gradle.kts` files). +* **Code Generation:** FreeMarker templates are located in `src/main/resources/templates/`. Modifications to these templates will change the generated code structure. +* **IntelliJ Platform APIs:** Development involves using IntelliJ Platform SDK for UI actions, virtual file system operations, and database schema access. +* **Action Definition:** New actions are defined in `src/main/resources/META-INF/plugin.xml`. diff --git a/src/main/java/com/sdk/generators/GUtils.java b/src/main/java/com/sdk/generators/GUtils.java new file mode 100644 index 0000000..a873a44 --- /dev/null +++ b/src/main/java/com/sdk/generators/GUtils.java @@ -0,0 +1,4 @@ +package com.sdk.generators; + +public class GUtils { +} diff --git a/src/main/java/com/sdk/actionbean/generator/GenerateAction.java b/src/main/java/com/sdk/generators/actionmodels/GenerateAction.java similarity index 100% rename from src/main/java/com/sdk/actionbean/generator/GenerateAction.java rename to src/main/java/com/sdk/generators/actionmodels/GenerateAction.java diff --git a/src/main/java/com/sdk/actionbean/generator/GenerateBeanAction.java b/src/main/java/com/sdk/generators/actionmodels/GenerateBeanAction.java similarity index 100% rename from src/main/java/com/sdk/actionbean/generator/GenerateBeanAction.java rename to src/main/java/com/sdk/generators/actionmodels/GenerateBeanAction.java diff --git a/src/main/java/com/sdk/actionbean/generator/GeneratorServices.java b/src/main/java/com/sdk/generators/actionmodels/GeneratorServices.java similarity index 100% rename from src/main/java/com/sdk/actionbean/generator/GeneratorServices.java rename to src/main/java/com/sdk/generators/actionmodels/GeneratorServices.java diff --git a/src/main/resources/template/actionBean.extend.ftl b/src/main/resources/templates/actionBean.extend.ftl similarity index 100% rename from src/main/resources/template/actionBean.extend.ftl rename to src/main/resources/templates/actionBean.extend.ftl diff --git a/src/main/resources/template/actionBean.ftl b/src/main/resources/templates/actionBean.ftl similarity index 100% rename from src/main/resources/template/actionBean.ftl rename to src/main/resources/templates/actionBean.ftl diff --git a/src/main/resources/templates/actionDTO.extend.ftl b/src/main/resources/templates/actionDTO.extend.ftl new file mode 100644 index 0000000..5c51b76 --- /dev/null +++ b/src/main/resources/templates/actionDTO.extend.ftl @@ -0,0 +1,18 @@ +package ${basePackage}.bean; + +/** +* Generated by IntelliJ ActionBean Generator +* For Table : ${tableName} +*/ + +import sdk.dbutils.*; + +public class ${tableName} extends ${basePackage}.bean.base.${tableName} { + public ${tableName}(DBConnector connector) { //class construction + super(connector); + } + + public ${tableName}() { //class construction + super(); + } +} diff --git a/src/main/resources/templates/actionDTO.ftl b/src/main/resources/templates/actionDTO.ftl new file mode 100644 index 0000000..4fcbcb5 --- /dev/null +++ b/src/main/resources/templates/actionDTO.ftl @@ -0,0 +1,103 @@ +package ${basePackage}.bean.base; + +/** +* Generated by IntelliJ ActionBean Generator +* For Table: ${tableName} +*/ + +import sdk.dbutils.*; +import sdk.utils.*; +import ${basePackage}.dto.*; + +public class ${className} extends ActionBean { + + public static final String tableName = "${tableName}"; + public static final String schemaName = "${dbSchema}"; + public static final String fullTableName = "${tableName}"; + private DTO_${tableName} myDTO; + + public ${className}(DBConnector dbConnector) { //class construction + super(dbConnector, fullTableName); + myDTO = new DTO_${tableName}(); + initFieldDefs(); + fieldList = "${fieldList}"; + keyList = "${keyList}"; + } + + public ${className}() { //class construction + super(); + myDTO = new DTO_${tableName}(); + initFieldDefs(); + fieldList = "${fieldList}"; + keyList = "${keyList}"; + } + + @Override + protected void initFieldDefs() { + fieldDefs.clear(); + <#list columns as col> + fieldDefs.put("${col.name}", "${col.customType}<#if col.isPk>:KEY"); + + } + + public DTO_${tableName} getInstanceDTO() { + myDTO.setDTO(this.getDTO()); + return myDTO; + } + + @Override + protected void initSqlSelect() { + StringBuilder Sql = new StringBuilder(); + Sql.append("SELECT "); + <#list columns as col> + <#if col?is_first> + Sql.append(" <#if col.customType == 'DATE'>JDTOET(${col.name}) ${col.name}, ${col.name} AS DT_${col.name}<#else> ${col.name}\n"); + <#else> + Sql.append(" ,<#if col.customType == 'DATE'>JDTOET(${col.name}) ${col.name}, ${col.name} AS DT_${col.name}<#else>${col.name}\n"); + + + Sql.append(" FROM ${tableName}\n"); + Sql.append(" WHERE 0=0 \n"); + + sqlSelect = new StringBuilder(Sql); + } + +<#-- Generate Setters --> +<#list columns as col> + public void set${col.name}(String value) { + <#if col.isPk> + if (JUtils.isMacro(value)) { + setKeyField(${col.name}, value); + fieldByName(${col.name}).setAsString(value); + } else { + setKeyField(${col.name}, JUtils.cleanUpNumber(value)); + fieldByName(${col.name}).setAsString(JUtils.cleanUpNumber(value)); + } + <#elseif col.customType == "DATE"> + if (JUtils.isMacro(value)) { + setField(${col.name}, value); + fieldByName(${col.name}).setAsString(value); + } else { + setField(${col.name}, DateUtils.strToSqlDate(value)); + fieldByName(${col.name}).setAsString(value); + } + <#else> + setField(${col.name}, value); + fieldByName(${col.name}).setAsString(value); + + } + + + +<#-- Generate Getters and Constants --> +<#list columns as col> + public static final String ${col.name} = "${col.name}"; + public String get${col.name}() { + return getValue(${col.name}); + } + public String get${col.name}(String defValue) { + return getValue(${col.name}, defValue); + } + + +} \ No newline at end of file