Skip to content

Commit

Permalink
minidao 1.9.0版本发布
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdaiscott committed Sep 2, 2022
1 parent 44ec8dd commit c9410df
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 73 deletions.
4 changes: 2 additions & 2 deletions minidao-pe-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@


<properties>
<minidao.version>1.8.3</minidao.version>
<minidao.version>1.9.0</minidao.version>
<junit.version>4.13.1</junit.version>
<springframework.version>5.2.10.RELEASE</springframework.version>
<springframework.version>5.3.18</springframework.version>
<!-- 数据库驱动 -->
<mysql.version>8.0.21</mysql.version>
<postgresql.version>42.2.6</postgresql.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Employee implements Serializable {
*主键
*@TableId 支持uuid(默认)\AUTO(自增)\ID_WORKER(雪花ID)\ID_SEQ(序列seq,必须配置seqName)
*/
@TableId(type = IdType.UUID)
@TableId(type = IdType.AUTO)
private String id;
/**
*雇员编号
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class MinidaoInterceptor implements EmptyInterceptor {
public boolean onInsert(Field[] fields, Object obj) {
Map<Object, Object> map = new HashMap<Object, Object>();
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
//fields[j].setAccessible(true);
String fieldName = fields[j].getName();
if ("createDate".equals(fieldName)) {
map.put("createDate", new Date());
}
if ("createBy".equals(fieldName)) {
map.put("createBy", "scott");
map.put("createBy", "admin");
}
}
try {
Expand All @@ -42,7 +42,7 @@ public boolean onInsert(Field[] fields, Object obj) {
public boolean onUpdate(Field[] fields, Object obj) {
Map<Object, Object> map = new HashMap<Object, Object>();
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
//fields[j].setAccessible(true);
String fieldName = fields[j].getName();
if ("updateBy".equals(fieldName)) {
map.put("updateBy", "scott");
Expand Down
8 changes: 4 additions & 4 deletions minidao-pe-example/src/test/java/test/ClientDaoIdNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static void main(String args[]) {
EmployeeDao employeeDao = (EmployeeDao) factory.getBean("employeeDao");

Employee employee = new Employee();
employee.setEmpno("200");
employee.setName("scott");
employee.setEmpno("2001");
employee.setName("scott1");
employee.setBirthday(new Date());
employee.setAge(20);
employee.setSalary(new BigDecimal(88888));
employee.setAge(21);
employee.setSalary(new BigDecimal(88888111));
employeeDao.insertNative(employee);
System.out.println("对象值:"+employee.toString());
}
Expand Down
36 changes: 36 additions & 0 deletions minidao-pe-example/src/test/java/test/ClientDaoPageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package test;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.JdbcUtils;
import examples.dao.EmployeeDao;
import examples.entity.Employee;
import org.jeecgframework.minidao.pojo.MiniDaoPage;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.math.BigDecimal;
import java.util.Date;

/**
* 测试ID主键规则: Int 自增
* (注意:测试该方法需要把数据库ID类型改成int,自增)
*/
public class ClientDaoPageTest {
private final static Log log = LogFactory.getLog(ClientDaoPageTest.class);
public static void main(String args[]) {
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
EmployeeDao employeeDao = (EmployeeDao) factory.getBean("employeeDao");

//第一页数据
MiniDaoPage<Employee> pageList1 = employeeDao.getAll(new Employee(),2,10);
log.info("getTotal1 = "+pageList1.getTotal());
log.info("getPages1 = "+pageList1.getPages());


//第二页数据
MiniDaoPage<Employee> pageList2 = employeeDao.getAll(new Employee(),2,10);
log.info("getTotal2 = "+pageList2.getTotal());
log.info("getPages2 = "+pageList2.getPages());
}
}
20 changes: 13 additions & 7 deletions minidao-pe-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.jeecgframework</groupId>
<artifactId>minidao-pe</artifactId>
<version>1.8.3</version>
<version>1.9.0</version>
<packaging>jar</packaging>

<name>minidao-pe</name>
Expand All @@ -31,14 +31,14 @@

<properties>
<aspectj.version>1.9.6</aspectj.version>
<commons-collections.version>3.2.1</commons-collections.version>
<commons-collections.version>3.2.2</commons-collections.version>
<freemarker.version>2.3.30</freemarker.version>
<ognl.version>2.6.11</ognl.version>
<ognl.version>3.2.21</ognl.version>
<commons-logging.version>1.2</commons-logging.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<org.springframework.version>5.2.10.RELEASE</org.springframework.version>
<javassist.version>3.15.0-GA</javassist.version>
<jsqlparser.version>3.2</jsqlparser.version>
<org.springframework.version>5.3.18</org.springframework.version>
<javassist.version>3.25.0-GA</javassist.version>
<jsqlparser.version>4.3</jsqlparser.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -91,9 +91,15 @@
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>${ognl.version}</version>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>org.javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jeecgframework.minidao.util.*;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Lazy;
import org.springframework.dao.EmptyResultDataAccessException;
Expand All @@ -43,6 +44,7 @@
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import javax.annotation.Resource;
import javax.sql.DataSource;

/**
Expand All @@ -57,7 +59,12 @@
@SuppressWarnings("rawtypes")
public class MiniDaoHandler implements InvocationHandler {
private static final Log logger = LogFactory.getLog(MiniDaoHandler.class);


/**自定义的数据源*/
@Autowired(required = false)
@Qualifier("minidaoDataSource")
public DataSource dataSource;

@Autowired
@Lazy
private JdbcTemplate jdbcTemplate;
Expand Down Expand Up @@ -284,7 +291,15 @@ public JdbcTemplate getJdbcTemplate() {
jdbcTemplate = new JdbcTemplate(multDataSourceMap.get(keyOfTheFirst));
}
}
}
}else{
//update-begin--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源
if(null != dataSource){
namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
jdbcTemplate = new JdbcTemplate(dataSource);
}
//update-end--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源
}

