Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring boot 1.5.4.RELEASE -> 2.1.4.RELEASE #69

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ax-boot-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<parent>
<groupId>com.chequer.axboot</groupId>
<artifactId>ax-boot-framework</artifactId>
<version>2.1.4</version>
<version>2.2.0</version>
</parent>

<dependencies>
<dependency>
<groupId>com.chequer.axboot</groupId>
<artifactId>ax-boot-core</artifactId>
<version>2.1.38</version>
<version>2.2.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void saveUser(List<User> 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())) {
Expand Down
4 changes: 2 additions & 2 deletions ax-boot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<artifactId>ax-boot-core</artifactId>
<name>AX Boot Core</name>
<description>AX Boot Core</description>
<version>2.1.38</version>
<version>2.2.0</version>
<url>http://www.axboot.com</url>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.chequer.axboot</groupId>
<artifactId>ax-boot-framework</artifactId>
<version>2.1.4</version>
<version>2.2.0</version>
</parent>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TargetType> 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<String> DDLs = IOUtils.readLines(new FileInputStream(scriptOutputPath), "UTF-8");
List<String> convertedDDLs = new ArrayList<>();
Expand Down Expand Up @@ -119,7 +118,7 @@ public void setPosition(Field field, List<ColumnDefinition> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
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;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
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 {

Expand All @@ -48,6 +47,16 @@ public class SchemaGeneratorBase {
@Autowired
private AXBootContextConfig axBootContextConfig;

/**
* key : TableName
* value: EntityClass
*/
private Map<String, Class<?>> tableNameEntityClassMap;

public SchemaGeneratorBase() {
tableNameEntityClassMap = getTableNameEntityClassMap();
}

protected SessionFactoryImpl getSessionFactory() {
Session session = (Session) entityManager.getDelegate();
return (SessionFactoryImpl) session.getSessionFactory();
Expand Down Expand Up @@ -77,61 +86,32 @@ protected Metadata getMetaData() {
return metadataSources.buildMetadata();
}

public List<String> getTableList() {
List<String> tableName = new ArrayList();

new Reflections()
.getTypesAnnotatedWith(Entity.class)
.forEach(clazz -> {
if (clazz.isAnnotationPresent(Table.class)) {
tableName.add(clazz.getAnnotation(Table.class).name());
}
});
public Map<String, Class<?>> 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<String> 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<EntityType<?>> entities = sessionFactory.getMetamodel().getEntities();

Map<String, ClassMetadata> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public Page<T> findAll(Pageable pageable, String searchParams) {
}

public List<T> findAll(Iterable<ID> 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<T> findAll(Predicate predicate) {
Expand Down Expand Up @@ -155,11 +155,11 @@ public <S extends T> Collection<S> save(Collection<S> 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() {
Expand All @@ -168,7 +168,7 @@ public long count() {

@Transactional
public void delete(ID var1) {
repository.delete(var1);
repository.deleteById(var1);
}

@Transactional
Expand All @@ -178,7 +178,7 @@ public void delete(T var1) {

@Transactional
public void delete(Iterable<? extends T> var1) {
repository.delete(var1);
repository.deleteAll(var1);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T, ID extends Serializable> extends JpaRepository<T, ID>, QueryDslPredicateExecutor<T> {
public interface AXBootJPAQueryDSLRepository<T, ID extends Serializable> extends JpaRepository<T, ID>, QuerydslPredicateExecutor<T> {
}
4 changes: 2 additions & 2 deletions ax-boot-initialzr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<parent>
<artifactId>ax-boot-framework</artifactId>
<groupId>com.chequer.axboot</groupId>
<version>2.1.4</version>
<version>2.2.0</version>
</parent>

<dependencies>
<dependency>
<groupId>com.chequer.axboot</groupId>
<artifactId>ax-boot-core</artifactId>
<version>2.1.38</version>
<version>2.2.0</version>
</dependency>

<dependency>
Expand Down
Loading