fix(db): rm mysql + better name research
This commit is contained in:
parent
2cdc7e4aac
commit
ee77975c9c
4
pom.xml
4
pom.xml
@ -43,10 +43,6 @@
|
|||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
|
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.quarkus</groupId>
|
|
||||||
<artifactId>quarkus-reactive-mysql-client</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-reactive-pg-client</artifactId>
|
<artifactId>quarkus-reactive-pg-client</artifactId>
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
package fr.titionfire.ffsaf.data;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.FunctionContributions;
|
||||||
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
|
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
|
||||||
|
import org.hibernate.type.BasicType;
|
||||||
|
import org.hibernate.type.BasicTypeRegistry;
|
||||||
|
import org.hibernate.type.StandardBasicTypes;
|
||||||
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
public class CustomPostgreSQLDialect extends PostgreSQLDialect {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(PostgreSQLDialect.class);
|
||||||
|
|
||||||
|
public CustomPostgreSQLDialect() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
|
||||||
|
super.initializeFunctionRegistry(functionContributions);
|
||||||
|
|
||||||
|
LOGGER.info("Initializing custom function registry");
|
||||||
|
|
||||||
|
SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
|
||||||
|
TypeConfiguration typeConfiguration = functionContributions.getTypeConfiguration();
|
||||||
|
BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
|
||||||
|
BasicType<String> stringType = basicTypeRegistry.resolve(StandardBasicTypes.STRING);
|
||||||
|
|
||||||
|
functionRegistry.namedDescriptorBuilder("unaccent").setInvariantType(stringType).setExactArgumentCount(1)
|
||||||
|
.setParameterTypes(new FunctionParameterType[]{FunctionParameterType.STRING}).register();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -252,7 +252,7 @@ public class CompetitionService {
|
|||||||
} else {
|
} else {
|
||||||
if (fname == null || lname == null)
|
if (fname == null || lname == null)
|
||||||
return Uni.createFrom().failure(new DBadRequestException("Nom et prénom requis"));
|
return Uni.createFrom().failure(new DBadRequestException("Nom et prénom requis"));
|
||||||
return combRepository.find("LOWER(lname) LIKE LOWER(?1) AND LOWER(fname) LIKE LOWER(?2)", lname,
|
return combRepository.find("unaccent(lname) ILIKE unaccent(?1) AND unaccent(fname) ILIKE unaccent(?2)", lname,
|
||||||
fname).firstResult()
|
fname).firstResult()
|
||||||
.invoke(Unchecked.consumer(combModel -> {
|
.invoke(Unchecked.consumer(combModel -> {
|
||||||
if (combModel == null)
|
if (combModel == null)
|
||||||
|
|||||||
@ -69,7 +69,8 @@ public class MembreService {
|
|||||||
|
|
||||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||||
repository.find("licence = ?1 AND (LOWER(lname) LIKE LOWER(?2) OR LOWER(fname) LIKE LOWER(?2))",
|
repository.find(
|
||||||
|
"licence = ?1 AND (unaccent(lname) ILIKE unaccent(?2) OR unaccent(fname) ILIKE unaccent(?2))",
|
||||||
licence, np).firstResult().map(SimpleCombModel::fromModel)));
|
licence, np).firstResult().map(SimpleCombModel::fromModel)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,19 +79,22 @@ public class MembreService {
|
|||||||
() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleCombModel::fromModel)));
|
() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleCombModel::fromModel)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final static String FIND_NAME_REQUEST = "unaccent(fname) ILIKE unaccent(?1) OR unaccent(lname) ILIKE unaccent(?1) " +
|
||||||
|
"OR unaccent(fname || ' ' || lname) ILIKE unaccent(?1) OR unaccent(lname || ' ' || fname) ILIKE unaccent(?1)";
|
||||||
|
|
||||||
public Uni<PageResult<SimpleMembre>> searchAdmin(int limit, int page, String search, String club) {
|
public Uni<PageResult<SimpleMembre>> searchAdmin(int limit, int page, String search, String club) {
|
||||||
if (search == null)
|
if (search == null)
|
||||||
search = "";
|
search = "";
|
||||||
search = search + "%";
|
search = "%" + search.replaceAll(" ", "% %") + "%";
|
||||||
|
|
||||||
PanacheQuery<MembreModel> query;
|
PanacheQuery<MembreModel> query;
|
||||||
|
|
||||||
if (club == null || club.isBlank())
|
if (club == null || club.isBlank()) {
|
||||||
query = repository.find("(LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?1))",
|
query = repository.find(FIND_NAME_REQUEST, Sort.ascending("fname", "lname"), search)
|
||||||
Sort.ascending("fname", "lname"), search).page(Page.ofSize(limit));
|
.page(Page.ofSize(limit));
|
||||||
else
|
} else
|
||||||
query = repository.find(
|
query = repository.find(
|
||||||
"LOWER(club.name) LIKE LOWER(?2) AND (LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?1))",
|
"LOWER(club.name) LIKE LOWER(?2) AND (" + FIND_NAME_REQUEST + ")",
|
||||||
Sort.ascending("fname", "lname"), search, club + "%").page(Page.ofSize(limit));
|
Sort.ascending("fname", "lname"), search, club + "%").page(Page.ofSize(limit));
|
||||||
return getPageResult(query, limit, page);
|
return getPageResult(query, limit, page);
|
||||||
}
|
}
|
||||||
@ -98,12 +102,13 @@ public class MembreService {
|
|||||||
public Uni<PageResult<SimpleMembre>> search(int limit, int page, String search, String subject) {
|
public Uni<PageResult<SimpleMembre>> search(int limit, int page, String search, String subject) {
|
||||||
if (search == null)
|
if (search == null)
|
||||||
search = "";
|
search = "";
|
||||||
search = search + "%";
|
search = "%" + search.replaceAll(" ", "% %") + "%";
|
||||||
|
|
||||||
String finalSearch = search;
|
String finalSearch = search;
|
||||||
return repository.find("userId = ?1", subject).firstResult()
|
return repository.find("userId = ?1", subject).firstResult()
|
||||||
.chain(membreModel -> {
|
.chain(membreModel -> {
|
||||||
PanacheQuery<MembreModel> query = repository.find(
|
PanacheQuery<MembreModel> query = repository.find(
|
||||||
"club = ?1 AND (LOWER(lname) LIKE LOWER(?2) OR LOWER(fname) LIKE LOWER(?2))",
|
"club = ?1 AND (" + FIND_NAME_REQUEST + ")",
|
||||||
Sort.ascending("fname", "lname"), membreModel.getClub(), finalSearch)
|
Sort.ascending("fname", "lname"), membreModel.getClub(), finalSearch)
|
||||||
.page(Page.ofSize(limit));
|
.page(Page.ofSize(limit));
|
||||||
return getPageResult(query, limit, page);
|
return getPageResult(query, limit, page);
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
# DEV
|
|
||||||
%dev.quarkus.datasource.db-kind=mysql
|
|
||||||
%dev.quarkus.datasource.reactive.url=mysql://${database.hostname}:${database.port}/${database.database}?charset=utf8mb4
|
|
||||||
|
|
||||||
# DB
|
# DB
|
||||||
quarkus.datasource.db-kind=postgresql
|
quarkus.datasource.db-kind=postgresql
|
||||||
quarkus.datasource.username=${database.user}
|
quarkus.datasource.username=${database.user}
|
||||||
@ -11,6 +7,8 @@ quarkus.datasource.reactive.url=postgresql://${database.hostname}:${database.por
|
|||||||
quarkus.hibernate-orm.database.generation=update
|
quarkus.hibernate-orm.database.generation=update
|
||||||
quarkus.hibernate-orm.physical-naming-strategy=fr.titionfire.ffsaf.data.SafcaNamingStrategy
|
quarkus.hibernate-orm.physical-naming-strategy=fr.titionfire.ffsaf.data.SafcaNamingStrategy
|
||||||
|
|
||||||
|
quarkus.hibernate-orm.dialect=fr.titionfire.ffsaf.data.CustomPostgreSQLDialect
|
||||||
|
|
||||||
quarkus.http.cors=true
|
quarkus.http.cors=true
|
||||||
quarkus.quartz.start-mode=forced
|
quarkus.quartz.start-mode=forced
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user