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 | 
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 | 
14 |
15 | Example of the User DTO class:
16 |
17 | 
18 |
19 | ### Options
20 |
21 | 
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 | 
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 extends DasColumn> columnsIter = DasUtil.getColumns(tableElement);
64 | List extends DasColumn> 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 |
100 |
--------------------------------------------------------------------------------
/pojo-generator/src/main/resources/META-INF/pluginIcon_dark.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 super ConfigurableJPAMapping, ? extends ConfigurableJPAMapping> 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 |
11 |
an JPA Entity (JPA Annotated POJO)
12 |
13 |
There is no relationship between table
14 |
JPA annotations are generates over attributes
15 |
@GeneratedValue annotation if sequence over column are auto generated (H2, Microsoft SQL Server, MySQL and PostgreSQL)
16 |
@ManyToOne and @JoinColumn annotations on columns with foreign key
17 |
Generate composite primary key with @IdClass or @EmbeddedId annotations
18 |
19 |
20 |
a Data Transfert Object
21 |
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 |
DBMS
30 |
SQL data type
31 |
Java data type
32 |
JPA columnDefinition
33 |
34 |
35 |
36 |
37 |
H2
38 |
BIGINT
39 |
Long
40 |
41 |
42 |
H2
43 |
DATE
44 |
LocalDate
45 |
46 |
47 |
H2
48 |
VARCHAR
49 |
String
50 |
51 |
52 |
Microsoft SQL Server
53 |
bigint
54 |
Long
55 |
56 |
57 |
Microsoft SQL Server
58 |
bit
59 |
Boolean
60 |
61 |
62 |
Microsoft SQL Server
63 |
datetime
64 |
LocalDateTime
65 |
66 |
67 |
Microsoft SQL Server
68 |
datetime2
69 |
LocalDateTime
70 |
71 |
72 |
Microsoft SQL Server
73 |
decimal
74 |
BigDecimal
75 |
76 |
77 |
Microsoft SQL Server
78 |
int
79 |
Integer
80 |
81 |
82 |
Microsoft SQL Server
83 |
nvarchar
84 |
String
85 |
86 |
87 |
Microsoft SQL Server
88 |
varchar
89 |
String
90 |
91 |
92 |
MySQL
93 |
bigint
94 |
Long
95 |
96 |
97 |
MySQL
98 |
bit
99 |
Boolean
100 |
101 |
102 |
MySQL
103 |
date
104 |
LocalDate
105 |
106 |
107 |
MySQL
108 |
datetime
109 |
LocalDateTime
110 |
111 |
112 |
MySQL
113 |
decimal
114 |
BigDecimal
115 |
116 |
117 |
MySQL
118 |
double
119 |
Double
120 |
121 |
122 |
MySQL
123 |
enum
124 |
String
125 |
126 |
127 |
MySQL
128 |
float
129 |
Float
130 |
131 |
132 |
MySQL
133 |
int
134 |
Integer
135 |
136 |
137 |
MySQL
138 |
json
139 |
String
140 |
141 |
142 |
MySQL
143 |
smallint
144 |
Integer
145 |
146 |
147 |
MySQL
148 |
text
149 |
String
150 |
151 |
152 |
MySQL
153 |
timestamp
154 |
LocalDateTime
155 |
156 |
157 |
MySQL
158 |
tinyint
159 |
java.lang.Byte
160 |
161 |
162 |
MySQL
163 |
varchar
164 |
String
165 |
166 |
167 |
Oracle
168 |
CHAR
169 |
String
170 |
CHAR
171 |
172 |
173 |
Oracle
174 |
DATE
175 |
LocalDate
176 |
177 |
178 |
Oracle
179 |
FLOAT
180 |
Float
181 |
182 |
183 |
Oracle
184 |
NUMBER
185 |
Long
186 |
187 |
188 |
Oracle
189 |
TIMESTAMP
190 |
LocalDateTime
191 |
192 |
193 |
Oracle
194 |
VARCHAR2
195 |
String
196 |
197 |
198 |
PostgreSQL
199 |
bigint
200 |
Long
201 |
202 |
203 |
PostgreSQL
204 |
boolean
205 |
Boolean
206 |
207 |
208 |
PostgreSQL
209 |
date
210 |
LocalDate
211 |
212 |
213 |
PostgreSQL
214 |
integer
215 |
Long
216 |
217 |
218 |
PostgreSQL
219 |
varchar
220 |
String
221 |
222 |
223 |
224 | ]]>
225 |
226 |
228 |
[New] Possibility to customize the header template of the class: