Skip to content

Commit

Permalink
Merge pull request #101 from hs-web/3.0.x
Browse files Browse the repository at this point in the history
3.0.x
  • Loading branch information
zhou-hao authored Nov 26, 2018
2 parents 8a4cfab + fbd2a0d commit e8dc76c
Show file tree
Hide file tree
Showing 144 changed files with 409 additions and 225 deletions.
2 changes: 1 addition & 1 deletion hsweb-authorization/hsweb-authorization-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/hsweb-authorization-basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/hsweb-authorization-jwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-authorization-oauth2</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<!--<relativePath>../../pom.xml</relativePath>-->
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/hsweb-authorization-oauth2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-authorization</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-framework</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-aop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-excel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/hsweb-boost-ftp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-boost</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-boost/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-framework</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-bean/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons-dao</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -109,7 +106,7 @@ public Transaction newTransaction(DataSource dataSource, TransactionIsolationLev
factory.setMapperLocations(mybatisProperties.resolveMapperLocations());

SqlSessionFactory sqlSessionFactory = factory.getObject();
MybatisUtils.sqlSession=sqlSessionFactory;
MybatisUtils.sqlSession = sqlSessionFactory;

EnumDictHandlerRegister.typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();
EnumDictHandlerRegister.register("org.hswebframework.web;" + mybatisProperties.getTypeHandlersPackage());
Expand All @@ -121,8 +118,6 @@ public Transaction newTransaction(DataSource dataSource, TransactionIsolationLev
}
EasyOrmSqlBuilder.getInstance().entityFactory = entityFactory;

sqlSessionFactory.getConfiguration().getTypeAliasRegistry();

return sqlSessionFactory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,19 @@ protected RDBTableMetaData createMeta(String tableName, String resultMapId) {
}
column.setJavaType(resultMapping.getJavaType());
column.setProperty("resultMapping", resultMapping);
ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) {
@Override
public Object getData(Object value) {
if (value instanceof Number) {
return new Date(((Number) value).longValue());
//时间
if (column.getJdbcType() == JDBCType.DATE || column.getJdbcType() == JDBCType.TIMESTAMP) {
ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) {
@Override
public Object getData(Object value) {
if (value instanceof Number) {
return new Date(((Number) value).longValue());
}
return super.getData(value);
}
return super.getData(value);
}
};
if (column.getJdbcType() == JDBCType.DATE) {
column.setValueConverter(dateConvert);
} else if (column.getJdbcType() == JDBCType.TIMESTAMP) {
};
column.setValueConverter(dateConvert);
} else if (column.getJdbcType() == JDBCType.NUMERIC) {
} else if (TypeUtils.isNumberType(column)) { //数字
column.setValueConverter(new NumberValueConverter(column.getJavaType()));
}
rdbTableMetaData.addColumn(column);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.hswebframework.web.dao.mybatis.builder;

import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.JDBCType;
import java.util.Arrays;
import java.util.List;

/**
* @author zhouhao
* @since 3.0.3
*/
public class TypeUtils {
private static final List<Class> numberType = Arrays.asList(
byte.class, Byte.class
, short.class, Short.class
, int.class, Integer.class
, float.class, Float.class
, double.class, Double.class
, long.class, Long.class
, BigDecimal.class, BigInteger.class
);

private static final List<JDBCType> numberJdbcType = Arrays.asList(
JDBCType.TINYINT, JDBCType.DECIMAL, JDBCType.NUMERIC,
JDBCType.BIGINT, JDBCType.SMALLINT, JDBCType.INTEGER,
JDBCType.DECIMAL, JDBCType.BIT
);

public static boolean isNumberType(RDBColumnMetaData columnMetaData) {
return numberType.contains(columnMetaData.getJavaType())
|| Number.class.isAssignableFrom(columnMetaData.getJavaType())
|| numberJdbcType.contains(columnMetaData.getJdbcType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hswebframework.ezorm.rdb.meta.converter.DateTimeConverter;
import org.hswebframework.ezorm.rdb.meta.converter.NumberValueConverter;
import org.hswebframework.utils.ClassUtils;
import org.hswebframework.web.dao.mybatis.builder.TypeUtils;
import org.hswebframework.web.dict.EnumDict;
import org.springframework.core.annotation.AnnotationUtils;

Expand All @@ -25,6 +26,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
* jpa 注解解析器
Expand All @@ -34,21 +36,34 @@
*/
public class JpaAnnotationParser {

private static final Map<Class, RDBTableMetaData> metaDataCache = new ConcurrentHashMap<>(256);

private static final Map<Class, JDBCType> jdbcTypeMapping = new HashMap<>();

private static final List<BiFunction<Class, PropertyDescriptor, JDBCType>> jdbcTypeConvert = new ArrayList<>();

static {
jdbcTypeMapping.put(String.class, JDBCType.VARCHAR);

jdbcTypeMapping.put(Byte.class, JDBCType.TINYINT);
jdbcTypeMapping.put(byte.class, JDBCType.TINYINT);

jdbcTypeMapping.put(Short.class, JDBCType.INTEGER);
jdbcTypeMapping.put(short.class, JDBCType.INTEGER);

jdbcTypeMapping.put(Integer.class, JDBCType.INTEGER);
jdbcTypeMapping.put(int.class, JDBCType.INTEGER);

jdbcTypeMapping.put(Character.class, JDBCType.CHAR);
jdbcTypeMapping.put(char.class, JDBCType.CHAR);

jdbcTypeMapping.put(Long.class, JDBCType.BIGINT);
jdbcTypeMapping.put(long.class, JDBCType.BIGINT);

jdbcTypeMapping.put(Double.class, JDBCType.DECIMAL);
jdbcTypeMapping.put(double.class, JDBCType.DECIMAL);

jdbcTypeMapping.put(Float.class, JDBCType.DECIMAL);
jdbcTypeMapping.put(float.class, JDBCType.DECIMAL);

jdbcTypeMapping.put(Boolean.class, JDBCType.BIT);
jdbcTypeMapping.put(boolean.class, JDBCType.BIT);

Expand Down Expand Up @@ -89,6 +104,7 @@ public class JpaAnnotationParser {
});
}


public static RDBTableMetaData parseMetaDataFromEntity(Class entityClass) {
Table table = AnnotationUtils.findAnnotation(entityClass, Table.class);
if (table == null) {
Expand Down Expand Up @@ -133,11 +149,10 @@ public Object getData(Object value) {
}
};

if (columnMetaData.getJdbcType() == JDBCType.DATE) {
if (columnMetaData.getJdbcType() == JDBCType.DATE
|| columnMetaData.getJdbcType() == JDBCType.TIMESTAMP) {
columnMetaData.setValueConverter(dateConvert);
} else if (columnMetaData.getJdbcType() == JDBCType.TIMESTAMP) {
columnMetaData.setValueConverter(dateConvert);
} else if (columnMetaData.getJdbcType() == JDBCType.NUMERIC) {
} else if (TypeUtils.isNumberType(columnMetaData)) {
columnMetaData.setValueConverter(new NumberValueConverter(columnMetaData.getJavaType()));
}

Expand All @@ -147,6 +162,7 @@ public Object getData(Object value) {
return tableMetaData;
}


private static <T extends Annotation> T getAnnotation(Class entityClass, PropertyDescriptor descriptor, Class<T> type) {
T ann = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hswebframework.ezorm.core.param.Term;
import org.hswebframework.web.commons.entity.QueryEntity;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.asm.ClassReader;

import java.lang.invoke.LambdaMetafactory;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;

import static org.junit.Assert.*;

Expand All @@ -23,6 +23,17 @@
* @since 1.0
*/
public class SqlParamParserTest {
@SneakyThrows
public static <T> void test(Function<T, Object> function) {
Class t=function.getClass();

System.out.println(t);
}

public static void main(String[] args) {
test(TestQueryEntity::getName$like);
}


@Test
public void testParseQueryParam() {
Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-dao/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-entity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hsweb-commons/hsweb-commons-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<artifactId>hsweb-commons</artifactId>
<groupId>org.hswebframework.web</groupId>
<version>3.0.2</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit e8dc76c

Please sign in to comment.