return jdbcTemplate;
}

Expand Down Expand Up @@ -322,7 +337,15 @@ private Object getReturnMinidaoResult(MiniDaoPage pageSetting, Method method, St
jdbcTemplate = new JdbcTemplate(multDataSourceMap.get(keyOfTheFirst));
}
}
}
}else{
//update-begin--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源
if(null!=dataSource){
namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
jdbcTemplate = new JdbcTemplate(dataSource);
}
//update-end--Author:wangshuai--Date:20211018--for: 用户自定义的数据源是否为空,不为空则走用户自定义的数据源
}

if(emptyInterceptor==null){
try {
emptyInterceptor = applicationContext.getBean(EmptyInterceptor.class);
Expand Down Expand Up @@ -556,18 +579,20 @@ private String installDaoMetaData(MiniDaoPage pageSetting, Method method, Map<St
if(emptyInterceptor!=null && args!= null && args.length==1){
String methodName = method.getName();
Object obj = args[0];
Field[] fields = obj.getClass().getDeclaredFields();
if(methodName.startsWith("insert")){
if(emptyInterceptor!=null){
emptyInterceptor.onInsert(fields, obj);
if(obj!=null){
Field[] fields = obj.getClass().getDeclaredFields();
if(methodName.startsWith("insert")){
if(emptyInterceptor!=null){
emptyInterceptor.onInsert(fields, obj);
}
}
}
if(methodName.startsWith("update")){
if(emptyInterceptor!=null){
emptyInterceptor.onUpdate(fields, obj);
if(methodName.startsWith("update")){
if(emptyInterceptor!=null){
emptyInterceptor.onUpdate(fields, obj);
}
}
//reflect(obj);
}
//reflect(obj);
}
//update-begin---author:scott----date:20160511------for:minidao拦截器逻辑--------

Expand Down Expand Up @@ -661,7 +686,7 @@ private String installDaoMetaData(MiniDaoPage pageSetting, Method method, Map<St
private void initIdAnnotation(Field[] fields, Object obj) throws Exception {
Map<Object, Object> map = new HashMap<Object, Object>();
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
//fields[j].setAccessible(true);
String fieldName = fields[j].getName();
//1.获取所有的注解
TableId annotation = fields[j].getAnnotation(TableId.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MinidaoInterceptor implements EmptyInterceptor {
public boolean onInsert(Field[] fields, Object obj) {
Map<Object, Object> map = new HashMap<Object, Object>();
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
//fields[j].setAccessible(true);
String fieldName = fields[j].getName();
if ("createBy".equals(fieldName)) {
map.put("createBy", "scott");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.jeecgframework.minidao.pojo.MiniDaoPage;

import java.text.MessageFormat;
import java.util.Locale;

/**
* Hsqldb
Expand All @@ -13,14 +14,29 @@ public class HsqldbDialect extends AbstractHelperDialect {
@Override
public String getPageSql(String sql, MiniDaoPage miniDaoPage) {
StringBuilder sqlBuilder = new StringBuilder(sql.length() + 20);
sqlBuilder.append(sql);
String[] sqlParam = this.getPageParam(miniDaoPage);
if (Integer.valueOf(sqlParam[1]) > 0) {
sqlBuilder.append("\n LIMIT {1} ");
}
if (Integer.valueOf(sqlParam[0]) > 0) {
sqlBuilder.append("\n OFFSET {0} ");
//update-begin--Author:wangshuai--Date:20211201--for:判断Hsql是否包含limit或offset,包含用select包裹起来,不包含直接拼接
if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){
String[] sqlParam = this.getPageParam(miniDaoPage);
sqlBuilder.append("SELECT * FROM (");
sqlBuilder.append(sql);
sqlBuilder.append(") TMP_PAGE ");
if (Integer.valueOf(sqlParam[1]) > 0) {
sqlBuilder.append("\n LIMIT {1} ");
}
if (Integer.valueOf(sqlParam[0]) > 0) {
sqlBuilder.append("\n OFFSET {0} ");
}
}else{
sqlBuilder.append(sql);
String[] sqlParam = this.getPageParam(miniDaoPage);
if (Integer.valueOf(sqlParam[1]) > 0) {
sqlBuilder.append("\n LIMIT {1} ");
}
if (Integer.valueOf(sqlParam[0]) > 0) {
sqlBuilder.append("\n OFFSET {0} ");
}
}
//update-begin--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接
String newSql = sqlBuilder.toString();
newSql = super.format(newSql, super.getPageParam(miniDaoPage));
return newSql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ public class MySqlDialect extends AbstractHelperDialect {
@Override
public String getPageSql(String sql, MiniDaoPage miniDaoPage) {
StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
sqlBuilder.append(sql);
String[] sqlParam = super.getPageParam(miniDaoPage);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1} ");
} else {
sqlBuilder.append("\n LIMIT {0}, {1} ");
//update-begin--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接
if(sql.toUpperCase().contains("LIMIT")){
sqlBuilder.append("SELECT * FROM ( ");
sqlBuilder.append(sql);
sqlBuilder.append(" ) TMP_PAGE ");
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1}");
} else {
sqlBuilder.append("\n LIMIT {0}, {1} ");
}
}else{
sqlBuilder.append(sql);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1} ");
} else {
sqlBuilder.append("\n LIMIT {0}, {1} ");
}
}
//update-end--Author:wangshuai--Date:20211201--for:判断mysql是否包含limit,包含用select包裹起来,不包含直接拼接
String newSql = sqlBuilder.toString();
newSql = super.format(newSql,sqlParam);
return newSql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ public class OscarDialect extends AbstractHelperDialect {
@Override
public String getPageSql(String sql, MiniDaoPage miniDaoPage) {
StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
sqlBuilder.append(sql);
//update-begin--Author:wangshuai--Date:20211201--for:判断oscar是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接
String[] sqlParam = this.getPageParam(miniDaoPage);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1} ");
} else {
sqlBuilder.append("\n LIMIT {1} OFFSET {0} ");
if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){
sqlBuilder.append("SELECT * FROM (");
sqlBuilder.append(sql);
sqlBuilder.append(") TMP_PAGE ");
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1} ");
}else{
sqlBuilder.append("\n LIMIT {1} OFFSET {0} ");
}
}else{
sqlBuilder.append(sql);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlBuilder.append("\n LIMIT {1} ");
} else {
sqlBuilder.append("\n LIMIT {1} OFFSET {0} ");
}
}
String newSql = sqlBuilder.toString();
newSql = super.format(newSql, super.getPageParam(miniDaoPage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@ public class PostgreSqlDialect extends MySqlDialect {
@Override
public String getPageSql(String sql, MiniDaoPage miniDaoPage) {
StringBuilder sqlStr = new StringBuilder(sql.length() + 17);
sqlStr.append(sql);
//update-begin--Author:wangshuai--Date:20211201--for:判断postgresql是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接
String[] sqlParam = super.getPageParam(miniDaoPage);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlStr.append(" LIMIT {1}");
} else {
sqlStr.append(" OFFSET {0} LIMIT {1}");
if(sql.toUpperCase().contains("LIMIT") || sql.toUpperCase().contains("OFFSET")){
sqlStr.append("SELECT * FROM (");
sqlStr.append(sql);
sqlStr.append(") TMP_PAGE ");
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlStr.append(" LIMIT {1} ");
}else{
sqlStr.append(" OFFSET {0} LIMIT {1}");
}
}else{
sqlStr.append(sql);
if (Integer.valueOf(sqlParam[0]) == 0) {
sqlStr.append(" LIMIT {1}");
} else {
sqlStr.append(" OFFSET {0} LIMIT {1}");
}
}
//update-end--Author:wangshuai--Date:20211201--for:判断postgresql是否包含limit或OFFSET,包含用select包裹起来,不包含直接拼接
String newSql = sqlStr.toString();
newSql = super.format(newSql, super.getPageParam(miniDaoPage));
return newSql;
Expand Down
Loading

0 comments on commit c9410df

Please sign in to comment.