-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hibernate Search: Add support for projection constructors
- Loading branch information
Showing
8 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
.../search/orm/elasticsearch/runtime/mapping/QuarkusHibernateOrmSearchMappingConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.runtime.mapping; | ||
|
||
import java.util.Set; | ||
|
||
import org.hibernate.search.mapper.orm.mapping.HibernateOrmMappingConfigurationContext; | ||
import org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer; | ||
|
||
public class QuarkusHibernateOrmSearchMappingConfigurer implements HibernateOrmSearchMappingConfigurer { | ||
private final Set<Class<?>> rootAnnotationMappedClasses; | ||
|
||
public QuarkusHibernateOrmSearchMappingConfigurer(Set<Class<?>> rootAnnotationMappedClasses) { | ||
this.rootAnnotationMappedClasses = rootAnnotationMappedClasses; | ||
} | ||
|
||
@Override | ||
public void configure(HibernateOrmMappingConfigurationContext context) { | ||
// Jandex is not available at runtime in Quarkus, | ||
// so Hibernate Search cannot perform classpath scanning on startup. | ||
context.annotationMapping() | ||
.discoverJandexIndexesFromAddedTypes(false) | ||
.buildMissingDiscoveredJandexIndexes(false); | ||
|
||
// ... but we do better: we perform classpath scanning during the build, | ||
// and propagate the result here. | ||
context.annotationMapping().add(rootAnnotationMappedClasses); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rch/src/main/java/io/quarkus/it/hibernate/search/orm/elasticsearch/search/AddressDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.it.hibernate.search.orm.elasticsearch.search; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor; | ||
|
||
// Ideally we'd use records, but Quarkus still has to compile with JDK 11 at the moment. | ||
public class AddressDTO { | ||
public final String city; | ||
|
||
@ProjectionConstructor | ||
public AddressDTO(String city) { | ||
this.city = city; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AddressDTO{" + | ||
"city='" + city + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...arch/src/main/java/io/quarkus/it/hibernate/search/orm/elasticsearch/search/PersonDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.it.hibernate.search.orm.elasticsearch.search; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IdProjection; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor; | ||
|
||
// Ideally we'd use records, but Quarkus still has to compile with JDK 11 at the moment. | ||
public class PersonDTO { | ||
public final long id; | ||
public final String name; | ||
public final AddressDTO address; | ||
|
||
@ProjectionConstructor | ||
public PersonDTO(@IdProjection long id, String name, AddressDTO address) { | ||
this.id = id; | ||
this.name = name; | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PersonDTO{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
", address=" + address + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters