Skip to content

Commit

Permalink
wip: refactor after review
Browse files Browse the repository at this point in the history
Related to quarkusio#6192
  • Loading branch information
aureamunoz committed Dec 23, 2019
1 parent 583e628 commit 1f1557b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package io.quarkus.spring.data.deployment;

import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.toList;

import java.lang.reflect.Modifier;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
Expand Down Expand Up @@ -55,33 +65,43 @@ void build(CombinedIndexBuildItem index,
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

detectAndLogSpecificSpringPropertiesIfExist();

IndexView indexIndex = index.getIndex();
List<ClassInfo> interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES,
indexIndex);

removeNoRepositoryBeanClasses(interfacesExtendingCrudRepository);
implementCrudRepositories(generatedBeans, additionalBeans, interfacesExtendingCrudRepository, indexIndex);
}

private void detectAndLogSpecificSpringPropertiesIfExist() {
Config config = ConfigProvider.getConfig();
Optional<String> springJpaConfig = config.getOptionalValue("spring.jpa.show-sql", String.class);
Map<String, String> springJpaPropertiesMap = new HashMap<>();
springJpaPropertiesMap.put("spring.jpa.show-sql", "quarkus.hibernate-orm.log.sql");
springJpaPropertiesMap.put("spring.jpa.properties.hibernate.dialect ", "quarkus.hibernate-orm.dialect");
springJpaPropertiesMap.put("spring.jpa.properties.hibernate.dialect.storage_engine",
Map<String, String> springJpaToQuarkusOrmPropertiesMap = new HashMap<>();
springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.show-sql", "quarkus.hibernate-orm.log.sql");
springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.properties.hibernate.dialect ", "quarkus.hibernate-orm.dialect");
springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.properties.hibernate.dialect.storage_engine",
"quarkus.hibernate-orm.dialect.storage-engine");
springJpaPropertiesMap.put("spring.jpa.generate-ddl", "quarkus.hibernate-orm.database.generation");
springJpaToQuarkusOrmPropertiesMap.put("spring.jpa.generate-ddl", "quarkus.hibernate-orm.database.generation");

Iterable<String> iterablePropertyNames = config.getPropertyNames();
List<String> propertyNames = new ArrayList<String>();
iterablePropertyNames.forEach(propertyNames::add);
List<String> springProperties = propertyNames.stream().filter(s -> s.matches("spring.jpa.*")).collect(toList());
Pattern pattern = Pattern.compile("spring\\.jpa\\..*");
Matcher matcher = pattern.matcher("");
List<String> springProperties = propertyNames.stream().filter(s -> matcher.reset(s).matches()).collect(toList());
if (!springProperties.isEmpty()) {
String warningLog = "Quarkus does not support the ";
for (String springProperty : springProperties) {
LOGGER.warn("Quarkus does not support the " + springProperty
+ " you may try to use the quarkus equivalent : " + springJpaPropertiesMap.get(springProperty));
String quarkusProperty = springJpaToQuarkusOrmPropertiesMap.get(springProperty);
if (quarkusProperty != null) {
warningLog = warningLog + springProperty + "property " + "you may try to use the Quarkus equivalent one : "
+ quarkusProperty + ".";
}
LOGGER.warn(warningLog + springProperty + "property. ");
}

}

IndexView indexIndex = index.getIndex();
List<ClassInfo> interfacesExtendingCrudRepository = getAllInterfacesExtending(DotNames.SUPPORTED_REPOSITORIES,
indexIndex);

removeNoRepositoryBeanClasses(interfacesExtendingCrudRepository);
implementCrudRepositories(generatedBeans, additionalBeans, interfacesExtendingCrudRepository, indexIndex);
}

private void removeNoRepositoryBeanClasses(List<ClassInfo> interfacesExtendingCrudRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ quarkus.hibernate-orm.database.generation=drop-and-create
#quarkus.hibernate-orm.log.sql=true

%prod.quarkus.hibernate-orm.sql-load-script=import.sql
spring.jpa.show-sql=true
spring.jpa.data.hibernate.dialect=blabla

0 comments on commit 1f1557b

Please sign in to comment.