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.
This commit is contained in:
44
GEMINI.md
Normal file
44
GEMINI.md
Normal file
@@ -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`.
|
||||
4
src/main/java/com/sdk/generators/GUtils.java
Normal file
4
src/main/java/com/sdk/generators/GUtils.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.sdk.generators;
|
||||
|
||||
public class GUtils {
|
||||
}
|
||||
18
src/main/resources/templates/actionDTO.extend.ftl
Normal file
18
src/main/resources/templates/actionDTO.extend.ftl
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
103
src/main/resources/templates/actionDTO.ftl
Normal file
103
src/main/resources/templates/actionDTO.ftl
Normal file
@@ -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</#if>");
|
||||
</#list>
|
||||
}
|
||||
|
||||
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}</#if>\n");
|
||||
<#else>
|
||||
Sql.append(" ,<#if col.customType == 'DATE'>JDTOET(${col.name}) ${col.name}, ${col.name} AS DT_${col.name}<#else>${col.name}</#if>\n");
|
||||
</#if>
|
||||
</#list>
|
||||
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);
|
||||
</#if>
|
||||
}
|
||||
|
||||
</#list>
|
||||
|
||||
<#-- 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);
|
||||
}
|
||||
|
||||
</#list>
|
||||
}
|
||||
Reference in New Issue
Block a user