feat: Initial commit of the ActionBean generator plugin

This commit includes the basic project structure, the initial implementation of the plugin, and fixes for duplicate API calls and deprecated code.
This commit is contained in:
2025-07-08 19:13:39 +07:00
commit fb3b704285
39 changed files with 1509 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<!-- Unique id for this plugin. Must stay constant for the life of the plugin. -->
<id>com.sdk.actionbean.generator</id>
<name>Database Action Models Generator</name>
<vendor>Sakda Sakprapakorn</vendor>
<description><![CDATA[
Generates ActionBean Java classes from a database schema.
Right-click on a package and select "Generate Database Action Models" to start.
]]></description>
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>com.intellij.database</depends>
<actions>
<!-- Defines an action that will appear in the context menu for project directories -->
<action id="ActionModelGenerator.GenerateAction"
class="com.sdk.actionbean.generator.GenerateBeanAction"
text="Generate Database Action Models"
description="Generates ActionBean classes from a database schema.">
<add-to-group group-id="GenerateGroup" anchor="first"/>
<!-- This makes the action visible only when right-clicking a source package -->
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt G"/>
</action>
</actions>
</idea-plugin>

View File

@@ -0,0 +1,11 @@
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M32.0845 7.94025V4H24.0203V7.9896H16.029V4H7.91553V7.94025H4V36H16.0044V32.0045C16.0058 30.9457 16.4274 29.9308 17.1766 29.1826C17.9258 28.4345 18.9412 28.0143 20 28.0143C21.0588 28.0143 22.0743 28.4345 22.8234 29.1826C23.5726 29.9308 23.9942 30.9457 23.9956 32.0045V36H36V7.94025H32.0845Z"
fill="url(#paint0_linear)"/>
<defs>
<linearGradient id="paint0_linear" x1="2.94192" y1="4.89955" x2="37.7772" y2="39.7345" gradientUnits="userSpaceOnUse">
<stop offset="0.15937" stop-color="#3BEA62"/>
<stop offset="0.5404" stop-color="#3C99CC"/>
<stop offset="0.93739" stop-color="#6B57FF"/>
</linearGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 794 B

View File

@@ -0,0 +1,18 @@
package ${packageName}.bean;
/**
* Generated by IntelliJ ActionBean Generator
* Table: ${tableName}
*/
import sdk.dbutils.*;
public class ${tableName} extends ${packageName}.bean.base.${tableName} {
public ${tableName}(DBConnector connector) { //class construction
super(connector);
}
public ${tableName}() { //class construction
super();
}
}

View File

@@ -0,0 +1,103 @@
package ${packageName}.bean.base;
/**
* Generated by IntelliJ ActionBean Generator
* 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>
}