refactor(all): 调整模块依赖,划分代码范围
This commit is contained in:
61
pom.xml
61
pom.xml
@@ -11,9 +11,10 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>spring-boot-service-template-common</module>
|
<module>spring-boot-service-template-common</module>
|
||||||
<module>spring-boot-service-template-eq</module>
|
<module>spring-boot-service-template-database/spring-boot-service-template-database-common</module>
|
||||||
<module>spring-boot-service-template-jpa</module>
|
<module>spring-boot-service-template-database/spring-boot-service-template-database-eq</module>
|
||||||
<module>spring-boot-service-template-xbatis</module>
|
<module>spring-boot-service-template-database/spring-boot-service-template-database-jpa</module>
|
||||||
|
<module>spring-boot-service-template-database/spring-boot-service-template-database-xbatis</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
<mapstruct.version>1.6.3</mapstruct.version>
|
<mapstruct.version>1.6.3</mapstruct.version>
|
||||||
<mapstruct-plus.version>1.5.0</mapstruct-plus.version>
|
<mapstruct-plus.version>1.5.0</mapstruct-plus.version>
|
||||||
<datasource-decorator.version>2.0.0</datasource-decorator.version>
|
<datasource-decorator.version>2.0.0</datasource-decorator.version>
|
||||||
|
<easy-query.version>3.1.68</easy-query.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -36,6 +38,10 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jspecify</groupId>
|
||||||
|
<artifactId>jspecify</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -47,7 +53,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lanyuanxiaoyao</groupId>
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
<artifactId>spring-boot-service-template-jpa</artifactId>
|
<artifactId>spring-boot-service-template-database-common</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -67,23 +73,6 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.blinkfox</groupId>
|
|
||||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
|
||||||
<version>${fenix.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.openfeign.querydsl</groupId>
|
|
||||||
<artifactId>querydsl-jpa</artifactId>
|
|
||||||
<version>${querydsl.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate.orm</groupId>
|
|
||||||
<artifactId>hibernate-ant</artifactId>
|
|
||||||
<version>${hibernate.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mapstruct</groupId>
|
<groupId>org.mapstruct</groupId>
|
||||||
<artifactId>mapstruct</artifactId>
|
<artifactId>mapstruct</artifactId>
|
||||||
@@ -102,10 +91,21 @@
|
|||||||
<version>${datasource-decorator.version}</version>
|
<version>${datasource-decorator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jpa -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jspecify</groupId>
|
<groupId>com.blinkfox</groupId>
|
||||||
<artifactId>jspecify</artifactId>
|
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>${fenix.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign.querydsl</groupId>
|
||||||
|
<artifactId>querydsl-jpa</artifactId>
|
||||||
|
<version>${querydsl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-ant</artifactId>
|
||||||
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- xbatis -->
|
<!-- xbatis -->
|
||||||
@@ -116,6 +116,19 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- easy-query -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.easy-query</groupId>
|
||||||
|
<artifactId>sql-springboot4-starter</artifactId>
|
||||||
|
<version>3.1.68</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jspecify</groupId>
|
||||||
|
<artifactId>jspecify</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -1,125 +0,0 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.service;
|
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
|
||||||
|
|
||||||
public abstract class QueryParser<O> {
|
|
||||||
protected abstract void nullEqual(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notNullEqual(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void empty(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notEmpty(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void equal(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notEqual(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void like(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notLike(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void contain(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notContain(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void startWith(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notStartWith(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void endWith(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notEndWith(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void great(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void less(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void greatEqual(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void lessEqual(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void inside(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notInside(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void between(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract void notBetween(Query.Queryable queryable);
|
|
||||||
|
|
||||||
protected abstract O build();
|
|
||||||
|
|
||||||
public O build(Query.Queryable queryable) {
|
|
||||||
if (ObjectHelper.isNull(queryable)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.nullEqual())) {
|
|
||||||
nullEqual(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notNullEqual())) {
|
|
||||||
notNullEqual(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.empty())) {
|
|
||||||
empty(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notEmpty())) {
|
|
||||||
notEmpty(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.equal())) {
|
|
||||||
equal(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notEqual())) {
|
|
||||||
notEqual(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.like())) {
|
|
||||||
like(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notLike())) {
|
|
||||||
notLike(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.contain())) {
|
|
||||||
contain(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notContain())) {
|
|
||||||
notContain(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.startWith())) {
|
|
||||||
startWith(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notStartWith())) {
|
|
||||||
notStartWith(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.endWith())) {
|
|
||||||
endWith(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notEndWith())) {
|
|
||||||
notEndWith(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.great())) {
|
|
||||||
great(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.less())) {
|
|
||||||
less(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.greatEqual())) {
|
|
||||||
greatEqual(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.lessEqual())) {
|
|
||||||
lessEqual(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.inside())) {
|
|
||||||
inside(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notInside())) {
|
|
||||||
notInside(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.between())) {
|
|
||||||
between(queryable);
|
|
||||||
}
|
|
||||||
if (ObjectHelper.isNotEmpty(queryable.notBetween())) {
|
|
||||||
notBetween(queryable);
|
|
||||||
}
|
|
||||||
return build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
|
<artifactId>spring-boot-service-template</artifactId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>spring-boot-service-template-database-common</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
|
<artifactId>spring-boot-service-template-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.gavlyukovskiy</groupId>
|
||||||
|
<artifactId>p6spy-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.controller;
|
package com.lanyuanxiaoyao.service.template.database.common.controller;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询控制器接口,用于定义统一的查询实体详情和列表的接口规范
|
* 查询控制器接口,用于定义统一的查询实体详情和列表的接口规范
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.controller;
|
package com.lanyuanxiaoyao.service.template.database.common.controller;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除控制器接口,用于定义统一的删除实体对象的接口规范
|
* 删除控制器接口,用于定义统一的删除实体对象的接口规范
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.controller;
|
package com.lanyuanxiaoyao.service.template.database.common.controller;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存控制器接口,用于定义统一的保存实体对象的接口规范
|
* 保存控制器接口,用于定义统一的保存实体对象的接口规范
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.controller;
|
package com.lanyuanxiaoyao.service.template.database.common.controller;
|
||||||
|
|
||||||
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, QueryController<LIST_ITEM, DETAIL_ITEM>, RemoveController {
|
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, QueryController<LIST_ITEM, DETAIL_ITEM>, RemoveController {
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.entity;
|
package com.lanyuanxiaoyao.service.template.database.common.entity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.entity;
|
package com.lanyuanxiaoyao.service.template.database.common.entity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.entity;
|
package com.lanyuanxiaoyao.service.template.database.common.entity;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.exception;
|
package com.lanyuanxiaoyao.service.template.database.common.exception;
|
||||||
|
|
||||||
public class IdNotFoundException extends RuntimeException {
|
public class IdNotFoundException extends RuntimeException {
|
||||||
public IdNotFoundException(Long id) {
|
public IdNotFoundException(Long id) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.exception;
|
package com.lanyuanxiaoyao.service.template.database.common.exception;
|
||||||
|
|
||||||
public class NotCollectionException extends RuntimeException {
|
public class NotCollectionException extends RuntimeException {
|
||||||
public NotCollectionException(String variable) {
|
public NotCollectionException(String variable) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.exception;
|
package com.lanyuanxiaoyao.service.template.database.common.exception;
|
||||||
|
|
||||||
public class NotComparableException extends RuntimeException {
|
public class NotComparableException extends RuntimeException {
|
||||||
public NotComparableException(String variable) {
|
public NotComparableException(String variable) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.exception;
|
package com.lanyuanxiaoyao.service.template.database.common.exception;
|
||||||
|
|
||||||
public class NotStringException extends RuntimeException {
|
public class NotStringException extends RuntimeException {
|
||||||
public NotStringException(String variable) {
|
public NotStringException(String variable) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.helper;
|
package com.lanyuanxiaoyao.service.template.database.common.helper;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.template.database.common.service;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
|
public abstract class QueryParser<O> {
|
||||||
|
private final Query.Queryable queryable;
|
||||||
|
private final O container;
|
||||||
|
|
||||||
|
protected abstract void nullEqual(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notNullEqual(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void empty(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notEmpty(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void equal(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notEqual(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void like(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notLike(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void contain(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notContain(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void startWith(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notStartWith(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void endWith(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notEndWith(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void great(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void less(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void greatEqual(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void lessEqual(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void inside(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notInside(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void between(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
protected abstract void notBetween(Query.Queryable queryable, O container);
|
||||||
|
|
||||||
|
public void build() {
|
||||||
|
if (ObjectHelper.isNull(queryable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.nullEqual())) {
|
||||||
|
nullEqual(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notNullEqual())) {
|
||||||
|
notNullEqual(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.empty())) {
|
||||||
|
empty(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notEmpty())) {
|
||||||
|
notEmpty(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.equal())) {
|
||||||
|
equal(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notEqual())) {
|
||||||
|
notEqual(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.like())) {
|
||||||
|
like(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notLike())) {
|
||||||
|
notLike(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.contain())) {
|
||||||
|
contain(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notContain())) {
|
||||||
|
notContain(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.startWith())) {
|
||||||
|
startWith(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notStartWith())) {
|
||||||
|
notStartWith(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.endWith())) {
|
||||||
|
endWith(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notEndWith())) {
|
||||||
|
notEndWith(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.great())) {
|
||||||
|
great(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.less())) {
|
||||||
|
less(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.greatEqual())) {
|
||||||
|
greatEqual(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.lessEqual())) {
|
||||||
|
lessEqual(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.inside())) {
|
||||||
|
inside(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notInside())) {
|
||||||
|
notInside(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.between())) {
|
||||||
|
between(queryable, container);
|
||||||
|
}
|
||||||
|
if (ObjectHelper.isNotEmpty(queryable.notBetween())) {
|
||||||
|
notBetween(queryable, container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.service;
|
package com.lanyuanxiaoyao.service.template.database.common.service;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Page;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Page;
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.service;
|
package com.lanyuanxiaoyao.service.template.database.common.service;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.service;
|
package com.lanyuanxiaoyao.service.template.database.common.service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存服务接口,用于定义统一的保存实体对象的服务规范
|
* 保存服务接口,用于定义统一的保存实体对象的服务规范
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.common.service;
|
package com.lanyuanxiaoyao.service.template.database.common.service;
|
||||||
|
|
||||||
public interface SimpleService<ENTITY> extends SaveService<ENTITY>, QueryService<ENTITY>, RemoveService<ENTITY> {
|
public interface SimpleService<ENTITY> extends SaveService<ENTITY>, QueryService<ENTITY>, RemoveService<ENTITY> {
|
||||||
}
|
}
|
||||||
@@ -9,32 +9,23 @@
|
|||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>spring-boot-service-template-eq</artifactId>
|
<artifactId>spring-boot-service-template-database-eq</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lanyuanxiaoyao</groupId>
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
<artifactId>spring-boot-service-template-common</artifactId>
|
<artifactId>spring-boot-service-template-database-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.easy-query</groupId>
|
<groupId>com.easy-query</groupId>
|
||||||
<artifactId>sql-springboot4-starter</artifactId>
|
<artifactId>sql-springboot4-starter</artifactId>
|
||||||
<version>3.1.68</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.gavlyukovskiy</groupId>
|
|
||||||
<artifactId>p6spy-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jspecify</groupId>
|
|
||||||
<artifactId>jspecify</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -70,7 +61,7 @@
|
|||||||
<path>
|
<path>
|
||||||
<groupId>com.easy-query</groupId>
|
<groupId>com.easy-query</groupId>
|
||||||
<artifactId>sql-processor</artifactId>
|
<artifactId>sql-processor</artifactId>
|
||||||
<version>3.1.68</version>
|
<version>${easy-query.version}</version>
|
||||||
</path>
|
</path>
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -2,10 +2,10 @@ package com.lanyuanxiaoyao.service.template.eq.controller;
|
|||||||
|
|
||||||
import com.easy.query.core.proxy.AbstractProxyEntity;
|
import com.easy.query.core.proxy.AbstractProxyEntity;
|
||||||
import com.easy.query.core.proxy.ProxyEntityAvailable;
|
import com.easy.query.core.proxy.ProxyEntityAvailable;
|
||||||
import com.lanyuanxiaoyao.service.template.common.controller.SimpleController;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.controller.SimpleController;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
import com.lanyuanxiaoyao.service.template.eq.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.eq.entity.SimpleEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.eq.service.SimpleServiceSupport;
|
import com.lanyuanxiaoyao.service.template.eq.service.SimpleServiceSupport;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.eq.entity;
|
package com.lanyuanxiaoyao.service.template.eq.entity;
|
||||||
|
|
||||||
import com.easy.query.core.basic.extension.generated.PrimaryKeyGenerator;
|
import com.easy.query.core.basic.extension.generated.PrimaryKeyGenerator;
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.SnowflakeHelper;
|
import com.lanyuanxiaoyao.service.template.database.common.helper.SnowflakeHelper;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -4,12 +4,12 @@ import com.easy.query.api.proxy.client.EasyEntityQuery;
|
|||||||
import com.easy.query.core.enums.SQLExecuteStrategyEnum;
|
import com.easy.query.core.enums.SQLExecuteStrategyEnum;
|
||||||
import com.easy.query.core.proxy.AbstractProxyEntity;
|
import com.easy.query.core.proxy.AbstractProxyEntity;
|
||||||
import com.easy.query.core.proxy.ProxyEntityAvailable;
|
import com.easy.query.core.proxy.ProxyEntityAvailable;
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Page;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.IdNotFoundException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.QueryParser;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Page;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.SimpleService;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.IdNotFoundException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.QueryParser;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.SimpleService;
|
||||||
import com.lanyuanxiaoyao.service.template.eq.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.eq.entity.SimpleEntity;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -17,6 +17,8 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.mapstruct.Named;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -27,6 +29,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
protected final EasyEntityQuery entityQuery;
|
protected final EasyEntityQuery entityQuery;
|
||||||
private final Class<ENTITY> target;
|
private final Class<ENTITY> target;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public Long save(ENTITY entity) {
|
public Long save(ENTITY entity) {
|
||||||
if (ObjectHelper.isNull(entity.getId())) {
|
if (ObjectHelper.isNull(entity.getId())) {
|
||||||
@@ -39,6 +42,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void save(Iterable<ENTITY> entities) {
|
public void save(Iterable<ENTITY> entities) {
|
||||||
var insertList = new ArrayList<ENTITY>();
|
var insertList = new ArrayList<ENTITY>();
|
||||||
@@ -94,7 +98,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
|
|
||||||
var result = entityQuery.queryable(target)
|
var result = entityQuery.queryable(target)
|
||||||
.where(this::commonPredicates)
|
.where(this::commonPredicates)
|
||||||
.where(proxy -> new EqQueryParser<ENTITY, PROXY>(proxy).build(query.query()))
|
.where(proxy -> new EqQueryParser<ENTITY, PROXY>(query.query(), proxy).build())
|
||||||
.orderBy(ObjectHelper.isNotEmpty(query.sort()), proxy -> query.sort().forEach(sort -> proxy.anyColumn(sort.column()).orderBy(Query.Sortable.Direction.ASC.equals(sort.direction()))))
|
.orderBy(ObjectHelper.isNotEmpty(query.sort()), proxy -> query.sort().forEach(sort -> proxy.anyColumn(sort.column()).orderBy(Query.Sortable.Direction.ASC.equals(sort.direction()))))
|
||||||
.toPageResult(index, size);
|
.toPageResult(index, size);
|
||||||
|
|
||||||
@@ -110,16 +114,19 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
.singleOptional();
|
.singleOptional();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Named("detail")
|
||||||
@Override
|
@Override
|
||||||
public ENTITY detail(Long id) {
|
public ENTITY detail(Long id) {
|
||||||
return detailOptional(id).orElse(null);
|
return detailOptional(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Named("detailOrThrow")
|
||||||
@Override
|
@Override
|
||||||
public ENTITY detailOrThrow(Long id) {
|
public ENTITY detailOrThrow(Long id) {
|
||||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Long id) {
|
public void remove(Long id) {
|
||||||
if (ObjectHelper.isNotNull(id)) {
|
if (ObjectHelper.isNotNull(id)) {
|
||||||
@@ -130,6 +137,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Set<Long> ids) {
|
public void remove(Set<Long> ids) {
|
||||||
if (ObjectHelper.isNotEmpty(ids)) {
|
if (ObjectHelper.isNotEmpty(ids)) {
|
||||||
@@ -140,102 +148,103 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
private static final class EqQueryParser<ENTITY extends SimpleEntity & ProxyEntityAvailable<ENTITY, PROXY>, PROXY extends AbstractProxyEntity<PROXY, ENTITY>> extends QueryParser<PROXY> {
|
||||||
private static final class EqQueryParser<ENTITY extends SimpleEntity & ProxyEntityAvailable<ENTITY, PROXY>, PROXY extends AbstractProxyEntity<PROXY, ENTITY>> extends QueryParser<Void> {
|
public EqQueryParser(Query.Queryable queryable, PROXY container) {
|
||||||
private final PROXY proxy;
|
super(queryable, container);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void nullEqual(Query.Queryable queryable) {
|
protected void nullEqual(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.nullEqual().forEach(column -> proxy.anyColumn(column).isNull());
|
queryable.nullEqual().forEach(column -> proxy.anyColumn(column).isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notNullEqual(Query.Queryable queryable) {
|
protected void notNullEqual(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notNullEqual().forEach(column -> proxy.anyColumn(column).isNotNull());
|
queryable.notNullEqual().forEach(column -> proxy.anyColumn(column).isNotNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void empty(Query.Queryable queryable) {
|
protected void empty(Query.Queryable queryable, PROXY proxy) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEmpty(Query.Queryable queryable) {
|
protected void notEmpty(Query.Queryable queryable, PROXY proxy) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void equal(Query.Queryable queryable) {
|
protected void equal(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.equal().forEach((column, value) -> proxy.anyColumn(column).eq(value));
|
queryable.equal().forEach((column, value) -> proxy.anyColumn(column).eq(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEqual(Query.Queryable queryable) {
|
protected void notEqual(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notEqual().forEach((column, value) -> proxy.anyColumn(column).ne(value));
|
queryable.notEqual().forEach((column, value) -> proxy.anyColumn(column).ne(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void like(Query.Queryable queryable) {
|
protected void like(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.like().forEach((column, value) -> proxy.anyColumn(column).likeRaw(value));
|
queryable.like().forEach((column, value) -> proxy.anyColumn(column).likeRaw(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notLike(Query.Queryable queryable) {
|
protected void notLike(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notLike().forEach((column, value) -> proxy.anyColumn(column).notLikeRaw(value));
|
queryable.notLike().forEach((column, value) -> proxy.anyColumn(column).notLikeRaw(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void contain(Query.Queryable queryable) {
|
protected void contain(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.contain().forEach((column, value) -> proxy.anyColumn(column).like(value));
|
queryable.contain().forEach((column, value) -> proxy.anyColumn(column).like(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notContain(Query.Queryable queryable) {
|
protected void notContain(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notContain().forEach((column, value) -> proxy.anyColumn(column).notLike(value));
|
queryable.notContain().forEach((column, value) -> proxy.anyColumn(column).notLike(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startWith(Query.Queryable queryable) {
|
protected void startWith(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.startWith().forEach((column, value) -> proxy.anyColumn(column).likeMatchLeft(value));
|
queryable.startWith().forEach((column, value) -> proxy.anyColumn(column).likeMatchLeft(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notStartWith(Query.Queryable queryable) {
|
protected void notStartWith(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notStartWith().forEach((column, value) -> proxy.anyColumn(column).notLikeMatchLeft(value));
|
queryable.notStartWith().forEach((column, value) -> proxy.anyColumn(column).notLikeMatchLeft(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void endWith(Query.Queryable queryable) {
|
protected void endWith(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.endWith().forEach((column, value) -> proxy.anyColumn(column).likeMatchRight(value));
|
queryable.endWith().forEach((column, value) -> proxy.anyColumn(column).likeMatchRight(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEndWith(Query.Queryable queryable) {
|
protected void notEndWith(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notEndWith().forEach((column, value) -> proxy.anyColumn(column).notLikeMatchRight(value));
|
queryable.notEndWith().forEach((column, value) -> proxy.anyColumn(column).notLikeMatchRight(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void great(Query.Queryable queryable) {
|
protected void great(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.great().forEach((column, value) -> proxy.anyColumn(column).gt(value));
|
queryable.great().forEach((column, value) -> proxy.anyColumn(column).gt(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void less(Query.Queryable queryable) {
|
protected void less(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.less().forEach((column, value) -> proxy.anyColumn(column).lt(value));
|
queryable.less().forEach((column, value) -> proxy.anyColumn(column).lt(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void greatEqual(Query.Queryable queryable) {
|
protected void greatEqual(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.greatEqual().forEach((column, value) -> proxy.anyColumn(column).ge(value));
|
queryable.greatEqual().forEach((column, value) -> proxy.anyColumn(column).ge(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void lessEqual(Query.Queryable queryable) {
|
protected void lessEqual(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.lessEqual().forEach((column, value) -> proxy.anyColumn(column).le(value));
|
queryable.lessEqual().forEach((column, value) -> proxy.anyColumn(column).le(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inside(Query.Queryable queryable) {
|
protected void inside(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.inside()
|
queryable.inside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -244,7 +253,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notInside(Query.Queryable queryable) {
|
protected void notInside(Query.Queryable queryable, PROXY proxy) {
|
||||||
queryable.notInside()
|
queryable.notInside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -253,18 +262,13 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity & ProxyEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void between(Query.Queryable queryable) {
|
protected void between(Query.Queryable queryable, PROXY proxy) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notBetween(Query.Queryable queryable) {
|
protected void notBetween(Query.Queryable queryable, PROXY proxy) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void build() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: Test
|
name: Test
|
||||||
datasource:
|
datasource:
|
||||||
url: "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL;DATABASE_TO_LOWER=TRUE;INIT=runscript from '/Users/lanyuanxiaoyao/Project/IdeaProjects/spring-boot-service-template/spring-boot-service-template-eq/src/test/initial.sql'"
|
url: "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL;DATABASE_TO_LOWER=TRUE;INIT=runscript from '/Users/lanyuanxiaoyao/Project/IdeaProjects/spring-boot-service-template/spring-boot-service-template-database/spring-boot-service-template-database-eq/src/test/initial.sql'"
|
||||||
username: test
|
username: test
|
||||||
password: test
|
password: test
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
@@ -9,12 +9,12 @@
|
|||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>spring-boot-service-template-jpa</artifactId>
|
<artifactId>spring-boot-service-template-database-jpa</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lanyuanxiaoyao</groupId>
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
<artifactId>spring-boot-service-template-common</artifactId>
|
<artifactId>spring-boot-service-template-database-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
@@ -40,22 +41,6 @@
|
|||||||
<artifactId>hibernate-ant</artifactId>
|
<artifactId>hibernate-ant</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mapstruct</groupId>
|
|
||||||
<artifactId>mapstruct</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.gavlyukovskiy</groupId>
|
|
||||||
<artifactId>p6spy-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jspecify</groupId>
|
|
||||||
<artifactId>jspecify</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.jpa.controller;
|
package com.lanyuanxiaoyao.service.template.jpa.controller;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.controller.SimpleController;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.controller.SimpleController;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
import com.lanyuanxiaoyao.service.template.jpa.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.jpa.entity.SimpleEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.jpa.service.SimpleServiceSupport;
|
import com.lanyuanxiaoyao.service.template.jpa.service.SimpleServiceSupport;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.jpa.entity;
|
package com.lanyuanxiaoyao.service.template.jpa.entity;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.SnowflakeHelper;
|
import com.lanyuanxiaoyao.service.template.database.common.helper.SnowflakeHelper;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.jpa.service;
|
package com.lanyuanxiaoyao.service.template.jpa.service;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Page;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.IdNotFoundException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.NotCollectionException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.NotComparableException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.NotStringException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.QueryParser;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Page;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.SimpleService;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.IdNotFoundException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.NotCollectionException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.NotComparableException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.NotStringException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.QueryParser;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.SimpleService;
|
||||||
import com.lanyuanxiaoyao.service.template.jpa.entity.IdOnlyEntity;
|
import com.lanyuanxiaoyao.service.template.jpa.entity.IdOnlyEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.jpa.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.jpa.entity.SimpleEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.jpa.repository.SimpleRepository;
|
import com.lanyuanxiaoyao.service.template.jpa.repository.SimpleRepository;
|
||||||
@@ -17,7 +17,6 @@ import jakarta.persistence.criteria.CriteriaQuery;
|
|||||||
import jakarta.persistence.criteria.Path;
|
import jakarta.persistence.criteria.Path;
|
||||||
import jakarta.persistence.criteria.Predicate;
|
import jakarta.persistence.criteria.Predicate;
|
||||||
import jakarta.persistence.criteria.Root;
|
import jakarta.persistence.criteria.Root;
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -29,6 +28,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.mapstruct.Named;
|
import org.mapstruct.Named;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 简单服务支持类,提供基础的业务逻辑实现
|
* 简单服务支持类,提供基础的业务逻辑实现
|
||||||
@@ -87,7 +87,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
* @param entity 需要保存的实体对象
|
* @param entity 需要保存的实体对象
|
||||||
* @return 返回保存后的实体ID
|
* @return 返回保存后的实体ID
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Throwable.class)
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public Long save(ENTITY entity) {
|
public Long save(ENTITY entity) {
|
||||||
entity = repository.saveOrUpdateByNotNullProperties(entity);
|
entity = repository.saveOrUpdateByNotNullProperties(entity);
|
||||||
@@ -103,7 +103,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
*
|
*
|
||||||
* @param entities 需要保存的实体对象集合
|
* @param entities 需要保存的实体对象集合
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Throwable.class)
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void save(Iterable<ENTITY> entities) {
|
public void save(Iterable<ENTITY> entities) {
|
||||||
repository.saveOrUpdateAllByNotNullProperties(entities);
|
repository.saveOrUpdateAllByNotNullProperties(entities);
|
||||||
@@ -194,7 +194,11 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
var result = repository.findAll(
|
var result = repository.findAll(
|
||||||
(root, query, builder) -> {
|
(root, query, builder) -> {
|
||||||
var predicate = commonPredicates(root, query, builder);
|
var predicate = commonPredicates(root, query, builder);
|
||||||
var queryPredicate = new JpaQueryParser<>(root, query, builder).build(listQuery.query());
|
var predicates = new ArrayList<Predicate>();
|
||||||
|
new JpaQueryParser<>(listQuery.query(), predicates, root, query, builder).build();
|
||||||
|
var queryPredicate = predicates.size() == 1
|
||||||
|
? predicates.get(0)
|
||||||
|
: builder.and(predicates.toArray(Predicate[]::new));
|
||||||
return ObjectHelper.isNull(predicate)
|
return ObjectHelper.isNull(predicate)
|
||||||
? queryPredicate
|
? queryPredicate
|
||||||
: builder.and(predicate, queryPredicate);
|
: builder.and(predicate, queryPredicate);
|
||||||
@@ -268,7 +272,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
*
|
*
|
||||||
* @param id 实体主键ID
|
* @param id 实体主键ID
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Throwable.class)
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Long id) {
|
public void remove(Long id) {
|
||||||
if (ObjectHelper.isNotNull(id)) {
|
if (ObjectHelper.isNotNull(id)) {
|
||||||
@@ -286,7 +290,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
*
|
*
|
||||||
* @param ids 实体主键ID集合
|
* @param ids 实体主键ID集合
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackOn = Throwable.class)
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Set<Long> ids) {
|
public void remove(Set<Long> ids) {
|
||||||
if (ObjectHelper.isNotEmpty(ids)) {
|
if (ObjectHelper.isNotEmpty(ids)) {
|
||||||
@@ -295,14 +299,14 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static final class JpaQueryParser<ENTITY> extends QueryParser<Predicate> {
|
private static final class JpaQueryParser<ENTITY> extends QueryParser<List<Predicate>> {
|
||||||
private final Root<ENTITY> root;
|
private final Root<ENTITY> root;
|
||||||
@SuppressWarnings({"unused", "FieldCanBeLocal"})
|
@SuppressWarnings({"unused", "FieldCanBeLocal"})
|
||||||
private final CriteriaQuery<?> query;
|
private final CriteriaQuery<?> query;
|
||||||
private final CriteriaBuilder builder;
|
private final CriteriaBuilder builder;
|
||||||
private final List<Predicate> predicates = new ArrayList<>();
|
|
||||||
|
|
||||||
private JpaQueryParser(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
private JpaQueryParser(Query.Queryable queryable, List<Predicate> predicates, Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||||
|
super(queryable, predicates);
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
@@ -434,17 +438,17 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void nullEqual(Query.Queryable queryable) {
|
protected void nullEqual(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.nullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
queryable.nullEqual().forEach(column -> predicates.add(builder.isNull(column(root, column))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notNullEqual(Query.Queryable queryable) {
|
protected void notNullEqual(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notNullEqual().forEach(column -> predicates.add(builder.isNotNull(column(root, column))));
|
queryable.notNullEqual().forEach(column -> predicates.add(builder.isNotNull(column(root, column))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void empty(Query.Queryable queryable) {
|
protected void empty(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.empty().forEach(column -> {
|
queryable.empty().forEach(column -> {
|
||||||
var path = this.<Collection<Object>>column(root, column);
|
var path = this.<Collection<Object>>column(root, column);
|
||||||
checkCollection(path, column);
|
checkCollection(path, column);
|
||||||
@@ -453,7 +457,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEmpty(Query.Queryable queryable) {
|
protected void notEmpty(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notEmpty().forEach(column -> {
|
queryable.notEmpty().forEach(column -> {
|
||||||
var path = this.<Collection<Object>>column(root, column);
|
var path = this.<Collection<Object>>column(root, column);
|
||||||
checkCollection(path, column);
|
checkCollection(path, column);
|
||||||
@@ -462,7 +466,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void equal(Query.Queryable queryable) {
|
protected void equal(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.equal().forEach((column, value) -> {
|
queryable.equal().forEach((column, value) -> {
|
||||||
var path = column(root, column);
|
var path = column(root, column);
|
||||||
predicates.add(builder.equal(path, value(path, value)));
|
predicates.add(builder.equal(path, value(path, value)));
|
||||||
@@ -470,7 +474,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEqual(Query.Queryable queryable) {
|
protected void notEqual(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notEqual().forEach((column, value) -> {
|
queryable.notEqual().forEach((column, value) -> {
|
||||||
var path = column(root, column);
|
var path = column(root, column);
|
||||||
predicates.add(builder.notEqual(path, value(path, value)));
|
predicates.add(builder.notEqual(path, value(path, value)));
|
||||||
@@ -478,7 +482,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void like(Query.Queryable queryable) {
|
protected void like(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.like().forEach((column, value) -> {
|
queryable.like().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -487,7 +491,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notLike(Query.Queryable queryable) {
|
protected void notLike(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notLike().forEach((column, value) -> {
|
queryable.notLike().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -496,7 +500,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void contain(Query.Queryable queryable) {
|
protected void contain(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.contain().forEach((column, value) -> {
|
queryable.contain().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -505,7 +509,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notContain(Query.Queryable queryable) {
|
protected void notContain(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notContain().forEach((column, value) -> {
|
queryable.notContain().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -514,7 +518,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startWith(Query.Queryable queryable) {
|
protected void startWith(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.startWith().forEach((column, value) -> {
|
queryable.startWith().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -523,7 +527,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notStartWith(Query.Queryable queryable) {
|
protected void notStartWith(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notStartWith().forEach((column, value) -> {
|
queryable.notStartWith().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -532,7 +536,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void endWith(Query.Queryable queryable) {
|
protected void endWith(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.endWith().forEach((column, value) -> {
|
queryable.endWith().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -541,7 +545,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEndWith(Query.Queryable queryable) {
|
protected void notEndWith(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notEndWith().forEach((column, value) -> {
|
queryable.notEndWith().forEach((column, value) -> {
|
||||||
var path = this.<String>column(root, column);
|
var path = this.<String>column(root, column);
|
||||||
checkString(path, value, column);
|
checkString(path, value, column);
|
||||||
@@ -550,7 +554,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void great(Query.Queryable queryable) {
|
protected void great(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.great().forEach((column, value) -> {
|
queryable.great().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
@@ -559,7 +563,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void less(Query.Queryable queryable) {
|
protected void less(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.less().forEach((column, value) -> {
|
queryable.less().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
@@ -568,7 +572,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void greatEqual(Query.Queryable queryable) {
|
protected void greatEqual(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.greatEqual().forEach((column, value) -> {
|
queryable.greatEqual().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
@@ -577,7 +581,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void lessEqual(Query.Queryable queryable) {
|
protected void lessEqual(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.lessEqual().forEach((column, value) -> {
|
queryable.lessEqual().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
@@ -586,7 +590,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inside(Query.Queryable queryable) {
|
protected void inside(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.inside()
|
queryable.inside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -595,7 +599,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notInside(Query.Queryable queryable) {
|
protected void notInside(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notInside()
|
queryable.notInside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -604,7 +608,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void between(Query.Queryable queryable) {
|
protected void between(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.between().forEach((column, value) -> {
|
queryable.between().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
@@ -613,19 +617,12 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notBetween(Query.Queryable queryable) {
|
protected void notBetween(Query.Queryable queryable, List<Predicate> predicates) {
|
||||||
queryable.notBetween().forEach((column, value) -> {
|
queryable.notBetween().forEach((column, value) -> {
|
||||||
var path = this.<Comparable<Object>>column(root, column);
|
var path = this.<Comparable<Object>>column(root, column);
|
||||||
checkComparable(path, value, column);
|
checkComparable(path, value, column);
|
||||||
predicates.add(builder.between(path, (Comparable<Object>) value(path, value.start()), (Comparable<Object>) value(path, value.end())).not());
|
predicates.add(builder.between(path, (Comparable<Object>) value(path, value.start()), (Comparable<Object>) value(path, value.end())).not());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Predicate build() {
|
|
||||||
return predicates.size() == 1
|
|
||||||
? predicates.get(0)
|
|
||||||
: builder.and(predicates.toArray(Predicate[]::new));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,12 @@
|
|||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>spring-boot-service-template-xbatis</artifactId>
|
<artifactId>spring-boot-service-template-database-xbatis</artifactId>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.lanyuanxiaoyao</groupId>
|
<groupId>com.lanyuanxiaoyao</groupId>
|
||||||
<artifactId>spring-boot-service-template-common</artifactId>
|
<artifactId>spring-boot-service-template-database-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -22,27 +22,12 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.xbatis</groupId>
|
<groupId>cn.xbatis</groupId>
|
||||||
<artifactId>xbatis-spring-boot-starter</artifactId>
|
<artifactId>xbatis-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.gavlyukovskiy</groupId>
|
|
||||||
<artifactId>p6spy-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mapstruct</groupId>
|
|
||||||
<artifactId>mapstruct</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jspecify</groupId>
|
|
||||||
<artifactId>jspecify</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.xbatis.controller;
|
package com.lanyuanxiaoyao.service.template.xbatis.controller;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.controller.SimpleController;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.GlobalResponse;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.controller.SimpleController;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.GlobalResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
import com.lanyuanxiaoyao.service.template.xbatis.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.xbatis.entity.SimpleEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.xbatis.service.SimpleServiceSupport;
|
import com.lanyuanxiaoyao.service.template.xbatis.service.SimpleServiceSupport;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.template.xbatis.entity;
|
package com.lanyuanxiaoyao.service.template.xbatis.entity;
|
||||||
|
|
||||||
import cn.xbatis.core.incrementer.Generator;
|
import cn.xbatis.core.incrementer.Generator;
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.SnowflakeHelper;
|
import com.lanyuanxiaoyao.service.template.database.common.helper.SnowflakeHelper;
|
||||||
|
|
||||||
public class SnowflakeIdGenerator implements Generator<Long> {
|
public class SnowflakeIdGenerator implements Generator<Long> {
|
||||||
@Override
|
@Override
|
||||||
@@ -3,12 +3,12 @@ package com.lanyuanxiaoyao.service.template.xbatis.service;
|
|||||||
import cn.xbatis.core.mybatis.mapper.context.Pager;
|
import cn.xbatis.core.mybatis.mapper.context.Pager;
|
||||||
import cn.xbatis.core.sql.MybatisCmdFactory;
|
import cn.xbatis.core.sql.MybatisCmdFactory;
|
||||||
import cn.xbatis.core.sql.executor.chain.QueryChain;
|
import cn.xbatis.core.sql.executor.chain.QueryChain;
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Page;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.entity.Query;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.exception.IdNotFoundException;
|
|
||||||
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
import com.lanyuanxiaoyao.service.template.common.helper.ObjectHelper;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.QueryParser;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Page;
|
||||||
import com.lanyuanxiaoyao.service.template.common.service.SimpleService;
|
import com.lanyuanxiaoyao.service.template.database.common.entity.Query;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.exception.IdNotFoundException;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.QueryParser;
|
||||||
|
import com.lanyuanxiaoyao.service.template.database.common.service.SimpleService;
|
||||||
import com.lanyuanxiaoyao.service.template.xbatis.entity.SimpleEntity;
|
import com.lanyuanxiaoyao.service.template.xbatis.entity.SimpleEntity;
|
||||||
import com.lanyuanxiaoyao.service.template.xbatis.mapper.MybatisBasicMapper;
|
import com.lanyuanxiaoyao.service.template.xbatis.mapper.MybatisBasicMapper;
|
||||||
import db.sql.api.cmd.LikeMode;
|
import db.sql.api.cmd.LikeMode;
|
||||||
@@ -18,6 +18,8 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.mapstruct.Named;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implements SimpleService<ENTITY> {
|
public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implements SimpleService<ENTITY> {
|
||||||
@@ -32,11 +34,13 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public Long save(ENTITY entity) {
|
public Long save(ENTITY entity) {
|
||||||
return (long) mapper.save(entity);
|
return (long) mapper.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void save(Iterable<ENTITY> entities) {
|
public void save(Iterable<ENTITY> entities) {
|
||||||
mapper.save(entities);
|
mapper.save(entities);
|
||||||
@@ -79,7 +83,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
|
|
||||||
var where = chain.where();
|
var where = chain.where();
|
||||||
commonPredicates(where);
|
commonPredicates(where);
|
||||||
new XBatisQueryParser<>(target, factory, where).build(query.query());
|
new XBatisQueryParser<>(query.query(), where, target, factory).build();
|
||||||
|
|
||||||
return new Page<>(chain.list(), chain.count());
|
return new Page<>(chain.list(), chain.count());
|
||||||
}
|
}
|
||||||
@@ -91,129 +95,132 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
return Optional.ofNullable(mapper.getById(target, id));
|
return Optional.ofNullable(mapper.getById(target, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Named("detail")
|
||||||
@Override
|
@Override
|
||||||
public ENTITY detail(Long id) {
|
public ENTITY detail(Long id) {
|
||||||
return detailOptional(id).orElse(null);
|
return detailOptional(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Named("detailOrThrow")
|
||||||
@Override
|
@Override
|
||||||
public ENTITY detailOrThrow(Long id) {
|
public ENTITY detailOrThrow(Long id) {
|
||||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Long id) {
|
public void remove(Long id) {
|
||||||
mapper.deleteById(target, id);
|
mapper.deleteById(target, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
@Override
|
@Override
|
||||||
public void remove(Set<Long> ids) {
|
public void remove(Set<Long> ids) {
|
||||||
mapper.deleteByIds(target, ids);
|
mapper.deleteByIds(target, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class XBatisQueryParser<ENTITY> extends QueryParser<Void> {
|
private static final class XBatisQueryParser<ENTITY> extends QueryParser<Where> {
|
||||||
private final Class<ENTITY> target;
|
private final Class<ENTITY> target;
|
||||||
private final MybatisCmdFactory factory;
|
private final MybatisCmdFactory factory;
|
||||||
private final Where where;
|
|
||||||
|
|
||||||
private XBatisQueryParser(Class<ENTITY> target, MybatisCmdFactory factory, Where where) {
|
private XBatisQueryParser(Query.Queryable queryable, Where where, Class<ENTITY> target, MybatisCmdFactory factory) {
|
||||||
|
super(queryable, where);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.where = where;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void nullEqual(Query.Queryable queryable) {
|
protected void nullEqual(Query.Queryable queryable, Where where) {
|
||||||
queryable.nullEqual().forEach(column -> where.isNull(factory.field(target, column)));
|
queryable.nullEqual().forEach(column -> where.isNull(factory.field(target, column)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notNullEqual(Query.Queryable queryable) {
|
protected void notNullEqual(Query.Queryable queryable, Where where) {
|
||||||
queryable.notNullEqual().forEach(column -> where.isNotNull(factory.field(target, column)));
|
queryable.notNullEqual().forEach(column -> where.isNotNull(factory.field(target, column)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void empty(Query.Queryable queryable) {
|
protected void empty(Query.Queryable queryable, Where where) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEmpty(Query.Queryable queryable) {
|
protected void notEmpty(Query.Queryable queryable, Where where) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void equal(Query.Queryable queryable) {
|
protected void equal(Query.Queryable queryable, Where where) {
|
||||||
queryable.equal().forEach((column, value) -> where.eq(factory.field(target, column), value));
|
queryable.equal().forEach((column, value) -> where.eq(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEqual(Query.Queryable queryable) {
|
protected void notEqual(Query.Queryable queryable, Where where) {
|
||||||
queryable.notEqual().forEach((column, value) -> where.ne(factory.field(target, column), value));
|
queryable.notEqual().forEach((column, value) -> where.ne(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void like(Query.Queryable queryable) {
|
protected void like(Query.Queryable queryable, Where where) {
|
||||||
queryable.like().forEach((column, value) -> where.like(LikeMode.NONE, factory.field(target, column), value));
|
queryable.like().forEach((column, value) -> where.like(LikeMode.NONE, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notLike(Query.Queryable queryable) {
|
protected void notLike(Query.Queryable queryable, Where where) {
|
||||||
queryable.notLike().forEach((column, value) -> where.notLike(LikeMode.NONE, factory.field(target, column), value));
|
queryable.notLike().forEach((column, value) -> where.notLike(LikeMode.NONE, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void contain(Query.Queryable queryable) {
|
protected void contain(Query.Queryable queryable, Where where) {
|
||||||
queryable.contain().forEach((column, value) -> where.like(factory.field(target, column), value));
|
queryable.contain().forEach((column, value) -> where.like(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notContain(Query.Queryable queryable) {
|
protected void notContain(Query.Queryable queryable, Where where) {
|
||||||
queryable.notContain().forEach((column, value) -> where.notLike(factory.field(target, column), value));
|
queryable.notContain().forEach((column, value) -> where.notLike(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startWith(Query.Queryable queryable) {
|
protected void startWith(Query.Queryable queryable, Where where) {
|
||||||
queryable.startWith().forEach((column, value) -> where.like(LikeMode.LEFT, factory.field(target, column), value));
|
queryable.startWith().forEach((column, value) -> where.like(LikeMode.LEFT, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notStartWith(Query.Queryable queryable) {
|
protected void notStartWith(Query.Queryable queryable, Where where) {
|
||||||
queryable.notStartWith().forEach((column, value) -> where.notLike(LikeMode.LEFT, factory.field(target, column), value));
|
queryable.notStartWith().forEach((column, value) -> where.notLike(LikeMode.LEFT, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void endWith(Query.Queryable queryable) {
|
protected void endWith(Query.Queryable queryable, Where where) {
|
||||||
queryable.endWith().forEach((column, value) -> where.like(LikeMode.RIGHT, factory.field(target, column), value));
|
queryable.endWith().forEach((column, value) -> where.like(LikeMode.RIGHT, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notEndWith(Query.Queryable queryable) {
|
protected void notEndWith(Query.Queryable queryable, Where where) {
|
||||||
queryable.notEndWith().forEach((column, value) -> where.notLike(LikeMode.RIGHT, factory.field(target, column), value));
|
queryable.notEndWith().forEach((column, value) -> where.notLike(LikeMode.RIGHT, factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void great(Query.Queryable queryable) {
|
protected void great(Query.Queryable queryable, Where where) {
|
||||||
queryable.great().forEach((column, value) -> where.gt(factory.field(target, column), value));
|
queryable.great().forEach((column, value) -> where.gt(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void less(Query.Queryable queryable) {
|
protected void less(Query.Queryable queryable, Where where) {
|
||||||
queryable.less().forEach((column, value) -> where.lt(factory.field(target, column), value));
|
queryable.less().forEach((column, value) -> where.lt(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void greatEqual(Query.Queryable queryable) {
|
protected void greatEqual(Query.Queryable queryable, Where where) {
|
||||||
queryable.greatEqual().forEach((column, value) -> where.gte(factory.field(target, column), value));
|
queryable.greatEqual().forEach((column, value) -> where.gte(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void lessEqual(Query.Queryable queryable) {
|
protected void lessEqual(Query.Queryable queryable, Where where) {
|
||||||
queryable.lessEqual().forEach((column, value) -> where.lte(factory.field(target, column), value));
|
queryable.lessEqual().forEach((column, value) -> where.lte(factory.field(target, column), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inside(Query.Queryable queryable) {
|
protected void inside(Query.Queryable queryable, Where where) {
|
||||||
queryable.inside()
|
queryable.inside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -222,7 +229,7 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notInside(Query.Queryable queryable) {
|
protected void notInside(Query.Queryable queryable, Where where) {
|
||||||
queryable.notInside()
|
queryable.notInside()
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -231,18 +238,13 @@ public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void between(Query.Queryable queryable) {
|
protected void between(Query.Queryable queryable, Where where) {
|
||||||
queryable.between().forEach((column, value) -> where.between(factory.field(target, column), value.start(), value.end()));
|
queryable.between().forEach((column, value) -> where.between(factory.field(target, column), value.start(), value.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notBetween(Query.Queryable queryable) {
|
protected void notBetween(Query.Queryable queryable, Where where) {
|
||||||
queryable.notBetween().forEach((column, value) -> where.notBetween(factory.field(target, column), value.start(), value.end()));
|
queryable.notBetween().forEach((column, value) -> where.notBetween(factory.field(target, column), value.start(), value.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void build() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: Test
|
name: Test
|
||||||
datasource:
|
datasource:
|
||||||
url: "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL;DATABASE_TO_LOWER=TRUE;INIT=runscript from '/Users/lanyuanxiaoyao/Project/IdeaProjects/spring-boot-service-template/spring-boot-service-template-xbatis/src/test/initial.sql'"
|
url: "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MySQL;DATABASE_TO_LOWER=TRUE;INIT=runscript from '/Users/lanyuanxiaoyao/Project/IdeaProjects/spring-boot-service-template/spring-boot-service-template-database/spring-boot-service-template-database-xbatis/src/test/initial.sql'"
|
||||||
username: test
|
username: test
|
||||||
password: test
|
password: test
|
||||||
driver-class-name: org.h2.Driver
|
driver-class-name: org.h2.Driver
|
||||||
Reference in New Issue
Block a user