├── pojo-generator ├── settings.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradle.properties ├── build.gradle ├── src │ └── main │ │ ├── java │ │ └── fr │ │ │ └── jukien │ │ │ └── intellij │ │ │ └── plugins │ │ │ ├── ui │ │ │ ├── DBMS.java │ │ │ ├── JPAMappingPanel.form │ │ │ ├── JPAMappingConfigurable.java │ │ │ ├── DBMSFamily.java │ │ │ ├── ConfigurableJPAMapping.java │ │ │ ├── JPAMappingSettings.java │ │ │ ├── POJOGeneratorPanel.java │ │ │ ├── JPAMappingPanel.java │ │ │ ├── POJOGeneratorSettings.java │ │ │ ├── POJOGeneratorConfigurable.java │ │ │ └── POJOGeneratorPanel.form │ │ │ ├── util │ │ │ ├── Field.java │ │ │ ├── TableInfo.java │ │ │ └── Util.java │ │ │ └── action │ │ │ ├── DTO.java │ │ │ └── Entity.java │ │ └── resources │ │ └── META-INF │ │ ├── pluginIcon.svg │ │ ├── pluginIcon_dark.svg │ │ └── plugin.xml ├── gradlew.bat ├── gradlew └── pom.xml ├── .gitignore ├── pojo-generator-install ├── src │ ├── site │ │ └── resources │ │ │ └── images │ │ │ ├── user.png │ │ │ ├── settings.png │ │ │ ├── user-dto.png │ │ │ ├── jpa-mapping.png │ │ │ └── right-click-pojo-generator-entity.png │ └── assembly │ │ └── documentation │ │ └── note-version.md └── pom.xml ├── LICENSE ├── README.md └── pom.xml /pojo-generator/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'pojo-generator' 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea/ 3 | target/ 4 | *.iml 5 | /pojo-generator/build/ 6 | /pojo-generator-install/src/site/markdown/ 7 | -------------------------------------------------------------------------------- /pojo-generator/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /pojo-generator-install/src/site/resources/images/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator-install/src/site/resources/images/user.png -------------------------------------------------------------------------------- /pojo-generator/gradle.properties: -------------------------------------------------------------------------------- 1 | #org.gradle.java.home = C:/Program Files/Java/jdk-17 2 | org.gradle.java.home = /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home 3 | -------------------------------------------------------------------------------- /pojo-generator-install/src/site/resources/images/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator-install/src/site/resources/images/settings.png -------------------------------------------------------------------------------- /pojo-generator-install/src/site/resources/images/user-dto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator-install/src/site/resources/images/user-dto.png -------------------------------------------------------------------------------- /pojo-generator-install/src/site/resources/images/jpa-mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator-install/src/site/resources/images/jpa-mapping.png -------------------------------------------------------------------------------- /pojo-generator-install/src/site/resources/images/right-click-pojo-generator-entity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jukien/POJO-Generator/HEAD/pojo-generator-install/src/site/resources/images/right-click-pojo-generator-entity.png -------------------------------------------------------------------------------- /pojo-generator/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 30 08:56:35 CEST 2019 2 | distributionUrl = https\://services.gradle.org/distributions/gradle-8.9-all.zip 3 | distributionBase = GRADLE_USER_HOME 4 | distributionPath = wrapper/dists 5 | zipStorePath = wrapper/dists 6 | zipStoreBase = GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /pojo-generator/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.jetbrains.intellij' version '1.17.4' 4 | } 5 | 6 | group '${project.groupId}' 7 | version '${project.version}' 8 | 9 | sourceCompatibility = 17 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | /*dependencies { 16 | testCompile group: 'junit', name: 'junit', version: '4.12' 17 | }*/ 18 | 19 | // See https://github.com/JetBrains/gradle-intellij-plugin/ 20 | intellij { 21 | version = '2024.1' 22 | type = 'IU' 23 | plugins = ['java', 'DatabaseTools'] 24 | updateSinceUntilBuild = false 25 | } 26 | 27 | patchPluginXml { 28 | sinceBuild = '231' 29 | } 30 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/DBMS.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | import javax.swing.*; 7 | import java.util.UUID; 8 | 9 | /** 10 | * Created on 24/08/2019 11 | * 12 | * @author JDI 13 | * @version 2.2.0 14 | * @since 2.0.0 15 | */ 16 | public abstract class DBMS { 17 | @NotNull 18 | public abstract String getSqlDataType(); 19 | 20 | @NotNull 21 | public abstract UUID getId(); 22 | 23 | @NotNull 24 | public abstract DBMSFamily getFamily(); 25 | 26 | @NotNull 27 | public abstract Icon getIcon(); 28 | 29 | @NotNull 30 | public abstract String getJavaDataType(); 31 | 32 | @Nullable 33 | public abstract String getJavaColumnDefinition(); 34 | 35 | @Nullable 36 | public abstract Boolean isLengthAttributeEnabled(); 37 | } 38 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/JPAMappingPanel.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Julien DIEMER 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

 POJO Generator

2 | 3 | Generate JPA Entity POJO from database table 4 | 5 | ## Usage 6 | 7 | ![Right click POJO Generator Entity](pojo-generator-install/src/site/resources/images/right-click-pojo-generator-entity.png "Right click POJO Generator Entity") 8 | 9 | 1. Right click on the table for generate a JPA Entity POJO or a Data Transfert Object POJO 10 | 2. Choose the path where to store the java file 11 | 3. The Java class is generated 12 | 13 | ![User entity](pojo-generator-install/src/site/resources/images/user.png "User entity") 14 | 15 | Example of the User DTO class: 16 | 17 | ![User DTO](pojo-generator-install/src/site/resources/images/user-dto.png "User DTO") 18 | 19 | ### Options 20 | 21 | ![Settings](pojo-generator-install/src/site/resources/images/settings.png "Settings") 22 | 23 | 1. You can capitalize table name and column name in annotation 24 | 2. You can add `@GeneratedValue` annotation over column which have auto increment sequence (H2, Microsoft SQL Server, MySQL and PostgreSQL) 25 | 3. You can add `@ManyToOne` and `@JoinColumn` annotations on columns with foreign key 26 | 4. You can generate composite primary key with `@IdClass` or `@EmbeddedId` annotations 27 | 28 | ### JPA Mapping 29 | 30 | ![JPA Mapping](pojo-generator-install/src/site/resources/images/jpa-mapping.png "JPA Mapping") 31 | 32 | You can change the JPA mapping and add new ones 33 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/JPAMappingConfigurable.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.openapi.options.Configurable; 4 | import com.intellij.openapi.project.Project; 5 | import org.jetbrains.annotations.Nls; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import javax.swing.*; 9 | 10 | /** 11 | * Created on 24/08/2019 12 | * 13 | * @author JDI 14 | * @version 2.4.0 15 | * @since 2.0.0 16 | */ 17 | public class JPAMappingConfigurable implements Configurable { 18 | private final JPAMappingSettings jpaMappingSettings; 19 | 20 | private JPAMappingPanel jpaMappingPanel; 21 | 22 | public JPAMappingConfigurable(Project project) { 23 | this.jpaMappingSettings = project.getService(JPAMappingSettings.class); 24 | } 25 | 26 | @Nls(capitalization = Nls.Capitalization.Title) 27 | @Override 28 | public String getDisplayName() { 29 | return "JPA Mapping"; 30 | } 31 | 32 | @Nullable 33 | @Override 34 | public JComponent createComponent() { 35 | if (null == jpaMappingPanel) { 36 | jpaMappingPanel = new JPAMappingPanel(); 37 | } 38 | return jpaMappingPanel.getPanel(); 39 | } 40 | 41 | @Override 42 | public boolean isModified() { 43 | return !jpaMappingPanel.getJpaMappingEditor().getModel().getItems().equals(jpaMappingSettings.getJpaMappings()); 44 | } 45 | 46 | @Override 47 | public void apply() { 48 | jpaMappingSettings.setJpaMappings(jpaMappingPanel.getJpaMappingEditor().apply()); 49 | } 50 | 51 | public void reset() { 52 | jpaMappingPanel.getJpaMappingEditor().reset(jpaMappingSettings.getJpaMappings()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | fr.jukien.intellij.plugins 6 | pojo-generator-parent 7 | 2.6.1-SNAPSHOT 8 | pom 9 | 10 | POJO Generator 11 | 12 | 13 | UTF-8 14 | 17 15 | ${java.version} 16 | ${java.version} 17 | 18 | 19 | 20 | pojo-generator 21 | pojo-generator-install 22 | 23 | 24 | 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-release-plugin 29 | 3.1.1 30 | 31 | true 32 | v@{project.version} 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | ${deployment.repository.id} 41 | ${deployment.repository.url} 42 | 43 | 44 | 45 | 46 | scm:git:https://github.com/Jukien/POJO-Generator.git 47 | HEAD 48 | 49 | 50 | -------------------------------------------------------------------------------- /pojo-generator/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/util/Field.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.util; 2 | 3 | import com.intellij.database.model.DataType; 4 | 5 | /** 6 | * Created on 24/04/2019 7 | * 8 | * @author JDI 9 | * @version 2.3.0 10 | * @since 1.0.0 11 | */ 12 | public class Field { 13 | private String name; 14 | private Boolean isAutoGenerated; 15 | private Boolean isEmbeddedId; 16 | private Boolean isPrimary; 17 | private Boolean isForeignKey; 18 | private DataType SQLType; 19 | private String javaType; 20 | private String columnDefinition; 21 | private Integer length; 22 | 23 | public Field() { 24 | this.isAutoGenerated = false; 25 | this.isEmbeddedId = false; 26 | this.isPrimary = false; 27 | this.isForeignKey = false; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public Boolean getAutoGenerated() { 39 | return isAutoGenerated; 40 | } 41 | 42 | public void setAutoGenerated(Boolean autoGenerated) { 43 | isAutoGenerated = autoGenerated; 44 | } 45 | 46 | public Boolean getEmbeddedId() { 47 | return isEmbeddedId; 48 | } 49 | 50 | public void setEmbeddedId(Boolean embeddedId) { 51 | isEmbeddedId = embeddedId; 52 | } 53 | 54 | public Boolean getPrimary() { 55 | return isPrimary; 56 | } 57 | 58 | public void setPrimary(Boolean primary) { 59 | isPrimary = primary; 60 | } 61 | 62 | public Boolean getForeignKey() { 63 | return isForeignKey; 64 | } 65 | 66 | public void setForeignKey(Boolean foreignKey) { 67 | isForeignKey = foreignKey; 68 | } 69 | 70 | public DataType getSQLType() { 71 | return SQLType; 72 | } 73 | 74 | public void setSQLType(DataType SQLType) { 75 | this.SQLType = SQLType; 76 | } 77 | 78 | public String getJavaType() { 79 | return javaType; 80 | } 81 | 82 | public void setJavaType(String javaType) { 83 | this.javaType = javaType; 84 | } 85 | 86 | public String getColumnDefinition() { 87 | return columnDefinition; 88 | } 89 | 90 | public void setColumnDefinition(String columnDefinition) { 91 | this.columnDefinition = columnDefinition; 92 | } 93 | 94 | public Integer getLength() { 95 | return length; 96 | } 97 | 98 | public void setLength(Integer length) { 99 | this.length = length; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/DBMSFamily.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.icons.AllIcons; 4 | import com.intellij.openapi.util.Iconable; 5 | import org.jetbrains.annotations.NotNull; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import javax.swing.*; 9 | 10 | /** 11 | * Created on 24/08/2019 12 | * 13 | * @author JDI 14 | * @version 2.5.0 15 | * @since 2.0.0 16 | */ 17 | public enum DBMSFamily implements Iconable { 18 | H2("H2", AllIcons.Providers.H2, "VARCHAR", "String"), 19 | MYSQL("MySQL", AllIcons.Providers.Mysql, "varchar", "String"), 20 | ORACLE("Oracle", AllIcons.Providers.Oracle, "VARCHAR2", "String"), 21 | POSTGRES("PostgreSQL", AllIcons.Providers.Postgresql, "varchar", "String"), 22 | SQLSERVER("Microsoft SQL Server", AllIcons.Providers.SqlServer, "varchar", "String"); 23 | 24 | private final String name; 25 | private final Icon icon; 26 | private final String sqlDataType; 27 | private final String javaDataType; 28 | private final String javaColumnDefinition; 29 | private final Boolean isLengthAttributeEnabled; 30 | 31 | DBMSFamily(@NotNull String name, 32 | @NotNull Icon icon, 33 | @NotNull String sqlDataType, 34 | @NotNull String javaDataType) { 35 | this(name, icon, sqlDataType, javaDataType, null, false); 36 | } 37 | 38 | DBMSFamily(@NotNull String name, 39 | @NotNull Icon icon, 40 | @NotNull String sqlDataType, 41 | @NotNull String javaDataType, 42 | @Nullable String javaColumnDefinition, 43 | @Nullable Boolean isLengthAttributeEnabled) { 44 | this.name = name; 45 | this.icon = icon; 46 | this.sqlDataType = sqlDataType; 47 | this.javaDataType = javaDataType; 48 | this.javaColumnDefinition = javaColumnDefinition; 49 | this.isLengthAttributeEnabled = isLengthAttributeEnabled; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public Icon getIcon() { 57 | return icon; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return name; 63 | } 64 | 65 | @Override 66 | public Icon getIcon(@IconFlags int flags) { 67 | return getIcon(); 68 | } 69 | 70 | public String getSqlDataType() { 71 | return sqlDataType; 72 | } 73 | 74 | public String getJavaDataType() { 75 | return javaDataType; 76 | } 77 | 78 | public String getJavaColumnDefinition() { 79 | return javaColumnDefinition; 80 | } 81 | 82 | public Boolean isLengthAttributeEnabled() { 83 | return isLengthAttributeEnabled; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/util/TableInfo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BSD 3-Clause License 3 | *

