Skip to content

Commit a4dfdbd

Browse files
authored
Merge branch '5.x' into feature/#176-5.x
2 parents 29b8252 + 97b70db commit a4dfdbd

File tree

17 files changed

+599
-60
lines changed

17 files changed

+599
-60
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ jobs:
88

99
if: github.actor == github.event.repository.owner.login
1010

11+
env:
12+
MAVEN_REPO_USERNAME: ${{ secrets.nexus_username }}
13+
MAVEN_REPO_PASSWORD: ${{ secrets.nexus_password }}
1114
steps:
1215
- uses: actions/checkout@v2
1316
with:

.github/workflows/snapshot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212
if: "!contains(github.event.head_commit.message, '[maven-release-plugin] prepare')"
1313

14+
env:
15+
MAVEN_REPO_USERNAME: ${{ secrets.nexus_username }}
16+
MAVEN_REPO_PASSWORD: ${{ secrets.nexus_password }}
1417
steps:
1518
- uses: actions/checkout@v2
1619
- name: Set up JDK 1.8

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# rsql-jpa-specification
22

3-
[![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/io.github.perplexhub/rsql?label=Release&logo=Release&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/#nexus-search;gav~io.github.perplexhub~rsql*)
4-
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/io.github.perplexhub/rsql?label=Snapshot&logo=Snapshot&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/#nexus-search;gav~io.github.perplexhub~rsql~~~)
5-
6-
[![Release Workflow Status](https://img.shields.io/github/workflow/status/perplexhub/rsql-jpa-specification/Maven%20Release?label=Release&logo=Release)](https://github.com/perplexhub/rsql-jpa-specification/actions?query=workflow%3A%22Maven+Release%22)
7-
[![Snapshot Workflow Status](https://img.shields.io/github/workflow/status/perplexhub/rsql-jpa-specification/Java%20CI?label=Snapshot&logo=Snapshot)](https://github.com/perplexhub/rsql-jpa-specification/actions?query=workflow%3A%22Java+CI%22)
8-
[![PR Workflow Status](https://img.shields.io/github/workflow/status/perplexhub/rsql-jpa-specification/Java%20Pull%20Request%20CI?label=Pull+Request&logo=PR)](https://github.com/perplexhub/rsql-jpa-specification/actions?query=workflow%3A%22Java+Pull+Request+CI%22)
3+
[![Maven Central (Releases)](https://img.shields.io/maven-central/v/io.github.perplexhub/rsql)](https://central.sonatype.com/search?q=io.github.perplexhub+rsql)
4+
[![Release Workflow Status](https://img.shields.io/github/actions/workflow/status/perplexhub/rsql-jpa-specification/release.yml?label=Release&style=plastic)](https://github.com/perplexhub/rsql-jpa-specification/actions/workflows/release.yml)
5+
[![Snapshot Workflow Status](https://img.shields.io/github/actions/workflow/status/perplexhub/rsql-jpa-specification/snapshot.yml?label=Snapshot&style=plastic)](https://github.com/perplexhub/rsql-jpa-specification/actions/workflows/snapshot.yml)
6+
[![PR Workflow Status](https://img.shields.io/github/actions/workflow/status/perplexhub/rsql-jpa-specification/pull_request.yml?label=Pull%20Request&style=plastic)](https://github.com/perplexhub/rsql-jpa-specification/actions/workflows/pull_request.yml)
97

108
Translate RSQL query into org.springframework.data.jpa.domain.Specification or com.querydsl.core.types.Predicate and support entities association query.
119

@@ -15,11 +13,11 @@ Translate RSQL query into org.springframework.data.jpa.domain.Specification or c
1513

1614
## Maven Repository
1715

18-
<https://oss.sonatype.org/#nexus-search;gav~io.github.perplexhub~rsql*>
16+
<https://central.sonatype.com/search?q=io.github.perplexhub+rsql>
1917

2018
## Add rsql-jpa-spring-boot-starter for RSQL to Spring JPA translation
2119

22-
### Maven dependency for rsql-jpa-spring-boot-starter [![](https://img.shields.io/nexus/r/io.github.perplexhub/rsql-jpa-spring-boot-starter?color=black&label=%20&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/#nexus-search;gav~io.github.perplexhub~rsql-jpa-spring-boot-starter*)
20+
### Maven dependency for rsql-jpa-spring-boot-starter [![](https://img.shields.io/maven-central/v/io.github.perplexhub/rsql-jpa-spring-boot-starter?label=%20&color=black)](https://central.sonatype.com/artifact/io.github.perplexhub/rsql-jpa-spring-boot-starter/versions)
2321

2422
```xml
2523
<dependency>
@@ -45,7 +43,7 @@ public interface UserRepository extends JpaRepository<User, String>, JpaSpecific
4543

4644
## Add rsql-querydsl-spring-boot-starter for RSQL to Spring JPA and QueryDSL translation
4745

48-
### Maven dependency for rsql-querydsl-spring-boot-starter [![](https://img.shields.io/nexus/r/io.github.perplexhub/rsql-querydsl-spring-boot-starter?color=black&label=%20&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/#nexus-search;gav~io.github.perplexhub~rsql-querydsl-spring-boot-starter*)
46+
### Maven dependency for rsql-querydsl-spring-boot-starter [![](https://img.shields.io/maven-central/v/io.github.perplexhub/rsql-querydsl-spring-boot-starter?label=%20&color=black)](https://central.sonatype.com/artifact/io.github.perplexhub/rsql-querydsl-spring-boot-starter/versions)
4947

5048
```xml
5149
<dependency>

pom.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,14 @@
8989
<build>
9090
<plugins>
9191
<plugin>
92-
<groupId>org.sonatype.plugins</groupId>
93-
<artifactId>nexus-staging-maven-plugin</artifactId>
94-
<version>1.6.13</version>
92+
<groupId>org.sonatype.central</groupId>
93+
<artifactId>central-publishing-maven-plugin</artifactId>
94+
<version>0.8.0</version>
9595
<extensions>true</extensions>
9696
<configuration>
97-
<serverId>ossrh</serverId>
98-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
99-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
100-
<stagingProgressTimeoutMinutes>60</stagingProgressTimeoutMinutes>
97+
<publishingServerId>central</publishingServerId>
98+
<autoPublish>true</autoPublish>
99+
<waitUntil>validated</waitUntil>
101100
</configuration>
102101
</plugin>
103102
<plugin>
@@ -285,8 +284,8 @@
285284
</profiles>
286285
<distributionManagement>
287286
<snapshotRepository>
288-
<id>ossrh</id>
289-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
287+
<id>central</id>
288+
<url>https://central.sonatype.com/repository/maven-snapshots</url>
290289
</snapshotRepository>
291290
</distributionManagement>
292291
</project>

rsql-common/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
<artifactId>hamcrest</artifactId>
3838
<scope>test</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>io.hypersistence</groupId>
42+
<artifactId>hypersistence-utils-hibernate-62</artifactId>
43+
<version>3.5.1</version>
44+
<scope>test</scope>
45+
</dependency>
4046
<dependency>
4147
<groupId>com.h2database</groupId>
4248
<artifactId>h2</artifactId>

rsql-common/src/main/java/io/github/perplexhub/rsql/RSQLVisitorBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import javax.persistence.metamodel.ManagedType;
1313
import javax.persistence.metamodel.PluralAttribute;
1414

15+
import lombok.Getter;
1516
import org.springframework.core.convert.support.ConfigurableConversionService;
17+
import org.springframework.orm.jpa.vendor.Database;
1618
import org.springframework.util.StringUtils;
1719

1820
import cz.jirutka.rsql.parser.ast.RSQLVisitor;
@@ -26,6 +28,7 @@ public abstract class RSQLVisitorBase<R, A> implements RSQLVisitor<R, A> {
2628

2729
protected static volatile @Setter Map<Class, ManagedType> managedTypeMap;
2830
protected static volatile @Setter Map<String, EntityManager> entityManagerMap;
31+
protected static volatile @Setter @Getter Map<EntityManager, Database> entityManagerDatabase = new HashMap();
2932
protected static final Map<Class, Class> primitiveToWrapper;
3033
protected static volatile @Setter Map<Class<?>, Map<String, String>> propertyRemapping;
3134
protected static volatile @Setter Map<Class<?>, List<String>> globalPropertyWhitelist;
Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,122 @@
11
package io.github.perplexhub.rsql;
22

3-
import java.util.Map;
43

4+
import io.github.perplexhub.rsql.RSQLJPAAutoConfiguration.HibernateEntityManagerDatabaseConfiguration;
55
import javax.persistence.EntityManager;
6-
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
import java.util.Objects;
9+
import lombok.extern.slf4j.Slf4j;
10+
import org.hibernate.Session;
11+
import org.hibernate.SessionFactory;
12+
import org.hibernate.dialect.DB2Dialect;
13+
import org.hibernate.dialect.DerbyDialect;
14+
import org.hibernate.dialect.Dialect;
15+
import org.hibernate.dialect.H2Dialect;
16+
import org.hibernate.dialect.HSQLDialect;
17+
import org.hibernate.dialect.MySQLDialect;
18+
import org.hibernate.dialect.OracleDialect;
19+
import org.hibernate.dialect.PostgreSQLDialect;
20+
import org.hibernate.dialect.SQLServerDialect;
21+
import org.hibernate.dialect.SybaseDialect;
22+
import org.hibernate.engine.spi.SessionImplementor;
23+
import org.hibernate.internal.SessionFactoryImpl;
24+
import org.springframework.beans.factory.ObjectProvider;
725
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
826
import org.springframework.context.annotation.Bean;
927
import org.springframework.context.annotation.Configuration;
10-
11-
import lombok.extern.slf4j.Slf4j;
28+
import org.springframework.context.annotation.Import;
29+
import org.springframework.orm.jpa.vendor.Database;
30+
import org.springframework.transaction.annotation.Transactional;
1231

1332
@Slf4j
1433
@Configuration
1534
@ConditionalOnClass(EntityManager.class)
35+
@Import(HibernateEntityManagerDatabaseConfiguration.class)
1636
public class RSQLJPAAutoConfiguration {
1737

18-
@Bean
19-
public RSQLCommonSupport rsqlCommonSupport(Map<String, EntityManager> entityManagerMap) {
20-
log.info("RSQLJPAAutoConfiguration.rsqlCommonSupport(entityManagerMap:{})", entityManagerMap.size());
21-
return new RSQLCommonSupport(entityManagerMap);
22-
}
38+
@Bean
39+
public RSQLCommonSupport rsqlCommonSupport(Map<String, EntityManager> entityManagerMap,
40+
ObjectProvider<EntityManagerDatabase> entityManagerDatabaseProvider) {
41+
log.info("RSQLJPAAutoConfiguration.rsqlCommonSupport(entityManagerMap:{})", entityManagerMap.size());
42+
EntityManagerDatabase entityManagerDatabase = entityManagerDatabaseProvider.getIfAvailable(() -> new EntityManagerDatabase(new HashMap()));
43+
44+
return new RSQLJPASupport(entityManagerMap, entityManagerDatabase.value());
45+
}
46+
47+
@Configuration
48+
@ConditionalOnClass(SessionImplementor.class)
49+
static
50+
class HibernateEntityManagerDatabaseConfiguration {
51+
52+
@Transactional
53+
@Bean
54+
public EntityManagerDatabase entityManagerDatabase(ObjectProvider<EntityManager> entityManagers) {
55+
Map<EntityManager, Database> value = new HashMap<>();
56+
EntityManager entityManager = entityManagers.getIfAvailable();
57+
SessionFactory sessionFactory = entityManager.unwrap(Session.class).getSessionFactory();
58+
Dialect dialect = ((SessionFactoryImpl) sessionFactory).getJdbcServices().getDialect();
59+
60+
Database db = toDatabase(dialect);
61+
if (db != null) {
62+
value.put(entityManager, db);
63+
}
64+
65+
return new EntityManagerDatabase(value);
66+
}
67+
68+
private Database toDatabase(Dialect dialect) {
69+
if (dialect instanceof PostgreSQLDialect) {
70+
return Database.POSTGRESQL;
71+
} else if (dialect instanceof MySQLDialect) {
72+
return Database.MYSQL;
73+
} else if (dialect instanceof SQLServerDialect) {
74+
return Database.SQL_SERVER;
75+
} else if (dialect instanceof OracleDialect) {
76+
return Database.ORACLE;
77+
} else if (dialect instanceof DerbyDialect) {
78+
return Database.DERBY;
79+
} else if (dialect instanceof DB2Dialect) {
80+
return Database.DB2;
81+
} else if (dialect instanceof H2Dialect) {
82+
return Database.H2;
83+
} else if (dialect instanceof HSQLDialect) {
84+
return Database.HSQL;
85+
} else if (dialect instanceof SybaseDialect) {
86+
return Database.SQL_SERVER;
87+
}
88+
89+
return null;
90+
}
91+
}
92+
93+
public static final class EntityManagerDatabase {
94+
private final Map<EntityManager, Database> value;
95+
96+
public EntityManagerDatabase(Map<EntityManager, Database> value) {
97+
this.value = value;
98+
}
99+
100+
public Map<EntityManager, Database> value() {
101+
return value;
102+
}
103+
104+
@Override
105+
public boolean equals(Object obj) {
106+
if (this == obj) return true;
107+
if (obj == null || getClass() != obj.getClass()) return false;
108+
EntityManagerDatabase that = (EntityManagerDatabase) obj;
109+
return Objects.equals(value, that.value);
110+
}
111+
112+
@Override
113+
public int hashCode() {
114+
return Objects.hash(value);
115+
}
23116

117+
@Override
118+
public String toString() {
119+
return "EntityManagerDatabase[value=" + value + "]";
120+
}
121+
}
24122
}

rsql-jpa/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,34 @@
4141
<artifactId>h2</artifactId>
4242
<scope>test</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>org.postgresql</groupId>
46+
<artifactId>postgresql</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.testcontainers</groupId>
51+
<artifactId>postgresql</artifactId>
52+
<version>1.19.0</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.hibernate.common</groupId>
57+
<artifactId>hibernate-commons-annotations</artifactId>
58+
<version>5.1.2.Final</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>io.hypersistence</groupId>
62+
<artifactId>hypersistence-utils-hibernate-52</artifactId>
63+
<version>3.7.6</version>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>net.java.dev.jna</groupId>
68+
<artifactId>jna</artifactId>
69+
<version>5.14.0</version>
70+
<scope>test</scope>
71+
</dependency>
4472
<dependency>
4573
<groupId>org.projectlombok</groupId>
4674
<artifactId>lombok</artifactId>

0 commit comments

Comments
 (0)