Skip to content

Commit

Permalink
Merge pull request #75 from imhansai/develop-jakarta
Browse files Browse the repository at this point in the history
处理 Jakarta EE apis 带来的改动
  • Loading branch information
blinkfox authored Oct 18, 2023
2 parents f69cc68 + 2a639cb commit 34e0ebf
Show file tree
Hide file tree
Showing 109 changed files with 318 additions and 404 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center"><img style="display: block; margin: 0 auto;" src="https://blinkfox.github.io/fenix/assets/images/logo.png" alt="fenix logo" /></div>

[![Build Status](https://secure.travis-ci.org/blinkfox/fenix.svg)](https://travis-ci.org/blinkfox/fenix) [![Javadocs](http://www.javadoc.io/badge/com.blinkfox/fenix.svg)](http://www.javadoc.io/doc/com.blinkfox/fenix) [![GitHub license](https://img.shields.io/github/license/blinkfox/fenix.svg)](https://github.com/blinkfox/fenix/blob/develop/LICENSE) [![fenix](https://img.shields.io/badge/fenix-v2.7.0-blue)](https://search.maven.org/artifact/com.blinkfox/fenix/2.7.0/jar) [![fenix starter](https://img.shields.io/badge/fenix%20spring%20boot%20starter-v2.7.0-blue)](https://search.maven.org/artifact/com.blinkfox/fenix-spring-boot-starter/2.7.0/jar) [![codecov](https://codecov.io/gh/blinkfox/fenix/branch/develop/graph/badge.svg)](https://codecov.io/gh/blinkfox/fenix)
[![Build Status](https://secure.travis-ci.org/blinkfox/fenix.svg)](https://travis-ci.org/blinkfox/fenix) [![Javadocs](http://www.javadoc.io/badge/com.blinkfox/fenix.svg)](http://www.javadoc.io/doc/com.blinkfox/fenix) [![GitHub license](https://img.shields.io/github/license/blinkfox/fenix.svg)](https://github.com/blinkfox/fenix/blob/develop/LICENSE) [![fenix](https://img.shields.io/badge/fenix-v3.0.0-blue)](https://search.maven.org/artifact/com.blinkfox/fenix/3.0.0/jar) [![fenix starter](https://img.shields.io/badge/fenix%20spring%20boot%20starter-v3.0.0-blue)](https://search.maven.org/artifact/com.blinkfox/fenix-spring-boot-starter/3.0.0/jar) [![codecov](https://codecov.io/gh/blinkfox/fenix/branch/develop/graph/badge.svg)](https://codecov.io/gh/blinkfox/fenix)

> [🔥 Fenix](https://github.com/blinkfox/fenix)(菲尼克斯)是一个为了解决复杂动态 SQL (`JPQL`) 而生的 `Spring Data JPA` 扩展库,能辅助开发者更方便快捷的书写复杂、动态且易于维护的 SQL,支持 ActiveRecord 模式和多种查询方式。
Expand Down Expand Up @@ -40,14 +40,14 @@
<dependency>
<groupId>com.blinkfox</groupId>
<artifactId>fenix-spring-boot-starter</artifactId>
<version>2.7.0</version>
<version>3.0.0</version>
</dependency>
```

### 🌵 2. Gradle

```bash
compile 'com.blinkfox:fenix-spring-boot-starter:2.7.0'
compile 'com.blinkfox:fenix-spring-boot-starter:3.0.0'
```

### 🏕️ 3. 激活 Fenix (@EnableFenix)
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](assets/images/logo.png)

# Fenix <small>2.7.0</small>
# Fenix <small>3.0.0</small>

> 为解决复杂动态 SQL 而生的 Spring Data JPA 扩展库
Expand Down
8 changes: 4 additions & 4 deletions docs/quick-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<dependency>
<groupId>com.blinkfox</groupId>
<artifactId>fenix-spring-boot-starter</artifactId>
<version>2.7.0</version>
<version>3.0.0</version>
</dependency>
```

### 🌵 2. Gradle :id=spring-boot-gradle

```bash
compile 'com.blinkfox:fenix-spring-boot-starter:2.7.0'
compile 'com.blinkfox:fenix-spring-boot-starter:3.0.0'
```

### 🏕️ 3. 激活 Fenix (@EnableFenix) :id=enable-fenix
Expand Down Expand Up @@ -100,14 +100,14 @@ fenix:
<dependency>
<groupId>com.blinkfox</groupId>
<artifactId>fenix</artifactId>
<version>2.7.0</version>
<version>3.0.0</version>
</dependency>
```

### 🌻 2. Gradle :id=project-gradle

```bash
compile 'com.blinkfox:fenix:2.7.0'
compile 'com.blinkfox:fenix:3.0.0'
```

### 🏔️ 3. 激活 Fenix :id=project-enable-fenix
Expand Down
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.blinkfox</groupId>
<artifactId>fenix</artifactId>
<version>2.7.0</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>fenix</name>
Expand Down Expand Up @@ -46,19 +46,19 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.7.6</version>
<version>3.0.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.14.Final</version>
<version>6.1.6.Final</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.5</version>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -78,7 +78,7 @@
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.28.0-GA</version>
<version>3.29.2-GA</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
Expand All @@ -96,7 +96,7 @@
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.2.0</version>
<version>2.0.0</version>
</dependency>

<!-- 以下是单元测试相关的包. -->
Expand All @@ -109,13 +109,13 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.23</version>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.5.1</version>
<version>2.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -145,8 +145,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand All @@ -160,7 +160,7 @@
<artifactId>maven-pmd-plugin</artifactId>
<version>3.16.0</version>
<configuration>
<targetJdk>1.8</targetJdk>
<targetJdk>17</targetJdk>
<printFailingErrors>true</printFailingErrors>
</configuration>
</plugin>
Expand Down Expand Up @@ -219,7 +219,7 @@
<artifactId>maven-pmd-plugin</artifactId>
<version>3.16.0</version>
<configuration>
<targetJdk>1.8</targetJdk>
<targetJdk>17</targetJdk>
<printFailingErrors>true</printFailingErrors>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blinkfox/fenix/EnableFenix.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import com.blinkfox.fenix.jpa.FenixJpaRepositoryFactoryBean;
import jakarta.persistence.EntityManagerFactory;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.persistence.EntityManagerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/blinkfox/fenix/ar/repo/JpaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* @author blinkfox on 2022-03-29.
* @since v2.7.0
*/
public interface JpaModel<T, ID, R extends JpaRepository<T, ID>> extends PagingAndSortingModel<T, ID, R> {
public interface JpaModel<T, ID, R extends JpaRepository<T, ID>> extends PagingAndSortingModel<T, ID, R>, CrudModel<T,
ID, R> {

/**
* 校验 Repository 接口是否是 {@link JpaRepository} 类型的接口.
Expand Down Expand Up @@ -60,7 +61,7 @@ default <S extends T> S saveAndFlush() {
* @return 实体对象
*/
default T getById() {
return this.getRepository().getById(this.getId());
return this.getRepository().getReferenceById(this.getId());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blinkfox.fenix.ar.repo;

import com.blinkfox.fenix.ar.BaseModel;
import com.blinkfox.fenix.exception.FenixException;
import com.blinkfox.fenix.helper.StringHelper;
import org.springframework.data.repository.PagingAndSortingRepository;
Expand All @@ -17,8 +18,7 @@
* @author blinkfox on 2022-03-29.
* @since v2.7.0
*/
public interface PagingAndSortingModel<T, ID, R extends PagingAndSortingRepository<T, ID>>
extends CrudModel<T, ID, R> {
public interface PagingAndSortingModel<T, ID, R extends PagingAndSortingRepository<T, ID>> extends BaseModel<R> {

/**
* 校验 Repository 接口是否是 {@link PagingAndSortingRepository} 类型的接口.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/blinkfox/fenix/ar/spec/FenixSpecModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ default void validExecutor(Object repository) {
/**
* 基于 {@link FenixPredicate} 返回与之匹配的单个对象的 {@link Optional} 实例.
*
* @param fenixPredicate Fenix 中用于动态构造 {@link javax.persistence.criteria.Predicate} 条件的接口
* @param fenixPredicate Fenix 中用于动态构造 {@link jakarta.persistence.criteria.Predicate} 条件的接口
* @return 不可能是 {@literal null}.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException 如果找到多个实例时抛出此异常.
*/
Expand All @@ -63,7 +63,7 @@ default Optional<T> findOneOfBean(Object beanParam) {
/**
* 基于 {@link FenixPredicate} 返回与之匹配的所有对象实例的集合.
*
* @param fenixPredicate Fenix 中用于动态构造 {@link javax.persistence.criteria.Predicate} 条件的接口
* @param fenixPredicate Fenix 中用于动态构造 {@link jakarta.persistence.criteria.Predicate} 条件的接口
* @return 不可能是 {@literal null}.
*/
default List<T> findAll(FenixPredicate fenixPredicate) {
Expand All @@ -73,7 +73,7 @@ default List<T> findAll(FenixPredicate fenixPredicate) {
/**
* 基于 {@link FenixPredicate} 和 {@link Pageable} 分页信息返回与之匹配的分页对象实例.
*
* @param fenixPredicate Fenix 中用于动态构造 {@link javax.persistence.criteria.Predicate} 条件的接口
* @param fenixPredicate Fenix 中用于动态构造 {@link jakarta.persistence.criteria.Predicate} 条件的接口
* @param pageable 分页信息,不能为 {@literal null}.
* @return 分页结果,不可能是 {@literal null}.
*/
Expand All @@ -84,7 +84,7 @@ default Page<T> findAll(FenixPredicate fenixPredicate, Pageable pageable) {
/**
* 基于 {@link FenixPredicate} 和 {@link Sort} 排序信息返回所有与之匹配的对象实例.
*
* @param fenixPredicate Fenix 中用于动态构造 {@link javax.persistence.criteria.Predicate} 条件的接口
* @param fenixPredicate Fenix 中用于动态构造 {@link jakarta.persistence.criteria.Predicate} 条件的接口
* @param sort 排序信息,不能为 {@literal null}.
* @return 排序结果,不可能是 {@literal null}.
*/
Expand Down Expand Up @@ -127,7 +127,7 @@ default List<T> findAllOfBean(Object beanParam, Sort sort) {
/**
* 基于 {@link FenixPredicate} 返回与之匹配的所有对象实例的总数量.
*
* @param fenixPredicate Fenix 中用于动态构造 {@link javax.persistence.criteria.Predicate} 条件的接口
* @param fenixPredicate Fenix 中用于动态构造 {@link jakarta.persistence.criteria.Predicate} 条件的接口
* @return 实例数量.
*/
default long count(FenixPredicate fenixPredicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class FenixConfigManager {
+ " | __)/ __ \\ / \\| \\ \\/ /\n"
+ " | \\\\ ___/| | \\ |> < \n"
+ " \\___ / \\___ >___| /__/__/\\_ \\\n"
+ " \\/ \\/ \\/ \\/ v2.7.0\n";
+ " \\/ \\/ \\/ \\/ v3.0.0\n";

/**
* Fenix 配置信息实例.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.data.repository.query.Param;

/**
* 通过仿射调用 class 方法中的指定方法的工具类.
* 通过反射调用 class 方法中的指定方法的工具类.
*
* @author blinkfox on 2019-08-11.
* @since v1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.List;
import lombok.Setter;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.BlobType;
import org.hibernate.type.descriptor.java.BlobJavaType;
import org.hibernate.type.descriptor.java.DataHelper;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.NotWritablePropertyException;
Expand Down Expand Up @@ -130,7 +130,7 @@ protected enum BlobToStringConverter implements Converter<Blob, String> {

@Override
public String convert(Blob source) {
return BlobType.INSTANCE.toString(source);
return BlobJavaType.INSTANCE.toString(source);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/blinkfox/fenix/jpa/FenixJpaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.blinkfox.fenix.helper.ClassMethodInvoker;
import com.blinkfox.fenix.helper.QueryHelper;
import com.blinkfox.fenix.helper.StringHelper;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import jakarta.persistence.Tuple;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.Tuple;
import lombok.Setter;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.query.AbstractJpaQuery;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.blinkfox.fenix.jpa;

import jakarta.persistence.EntityManager;
import java.util.Optional;
import javax.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.provider.PersistenceProvider;
import org.springframework.data.jpa.provider.QueryExtractor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.blinkfox.fenix.jpa;

import javax.persistence.EntityManager;
import jakarta.persistence.EntityManager;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.blinkfox.fenix.jpa;

import jakarta.persistence.EntityManager;
import java.lang.reflect.Method;
import javax.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.provider.QueryExtractor;
import org.springframework.data.jpa.repository.query.DefaultJpaQueryMethodFactory;
import org.springframework.data.jpa.repository.query.EscapeCharacter;
import org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy;
import org.springframework.data.jpa.repository.query.JpaQueryMethodFactory;
import org.springframework.data.jpa.repository.query.QueryRewriterProvider;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryMetadata;
Expand Down Expand Up @@ -75,9 +76,10 @@ private FenixQueryLookupStrategy(EntityManager entityManager, QueryLookupStrateg
if (FenixJpaClassWriter.hasDefaultJpaQueryMethodFactoryClass()) {
this.queryMethodFactory = new DefaultJpaQueryMethodFactory(extractor);
this.jpaQueryLookupStrategy = JpaQueryLookupStrategy.create(entityManager,
(JpaQueryMethodFactory) this.queryMethodFactory, key, provider, EscapeCharacter.DEFAULT);
(JpaQueryMethodFactory) this.queryMethodFactory, key, provider, QueryRewriterProvider.simple(),
EscapeCharacter.DEFAULT);
} else {
// 为了兼容 Spring Data JPA v2.3.0 之前的版本,此处使用 Javassist 来重写下面方法的中的字节码,来解决老版本的编译错误.
// 为了兼容 Spring Data JPA v2.3.0 之前的版本,此处使用 Javassist 来重写下面方法中的字节码,来解决老版本的编译错误.
this.jpaQueryLookupStrategy = this.createOldJpaQueryLookupStrategy(entityManager, key, extractor, provider,
EscapeCharacter.DEFAULT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.beans.BeanWrapper;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.convert.JodaTimeConverters;
import org.springframework.data.convert.Jsr310Converters;

/**
* 自定义查询结果的转换器.
Expand Down Expand Up @@ -45,7 +45,7 @@ public class FenixResultTransformer extends AbstractResultTransformer {

static {
// 添加一些默认的 ConversionService.
Collection<Converter<?, ?>> convertersToRegister = JodaTimeConverters.getConvertersToRegister();
Collection<Converter<?, ?>> convertersToRegister = Jsr310Converters.getConvertersToRegister();
for (Converter<?, ?> converter : convertersToRegister) {
oldConversionService.addConverter(converter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.blinkfox.fenix.consts.Const;
import com.blinkfox.fenix.helper.StringHelper;
import jakarta.persistence.EntityManager;
import jakarta.persistence.metamodel.SingularAttribute;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.metamodel.SingularAttribute;
import org.hibernate.Session;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
Expand Down
Loading

0 comments on commit 34e0ebf

Please sign in to comment.