Skip to content

Commit

Permalink
\sebersole#27 - --wip-- additional @Filter work
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Oct 24, 2023
1 parent 2a3b6bb commit 990879d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.hibernate.models.internal.CollectionHelper.isEmpty;
import static org.hibernate.models.orm.HibernateAnnotations.COLLECTION_TYPE_REG;
import static org.hibernate.models.orm.HibernateAnnotations.COMPOSITE_TYPE_REG;
import static org.hibernate.models.orm.HibernateAnnotations.CONVERTER_REG;
Expand Down Expand Up @@ -418,6 +419,10 @@ public void collectFilterDefinitions(AnnotationTarget annotationTarget) {

private Map<String, ClassDetails> extractFilterParameters(AnnotationUsage<FilterDef> source) {
final List<AnnotationUsage<ParamDef>> parameters = source.getAttributeValue( "parameters" );
if ( isEmpty( parameters ) ) {
return null;
}

final Map<String, ClassDetails> result = new HashMap<>( parameters.size() );
for ( AnnotationUsage<ParamDef> parameter : parameters ) {
result.put( parameter.getAttributeValue( "name" ), parameter.getAttributeValue( "type" ) );
Expand All @@ -439,14 +444,13 @@ public void collectFilterDefinitions(List<JaxbFilterDefImpl> filterDefinitions)

private Map<String, ClassDetails> extractFilterParameters(JaxbFilterDefImpl source) {
final List<JaxbFilterDefImpl.JaxbFilterParamImpl> parameters = source.getFilterParam();

// todo : update the mapping.xsd to account for new @ParamDef definition
// todo : handle simplified type names for XML, e.g. "String" instead of "java.lang.String",
// this can be done using XmlAnnotationHelper#resolveJavaType once integrated
if ( isEmpty( parameters ) ) {
return null;
}

final Map<String, ClassDetails> result = new HashMap<>( parameters.size() );
for ( JaxbFilterDefImpl.JaxbFilterParamImpl parameter : parameters ) {
// for now, don't check whether nothing was specified; this situation this
// for now, don't check whether nothing was specified; this situation
// should resolve to Object - let's see how that reacts
final ClassDetails targetClassDetails = XmlAnnotationHelper.resolveJavaType(
parameter.getType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private static void processEntityMetadata(
sourceModelBuildingContext
);

XmlAnnotationHelper.applyFilters( jaxbEntity.getFilter(), classDetails, sourceModelBuildingContext );
XmlAnnotationHelper.applyFilters( jaxbEntity.getFilters(), classDetails, sourceModelBuildingContext );

// todo : id-class
// todo : callbacks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
import org.hibernate.boot.jaxb.mapping.spi.JaxbGeneratedValueImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbLobImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNationalizedImpl;
Expand Down Expand Up @@ -93,6 +94,7 @@
import static org.hibernate.models.internal.CollectionHelper.arrayList;
import static org.hibernate.models.internal.CollectionHelper.isEmpty;
import static org.hibernate.models.orm.xml.internal.XmlProcessingHelper.getOrMakeAnnotation;
import static org.hibernate.models.orm.xml.internal.XmlProcessingHelper.getOrMakeNamedAnnotation;
import static org.hibernate.models.orm.xml.internal.XmlProcessingHelper.makeAnnotation;

/**
Expand Down Expand Up @@ -776,7 +778,7 @@ public static void applyJdbcTypeCode(
}

static void applyFilters(
List<JaxbHbmFilter> jaxbFilters,
List<JaxbHbmFilterImpl> jaxbFilters,
MutableAnnotationTarget target,
SourceModelBuildingContext sourceModelBuildingContext) {
// todo : apply filters to collections as well, after xsd is update to support them
Expand All @@ -786,7 +788,7 @@ static void applyFilters(
return;
}

for ( JaxbHbmFilter jaxbFilter : jaxbFilters ) {
for ( JaxbHbmFilterImpl jaxbFilter : jaxbFilters ) {
final MutableAnnotationUsage<Filter> filterAnn = getOrMakeNamedAnnotation(
Filter.class,
jaxbFilter.getName(),
Expand All @@ -800,8 +802,7 @@ static void applyFilters(
if ( !isEmpty( content ) ) {
final List<MutableAnnotationUsage<SqlFragmentAlias>> aliases = arrayList( content.size() );
for ( Serializable c : content ) {
assert c instanceof JaxbHbmFilter.JaxbAliases;
final JaxbHbmFilter.JaxbAliases alias = (JaxbHbmFilter.JaxbAliases) c;
final JaxbHbmFilterImpl.JaxbAliasesImpl alias = (JaxbHbmFilterImpl.JaxbAliasesImpl) c;
final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn = makeAnnotation(
SqlFragmentAlias.class,
null
Expand Down

0 comments on commit 990879d

Please sign in to comment.