From b10c5b630c5c05a554ea804541f341b5ffcc3f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Sat, 13 Apr 2019 00:39:40 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EC=9D=BC=EB=8B=A8=20=EB=B9=8C=EB=93=9C?= =?UTF-8?q?=EB=8A=94=20=EC=84=B1=EA=B3=B5~!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/AXBootApplicationInitializer.java | 8 +++---- .../axboot/admin/domain/user/UserService.java | 2 +- .../core/db/schema/SchemaGenerator.java | 21 +++++++++---------- .../axboot/core/db/type/LabelEnumType.java | 6 +++--- .../core/db/type/MySQLJSONUserType.java | 6 +++--- .../core/domain/base/AXBootBaseService.java | 12 +++++------ .../base/AXBootJPAQueryDSLRepository.java | 4 ++-- .../initialzr/AXBootInitialzrApplication.java | 2 +- ...AXBootInitialzrApplicationInitializer.java | 9 +++----- pom.xml | 11 ++++++++-- 10 files changed, 41 insertions(+), 40 deletions(-) diff --git a/ax-boot-admin/src/main/java/com/chequer/axboot/admin/AXBootApplicationInitializer.java b/ax-boot-admin/src/main/java/com/chequer/axboot/admin/AXBootApplicationInitializer.java index ae256d1d..895cf9bb 100644 --- a/ax-boot-admin/src/main/java/com/chequer/axboot/admin/AXBootApplicationInitializer.java +++ b/ax-boot-admin/src/main/java/com/chequer/axboot/admin/AXBootApplicationInitializer.java @@ -2,20 +2,18 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Configuration; @Configuration public class AXBootApplicationInitializer extends SpringBootServletInitializer { - public static final Object[] APPLICATION_SOURCES = new Object[]{AXBootApplication.class}; - @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(APPLICATION_SOURCES); + return application.sources(AXBootApplication.class); } public static void main(String[] args) { - SpringApplication.run(APPLICATION_SOURCES, args); + SpringApplication.run(AXBootApplication.class, args); } } diff --git a/ax-boot-admin/src/main/java/com/chequer/axboot/admin/domain/user/UserService.java b/ax-boot-admin/src/main/java/com/chequer/axboot/admin/domain/user/UserService.java index fb9ce7d5..555b726f 100644 --- a/ax-boot-admin/src/main/java/com/chequer/axboot/admin/domain/user/UserService.java +++ b/ax-boot-admin/src/main/java/com/chequer/axboot/admin/domain/user/UserService.java @@ -45,7 +45,7 @@ public void saveUser(List users) throws Exception { delete(qUserAuth).where(qUserAuth.userCd.eq(user.getUserCd())).execute(); String password = bCryptPasswordEncoder.encode(user.getUserPs()); - User originalUser = userRepository.findOne(user.getUserCd()); + User originalUser = userRepository.findById(user.getUserCd()).orElse(null); if (originalUser != null) { if (isNotEmpty(user.getUserPs())) { diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGenerator.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGenerator.java index fc86413a..66e430e7 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGenerator.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGenerator.java @@ -1,15 +1,19 @@ package com.chequer.axboot.core.db.schema; import com.chequer.axboot.core.annotations.ColumnPosition; + +import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.ImprovedNamingStrategy; import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy; +import org.hibernate.tool.schema.TargetType; import org.springframework.stereotype.Component; import javax.persistence.Column; import javax.persistence.Transient; + +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.lang.reflect.Field; @@ -21,17 +25,12 @@ public class SchemaGenerator extends SchemaGeneratorBase { public void createSchema() throws IOException, ClassNotFoundException { - SchemaExport export = new SchemaExport((MetadataImplementor) getMetaData()); String scriptOutputPath = System.getProperty("java.io.tmpdir") + "/schema.sql"; - /* - SchemaExport schemaExport = new SchemaExport(); FileUtils.deleteQuietly(new File(scriptOutputPath)); - EnumSet targetTypes = EnumSet.of(TargetType.SCRIPT); + + SchemaExport schemaExport = new SchemaExport(); schemaExport.setOutputFile(scriptOutputPath); - schemaExport.createOnly(targetTypes, getMetaData()); - */ - export.setOutputFile(scriptOutputPath); - export.create(true, true); + schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), getMetaData()); List DDLs = IOUtils.readLines(new FileInputStream(scriptOutputPath), "UTF-8"); List convertedDDLs = new ArrayList<>(); @@ -119,7 +118,7 @@ public void setPosition(Field field, List columnDefinitions) { if (column != null && !"".equals(column.name())) { columnName = column.name(); } else { - columnName = new SpringNamingStrategy().columnName(name); + columnName = new ImprovedNamingStrategy().columnName(name); } if (columnPosition != null && columnPosition.value() > 0) { diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/LabelEnumType.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/LabelEnumType.java index 3527de40..8fad27b7 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/LabelEnumType.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/LabelEnumType.java @@ -2,7 +2,7 @@ import com.chequer.axboot.core.code.LabelEnum; import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.usertype.DynamicParameterizedType; import org.hibernate.usertype.UserType; @@ -49,7 +49,7 @@ public boolean isMutable() { } @Override - public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { String label = rs.getString(names[0]); if (rs.wasNull()) { return null; @@ -66,7 +66,7 @@ public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor share } @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { if (value == null) { st.setNull(index, Types.VARCHAR); } else { diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/MySQLJSONUserType.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/MySQLJSONUserType.java index f3f86a12..6bd2e731 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/MySQLJSONUserType.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/type/MySQLJSONUserType.java @@ -5,7 +5,7 @@ import org.hibernate.HibernateException; import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.type.SerializationException; import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.UserType; @@ -40,7 +40,7 @@ public int[] sqlTypes() { } @Override - public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { + public Object nullSafeGet(ResultSet resultSet, String[] names, SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException, SQLException { try { if (resultSet.getBytes(names[0]) != null) { final String json = new String(resultSet.getBytes(names[0]), "UTF-8"); @@ -53,7 +53,7 @@ public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplemento } @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor sharedSessionContractImplementor) throws HibernateException, SQLException { try { final String json = value == null ? null : objectMapper.writeValueAsString(value); st.setObject(index, json); diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootBaseService.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootBaseService.java index e6407f09..4aaf1f81 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootBaseService.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootBaseService.java @@ -52,11 +52,11 @@ public Page findAll(Pageable pageable, String searchParams) { } public List findAll(Iterable iterable) { - return repository.findAll(iterable); + return repository.findAllById(iterable); } public T findOne(Predicate predicate) { - return repository.findOne(predicate); + return repository.findOne(predicate).orElse(null); } public List findAll(Predicate predicate) { @@ -155,11 +155,11 @@ public Collection save(Collection vars) { } public T findOne(ID var1) { - return repository.findOne(var1); + return repository.findById(var1).orElse(null); } public boolean exists(ID var1) { - return repository.exists(var1); + return repository.existsById(var1); } public long count() { @@ -168,7 +168,7 @@ public long count() { @Transactional public void delete(ID var1) { - repository.delete(var1); + repository.deleteById(var1); } @Transactional @@ -178,7 +178,7 @@ public void delete(T var1) { @Transactional public void delete(Iterable var1) { - repository.delete(var1); + repository.deleteAll(var1); } @Transactional diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootJPAQueryDSLRepository.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootJPAQueryDSLRepository.java index 77938fcf..f9511627 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootJPAQueryDSLRepository.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/domain/base/AXBootJPAQueryDSLRepository.java @@ -1,11 +1,11 @@ package com.chequer.axboot.core.domain.base; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.querydsl.QueryDslPredicateExecutor; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.data.repository.NoRepositoryBean; import java.io.Serializable; @NoRepositoryBean -public interface AXBootJPAQueryDSLRepository extends JpaRepository, QueryDslPredicateExecutor { +public interface AXBootJPAQueryDSLRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplication.java b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplication.java index bfd10a25..40129310 100644 --- a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplication.java +++ b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplication.java @@ -4,7 +4,7 @@ import com.chequer.axboot.core.config.AXBootContextConfig; import com.chequer.axboot.core.model.extract.service.jdbc.JdbcMetadataService; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; diff --git a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplicationInitializer.java b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplicationInitializer.java index 3e20fd68..e82ca11c 100644 --- a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplicationInitializer.java +++ b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/AXBootInitialzrApplicationInitializer.java @@ -1,24 +1,21 @@ package com.chequer.axboot.initialzr; -import com.chequer.axboot.core.AXBootCoreConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Configuration; import org.springframework.web.WebApplicationInitializer; @Configuration public class AXBootInitialzrApplicationInitializer extends SpringBootServletInitializer implements WebApplicationInitializer { - public static final Object[] APPLICATION_SOURCES = new Object[]{AXBootInitialzrApplication.class}; - @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { this.setRegisterErrorPageFilter(false); - return application.sources(APPLICATION_SOURCES); + return application.sources(AXBootInitialzrApplication.class); } public static void main(String[] args) { - SpringApplication.run(APPLICATION_SOURCES, args); + SpringApplication.run(AXBootInitialzrApplication.class, args); } } diff --git a/pom.xml b/pom.xml index 60829fe2..4e7ebffa 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.springframework.boot spring-boot-starter-parent - 1.5.4.RELEASE + 2.1.4.RELEASE @@ -157,8 +157,9 @@ 4.4 2.0 4.1.4 + 6.0.13.Final - 1.5.1.RELEASE + 2.1.4.RELEASE 2.7.1 1.1.1 1.0.2 @@ -527,6 +528,12 @@ ${hibernate.version} + + org.hibernate + hibernate-validator + ${hibernate.validator.version} + + From 4ae4354b8a8d2054392e786149c18eafa7922bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Sun, 14 Apr 2019 17:09:52 +0900 Subject: [PATCH 2/6] Initializer Templates updated. --- .../java/AXBootApplicationInitializer.java | 10 ++++------ .../templates/java/domain/user/UserService.java | 14 +++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java b/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java index 694ec12f..895cf9bb 100644 --- a/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java +++ b/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java @@ -1,21 +1,19 @@ -package ${basePackage}; +package com.chequer.axboot.admin; import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Configuration; @Configuration public class AXBootApplicationInitializer extends SpringBootServletInitializer { - public static final Object[] APPLICATION_SOURCES = new Object[]{AXBootApplication.class}; - @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(APPLICATION_SOURCES); + return application.sources(AXBootApplication.class); } public static void main(String[] args) { - SpringApplication.run(APPLICATION_SOURCES, args); + SpringApplication.run(AXBootApplication.class, args); } } diff --git a/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java b/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java index bb7f4536..555b726f 100644 --- a/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java +++ b/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java @@ -1,10 +1,10 @@ -package ${basePackage}.domain.user; +package com.chequer.axboot.admin.domain.user; -import ${basePackage}.domain.BaseService; -import ${basePackage}.domain.user.auth.UserAuth; -import ${basePackage}.domain.user.auth.UserAuthService; -import ${basePackage}.domain.user.role.UserRole; -import ${basePackage}.domain.user.role.UserRoleService; +import com.chequer.axboot.admin.domain.BaseService; +import com.chequer.axboot.admin.domain.user.auth.UserAuth; +import com.chequer.axboot.admin.domain.user.auth.UserAuthService; +import com.chequer.axboot.admin.domain.user.role.UserRole; +import com.chequer.axboot.admin.domain.user.role.UserRoleService; import com.chequer.axboot.core.parameter.RequestParams; import com.querydsl.core.BooleanBuilder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -45,7 +45,7 @@ public void saveUser(List users) throws Exception { delete(qUserAuth).where(qUserAuth.userCd.eq(user.getUserCd())).execute(); String password = bCryptPasswordEncoder.encode(user.getUserPs()); - User originalUser = userRepository.findOne(user.getUserCd()); + User originalUser = userRepository.findById(user.getUserCd()).orElse(null); if (originalUser != null) { if (isNotEmpty(user.getUserPs())) { From a540ead6c3bb397f15690f5b8b5817566b9356ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Sun, 14 Apr 2019 20:10:51 +0900 Subject: [PATCH 3/6] Initializer applied Try-with-Resources, fixed substract path for spring-boot:run mode. --- .../initialzr/service/ProjectGenerator.java | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java index 908124fa..bf601c4c 100644 --- a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java +++ b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -37,51 +38,48 @@ public void generate(ProjectGenerateRequest projectGenerateRequest, HttpServletR response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName); response.setContentType("application/zip"); - ServletOutputStream outputStream = response.getOutputStream(); - ZipOutputStream zos = new ZipOutputStream(outputStream); + try ( + ServletOutputStream outputStream = response.getOutputStream(); + ZipOutputStream zos = new ZipOutputStream(outputStream) + ) { + Map values = new HashMap<>(); - Map values = new HashMap<>(); + String uuid = UUID.randomUUID().toString(); - String uuid = UUID.randomUUID().toString(); + values.put("package", packageName); + values.put("basePackage", packageName); + values.put("domainPackage", packageName + ".domain"); + values.put("projectName", projectName); + values.put("artifactId", artifactId); + values.put("description", description); + values.put("groupId", groupId); + values.put("sessionCookie", uuid); + values.put("axbootCoreVersion", "2.1.38"); - values.put("package", packageName); - values.put("basePackage", packageName); - values.put("domainPackage", packageName + ".domain"); - values.put("projectName", projectName); - values.put("artifactId", artifactId); - values.put("description", description); - values.put("groupId", groupId); - values.put("sessionCookie", uuid); - values.put("axbootCoreVersion", "2.1.38"); + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + Resource[] resources = resolver.getResources("/templates/**"); - Resource[] resources = resolver.getResources("/templates/**"); + for (Resource resource : resources) { + File file = resource.getFile(); - for (Resource resource : resources) { - File file = resource.getFile(); + if (file.isFile()) { + byte[] bytes = getBytes(file, values); + String path = getPath(artifactId, packageName, file); - if (file.isFile()) { - byte[] bytes = getBytes(file, values); - String path = getPath(artifactId, packageName, file); - - ZipEntry entry = new ZipEntry(path); - entry.setSize(bytes.length); - zos.putNextEntry(entry); - zos.write(bytes); + ZipEntry entry = new ZipEntry(path); + entry.setSize(bytes.length); + zos.putNextEntry(entry); + zos.write(bytes); + } } } - - zos.closeEntry(); - IOUtils.closeQuietly(zos); - outputStream.flush(); } public String getPath(String projectName, String packageName, File file) { String baseName = projectName + "/src/main"; - String substract = "/WEB-INF/classes/templates"; + String substract = "/classes/templates"; - String name = FilenameUtils.getName(file.getName()); String ext = FilenameUtils.getExtension(file.getName()).toLowerCase(); String filePath = file.getAbsolutePath(); String path = filePath.substring(filePath.indexOf(substract) + substract.length()); @@ -98,7 +96,7 @@ public String getPath(String projectName, String packageName, File file) { return baseName + path; } - public byte[] getBytes(File file, Map values) throws IOException { + private byte[] getBytes(File file, Map values) throws IOException { String ext = FilenameUtils.getExtension(file.getName()).toLowerCase(); if (ext.equals("jsp") || @@ -117,7 +115,7 @@ public byte[] getBytes(File file, Map values) throws IOException String template = FileUtils.readFileToString(file, "UTF-8"); template = strSubstitutor.replace(template); - return template.getBytes("UTF-8"); + return template.getBytes(StandardCharsets.UTF_8); } return IOUtils.toByteArray(new FileInputStream(file)); } From 343a05746b318c59c15e4a6fdd2a61d189a23df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Sun, 14 Apr 2019 22:34:14 +0900 Subject: [PATCH 4/6] version up --- ax-boot-admin/pom.xml | 4 ++-- ax-boot-core/pom.xml | 4 ++-- ax-boot-initialzr/pom.xml | 4 ++-- .../chequer/axboot/initialzr/service/ProjectGenerator.java | 2 +- ax-boot-initialzr/src/main/resources/templates/root/pom.xml | 2 +- pom.xml | 3 +-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ax-boot-admin/pom.xml b/ax-boot-admin/pom.xml index fbb52fcb..3b5627b9 100644 --- a/ax-boot-admin/pom.xml +++ b/ax-boot-admin/pom.xml @@ -12,14 +12,14 @@ com.chequer.axboot ax-boot-framework - 2.1.4 + 2.2.0 com.chequer.axboot ax-boot-core - 2.1.38 + 2.2.0 diff --git a/ax-boot-core/pom.xml b/ax-boot-core/pom.xml index 835d3853..53def8dc 100644 --- a/ax-boot-core/pom.xml +++ b/ax-boot-core/pom.xml @@ -4,7 +4,7 @@ ax-boot-core AX Boot Core AX Boot Core - 2.1.38 + 2.2.0 http://www.axboot.com jar 4.0.0 @@ -12,7 +12,7 @@ com.chequer.axboot ax-boot-framework - 2.1.4 + 2.2.0 diff --git a/ax-boot-initialzr/pom.xml b/ax-boot-initialzr/pom.xml index 060f2ca0..359018a3 100644 --- a/ax-boot-initialzr/pom.xml +++ b/ax-boot-initialzr/pom.xml @@ -12,14 +12,14 @@ ax-boot-framework com.chequer.axboot - 2.1.4 + 2.2.0 com.chequer.axboot ax-boot-core - 2.1.38 + 2.2.0 diff --git a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java index bf601c4c..58a2b89b 100644 --- a/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java +++ b/ax-boot-initialzr/src/main/java/com/chequer/axboot/initialzr/service/ProjectGenerator.java @@ -54,7 +54,7 @@ public void generate(ProjectGenerateRequest projectGenerateRequest, HttpServletR values.put("description", description); values.put("groupId", groupId); values.put("sessionCookie", uuid); - values.put("axbootCoreVersion", "2.1.38"); + values.put("axbootCoreVersion", "2.2.0"); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); diff --git a/ax-boot-initialzr/src/main/resources/templates/root/pom.xml b/ax-boot-initialzr/src/main/resources/templates/root/pom.xml index 6efce386..fb086383 100644 --- a/ax-boot-initialzr/src/main/resources/templates/root/pom.xml +++ b/ax-boot-initialzr/src/main/resources/templates/root/pom.xml @@ -38,7 +38,7 @@ com.chequer.axboot ax-boot-framework - 2.1.2 + 2.2.0 diff --git a/pom.xml b/pom.xml index 4e7ebffa..c6517bb7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.chequer.axboot ax-boot-framework - 2.1.4 + 2.2.0 pom AX Boot Parent AX Boot Framework @@ -159,7 +159,6 @@ 4.1.4 6.0.13.Final - 2.1.4.RELEASE 2.7.1 1.1.1 1.0.2 From f9fb23a02ed38a93f3067146972f1ac6ba46f213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Sun, 14 Apr 2019 23:26:18 +0900 Subject: [PATCH 5/6] template ${basePackage} fixed --- .../templates/java/AXBootApplicationInitializer.java | 2 +- .../templates/java/domain/user/UserService.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java b/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java index 895cf9bb..9884f80a 100644 --- a/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java +++ b/ax-boot-initialzr/src/main/resources/templates/java/AXBootApplicationInitializer.java @@ -1,4 +1,4 @@ -package com.chequer.axboot.admin; +package ${basePackage}; import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder; diff --git a/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java b/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java index 555b726f..7a02e73e 100644 --- a/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java +++ b/ax-boot-initialzr/src/main/resources/templates/java/domain/user/UserService.java @@ -1,10 +1,10 @@ -package com.chequer.axboot.admin.domain.user; +package ${basePackage}.domain.user; -import com.chequer.axboot.admin.domain.BaseService; -import com.chequer.axboot.admin.domain.user.auth.UserAuth; -import com.chequer.axboot.admin.domain.user.auth.UserAuthService; -import com.chequer.axboot.admin.domain.user.role.UserRole; -import com.chequer.axboot.admin.domain.user.role.UserRoleService; +import ${basePackage}.domain.BaseService; +import ${basePackage}.domain.user.auth.UserAuth; +import ${basePackage}.domain.user.auth.UserAuthService; +import ${basePackage}.domain.user.role.UserRole; +import ${basePackage}.domain.user.role.UserRoleService; import com.chequer.axboot.core.parameter.RequestParams; import com.querydsl.core.BooleanBuilder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; From 80622c061143bd5e64a387af2946daf00ce47640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=A4=80?= Date: Mon, 15 Apr 2019 23:56:34 +0900 Subject: [PATCH 6/6] sessionFactory.getAllClassMetadata() deprecated. instead use Reflections --- .../core/db/schema/SchemaGeneratorBase.java | 108 +++++++----------- 1 file changed, 44 insertions(+), 64 deletions(-) diff --git a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGeneratorBase.java b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGeneratorBase.java index 3c5649e1..2d1f9b11 100644 --- a/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGeneratorBase.java +++ b/ax-boot-core/src/main/java/com/chequer/axboot/core/db/schema/SchemaGeneratorBase.java @@ -1,8 +1,17 @@ package com.chequer.axboot.core.db.schema; -import com.chequer.axboot.core.config.AXBootContextConfig; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; + +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Table; + +import org.apache.commons.lang3.StringUtils; import org.hibernate.Session; -import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.BootstrapServiceRegistry; @@ -10,23 +19,13 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.internal.SessionFactoryImpl; -import org.hibernate.metadata.ClassMetadata; import org.reflections.Reflections; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import javax.persistence.Entity; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Table; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import com.chequer.axboot.core.config.AXBootContextConfig; public class SchemaGeneratorBase { @@ -48,6 +47,16 @@ public class SchemaGeneratorBase { @Autowired private AXBootContextConfig axBootContextConfig; + /** + * key : TableName + * value: EntityClass + */ + private Map> tableNameEntityClassMap; + + public SchemaGeneratorBase() { + tableNameEntityClassMap = getTableNameEntityClassMap(); + } + protected SessionFactoryImpl getSessionFactory() { Session session = (Session) entityManager.getDelegate(); return (SessionFactoryImpl) session.getSessionFactory(); @@ -77,61 +86,32 @@ protected Metadata getMetaData() { return metadataSources.buildMetadata(); } - public List getTableList() { - List tableName = new ArrayList(); - - new Reflections() - .getTypesAnnotatedWith(Entity.class) - .forEach(clazz -> { - if (clazz.isAnnotationPresent(Table.class)) { - tableName.add(clazz.getAnnotation(Table.class).name()); - } - }); + public Map> getTableNameEntityClassMap() { + return new Reflections() + .getTypesAnnotatedWith(Entity.class) + .stream() + .filter(clazz -> clazz.isAnnotationPresent(Table.class)) + .collect(Collectors.toMap( + clazz -> clazz.getAnnotation(Table.class).name(), + clazz -> clazz + )); + } - return tableName; + public List getTableList() { + return tableNameEntityClassMap.values().stream() + .map(entity -> entity.getAnnotation(Table.class).name()) + .collect(Collectors.toList()); } - protected String getEntityClassName(String tableName) { - SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); - //Set> entities = sessionFactory.getMetamodel().getEntities(); - - Map classMetadataMap = sessionFactory.getAllClassMetadata(); - - for (String key : classMetadataMap.keySet()) { - try { - Class entityClass = Class.forName(key); - - if (entityClass.isAnnotationPresent(Table.class)) { - String entityTableName = entityClass.getAnnotation(Table.class).name(); - if (entityTableName.toLowerCase().equals(tableName.toLowerCase())) { - return entityClass.getName(); - } - } else { - if (entityClass.getName().equals(tableName)) { - return entityClass.getName(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } + protected String getEntityClassName(final String tableName) { + if (tableNameEntityClassMap.containsKey(tableName)) { + return tableNameEntityClassMap.get(tableName).getName(); } - /* - for (EntityType entityType : entities) { - Class entityClass = entityType.getJavaType(); - - if (entityClass.isAnnotationPresent(Table.class)) { - String entityTableName = entityClass.getAnnotation(Table.class).name(); - if (entityTableName.toLowerCase().equals(tableName.toLowerCase())) { - return entityClass.getName(); - } - } else { - if (entityClass.getName().equals(tableName)) { - return entityClass.getName(); - } - } - } - */ - return null; + return tableNameEntityClassMap.values().stream() + .filter(clazz -> StringUtils.equals(clazz.getName(), tableName)) + .map(Class::getName) + .findFirst() + .orElse(null); } }