4 | * Copyright (c) 2019, yseasony 5 | * All rights reserved. 6 | *

7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | *

10 | * * Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | *

13 | * * Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | *

17 | * * Neither the name of the copyright holder nor the names of its 18 | * contributors may be used to endorse or promote products derived from 19 | * this software without specific prior written permission. 20 | *

21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | package fr.jukien.intellij.plugins.util; 33 | 34 | import com.google.common.collect.Lists; 35 | import com.intellij.database.model.DasColumn; 36 | import com.intellij.database.psi.DbTable; 37 | import com.intellij.database.util.DasUtil; 38 | import com.intellij.util.containers.JBIterable; 39 | 40 | import java.util.ArrayList; 41 | import java.util.HashSet; 42 | import java.util.List; 43 | import java.util.Set; 44 | 45 | /** 46 | * Created on 24/04/2019 47 | * 48 | * @version 2.2.1 49 | * @since 1.0.0 50 | */ 51 | public class TableInfo { 52 | private final DbTable tableElement; 53 | private final String schemaName; 54 | private final List columns; 55 | private final List primaryKeys = new ArrayList(); 56 | 57 | public TableInfo(DbTable tableElement) { 58 | this.tableElement = tableElement; 59 | this.schemaName = DasUtil.getSchema(tableElement); 60 | 61 | List columns = new ArrayList(); 62 | 63 | JBIterable columnsIter = DasUtil.getColumns(tableElement); 64 | List dasColumns = columnsIter.toList(); 65 | for (DasColumn dasColumn : dasColumns) { 66 | columns.add(dasColumn); 67 | 68 | if (DasUtil.isPrimary(dasColumn)) { 69 | primaryKeys.add(dasColumn.getName()); 70 | } 71 | } 72 | this.columns = columns; 73 | } 74 | 75 | public String getTableName() { 76 | return tableElement.getName(); 77 | } 78 | 79 | public String getSchemaName() { 80 | return schemaName; 81 | } 82 | 83 | public List getColumns() { 84 | return columns; 85 | } 86 | 87 | public List getColumnsName() { 88 | List columnsName = Lists.newArrayList(); 89 | for (DasColumn column : columns) { 90 | columnsName.add(column.getName()); 91 | } 92 | return columnsName; 93 | } 94 | 95 | public List getPrimaryKeys() { 96 | return this.primaryKeys; 97 | } 98 | 99 | public List getNonPrimaryColumns() { 100 | Set pKNameSet = new HashSet(); 101 | for (String pkName : getPrimaryKeys()) { 102 | pKNameSet.add(pkName); 103 | } 104 | 105 | List ret = new ArrayList(); 106 | for (DasColumn column : columns) { 107 | if (!pKNameSet.contains(column.getName())) { 108 | ret.add(column); 109 | } 110 | } 111 | 112 | return ret; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/ConfigurableJPAMapping.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.jetbrains.annotations.Nullable; 5 | 6 | import javax.swing.*; 7 | import java.util.UUID; 8 | 9 | /** 10 | * Created on 24/08/2019 11 | * 12 | * @author JDI 13 | * @version 2.2.0 14 | * @since 2.0.0 15 | */ 16 | public class ConfigurableJPAMapping extends DBMS { 17 | private final UUID id; 18 | @NotNull 19 | private DBMSFamily family; 20 | @NotNull 21 | private String sqlDataType; 22 | @NotNull 23 | private String javaDataType; 24 | @Nullable 25 | private String javaColumnDefinition; 26 | @Nullable 27 | private Boolean isLengthAttributeEnabled; 28 | 29 | ConfigurableJPAMapping() { 30 | this(UUID.randomUUID(), DBMSFamily.ORACLE); 31 | } 32 | 33 | ConfigurableJPAMapping(@NotNull UUID id, 34 | @NotNull DBMSFamily family) { 35 | this(id, family, family.getSqlDataType(), family.getJavaDataType(), family.getJavaColumnDefinition(), family.isLengthAttributeEnabled()); 36 | } 37 | 38 | ConfigurableJPAMapping(@NotNull UUID id, 39 | @NotNull DBMSFamily family, 40 | @NotNull String sqlDataType, 41 | @NotNull String javaDataType) { 42 | this(id, family, sqlDataType, javaDataType, null, false); 43 | } 44 | 45 | ConfigurableJPAMapping(@NotNull UUID id, 46 | @NotNull DBMSFamily family, 47 | @NotNull String sqlDataType, 48 | @NotNull String javaDataType, 49 | @Nullable String javaColumnDefinition) { 50 | this(id, family, sqlDataType, javaDataType, javaColumnDefinition, false); 51 | } 52 | 53 | ConfigurableJPAMapping(@NotNull UUID id, 54 | @NotNull DBMSFamily family, 55 | @NotNull String sqlDataType, 56 | @NotNull String javaDataType, 57 | @Nullable Boolean isLengthAttributeEnabled) { 58 | this(id, family, sqlDataType, javaDataType, null, isLengthAttributeEnabled); 59 | } 60 | 61 | ConfigurableJPAMapping(@NotNull UUID id, 62 | @NotNull DBMSFamily family, 63 | @NotNull String sqlDataType, 64 | @NotNull String javaDataType, 65 | @Nullable String javaColumnDefinition, 66 | @Nullable Boolean isLengthAttributeEnabled) { 67 | this.id = id; 68 | this.family = family; 69 | this.sqlDataType = sqlDataType; 70 | this.javaDataType = javaDataType; 71 | this.javaColumnDefinition = javaColumnDefinition; 72 | this.isLengthAttributeEnabled = isLengthAttributeEnabled; 73 | } 74 | 75 | @NotNull 76 | @Override 77 | public UUID getId() { 78 | return id; 79 | } 80 | 81 | @NotNull 82 | @Override 83 | public DBMSFamily getFamily() { 84 | return family; 85 | } 86 | 87 | public void setFamily(@NotNull DBMSFamily value) { 88 | family = value; 89 | } 90 | 91 | @NotNull 92 | @Override 93 | public Icon getIcon() { 94 | return family.getIcon(); 95 | } 96 | 97 | @NotNull 98 | @Override 99 | public String getSqlDataType() { 100 | return sqlDataType; 101 | } 102 | 103 | public void setSqlDataType(@NotNull String value) { 104 | sqlDataType = value; 105 | } 106 | 107 | @NotNull 108 | @Override 109 | public String getJavaDataType() { 110 | return javaDataType; 111 | } 112 | 113 | public void setJavaDataType(@NotNull String value) { 114 | javaDataType = value; 115 | } 116 | 117 | @Nullable 118 | @Override 119 | public String getJavaColumnDefinition() { 120 | return javaColumnDefinition; 121 | } 122 | 123 | public void setJavaColumnDefinition(@Nullable String value) { 124 | javaColumnDefinition = value; 125 | } 126 | 127 | @Nullable 128 | @Override 129 | public Boolean isLengthAttributeEnabled() { 130 | return isLengthAttributeEnabled; 131 | } 132 | 133 | public void setLengthAttributeEnabled(@Nullable Boolean lengthAttributeEnabled) { 134 | isLengthAttributeEnabled = lengthAttributeEnabled; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /pojo-generator-install/src/assembly/documentation/note-version.md: -------------------------------------------------------------------------------- 1 | #### Changelog 2 | 3 | ##### Version ${parent.version} - Published on ${timestamp} 4 | ###### New 5 | - Possibility to customize the header template of the class: 6 | - Add default import (GitHub [#25](https://github.com/Jukien/POJO-Generator/issues/25)) 7 | - Add Lombok annotation for example (GitHub [#21](https://github.com/Jukien/POJO-Generator/issues/21)) 8 | 9 | ###### Fixed 10 | - `@GeneratedValue` was not generated for Postgres database 11 | - Fixed an internal error from the plugin on the IDE 12 | 13 | *** 14 | 15 | ##### Version 2.5.0 - Published on 30/06/2023 16 | ###### New 17 | - Microsoft SQL Server Database support (GitHub [#27](https://github.com/Jukien/POJO-Generator/issues/27)) 18 | 19 | *** 20 | 21 | ##### Version 2.4.0 - Published on 31/03/2023 22 | ###### Fixed 23 | - NoClassDefFoundError with IDEA 2023.1 (GitHub [#26](https://github.com/Jukien/POJO-Generator/issues/26)) 24 | 25 | *** 26 | 27 | ##### Version 2.3.1 - Published on 12/11/2020 28 | ###### Fixed 29 | - Compatibility with JBR 8 (GitHub [#22](https://github.com/Jukien/POJO-Generator/issues/22)) 30 | 31 | *** 32 | 33 | ##### Version 2.3.0 - Published on 27/10/2020 34 | ###### New 35 | - Possibility to generate composite primary key (GitHub [#17](https://github.com/Jukien/POJO-Generator/issues/17)) 36 | - H2 Database support (GitHub [#18](https://github.com/Jukien/POJO-Generator/issues/18)) 37 | 38 | *** 39 | 40 | ##### Version 2.2.1 - Published on 27/07/2020 41 | ###### New 42 | - GitHub [#16](https://github.com/Jukien/POJO-Generator/issues/16): Add schema name on entity 43 | 44 | *** 45 | 46 | ##### Version 2.2.0 - Published on 12/04/2020 47 | ###### New 48 | - GitHub [#11](https://github.com/Jukien/POJO-Generator/issues/11): Add compatibility with IntelliJ IDEA 2020.1 (Ultimate Edition) 49 | - GitHub [#12](https://github.com/Jukien/POJO-Generator/issues/12): Add possibility to see the differences if the file already exists 50 | - GitHub [#13](https://github.com/Jukien/POJO-Generator/issues/13): Add `@Column`'s length attribute 51 | - GitHub [#14](https://github.com/Jukien/POJO-Generator/issues/14): Add new default mapping types 52 | 53 | *** 54 | 55 | ##### Version 2.1.0 - Published on 06/01/2020 56 | ###### New 57 | - GitHub [#1](https://github.com/Jukien/POJO-Generator/issues/1): Ask only once the path to store files when we select multiple tables for generation 58 | - GitHub [#6](https://github.com/Jukien/POJO-Generator/issues/6): Keep folders location for entities and DTOs files 59 | - GitHub [#8](https://github.com/Jukien/POJO-Generator/issues/8): Add `@ManyToOne` and `@JoinColumn` annotations on columns with foreign key 60 | - GitHub [#9](https://github.com/Jukien/POJO-Generator/issues/9): Add the ability to customize the prefix and suffix of file names 61 | 62 | ###### Fixed 63 | - GitHub [#7](https://github.com/Jukien/POJO-Generator/issues/7): Error when the file already exists 64 | 65 | *** 66 | 67 | ##### Version 2.0.1 - Published on 29/11/2019 68 | ###### New 69 | - GitHub [#4](https://github.com/Jukien/POJO-Generator/issues/4): Add compatibility with IntelliJ IDEA 2019.3 (Ultimate Edition) 70 | - \[Add] New default mapping types 71 | 72 | ###### Fixed 73 | - GitHub [#5](https://github.com/Jukien/POJO-Generator/issues/5): Settings are not saved at project level 74 | 75 | *** 76 | 77 | ##### Version 2.0.0 - Published on 16/09/2019 78 | ###### New 79 | - \[Add] Possibility to customize the JPA mapping 80 | 81 | ###### Fixed 82 | - GitHub [#2](https://github.com/Jukien/POJO-Generator/issues/2): Settings for New Projects were not saved 83 | 84 | *** 85 | 86 | ##### Version 1.1.0 - Published on 30/07/2019 87 | ###### New 88 | - \[Add] ORACLE datatype : CHAR (with columnDefinition) 89 | - \[Add] Possibility to add `@GeneratedValue` annotation over column which have auto increment sequence (Tested with MySQL) 90 | - \[Modification] Compatible from 2019.1 91 | 92 | *** 93 | 94 | ##### Version 1.0.1 - Published on 18/07/2019 95 | ###### New 96 | - \[Add] MySQL datatype : date 97 | - \[Add] MySQL datatype : datetime 98 | - \[Modification] The plugin will be only compatible for Java IDE 99 | 100 | ###### Fixed 101 | - When generate a DTO file, the path choosed by the user wasn't take in count 102 | 103 | *** 104 | 105 | ##### Version 1.0.0 - Published on 08/07/2019 106 | ###### New 107 | - \[Add] DataType 108 | - \[Add] MySQL Database support 109 | - \[Add] Oracle Database support 110 | - \[Improvement] When database is not supported, actions are disabled 111 | - \[Improvement] When we generate a POJO, the directory choosing window position the user where he was the last time 112 | - \[Improvement] If the user select an element which is not a table, actions are disabled 113 | 114 | *** 115 | 116 | ##### Version 1.0.0-alpha-2 - Published on 30/04/2019 117 | ###### New 118 | - Can generate a Data Transfert Object from database table 119 | -------------------------------------------------------------------------------- /pojo-generator-install/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | pojo-generator-parent 6 | fr.jukien.intellij.plugins 7 | 2.6.1-SNAPSHOT 8 | 9 | 10 | pojo-generator-install 11 | pom 12 | 13 | POJO Generator :: Install 14 | 15 | 16 | 17 | ${maven.build.timestamp} 18 | dd/MM/yyyy 19 | 20 | 21 | 22 | 23 | 24 | maven-clean-plugin 25 | 3.4.0 26 | 27 | 28 | 29 | src/site/markdown 30 | 31 | **/* 32 | 33 | 34 | 35 | 36 | 37 | 38 | maven-resources-plugin 39 | 3.3.1 40 | 41 | 42 | copy-documentation 43 | generate-resources 44 | 45 | copy-resources 46 | 47 | 48 | 49 | 50 | ${basedir}/src/assembly/documentation 51 | *.md 52 | true 53 | 54 | 55 | ${basedir}/src/site/markdown 56 | 57 | 58 | 59 | copy-build-plugin-to-install-packaging 60 | generate-resources 61 | 62 | copy-resources 63 | 64 | 65 | 66 | 67 | ../pojo-generator/target/gradle/build/distributions 68 | 69 | 70 | target/install/plugin 71 | 72 | 73 | 74 | 75 | 76 | com.ragedunicorn.tools.maven 77 | github-release-maven-plugin 78 | 1.0.7 79 | 80 | 81 | default-cli 82 | ${github-release-maven-plugin.phase} 83 | 84 | github-release 85 | 86 | 87 | Jukien 88 | POJO-Generator 89 | github 90 | v${project.version} 91 | Version ${project.version} 92 | ${basedir}/src/site/markdown/note-version.md 93 | 94 | ${basedir}/target/install/plugin/pojo-generator-${project.version}.zip 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/action/DTO.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.action; 2 | 3 | import com.intellij.database.psi.DbTable; 4 | import com.intellij.openapi.actionSystem.ActionUpdateThread; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | import com.intellij.openapi.actionSystem.LangDataKeys; 8 | import com.intellij.openapi.fileChooser.FileChooser; 9 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 10 | import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; 11 | import com.intellij.openapi.project.Project; 12 | import com.intellij.openapi.vfs.VfsUtil; 13 | import com.intellij.openapi.vfs.VirtualFile; 14 | import com.intellij.psi.PsiElement; 15 | import fr.jukien.intellij.plugins.ui.JPAMappingSettings; 16 | import fr.jukien.intellij.plugins.ui.POJOGeneratorSettings; 17 | import fr.jukien.intellij.plugins.util.Field; 18 | import fr.jukien.intellij.plugins.util.TableInfo; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | import java.net.MalformedURLException; 22 | import java.nio.file.Path; 23 | import java.nio.file.Paths; 24 | import java.util.LinkedHashSet; 25 | 26 | import static fr.jukien.intellij.plugins.util.Util.*; 27 | 28 | /** 29 | * Created on 25/04/2019 30 | * 31 | * @author JDI 32 | * @version 2.6.0 33 | * @since 1.0.0 34 | */ 35 | public class DTO extends AnAction { 36 | private String actionText = ""; 37 | 38 | @Override 39 | public void actionPerformed(AnActionEvent anActionEvent) { 40 | final Project project = anActionEvent.getProject(); 41 | if (null == project) { 42 | return; 43 | } 44 | 45 | final POJOGeneratorSettings pojoGeneratorSettings = project.getService(POJOGeneratorSettings.class); 46 | final JPAMappingSettings jpaMappingSettings = project.getService(JPAMappingSettings.class); 47 | 48 | PsiElement[] psiElements = anActionEvent.getData(LangDataKeys.PSI_ELEMENT_ARRAY); 49 | if (psiElements == null || psiElements.length == 0) { 50 | return; 51 | } 52 | 53 | if (null != project.getBasePath()) { 54 | Path projectPath = Paths.get(project.getBasePath()); 55 | VirtualFile chooseFile = null; 56 | try { 57 | chooseFile = VfsUtil.findFileByURL(projectPath.toUri().toURL()); 58 | } catch (MalformedURLException e) { 59 | e.printStackTrace(); 60 | } 61 | FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); 62 | if (null != pojoGeneratorSettings.getDtoFolderPath()) { 63 | try { 64 | chooseFile = VfsUtil.findFileByURL(Paths.get(pojoGeneratorSettings.getDtoFolderPath()).toUri().toURL()); 65 | } catch (MalformedURLException e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | lastFileChosen = FileChooser.chooseFile(descriptor, project, chooseFile); 70 | if (null == lastFileChosen) { 71 | return; 72 | } else { 73 | pojoGeneratorSettings.setDtoFolderPath(lastFileChosen.getPath()); 74 | } 75 | 76 | for (PsiElement psiElement : psiElements) { 77 | if (!(psiElement instanceof DbTable)) { 78 | continue; 79 | } 80 | 81 | TableInfo tableInfo = new TableInfo((DbTable) psiElement); 82 | LinkedHashSet fields = getFields((DbTable) psiElement, jpaMappingSettings); 83 | String className = String.format("%s%s%s", pojoGeneratorSettings.getPrefixDto(), javaName(tableInfo.getTableName(), true), pojoGeneratorSettings.getSuffixDto()); 84 | 85 | StringBuilder javaTextFile = new StringBuilder(); 86 | //javaTextFile.append("\n"); 87 | String header = pojoGeneratorSettings.getHeaderDTO().replace("${CLASS_NAME}", className); 88 | 89 | javaTextFile.append(header).append("\n"); 90 | 91 | // javaTextFile.append("\n"); 92 | // javaTextFile.append("public class ").append(className).append(" {").append("\n"); 93 | 94 | for (Field field : fields) { 95 | javaTextFile.append(" private ").append(field.getJavaType()).append(" ").append(javaName(field.getName(), false)).append(";").append("\n"); 96 | } 97 | 98 | if (pojoGeneratorSettings.getGenerateGetterAndSetter()) { 99 | javaTextFile.append("\n"); 100 | addGetterSetter(fields, javaTextFile); 101 | } 102 | 103 | javaTextFile.append("}").append("\n"); 104 | 105 | String fileName = String.format("%s%s", className, ".java"); 106 | createFile(project, javaTextFile, fileName, pojoGeneratorSettings); 107 | } 108 | } 109 | } 110 | 111 | @Override 112 | public void update(@NotNull AnActionEvent anActionEvent) { 113 | if (actionText.isEmpty()) { 114 | actionText = anActionEvent.getPresentation().getText(); 115 | } 116 | 117 | checkActionVisibility(anActionEvent, actionText); 118 | super.update(anActionEvent); 119 | } 120 | 121 | @Override 122 | public @NotNull ActionUpdateThread getActionUpdateThread() { 123 | return ActionUpdateThread.BGT; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /pojo-generator/src/main/resources/META-INF/pluginIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 31 | 32 | 33 | 37 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 52 | 53 | 55 | 58 | 59 | 60 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /pojo-generator/src/main/resources/META-INF/pluginIcon_dark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 31 | 32 | 33 | 37 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 52 | 53 | 55 | 58 | 59 | 60 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/JPAMappingSettings.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.openapi.components.PersistentStateComponent; 4 | import com.intellij.openapi.components.State; 5 | import com.intellij.openapi.components.Storage; 6 | import com.intellij.util.xmlb.XmlSerializerUtil; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | import java.util.UUID; 14 | 15 | /** 16 | * Created on 24/08/2019 17 | * 18 | * @author JDI 19 | * @version 2.6.0 20 | * @since 2.0.0 21 | */ 22 | @State( 23 | name = "JPAMappingSettings", 24 | storages = { 25 | @Storage("JPAMappingSettings.xml")} 26 | ) 27 | public class JPAMappingSettings implements PersistentStateComponent { 28 | private List jpaMappings; 29 | 30 | public static List getPredefinedJPAMappings() { 31 | return Arrays.asList( 32 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.H2, "BIGINT", "Long"), 33 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.H2, "DATE", "LocalDate"), 34 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.H2, "VARCHAR", "String"), 35 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "bigint", "Long"), 36 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "bit", "Boolean"), 37 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "datetime", "LocalDateTime"), 38 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "datetime2", "LocalDateTime"), 39 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "decimal", "BigDecimal"), 40 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "int", "Integer"), 41 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "nvarchar", "String"), 42 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.SQLSERVER, "varchar", "String"), 43 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "bigint", "Long"), 44 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "bit", "Boolean"), 45 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "date", "LocalDate"), 46 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "datetime", "LocalDateTime"), 47 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "decimal", "BigDecimal"), 48 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "double", "Double"), 49 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "enum", "String"), 50 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "float", "Float"), 51 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "int", "Integer"), 52 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "json", "String"), 53 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "smallint", "Integer"), 54 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "text", "String"), 55 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "timestamp", "LocalDateTime"), 56 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "tinyint", "java.lang.Byte"), 57 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.MYSQL, "varchar", "String"), 58 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "CHAR", "String", "CHAR"), 59 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "DATE", "LocalDate"), 60 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "FLOAT", "Float"), 61 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "NUMBER", "Long"), 62 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "TIMESTAMP", "LocalDateTime"), 63 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.ORACLE, "VARCHAR2", "String"), 64 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "bigint", "Long"), 65 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "boolean", "Boolean"), 66 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "date", "LocalDate"), 67 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "integer", "Long"), 68 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "smallint", "Integer"), 69 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "timestamp", "LocalDateTime"), 70 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "uuid", "UUID"), 71 | new ConfigurableJPAMapping(UUID.randomUUID(), DBMSFamily.POSTGRES, "varchar", "String") 72 | ); 73 | } 74 | 75 | public JPAMappingSettings() { 76 | jpaMappings = new ArrayList<>(getPredefinedJPAMappings()); 77 | } 78 | 79 | @Nullable 80 | @Override 81 | public JPAMappingSettings getState() { 82 | return this; 83 | } 84 | 85 | @Override 86 | public void loadState(@NotNull JPAMappingSettings state) { 87 | XmlSerializerUtil.copyBean(state, this); 88 | } 89 | 90 | public List getJpaMappings() { 91 | return jpaMappings; 92 | } 93 | 94 | public void setJpaMappings(List jpaMappings) { 95 | this.jpaMappings = jpaMappings; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /pojo-generator/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /pojo-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | fr.jukien.intellij.plugins 7 | pojo-generator-parent 8 | 2.6.1-SNAPSHOT 9 | 10 | 11 | pojo-generator 12 | pom 13 | 14 | POJO Generator :: Plugin 15 | 16 | 17 | target/gradle 18 | 19 | 20 | 21 | 22 | 23 | maven-resources-plugin 24 | 3.3.1 25 | 26 | 27 | copy-gradle-project 28 | 29 | validate 30 | 31 | copy-resources 32 | 33 | 34 | 35 | 36 | ${basedir}/ 37 | 38 | src/** 39 | gradle.properties 40 | settings.gradle 41 | 42 | 43 | 44 | ${basedir}/${targetGradle} 45 | 46 | 47 | 48 | copy-build.gradle-filtered 49 | 50 | validate 51 | 52 | copy-resources 53 | 54 | 55 | 56 | 57 | ${basedir}/ 58 | 59 | build.gradle 60 | 61 | true 62 | 63 | 64 | ${basedir}/${targetGradle} 65 | 66 | 67 | 68 | 69 | 70 | org.apache.maven.plugins 71 | maven-compiler-plugin 72 | 3.13.0 73 | 74 | 75 | default-compile 76 | compile 77 | 78 | compile 79 | 80 | 81 | true 82 | 83 | 84 | 85 | 86 | 87 | org.codehaus.mojo 88 | exec-maven-plugin 89 | 3.3.0 90 | 91 | 92 | gradle-clean 93 | install 94 | 95 | ./gradlew 96 | 97 | clean 98 | -Dorg.gradle.java.home=${java.home} 99 | --project-dir 100 | ${basedir}/${targetGradle} 101 | 102 | 103 | 104 | exec 105 | 106 | 107 | 108 | gradle-buildPlugin 109 | install 110 | 111 | ./gradlew 112 | 113 | buildPlugin 114 | -Dorg.gradle.java.home=${java.home} 115 | --project-dir 116 | ${basedir}/${targetGradle} 117 | 118 | 119 | 120 | exec 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/POJOGeneratorPanel.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import javax.swing.*; 4 | 5 | /** 6 | * Created on 24/04/2019 7 | * 8 | * @author JDI 9 | * @version 2.6.0 10 | * @since 1.0.0 11 | */ 12 | public class POJOGeneratorPanel { 13 | private JPanel panel; 14 | private JCheckBox capitalizeCheckBox; 15 | /*private JCheckBox schemaAttributeCheckBox;*/ 16 | private JCheckBox generatedValueAnnotationsCheckBox; 17 | private JCheckBox manyToOneAndJoinColumnAnnotationsCheckBox; 18 | private JCheckBox generateCompositePrimaryKeyCheckBox; 19 | private JRadioButton idClassAnnotationRadioButton; 20 | private JRadioButton embeddedIdAnnotationRadioButton; 21 | private JLabel prefixCompositePrimaryKeyLabel; 22 | private JTextField prefixCompositePrimaryKeyTextField; 23 | private JLabel suffixCompositePrimaryKeyLabel; 24 | private JTextField suffixCompositePrimaryKeyTextField; 25 | private JCheckBox generateGetterAndSetterCheckBox; 26 | private JTextField prefixEntityTextField; 27 | private JTextField suffixEntityTextField; 28 | private JTextField prefixDTOTextField; 29 | private JTextField suffixDTOTextField; 30 | private JCheckBox alwaysShowDifferencesBetweenFilesCheckBox; 31 | private JTextArea headerEntityTextArea; 32 | private JTextArea headerEntityIdClassTextArea; 33 | private JTextArea headerDTOTextArea; 34 | private JTextArea templateTextArea; 35 | private JTextArea variablesTextArea; 36 | 37 | public POJOGeneratorPanel(POJOGeneratorSettings pojoGeneratorSettings) { 38 | // Initialise l'interface graphique avec les settings qui ont été enregistrés avant 39 | capitalizeCheckBox.setSelected(pojoGeneratorSettings.getCapitalize()); 40 | /*schemaAttributeCheckBox.setSelected(pojoGeneratorSettings.getWithSchemaAttribute());*/ 41 | generatedValueAnnotationsCheckBox.setSelected(pojoGeneratorSettings.getAutoGenerated()); 42 | manyToOneAndJoinColumnAnnotationsCheckBox.setSelected(pojoGeneratorSettings.getWithRelationshipAnnotations()); 43 | generateCompositePrimaryKeyCheckBox.setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKey()); 44 | idClassAnnotationRadioButton.setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithIdClassAnnotation()); 45 | embeddedIdAnnotationRadioButton.setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()); 46 | prefixCompositePrimaryKeyTextField.setText(pojoGeneratorSettings.getPrefixCompositePrimaryKey()); 47 | suffixCompositePrimaryKeyTextField.setText(pojoGeneratorSettings.getSuffixCompositePrimaryKey()); 48 | generateGetterAndSetterCheckBox.setSelected(pojoGeneratorSettings.getGenerateGetterAndSetter()); 49 | prefixEntityTextField.setText(pojoGeneratorSettings.getPrefixEntity()); 50 | suffixEntityTextField.setText(pojoGeneratorSettings.getSuffixEntity()); 51 | prefixDTOTextField.setText(pojoGeneratorSettings.getPrefixDto()); 52 | suffixDTOTextField.setText(pojoGeneratorSettings.getSuffixDto()); 53 | alwaysShowDifferencesBetweenFilesCheckBox.setSelected(pojoGeneratorSettings.getAlwaysShowDifferencesBetweenFiles()); 54 | headerEntityTextArea.setText(pojoGeneratorSettings.getHeaderEntity()); 55 | headerEntityIdClassTextArea.setText(pojoGeneratorSettings.getHeaderEntityIdClass()); 56 | headerDTOTextArea.setText(pojoGeneratorSettings.getHeaderDTO()); 57 | 58 | templateTextArea.setText(""" 59 | import jakarta.persistence.*; 60 | 61 | @Entity 62 | @Table(name = "${TABLE_NAME}", schema = "${SCHEMA_NAME}") 63 | public class ${CLASS_NAME} {"""); 64 | 65 | variablesTextArea.setText(""" 66 | ${TABLE_NAME}: table name 67 | ${SCHEMA_NAME}: schema name 68 | ${CLASS_NAME}: class name 69 | ${ID_CLASS_NAME}: IdClass name"""); 70 | } 71 | 72 | public JPanel getPanel() { 73 | return panel; 74 | } 75 | 76 | public JCheckBox getCapitalizeCheckBox() { 77 | return capitalizeCheckBox; 78 | } 79 | 80 | /*public JCheckBox getSchemaAttributeCheckBox() { 81 | return schemaAttributeCheckBox; 82 | }*/ 83 | 84 | public JCheckBox getGeneratedValueAnnotationsCheckBox() { 85 | return generatedValueAnnotationsCheckBox; 86 | } 87 | 88 | public JCheckBox getManyToOneAndJoinColumnAnnotationsCheckBox() { 89 | return manyToOneAndJoinColumnAnnotationsCheckBox; 90 | } 91 | 92 | public JCheckBox getGenerateCompositePrimaryKeyCheckBox() { 93 | return generateCompositePrimaryKeyCheckBox; 94 | } 95 | 96 | public JRadioButton getIdClassAnnotationRadioButton() { 97 | return idClassAnnotationRadioButton; 98 | } 99 | 100 | public JRadioButton getEmbeddedIdAnnotationRadioButton() { 101 | return embeddedIdAnnotationRadioButton; 102 | } 103 | 104 | public JLabel getPrefixCompositePrimaryKeyLabel() { 105 | return prefixCompositePrimaryKeyLabel; 106 | } 107 | 108 | public JTextField getPrefixCompositePrimaryKeyTextField() { 109 | return prefixCompositePrimaryKeyTextField; 110 | } 111 | 112 | public JLabel getSuffixCompositePrimaryKeyLabel() { 113 | return suffixCompositePrimaryKeyLabel; 114 | } 115 | 116 | public JTextField getSuffixCompositePrimaryKeyTextField() { 117 | return suffixCompositePrimaryKeyTextField; 118 | } 119 | 120 | public JCheckBox getGenerateGetterAndSetterCheckBox() { 121 | return generateGetterAndSetterCheckBox; 122 | } 123 | 124 | public JTextField getPrefixEntityTextField() { 125 | return prefixEntityTextField; 126 | } 127 | 128 | public JTextField getSuffixEntityTextField() { 129 | return suffixEntityTextField; 130 | } 131 | 132 | public JTextField getPrefixDTOTextField() { 133 | return prefixDTOTextField; 134 | } 135 | 136 | public JTextField getSuffixDTOTextField() { 137 | return suffixDTOTextField; 138 | } 139 | 140 | public JCheckBox getAlwaysShowDifferencesBetweenFilesCheckBox() { 141 | return alwaysShowDifferencesBetweenFilesCheckBox; 142 | } 143 | 144 | public JTextArea getHeaderEntityTextArea() { 145 | return headerEntityTextArea; 146 | } 147 | 148 | public JTextArea getHeaderEntityIdClassTextArea() { 149 | return headerEntityIdClassTextArea; 150 | } 151 | 152 | public JTextArea getHeaderDTOTextArea() { 153 | return headerDTOTextArea; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/JPAMappingPanel.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.util.Function; 4 | import com.intellij.util.ui.ColumnInfo; 5 | import com.intellij.util.ui.table.IconTableCellRenderer; 6 | import com.intellij.util.ui.table.TableModelEditor; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import javax.swing.*; 11 | import javax.swing.event.TableModelEvent; 12 | import javax.swing.table.TableCellRenderer; 13 | import java.util.UUID; 14 | 15 | /** 16 | * Created on 24/08/2019 17 | * 18 | * @author JDI 19 | * @version 2.4.0 20 | * @since 2.0.0 21 | */ 22 | public class JPAMappingPanel { 23 | private JPanel panel; 24 | private JComponent jpaMappingTable; 25 | private TableModelEditor jpaMappingEditor; 26 | 27 | private static final ColumnInfo[] COLUMNS = { 28 | new ColumnInfo("DBMS") { 29 | @Override 30 | public Class getColumnClass() { 31 | return DBMSFamily.class; 32 | } 33 | 34 | @NotNull 35 | @Override 36 | public DBMSFamily valueOf(ConfigurableJPAMapping configurableJPAMapping) { 37 | return configurableJPAMapping.getFamily(); 38 | } 39 | 40 | @Override 41 | public void setValue(ConfigurableJPAMapping item, DBMSFamily value) { 42 | item.setFamily(value); 43 | } 44 | 45 | @NotNull 46 | @Override 47 | public TableCellRenderer getRenderer(ConfigurableJPAMapping item) { 48 | return IconTableCellRenderer.ICONABLE; 49 | } 50 | 51 | @Override 52 | public boolean isCellEditable(ConfigurableJPAMapping item) { 53 | return true;//!WebBrowserManager.getInstance().isPredefinedBrowser(item); 54 | } 55 | }, 56 | new TableModelEditor.EditableColumnInfo("SQL data type") { 57 | @NotNull 58 | @Override 59 | public String valueOf(ConfigurableJPAMapping configurableJPAMapping) { 60 | return configurableJPAMapping.getSqlDataType(); 61 | } 62 | 63 | @Override 64 | public void setValue(ConfigurableJPAMapping item, String value) { 65 | item.setSqlDataType(value); 66 | } 67 | }, 68 | new TableModelEditor.EditableColumnInfo("Java data type") { 69 | @NotNull 70 | @Override 71 | public String valueOf(ConfigurableJPAMapping configurableJPAMapping) { 72 | return configurableJPAMapping.getJavaDataType(); 73 | } 74 | 75 | @Override 76 | public void setValue(ConfigurableJPAMapping item, String value) { 77 | item.setJavaDataType(value); 78 | } 79 | }, 80 | new TableModelEditor.EditableColumnInfo("Java columnDefinition attribute") { 81 | @Nullable 82 | @Override 83 | public String valueOf(ConfigurableJPAMapping configurableJPAMapping) { 84 | return configurableJPAMapping.getJavaColumnDefinition(); 85 | } 86 | 87 | @Override 88 | public void setValue(ConfigurableJPAMapping item, String value) { 89 | item.setJavaColumnDefinition(value); 90 | } 91 | }, 92 | new TableModelEditor.EditableColumnInfo("Java length attribute") { 93 | @Nullable 94 | @Override 95 | public Boolean valueOf(ConfigurableJPAMapping configurableJPAMapping) { 96 | return configurableJPAMapping.isLengthAttributeEnabled(); 97 | } 98 | 99 | @Override 100 | public Class getColumnClass() { 101 | return Boolean.class; 102 | } 103 | 104 | @Override 105 | public void setValue(ConfigurableJPAMapping configurableJPAMapping, Boolean value) { 106 | configurableJPAMapping.setLengthAttributeEnabled(value); 107 | } 108 | } 109 | }; 110 | 111 | public JPAMappingPanel() { 112 | } 113 | 114 | private void createUIComponents() { 115 | TableModelEditor.DialogItemEditor itemEditor = new TableModelEditor.DialogItemEditor() { 116 | @NotNull 117 | @Override 118 | public Class getItemClass() { 119 | return ConfigurableJPAMapping.class; 120 | } 121 | 122 | @Override 123 | public ConfigurableJPAMapping clone(@NotNull ConfigurableJPAMapping item, boolean forInPlaceEditing) { 124 | return new ConfigurableJPAMapping(forInPlaceEditing ? item.getId() : UUID.randomUUID(), 125 | item.getFamily(), item.getSqlDataType(), item.getJavaDataType(), item.getJavaColumnDefinition(), item.isLengthAttributeEnabled()); 126 | } 127 | 128 | @Override 129 | public void edit(@NotNull ConfigurableJPAMapping item, @NotNull Function mutator, boolean isAdd) { 130 | 131 | } 132 | 133 | @Override 134 | public void applyEdited(@NotNull ConfigurableJPAMapping oldItem, @NotNull ConfigurableJPAMapping newItem) { 135 | //oldItem.setSpecificSettings(newItem.getSpecificSettings()); 136 | } 137 | 138 | @Override 139 | public boolean isEditable(@NotNull ConfigurableJPAMapping browser) { 140 | return false;//browser.getSpecificSettings() != null; 141 | } 142 | 143 | @Override 144 | public boolean isRemovable(@NotNull ConfigurableJPAMapping item) { 145 | return true;//!WebBrowserManager.getInstance().isPredefinedBrowser(item); 146 | } 147 | }; 148 | jpaMappingEditor = new TableModelEditor<>(COLUMNS, itemEditor, "No JPA mapping configured") 149 | .modelListener(new TableModelEditor.DataChangedListener() { 150 | @Override 151 | public void tableChanged(@NotNull TableModelEvent event) { 152 | update(); 153 | } 154 | 155 | @Override 156 | public void dataChanged(@NotNull ColumnInfo columnInfo, int rowIndex) { 157 | /*if (columnInfo == PATH_COLUMN_INFO || columnInfo == ACTIVE_COLUMN_INFO) { 158 | update(); 159 | }*/ 160 | } 161 | 162 | private void update() { 163 | /*if (getDefaultBrowser() == DefaultBrowserPolicy.FIRST) { 164 | setCustomPathToFirstListed(); 165 | }*/ 166 | } 167 | }); 168 | jpaMappingTable = jpaMappingEditor.createComponent(); 169 | } 170 | 171 | public JPanel getPanel() { 172 | return panel; 173 | } 174 | 175 | public TableModelEditor getJpaMappingEditor() { 176 | return jpaMappingEditor; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /pojo-generator/src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | fr.jukien.intellij.plugins.pojo-generator 3 | POJO Generator 4 | Julien DIEMER 5 | 6 | Generate JPA Entity POJO from database table 8 |
9 | Can generate from database table:
10 |

22 |
23 | Works with H2, Microsoft SQL Server, MySQL, Oracle & PostgreSQL. 24 |

25 | Below the default mapping table used by the plugin:

26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 |
DBMSSQL data typeJava data typeJPA columnDefinition
H2BIGINTLong
H2DATELocalDate
H2VARCHARString
Microsoft SQL ServerbigintLong
Microsoft SQL ServerbitBoolean
Microsoft SQL ServerdatetimeLocalDateTime
Microsoft SQL Serverdatetime2LocalDateTime
Microsoft SQL ServerdecimalBigDecimal
Microsoft SQL ServerintInteger
Microsoft SQL ServernvarcharString
Microsoft SQL ServervarcharString
MySQLbigintLong
MySQLbitBoolean
MySQLdateLocalDate
MySQLdatetimeLocalDateTime
MySQLdecimalBigDecimal
MySQLdoubleDouble
MySQLenumString
MySQLfloatFloat
MySQLintInteger
MySQLjsonString
MySQLsmallintInteger
MySQLtextString
MySQLtimestampLocalDateTime
MySQLtinyintjava.lang.Byte
MySQLvarcharString
OracleCHARStringCHAR
OracleDATELocalDate
OracleFLOATFloat
OracleNUMBERLong
OracleTIMESTAMPLocalDateTime
OracleVARCHAR2String
PostgreSQLbigintLong
PostgreSQLbooleanBoolean
PostgreSQLdateLocalDate
PostgreSQLintegerLong
PostgreSQLvarcharString
224 | ]]> 225 | 226 | 228 |
  • [New] Possibility to customize the header template of the class:
  • 229 | 233 |
  • [Fixed] @GeneratedValue was not generated for Postgres database
  • 234 |
  • [Fixed] Fixed an internal error from the plugin on the IDE
  • 235 | 236 | ]]>
    237 | 238 | 240 | 243 | 244 | com.intellij.modules.java 245 | com.intellij.database 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/POJOGeneratorSettings.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.openapi.components.PersistentStateComponent; 4 | import com.intellij.openapi.components.State; 5 | import com.intellij.openapi.components.Storage; 6 | import com.intellij.util.xmlb.XmlSerializerUtil; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | /** 11 | * Created on 25/04/2019 12 | * 13 | * @author JDI 14 | * @version 2.6.0 15 | * @since 1.0.0 16 | */ 17 | @State( 18 | name = "POJOGeneratorSettings", 19 | storages = { 20 | @Storage("POJOGeneratorSettings.xml")} 21 | ) 22 | public class POJOGeneratorSettings implements PersistentStateComponent { 23 | private Boolean capitalize; 24 | @Deprecated 25 | private Boolean withSchemaAttribute; 26 | private Boolean autoGenerated; 27 | private Boolean withRelationshipAnnotations; 28 | private Boolean generateCompositePrimaryKey; 29 | private Boolean generateCompositePrimaryKeyWithIdClassAnnotation; 30 | private Boolean generateCompositePrimaryKeyWithEmbeddedIdAnnotation; 31 | private String dtoFolderPath; 32 | private String entityFolderPath; 33 | private String prefixCompositePrimaryKey; 34 | private String suffixCompositePrimaryKey; 35 | private Boolean generateGetterAndSetter; 36 | private String prefixEntity; 37 | private String suffixEntity; 38 | private String prefixDto; 39 | private String suffixDto; 40 | private Boolean alwaysShowDifferencesBetweenFiles; 41 | private String headerEntity; 42 | private String headerEntityIdClass; 43 | private String headerDTO; 44 | 45 | public POJOGeneratorSettings() { 46 | capitalize = false; 47 | autoGenerated = false; 48 | withSchemaAttribute = false; 49 | withRelationshipAnnotations = false; 50 | generateCompositePrimaryKey = false; 51 | generateCompositePrimaryKeyWithIdClassAnnotation = true; 52 | generateCompositePrimaryKeyWithEmbeddedIdAnnotation = false; 53 | prefixCompositePrimaryKey = ""; 54 | suffixCompositePrimaryKey = "Id"; 55 | generateGetterAndSetter = true; 56 | prefixEntity = ""; 57 | suffixEntity = ""; 58 | prefixDto = ""; 59 | suffixDto = "DTO"; 60 | alwaysShowDifferencesBetweenFiles = false; 61 | 62 | if (getWithSchemaAttribute()) { 63 | headerEntity = """ 64 | 65 | import jakarta.persistence.*; 66 | 67 | @Entity 68 | @Table(name = "${TABLE_NAME}", schema = "${SCHEMA_NAME}") 69 | public class ${CLASS_NAME} {"""; 70 | 71 | headerEntityIdClass = """ 72 | 73 | import jakarta.persistence.*; 74 | 75 | @Entity 76 | @IdClass(${ID_CLASS_NAME}.class) 77 | @Table(name = "${TABLE_NAME}", schema = "${SCHEMA_NAME}") 78 | public class ${CLASS_NAME} {"""; 79 | } else { 80 | headerEntity = """ 81 | 82 | import jakarta.persistence.*; 83 | 84 | @Entity 85 | @Table(name = "${TABLE_NAME}") 86 | public class ${CLASS_NAME} {"""; 87 | 88 | headerEntityIdClass = """ 89 | 90 | import jakarta.persistence.*; 91 | 92 | @Entity 93 | @IdClass(${ID_CLASS_NAME}.class) 94 | @Table(name = "${TABLE_NAME}") 95 | public class ${CLASS_NAME} {"""; 96 | } 97 | 98 | headerDTO = """ 99 | 100 | public class ${CLASS_NAME} {"""; 101 | } 102 | 103 | @Nullable 104 | @Override 105 | public POJOGeneratorSettings getState() { 106 | return this; 107 | } 108 | 109 | @Override 110 | public void loadState(@NotNull POJOGeneratorSettings state) { 111 | XmlSerializerUtil.copyBean(state, this); 112 | } 113 | 114 | public Boolean getCapitalize() { 115 | return capitalize; 116 | } 117 | 118 | public void setCapitalize(Boolean capitalize) { 119 | this.capitalize = capitalize; 120 | } 121 | 122 | @Deprecated 123 | public Boolean getWithSchemaAttribute() { 124 | return withSchemaAttribute; 125 | } 126 | 127 | @Deprecated 128 | public void setWithSchemaAttribute(Boolean withSchemaAttribute) { 129 | this.withSchemaAttribute = withSchemaAttribute; 130 | } 131 | 132 | public Boolean getAutoGenerated() { 133 | return autoGenerated; 134 | } 135 | 136 | public void setAutoGenerated(Boolean autoGenerated) { 137 | this.autoGenerated = autoGenerated; 138 | } 139 | 140 | public Boolean getWithRelationshipAnnotations() { 141 | return withRelationshipAnnotations; 142 | } 143 | 144 | public void setWithRelationshipAnnotations(Boolean withRelationshipAnnotations) { 145 | this.withRelationshipAnnotations = withRelationshipAnnotations; 146 | } 147 | 148 | public Boolean getGenerateCompositePrimaryKey() { 149 | return generateCompositePrimaryKey; 150 | } 151 | 152 | public void setGenerateCompositePrimaryKey(Boolean generateCompositePrimaryKey) { 153 | this.generateCompositePrimaryKey = generateCompositePrimaryKey; 154 | } 155 | 156 | public Boolean getGenerateCompositePrimaryKeyWithIdClassAnnotation() { 157 | return generateCompositePrimaryKeyWithIdClassAnnotation; 158 | } 159 | 160 | public void setGenerateCompositePrimaryKeyWithIdClassAnnotation(Boolean generateCompositePrimaryKeyWithIdClassAnnotation) { 161 | this.generateCompositePrimaryKeyWithIdClassAnnotation = generateCompositePrimaryKeyWithIdClassAnnotation; 162 | } 163 | 164 | public Boolean getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation() { 165 | return generateCompositePrimaryKeyWithEmbeddedIdAnnotation; 166 | } 167 | 168 | public void setGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation(Boolean generateCompositePrimaryKeyWithEmbeddedIdAnnotation) { 169 | this.generateCompositePrimaryKeyWithEmbeddedIdAnnotation = generateCompositePrimaryKeyWithEmbeddedIdAnnotation; 170 | } 171 | 172 | public String getDtoFolderPath() { 173 | return dtoFolderPath; 174 | } 175 | 176 | public void setDtoFolderPath(String dtoFolderPath) { 177 | this.dtoFolderPath = dtoFolderPath; 178 | } 179 | 180 | public String getEntityFolderPath() { 181 | return entityFolderPath; 182 | } 183 | 184 | public void setEntityFolderPath(String entityFolderPath) { 185 | this.entityFolderPath = entityFolderPath; 186 | } 187 | 188 | public String getPrefixCompositePrimaryKey() { 189 | return prefixCompositePrimaryKey; 190 | } 191 | 192 | public void setPrefixCompositePrimaryKey(String prefixCompositePrimaryKey) { 193 | this.prefixCompositePrimaryKey = prefixCompositePrimaryKey; 194 | } 195 | 196 | public String getSuffixCompositePrimaryKey() { 197 | return suffixCompositePrimaryKey; 198 | } 199 | 200 | public void setSuffixCompositePrimaryKey(String suffixCompositePrimaryKey) { 201 | this.suffixCompositePrimaryKey = suffixCompositePrimaryKey; 202 | } 203 | 204 | public Boolean getGenerateGetterAndSetter() { 205 | return generateGetterAndSetter; 206 | } 207 | 208 | public void setGenerateGetterAndSetter(Boolean generateGetterAndSetter) { 209 | this.generateGetterAndSetter = generateGetterAndSetter; 210 | } 211 | 212 | public String getPrefixEntity() { 213 | return prefixEntity; 214 | } 215 | 216 | public void setPrefixEntity(String prefixEntity) { 217 | this.prefixEntity = prefixEntity; 218 | } 219 | 220 | public String getSuffixEntity() { 221 | return suffixEntity; 222 | } 223 | 224 | public void setSuffixEntity(String suffixEntity) { 225 | this.suffixEntity = suffixEntity; 226 | } 227 | 228 | public String getPrefixDto() { 229 | return prefixDto; 230 | } 231 | 232 | public void setPrefixDto(String prefixDto) { 233 | this.prefixDto = prefixDto; 234 | } 235 | 236 | public String getSuffixDto() { 237 | return suffixDto; 238 | } 239 | 240 | public void setSuffixDto(String suffixDto) { 241 | this.suffixDto = suffixDto; 242 | } 243 | 244 | public Boolean getAlwaysShowDifferencesBetweenFiles() { 245 | return alwaysShowDifferencesBetweenFiles; 246 | } 247 | 248 | public void setAlwaysShowDifferencesBetweenFiles(Boolean alwaysShowDifferencesBetweenFiles) { 249 | this.alwaysShowDifferencesBetweenFiles = alwaysShowDifferencesBetweenFiles; 250 | } 251 | 252 | public String getHeaderEntity() { 253 | return headerEntity; 254 | } 255 | 256 | public void setHeaderEntity(String headerEntity) { 257 | this.headerEntity = headerEntity; 258 | } 259 | 260 | public String getHeaderEntityIdClass() { 261 | return headerEntityIdClass; 262 | } 263 | 264 | public void setHeaderEntityIdClass(String headerEntityIdClass) { 265 | this.headerEntityIdClass = headerEntityIdClass; 266 | } 267 | 268 | public String getHeaderDTO() { 269 | return headerDTO; 270 | } 271 | 272 | public void setHeaderDTO(String headerDTO) { 273 | this.headerDTO = headerDTO; 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/POJOGeneratorConfigurable.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.ui; 2 | 3 | import com.intellij.openapi.options.Configurable; 4 | import com.intellij.openapi.project.Project; 5 | import org.jetbrains.annotations.Nls; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import javax.swing.*; 9 | 10 | /** 11 | * Created on 24/04/2019 12 | * 13 | * @author JDI 14 | * @version 2.6.0 15 | * @since 1.0.0 16 | */ 17 | public class POJOGeneratorConfigurable implements Configurable { 18 | private final POJOGeneratorSettings pojoGeneratorSettings; 19 | 20 | private POJOGeneratorPanel pojoGeneratorPanel; 21 | 22 | public POJOGeneratorConfigurable(Project project) { 23 | this.pojoGeneratorSettings = project.getService(POJOGeneratorSettings.class); 24 | } 25 | 26 | @Nls(capitalization = Nls.Capitalization.Title) 27 | @Override 28 | public String getDisplayName() { 29 | return "POJO Generator"; 30 | } 31 | 32 | @Nullable 33 | @Override 34 | public JComponent createComponent() { 35 | if (null == pojoGeneratorPanel) { 36 | pojoGeneratorPanel = new POJOGeneratorPanel(pojoGeneratorSettings); 37 | } 38 | 39 | updateEnabled(); 40 | pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox().addItemListener(e -> updateEnabled()); 41 | pojoGeneratorPanel.getIdClassAnnotationRadioButton().addItemListener(e -> { 42 | pojoGeneratorPanel.getHeaderEntityIdClassTextArea().setEnabled(isIdClassAnnotationEnabled()); 43 | }); 44 | 45 | ButtonGroup group = new ButtonGroup(); 46 | group.add(pojoGeneratorPanel.getIdClassAnnotationRadioButton()); 47 | group.add(pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton()); 48 | 49 | return pojoGeneratorPanel.getPanel(); 50 | } 51 | 52 | @Override 53 | public boolean isModified() { 54 | if (pojoGeneratorPanel.getCapitalizeCheckBox().isSelected() != pojoGeneratorSettings.getCapitalize()) return true; 55 | /*if (pojoGeneratorPanel.getSchemaAttributeCheckBox().isSelected() != pojoGeneratorSettings.getWithSchemaAttribute()) return true;*/ 56 | if (pojoGeneratorPanel.getGeneratedValueAnnotationsCheckBox().isSelected() != pojoGeneratorSettings.getAutoGenerated()) return true; 57 | if (pojoGeneratorPanel.getManyToOneAndJoinColumnAnnotationsCheckBox().isSelected() != pojoGeneratorSettings.getWithRelationshipAnnotations()) return true; 58 | if (pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox().isSelected() != pojoGeneratorSettings.getGenerateCompositePrimaryKey()) return true; 59 | if (pojoGeneratorPanel.getIdClassAnnotationRadioButton().isSelected() != pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithIdClassAnnotation()) return true; 60 | if (pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton().isSelected() != pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()) return true; 61 | if (!pojoGeneratorPanel.getPrefixCompositePrimaryKeyTextField().getText().equals(pojoGeneratorSettings.getPrefixCompositePrimaryKey())) return true; 62 | if (!pojoGeneratorPanel.getSuffixCompositePrimaryKeyTextField().getText().equals(pojoGeneratorSettings.getSuffixCompositePrimaryKey())) return true; 63 | if (pojoGeneratorPanel.getGenerateGetterAndSetterCheckBox().isSelected() != pojoGeneratorSettings.getGenerateGetterAndSetter()) return true; 64 | if (!pojoGeneratorPanel.getPrefixEntityTextField().getText().equals(pojoGeneratorSettings.getPrefixEntity())) return true; 65 | if (!pojoGeneratorPanel.getSuffixEntityTextField().getText().equals(pojoGeneratorSettings.getSuffixEntity())) return true; 66 | if (!pojoGeneratorPanel.getPrefixDTOTextField().getText().equals(pojoGeneratorSettings.getPrefixDto())) return true; 67 | if (!pojoGeneratorPanel.getSuffixDTOTextField().getText().equals(pojoGeneratorSettings.getSuffixDto())) return true; 68 | if (pojoGeneratorPanel.getAlwaysShowDifferencesBetweenFilesCheckBox().isSelected() != pojoGeneratorSettings.getAlwaysShowDifferencesBetweenFiles()) return true; 69 | if (!pojoGeneratorPanel.getHeaderEntityTextArea().getText().equals(pojoGeneratorSettings.getHeaderEntity())) return true; 70 | if (!pojoGeneratorPanel.getHeaderEntityIdClassTextArea().getText().equals(pojoGeneratorSettings.getHeaderEntityIdClass())) return true; 71 | if (!pojoGeneratorPanel.getHeaderDTOTextArea().getText().equals(pojoGeneratorSettings.getHeaderDTO())) return true; 72 | return false; 73 | } 74 | 75 | @Override 76 | public void apply() { 77 | pojoGeneratorSettings.setCapitalize(pojoGeneratorPanel.getCapitalizeCheckBox().isSelected()); 78 | /*pojoGeneratorSettings.setWithSchemaAttribute(pojoGeneratorPanel.getSchemaAttributeCheckBox().isSelected());*/ 79 | pojoGeneratorSettings.setAutoGenerated(pojoGeneratorPanel.getGeneratedValueAnnotationsCheckBox().isSelected()); 80 | pojoGeneratorSettings.setWithRelationshipAnnotations(pojoGeneratorPanel.getManyToOneAndJoinColumnAnnotationsCheckBox().isSelected()); 81 | pojoGeneratorSettings.setGenerateCompositePrimaryKey(pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox().isSelected()); 82 | pojoGeneratorSettings.setGenerateCompositePrimaryKeyWithIdClassAnnotation(pojoGeneratorPanel.getIdClassAnnotationRadioButton().isSelected()); 83 | pojoGeneratorSettings.setGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation(pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton().isSelected()); 84 | pojoGeneratorSettings.setPrefixCompositePrimaryKey(pojoGeneratorPanel.getPrefixCompositePrimaryKeyTextField().getText()); 85 | pojoGeneratorSettings.setSuffixCompositePrimaryKey(pojoGeneratorPanel.getSuffixCompositePrimaryKeyTextField().getText()); 86 | pojoGeneratorSettings.setGenerateGetterAndSetter(pojoGeneratorPanel.getGenerateGetterAndSetterCheckBox().isSelected()); 87 | pojoGeneratorSettings.setPrefixEntity(pojoGeneratorPanel.getPrefixEntityTextField().getText()); 88 | pojoGeneratorSettings.setSuffixEntity(pojoGeneratorPanel.getSuffixEntityTextField().getText()); 89 | pojoGeneratorSettings.setPrefixDto(pojoGeneratorPanel.getPrefixDTOTextField().getText()); 90 | pojoGeneratorSettings.setSuffixDto(pojoGeneratorPanel.getSuffixDTOTextField().getText()); 91 | pojoGeneratorSettings.setAlwaysShowDifferencesBetweenFiles(pojoGeneratorPanel.getAlwaysShowDifferencesBetweenFilesCheckBox().isSelected()); 92 | pojoGeneratorSettings.setHeaderEntity(pojoGeneratorPanel.getHeaderEntityTextArea().getText()); 93 | pojoGeneratorSettings.setHeaderEntityIdClass(pojoGeneratorPanel.getHeaderEntityIdClassTextArea().getText()); 94 | pojoGeneratorSettings.setHeaderDTO(pojoGeneratorPanel.getHeaderDTOTextArea().getText()); 95 | } 96 | 97 | @Override 98 | public void reset() { 99 | pojoGeneratorPanel.getCapitalizeCheckBox().setSelected(pojoGeneratorSettings.getCapitalize()); 100 | pojoGeneratorPanel.getGeneratedValueAnnotationsCheckBox().setSelected(pojoGeneratorSettings.getAutoGenerated()); 101 | pojoGeneratorPanel.getManyToOneAndJoinColumnAnnotationsCheckBox().setSelected(pojoGeneratorSettings.getWithRelationshipAnnotations()); 102 | pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox().setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKey()); 103 | pojoGeneratorPanel.getIdClassAnnotationRadioButton().setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithIdClassAnnotation()); 104 | pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton().setSelected(pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()); 105 | pojoGeneratorPanel.getPrefixCompositePrimaryKeyTextField().setText(pojoGeneratorSettings.getPrefixCompositePrimaryKey()); 106 | pojoGeneratorPanel.getSuffixCompositePrimaryKeyTextField().setText(pojoGeneratorSettings.getSuffixCompositePrimaryKey()); 107 | pojoGeneratorPanel.getGenerateGetterAndSetterCheckBox().setSelected(pojoGeneratorSettings.getGenerateGetterAndSetter()); 108 | pojoGeneratorPanel.getPrefixEntityTextField().setText(pojoGeneratorSettings.getPrefixEntity()); 109 | pojoGeneratorPanel.getSuffixEntityTextField().setText(pojoGeneratorSettings.getSuffixEntity()); 110 | pojoGeneratorPanel.getPrefixDTOTextField().setText(pojoGeneratorSettings.getPrefixDto()); 111 | pojoGeneratorPanel.getSuffixDTOTextField().setText(pojoGeneratorSettings.getSuffixDto()); 112 | pojoGeneratorPanel.getAlwaysShowDifferencesBetweenFilesCheckBox().setSelected(pojoGeneratorSettings.getAlwaysShowDifferencesBetweenFiles()); 113 | pojoGeneratorPanel.getHeaderEntityTextArea().setText(pojoGeneratorSettings.getHeaderEntity()); 114 | pojoGeneratorPanel.getHeaderEntityIdClassTextArea().setText(pojoGeneratorSettings.getHeaderEntityIdClass()); 115 | pojoGeneratorPanel.getHeaderDTOTextArea().setText(pojoGeneratorSettings.getHeaderDTO()); 116 | } 117 | 118 | private boolean isGenerateCompositePrimaryKeyEnabled() { 119 | return pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox() != null && pojoGeneratorPanel.getGenerateCompositePrimaryKeyCheckBox().isSelected(); 120 | } 121 | 122 | private boolean isIdClassAnnotationEnabled() { 123 | return pojoGeneratorPanel.getIdClassAnnotationRadioButton() != null && pojoGeneratorPanel.getIdClassAnnotationRadioButton().isSelected(); 124 | } 125 | 126 | private void updateEnabled() { 127 | boolean enabled = isGenerateCompositePrimaryKeyEnabled(); 128 | if (pojoGeneratorPanel.getIdClassAnnotationRadioButton() != null) { 129 | pojoGeneratorPanel.getIdClassAnnotationRadioButton().setEnabled(enabled); 130 | } 131 | if (pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton() != null) { 132 | pojoGeneratorPanel.getEmbeddedIdAnnotationRadioButton().setEnabled(enabled); 133 | } 134 | if (pojoGeneratorPanel.getPrefixCompositePrimaryKeyLabel() != null) { 135 | pojoGeneratorPanel.getPrefixCompositePrimaryKeyLabel().setEnabled(enabled); 136 | } 137 | if (pojoGeneratorPanel.getPrefixCompositePrimaryKeyTextField() != null) { 138 | pojoGeneratorPanel.getPrefixCompositePrimaryKeyTextField().setEnabled(enabled); 139 | } 140 | if (pojoGeneratorPanel.getSuffixCompositePrimaryKeyLabel() != null) { 141 | pojoGeneratorPanel.getSuffixCompositePrimaryKeyLabel().setEnabled(enabled); 142 | } 143 | if (pojoGeneratorPanel.getSuffixCompositePrimaryKeyTextField() != null) { 144 | pojoGeneratorPanel.getSuffixCompositePrimaryKeyTextField().setEnabled(enabled); 145 | } 146 | if (pojoGeneratorPanel.getHeaderEntityIdClassTextArea() != null) { 147 | pojoGeneratorPanel.getHeaderEntityIdClassTextArea().setEnabled(enabled && isIdClassAnnotationEnabled()); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/util/Util.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.util; 2 | 3 | import com.intellij.database.model.DasColumn; 4 | import com.intellij.database.model.DasForeignKey; 5 | import com.intellij.database.psi.DbTable; 6 | import com.intellij.database.util.DasUtil; 7 | import com.intellij.diff.DiffContentFactory; 8 | import com.intellij.diff.DiffDialogHints; 9 | import com.intellij.diff.DiffManager; 10 | import com.intellij.diff.DiffRequestFactory; 11 | import com.intellij.diff.actions.impl.MutableDiffRequestChain; 12 | import com.intellij.diff.contents.DiffContent; 13 | import com.intellij.ide.highlighter.JavaClassFileType; 14 | import com.intellij.notification.Notification; 15 | import com.intellij.notification.NotificationAction; 16 | import com.intellij.notification.NotificationType; 17 | import com.intellij.notification.Notifications; 18 | import com.intellij.openapi.actionSystem.AnActionEvent; 19 | import com.intellij.openapi.actionSystem.LangDataKeys; 20 | import com.intellij.openapi.command.WriteCommandAction; 21 | import com.intellij.openapi.project.Project; 22 | import com.intellij.openapi.vfs.VirtualFile; 23 | import com.intellij.psi.PsiDirectory; 24 | import com.intellij.psi.PsiElement; 25 | import com.intellij.psi.PsiFile; 26 | import com.intellij.psi.PsiFileFactory; 27 | import com.intellij.psi.codeStyle.NameUtil; 28 | import com.intellij.psi.impl.file.PsiDirectoryFactory; 29 | import com.intellij.vcsUtil.VcsUtil; 30 | import fr.jukien.intellij.plugins.ui.ConfigurableJPAMapping; 31 | import fr.jukien.intellij.plugins.ui.DBMSFamily; 32 | import fr.jukien.intellij.plugins.ui.JPAMappingSettings; 33 | import fr.jukien.intellij.plugins.ui.POJOGeneratorSettings; 34 | import org.jetbrains.annotations.NotNull; 35 | 36 | import java.util.HashSet; 37 | import java.util.LinkedHashSet; 38 | import java.util.List; 39 | import java.util.Set; 40 | 41 | /** 42 | * Created on 25/04/2019 43 | * 44 | * @author JDI 45 | * @version 2.6.0 46 | * @since 1.0.0 47 | */ 48 | public class Util { 49 | public static VirtualFile lastFileChosen; 50 | 51 | public static LinkedHashSet getFields(DbTable dbTable, JPAMappingSettings jpaMappingSettings) { 52 | LinkedHashSet fields = new LinkedHashSet<>(); 53 | List jpaMappings = jpaMappingSettings.getJpaMappings(); 54 | for (DasColumn column : DasUtil.getColumns(dbTable)) { 55 | Field field = new Field(); 56 | field.setName(column.getName()); 57 | field.setAutoGenerated(DasUtil.isAutoGenerated(column)); 58 | field.setSQLType(column.getDasType().toDataType()); 59 | 60 | ConfigurableJPAMapping configurableJPAMapping = jpaMappings.stream() 61 | .filter(c -> dbTable.getDataSource().getDatabaseVersion().name.equals(c.getFamily().getName()) && 62 | column.getDasType().toDataType().typeName.equals(c.getSqlDataType())) 63 | .findAny() 64 | .orElse(null); 65 | 66 | if (null != configurableJPAMapping) { 67 | field.setJavaType(configurableJPAMapping.getJavaDataType()); 68 | field.setColumnDefinition(configurableJPAMapping.getJavaColumnDefinition()); 69 | if (null != configurableJPAMapping.isLengthAttributeEnabled() && configurableJPAMapping.isLengthAttributeEnabled()) { 70 | field.setLength(column.getDasType().toDataType().size); 71 | } 72 | } else { 73 | field.setJavaType(null); 74 | field.setColumnDefinition(null); 75 | } 76 | 77 | field.setPrimary(DasUtil.isPrimary(column)); 78 | fields.add(field); 79 | } 80 | 81 | for (DasForeignKey dasForeignKey : DasUtil.getForeignKeys(dbTable)) { 82 | dasForeignKey.getColumnsRef().names().forEach(s -> { 83 | fields.forEach(field -> { 84 | if (field.getName().equals(s)) { 85 | field.setForeignKey(true); 86 | } 87 | }); 88 | }); 89 | } 90 | return fields; 91 | } 92 | 93 | public static void addConstructor(String className, LinkedHashSet fields, StringBuilder javaTextFile) { 94 | StringBuilder fieldsToInitialize = new StringBuilder(); 95 | StringBuilder fieldsToInitializeAssignment = new StringBuilder(); 96 | javaTextFile.append(" public ").append(className).append("("); 97 | 98 | int index = 0; 99 | for (Field field : fields) { 100 | fieldsToInitialize.append(field.getJavaType()).append(" ").append(javaName(field.getName(), false)); 101 | 102 | if (index < fields.size() - 1) { 103 | fieldsToInitialize.append(", "); 104 | } 105 | 106 | fieldsToInitializeAssignment.append(" this.").append(javaName(field.getName(), false)).append(" = ").append(javaName(field.getName(), false)).append(";").append("\n"); 107 | 108 | index++; 109 | } 110 | 111 | javaTextFile.append(fieldsToInitialize).append(") {").append("\n"); 112 | javaTextFile.append(fieldsToInitializeAssignment); 113 | 114 | javaTextFile.append(" }").append("\n"); 115 | } 116 | 117 | public static void addGetterSetter(LinkedHashSet fields, StringBuilder javaTextFile) { 118 | int index = 0; 119 | for (Field field : fields) { 120 | javaTextFile.append(" public ").append(field.getJavaType()).append(" get").append(javaName(field.getName(), true)).append("() {").append("\n"); 121 | javaTextFile.append(" return this.").append(javaName(field.getName(), false)).append(";").append("\n"); 122 | javaTextFile.append(" }").append("\n"); 123 | 124 | javaTextFile.append("\n"); 125 | 126 | javaTextFile.append(" public void set").append(javaName(field.getName(), true)).append("(").append(field.getJavaType()).append(" ").append(javaName(field.getName(), false)).append(") {").append("\n"); 127 | javaTextFile.append(" this.").append(javaName(field.getName(), false)).append(" = ").append(javaName(field.getName(), false)).append(";").append("\n"); 128 | javaTextFile.append(" }").append("\n"); 129 | 130 | if (index < fields.size() - 1) { 131 | javaTextFile.append("\n"); 132 | } 133 | 134 | index++; 135 | } 136 | } 137 | 138 | public static String javaName(String str, Boolean capitalizeFirstLetter) { 139 | String[] strings = NameUtil.splitNameIntoWords(str); 140 | StringBuilder name = new StringBuilder(); 141 | 142 | for (int i = 0; strings.length > i; i++) { 143 | if (i == 0) { 144 | if (capitalizeFirstLetter) { 145 | name.append(convertToTitleCaseIteratingChars(strings[i])); 146 | } else { 147 | name.append(strings[i].toLowerCase()); 148 | } 149 | } else { 150 | name.append(convertToTitleCaseIteratingChars(strings[i])); 151 | } 152 | } 153 | return name.toString(); 154 | } 155 | 156 | public static String convertToTitleCaseIteratingChars(String text) { 157 | if (text == null || text.isEmpty()) { 158 | return text; 159 | } 160 | 161 | StringBuilder converted = new StringBuilder(); 162 | 163 | boolean convertNext = true; 164 | for (char ch : text.toCharArray()) { 165 | if (Character.isSpaceChar(ch)) { 166 | convertNext = true; 167 | } else if (convertNext) { 168 | ch = Character.toTitleCase(ch); 169 | convertNext = false; 170 | } else { 171 | ch = Character.toLowerCase(ch); 172 | } 173 | converted.append(ch); 174 | } 175 | 176 | return converted.toString(); 177 | } 178 | 179 | public static boolean isDatabaseSupported(PsiElement[] psiElements) { 180 | if (psiElements[0] instanceof DbTable) { 181 | return Util.getDatabases().contains(((DbTable) psiElements[0]).getDataSource().getDatabaseVersion().name); 182 | } else { 183 | return false; 184 | } 185 | } 186 | 187 | public static void checkActionVisibility(@NotNull AnActionEvent anActionEvent, String actionText) { 188 | final Project project = anActionEvent.getProject(); 189 | if (null == project) { 190 | return; 191 | } 192 | 193 | PsiElement[] psiElements = anActionEvent.getData(LangDataKeys.PSI_ELEMENT_ARRAY); 194 | if (psiElements == null || psiElements.length == 0) { 195 | return; 196 | } 197 | 198 | if (psiElements[0] instanceof DbTable) { 199 | if (isDatabaseSupported(psiElements)) { 200 | anActionEvent.getPresentation().setEnabled(true); 201 | } else { 202 | anActionEvent.getPresentation().setEnabled(false); 203 | anActionEvent.getPresentation().setText(String.format("%s : database not supported", actionText)); 204 | } 205 | } else { 206 | anActionEvent.getPresentation().setEnabled(false); 207 | anActionEvent.getPresentation().setText(String.format("%s : please, select a table", actionText)); 208 | } 209 | } 210 | 211 | public static Set getDatabases() { 212 | DBMSFamily[] dbmsFamilies = DBMSFamily.values(); 213 | Set names = new HashSet<>(); 214 | for (DBMSFamily dbmsFamily : dbmsFamilies) { 215 | names.add(dbmsFamily.getName()); 216 | } 217 | return names; 218 | } 219 | 220 | /** 221 | * Create file or show the differences if the file already exist 222 | * 223 | * @param project 224 | * @param javaTextFile 225 | * @param fileName 226 | * @since 2.1.0 227 | */ 228 | public static void createFile(Project project, StringBuilder javaTextFile, String fileName, POJOGeneratorSettings pojoGeneratorSettings) { 229 | PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, JavaClassFileType.INSTANCE, javaTextFile); 230 | PsiDirectory psiDirectory = PsiDirectoryFactory.getInstance(project).createDirectory(lastFileChosen); 231 | 232 | if (null == psiDirectory.findFile(file.getName())) { 233 | Runnable r = () -> psiDirectory.add(file); 234 | 235 | WriteCommandAction.runWriteCommandAction(project, r); 236 | } else if (!pojoGeneratorSettings.getAlwaysShowDifferencesBetweenFiles()) { 237 | Notification notification = new Notification("POJO Generator", "POJO Generator", String.format("The file [%s] already exists", fileName), NotificationType.WARNING); 238 | notification.addAction(NotificationAction.createSimple("Show Diff...", () -> { 239 | notification.expire(); 240 | 241 | showDifferences(project, psiDirectory, file); 242 | })); 243 | notification.addAction(NotificationAction.createSimple("Always Show Diff...", () -> { 244 | notification.expire(); 245 | pojoGeneratorSettings.setAlwaysShowDifferencesBetweenFiles(true); 246 | 247 | showDifferences(project, psiDirectory, file); 248 | })); 249 | Notifications.Bus.notify(notification, project); 250 | } else { 251 | showDifferences(project, psiDirectory, file); 252 | } 253 | } 254 | 255 | /** 256 | * Show differences between existing file and new created file based on file name 257 | * 258 | * @param project 259 | * @param psiDirectory 260 | * @param generatedFile 261 | * @since 2.1.0 262 | */ 263 | public static void showDifferences(Project project, PsiDirectory psiDirectory, PsiFile generatedFile) { 264 | VirtualFile existingFile = psiDirectory.findFile(generatedFile.getName()).getVirtualFile(); 265 | 266 | DiffContentFactory contentFactory = DiffContentFactory.getInstance(); 267 | DiffRequestFactory requestFactory = DiffRequestFactory.getInstance(); 268 | 269 | DiffContent generatedFileContent = contentFactory.create(project, generatedFile.getText()); 270 | DiffContent existingFileContent = contentFactory.create(project, existingFile); 271 | 272 | MutableDiffRequestChain chain = new MutableDiffRequestChain(generatedFileContent, existingFileContent); 273 | 274 | chain.setWindowTitle(String.format("%s vs %s", "Generated file", VcsUtil.getFilePath(existingFile).getName())); 275 | chain.setTitle1("Generated file"); 276 | chain.setTitle2(requestFactory.getContentTitle(existingFile)); 277 | 278 | DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.DEFAULT); 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/action/Entity.java: -------------------------------------------------------------------------------- 1 | package fr.jukien.intellij.plugins.action; 2 | 3 | import com.intellij.database.psi.DbTable; 4 | import com.intellij.openapi.actionSystem.ActionUpdateThread; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | import com.intellij.openapi.actionSystem.LangDataKeys; 8 | import com.intellij.openapi.fileChooser.FileChooser; 9 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 10 | import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; 11 | import com.intellij.openapi.project.Project; 12 | import com.intellij.openapi.vfs.VfsUtil; 13 | import com.intellij.openapi.vfs.VirtualFile; 14 | import com.intellij.psi.PsiElement; 15 | import fr.jukien.intellij.plugins.ui.JPAMappingSettings; 16 | import fr.jukien.intellij.plugins.ui.POJOGeneratorSettings; 17 | import fr.jukien.intellij.plugins.util.Field; 18 | import fr.jukien.intellij.plugins.util.TableInfo; 19 | import org.jetbrains.annotations.NotNull; 20 | 21 | import java.net.MalformedURLException; 22 | import java.nio.file.Path; 23 | import java.nio.file.Paths; 24 | import java.util.LinkedHashSet; 25 | 26 | import static fr.jukien.intellij.plugins.util.Util.*; 27 | 28 | /** 29 | * Created on 19/04/2019 30 | * 31 | * @author JDI 32 | * @version 2.6.0 33 | * @since 1.0.0 34 | */ 35 | public class Entity extends AnAction { 36 | private String actionText = ""; 37 | 38 | @Override 39 | public void actionPerformed(AnActionEvent anActionEvent) { 40 | final Project project = anActionEvent.getProject(); 41 | if (null == project) { 42 | return; 43 | } 44 | 45 | final POJOGeneratorSettings pojoGeneratorSettings = project.getService(POJOGeneratorSettings.class); 46 | final JPAMappingSettings jpaMappingSettings = project.getService(JPAMappingSettings.class); 47 | 48 | PsiElement[] psiElements = anActionEvent.getData(LangDataKeys.PSI_ELEMENT_ARRAY); 49 | if (psiElements == null || psiElements.length == 0) { 50 | return; 51 | } 52 | 53 | if (null != project.getBasePath()) { 54 | Path projectPath = Paths.get(project.getBasePath()); 55 | VirtualFile chooseFile = null; 56 | try { 57 | chooseFile = VfsUtil.findFileByURL(projectPath.toUri().toURL()); 58 | } catch (MalformedURLException e) { 59 | e.printStackTrace(); 60 | } 61 | FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); 62 | if (null != pojoGeneratorSettings.getEntityFolderPath()) { 63 | try { 64 | chooseFile = VfsUtil.findFileByURL(Paths.get(pojoGeneratorSettings.getEntityFolderPath()).toUri().toURL()); 65 | } catch (MalformedURLException e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | lastFileChosen = FileChooser.chooseFile(descriptor, project, chooseFile); 70 | if (null == lastFileChosen) { 71 | return; 72 | } else { 73 | pojoGeneratorSettings.setEntityFolderPath(lastFileChosen.getPath()); 74 | } 75 | 76 | for (PsiElement psiElement : psiElements) { 77 | if (!(psiElement instanceof DbTable)) { 78 | continue; 79 | } 80 | 81 | TableInfo tableInfo = new TableInfo((DbTable) psiElement); 82 | LinkedHashSet fields = getFields((DbTable) psiElement, jpaMappingSettings); 83 | 84 | String header; 85 | if (pojoGeneratorSettings.getGenerateCompositePrimaryKey() && pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithIdClassAnnotation()) { 86 | header = pojoGeneratorSettings.getHeaderEntityIdClass(); 87 | } else { 88 | header = pojoGeneratorSettings.getHeaderEntity(); 89 | } 90 | 91 | String classNameComposite = null; 92 | if (isCompositePrimaryKeyAvailable(pojoGeneratorSettings, tableInfo)) { 93 | classNameComposite = String.format("%s%s%s", pojoGeneratorSettings.getPrefixCompositePrimaryKey(), javaName(tableInfo.getTableName(), true), pojoGeneratorSettings.getSuffixCompositePrimaryKey()); 94 | 95 | header = header.replace("${ID_CLASS_NAME}", classNameComposite); 96 | 97 | StringBuilder javaTextFile = new StringBuilder(); 98 | javaTextFile.append("\n"); 99 | 100 | /*if (pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()) { 101 | javaTextFile.append("import javax.persistence.*;").append("\n"); 102 | }*/ 103 | javaTextFile.append("import java.io.Serializable;").append("\n"); 104 | 105 | javaTextFile.append("\n"); 106 | if (pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()) { 107 | javaTextFile.append("@Embeddable").append("\n"); 108 | } 109 | javaTextFile.append("public class ").append(classNameComposite).append(" implements Serializable {").append("\n"); 110 | 111 | LinkedHashSet primaryFields = new LinkedHashSet<>(); 112 | int index = 0; 113 | for (Field field : fields) { 114 | if (field.getPrimary()) { 115 | primaryFields.add(field); 116 | 117 | if (pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()) { 118 | if (pojoGeneratorSettings.getCapitalize()) { 119 | if (pojoGeneratorSettings.getWithRelationshipAnnotations() && field.getForeignKey()) { 120 | javaTextFile.append(" @ManyToOne").append("\n"); 121 | javaTextFile.append(" @JoinColumn(name = \"").append(field.getName().toUpperCase()).append("\""); 122 | } else { 123 | javaTextFile.append(" @Column(name = \"").append(field.getName().toUpperCase()).append("\""); 124 | addColumnAnnotationAttributes(javaTextFile, field); 125 | } 126 | } else { 127 | if (pojoGeneratorSettings.getWithRelationshipAnnotations() && field.getForeignKey()) { 128 | javaTextFile.append(" @ManyToOne").append("\n"); 129 | javaTextFile.append(" @JoinColumn(name = \"").append(field.getName()).append("\""); 130 | } else { 131 | javaTextFile.append(" @Column(name = \"").append(field.getName()).append("\""); 132 | addColumnAnnotationAttributes(javaTextFile, field); 133 | } 134 | } 135 | javaTextFile.append(")").append("\n"); 136 | } 137 | javaTextFile.append(" private ").append(field.getJavaType()).append(" ").append(javaName(field.getName(), false)).append(";").append("\n"); 138 | if (pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation() && index < tableInfo.getPrimaryKeys().size() - 1) { 139 | javaTextFile.append("\n"); 140 | } 141 | index++; 142 | } 143 | } 144 | 145 | javaTextFile.append("\n"); 146 | addConstructor(classNameComposite, new LinkedHashSet<>(), javaTextFile); 147 | javaTextFile.append("\n"); 148 | addConstructor(classNameComposite, primaryFields, javaTextFile); 149 | javaTextFile.append("\n"); 150 | addGetterSetter(primaryFields, javaTextFile); 151 | javaTextFile.append("}").append("\n"); 152 | 153 | String fileName = String.format("%s%s", classNameComposite, ".java"); 154 | createFile(project, javaTextFile, fileName, pojoGeneratorSettings); 155 | } 156 | 157 | String className = String.format("%s%s%s", pojoGeneratorSettings.getPrefixEntity(), javaName(tableInfo.getTableName(), true), pojoGeneratorSettings.getSuffixEntity()); 158 | 159 | StringBuilder javaTextFile = new StringBuilder(); 160 | // javaTextFile.append("\n"); 161 | if (pojoGeneratorSettings.getCapitalize()) { 162 | header = header.replace("${TABLE_NAME}", tableInfo.getTableName().toUpperCase()); 163 | } else { 164 | header = header.replace("${TABLE_NAME}", tableInfo.getTableName()); 165 | } 166 | header = header.replace("${SCHEMA_NAME}", tableInfo.getSchemaName()); 167 | header = header.replace("${CLASS_NAME}", className); 168 | 169 | javaTextFile.append(header).append("\n"); 170 | 171 | // javaTextFile.append("\n"); 172 | // javaTextFile.append("@Entity").append("\n"); 173 | /*if (isCompositePrimaryKeyAvailable(pojoGeneratorSettings, tableInfo) && pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithIdClassAnnotation()) { 174 | javaTextFile.append("@IdClass(").append(classNameComposite).append(".class)").append("\n"); 175 | }*/ 176 | if (isCompositePrimaryKeyAvailable(pojoGeneratorSettings, tableInfo) && pojoGeneratorSettings.getGenerateCompositePrimaryKeyWithEmbeddedIdAnnotation()) { 177 | LinkedHashSet fieldsWithoutPrimary = new LinkedHashSet<>(); 178 | 179 | Field field = new Field(); 180 | field.setEmbeddedId(true); 181 | field.setJavaType(classNameComposite); 182 | field.setName(classNameComposite); 183 | fieldsWithoutPrimary.add(field); 184 | 185 | for (Field field1 : fields) { 186 | if (!field1.getPrimary()) { 187 | fieldsWithoutPrimary.add(field1); 188 | } 189 | } 190 | fields.clear(); 191 | fields.addAll(fieldsWithoutPrimary); 192 | } 193 | /*if (pojoGeneratorSettings.getCapitalize()) { 194 | javaTextFile.append("@Table(name = \"").append(tableInfo.getTableName().toUpperCase()); 195 | } else { 196 | javaTextFile.append("@Table(name = \"").append(tableInfo.getTableName()); 197 | }*/ 198 | /*if (pojoGeneratorSettings.getWithSchemaAttribute()) { 199 | javaTextFile.append("\", schema = \"").append(tableInfo.getSchemaName()); 200 | }*/ 201 | // javaTextFile.append("\")").append("\n"); 202 | // javaTextFile.append("public class ").append(className).append(" {").append("\n"); 203 | 204 | int counter = 0; 205 | for (Field field : fields) { 206 | if (field.getEmbeddedId()) { 207 | javaTextFile.append(" @EmbeddedId").append("\n"); 208 | } else { 209 | if (field.getPrimary()) { 210 | javaTextFile.append(" @Id").append("\n"); 211 | } 212 | if (pojoGeneratorSettings.getAutoGenerated() && field.getAutoGenerated()) { 213 | javaTextFile.append(" @GeneratedValue(strategy = GenerationType.IDENTITY)").append("\n"); 214 | } 215 | if (pojoGeneratorSettings.getCapitalize()) { 216 | if (pojoGeneratorSettings.getWithRelationshipAnnotations() && field.getForeignKey()) { 217 | javaTextFile.append(" @ManyToOne").append("\n"); 218 | javaTextFile.append(" @JoinColumn(name = \"").append(field.getName().toUpperCase()).append("\""); 219 | } else { 220 | javaTextFile.append(" @Column(name = \"").append(field.getName().toUpperCase()).append("\""); 221 | addColumnAnnotationAttributes(javaTextFile, field); 222 | } 223 | } else { 224 | if (pojoGeneratorSettings.getWithRelationshipAnnotations() && field.getForeignKey()) { 225 | javaTextFile.append(" @ManyToOne").append("\n"); 226 | javaTextFile.append(" @JoinColumn(name = \"").append(field.getName()).append("\""); 227 | } else { 228 | javaTextFile.append(" @Column(name = \"").append(field.getName()).append("\""); 229 | addColumnAnnotationAttributes(javaTextFile, field); 230 | } 231 | } 232 | javaTextFile.append(")").append("\n"); 233 | } 234 | javaTextFile.append(" private ").append(field.getJavaType()).append(" ").append(javaName(field.getName(), false)).append(";").append("\n"); 235 | 236 | if (counter < fields.size() - 1 || pojoGeneratorSettings.getGenerateGetterAndSetter()) { 237 | javaTextFile.append("\n"); 238 | } 239 | 240 | counter++; 241 | } 242 | 243 | if (pojoGeneratorSettings.getGenerateGetterAndSetter()) { 244 | addGetterSetter(fields, javaTextFile); 245 | } 246 | 247 | javaTextFile.append("}").append("\n"); 248 | 249 | String fileName = String.format("%s%s", className, ".java"); 250 | createFile(project, javaTextFile, fileName, pojoGeneratorSettings); 251 | } 252 | } 253 | } 254 | 255 | private void addColumnAnnotationAttributes(StringBuilder javaTextFile, Field field) { 256 | if (null != field.getColumnDefinition()) { 257 | javaTextFile.append(", columnDefinition = \""); 258 | javaTextFile.append(field.getColumnDefinition()); 259 | javaTextFile.append("\""); 260 | } 261 | if (null != field.getLength()) { 262 | javaTextFile.append(", length = "); 263 | javaTextFile.append(field.getLength()); 264 | } 265 | } 266 | 267 | private boolean isCompositePrimaryKeyAvailable(POJOGeneratorSettings pojoGeneratorSettings, TableInfo tableInfo) { 268 | return pojoGeneratorSettings.getGenerateCompositePrimaryKey() && tableInfo.getPrimaryKeys().size() > 1; 269 | } 270 | 271 | @Override 272 | public void update(@NotNull AnActionEvent anActionEvent) { 273 | if (actionText.isEmpty()) { 274 | actionText = anActionEvent.getPresentation().getText(); 275 | } 276 | 277 | checkActionVisibility(anActionEvent, actionText); 278 | super.update(anActionEvent); 279 | } 280 | 281 | @Override 282 | public @NotNull ActionUpdateThread getActionUpdateThread() { 283 | return ActionUpdateThread.BGT; 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /pojo-generator/src/main/java/fr/jukien/intellij/plugins/ui/POJOGeneratorPanel.form: -------------------------------------------------------------------------------- 1 | 2 |
    3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | --------------------------------------------------------------------------------