|
27 | 27 | import java.util.Collection;
|
28 | 28 | import java.util.List;
|
29 | 29 |
|
| 30 | +import org.hibernate.annotations.FetchMode; |
| 31 | +import org.hibernate.internal.util.StringHelper; |
30 | 32 | import org.hibernate.internal.util.collections.CollectionHelper;
|
31 | 33 | import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
|
| 34 | +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFilterDef; |
| 35 | +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFetchProfile.JaxbFetch; |
| 36 | +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFilterDef.JaxbFilterParam; |
| 37 | +import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFetchProfile; |
32 | 38 | import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery;
|
33 | 39 | import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery;
|
34 | 40 | import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryHint;
|
|
39 | 45 | import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingFieldResult;
|
40 | 46 | import org.hibernate.metamodel.source.internal.jaxb.JaxbTableGenerator;
|
41 | 47 | import org.jboss.jandex.AnnotationInstance;
|
| 48 | +import org.jboss.jandex.AnnotationTarget; |
42 | 49 | import org.jboss.jandex.AnnotationValue;
|
43 | 50 |
|
44 | 51 | /**
|
@@ -73,6 +80,12 @@ void process() {
|
73 | 80 | if ( !globalAnnotations.getSqlResultSetMappingMap().isEmpty() ) {
|
74 | 81 | parseSqlResultSetMappings( globalAnnotations.getSqlResultSetMappingMap().values() );
|
75 | 82 | }
|
| 83 | + if ( !globalAnnotations.getFilterDefMap().isEmpty() ) { |
| 84 | + parseFilterDefs( globalAnnotations.getFilterDefMap().values() ); |
| 85 | + } |
| 86 | + if ( !globalAnnotations.getFetchProfileMap().isEmpty() ) { |
| 87 | + parseFetchProfiles( globalAnnotations.getFetchProfileMap().values() ); |
| 88 | + } |
76 | 89 | indexBuilder.finishGlobalConfigurationMocking( globalAnnotations );
|
77 | 90 | }
|
78 | 91 |
|
@@ -309,6 +322,100 @@ private AnnotationInstance parseTableGenerator(JaxbTableGenerator generator) {
|
309 | 322 |
|
310 | 323 | );
|
311 | 324 | }
|
| 325 | + |
| 326 | + private void parseFilterDefs(Collection<JaxbHbmFilterDef> filterDefs) { |
| 327 | + if (! filterDefs.isEmpty() ) { |
| 328 | + AnnotationValue[] filterDefAnnotations = new AnnotationValue[filterDefs.size()]; |
| 329 | + int i = 0; |
| 330 | + for ( JaxbHbmFilterDef filterDef : filterDefs ) { |
| 331 | + List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>(); |
| 332 | + MockHelper.stringValue( "name", filterDef.getName(), annotationValueList ); |
| 333 | + MockHelper.stringValue( "defaultCondition", filterDef.getCondition(), annotationValueList ); |
| 334 | + nestedFilterParams( filterDef.getFilterParam(), annotationValueList ); |
| 335 | + |
| 336 | + AnnotationInstance annotationInstance = create( |
| 337 | + HibernateDotNames.FILTER_DEF, null, annotationValueList ); |
| 338 | + filterDefAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); |
| 339 | + } |
| 340 | + |
| 341 | + List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>(); |
| 342 | + MockHelper.addToCollectionIfNotNull( annotationValueList, |
| 343 | + AnnotationValue.createArrayValue( "value", filterDefAnnotations ) ); |
| 344 | + |
| 345 | + create( HibernateDotNames.FILTER_DEFS, null, annotationValueList ); |
| 346 | + } |
| 347 | + } |
| 348 | + |
| 349 | + private void nestedFilterParams(List<JaxbFilterParam> filterParams, List<AnnotationValue> annotationValueList) { |
| 350 | + if (! filterParams.isEmpty() ) { |
| 351 | + AnnotationValue[] filterParamAnnotations = new AnnotationValue[filterParams.size()]; |
| 352 | + int i = 0; |
| 353 | + for ( JaxbFilterParam filterParam : filterParams ) { |
| 354 | + List<AnnotationValue> filterParamannotationValueList = new ArrayList<AnnotationValue>(); |
| 355 | + MockHelper.stringValue( "name", filterParam.getName(), filterParamannotationValueList ); |
| 356 | + MockHelper.stringValue( "type", filterParam.getType(), filterParamannotationValueList ); |
| 357 | + |
| 358 | + AnnotationInstance annotationInstance = create( |
| 359 | + HibernateDotNames.PARAM_DEF, null, filterParamannotationValueList ); |
| 360 | + filterParamAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); |
| 361 | + } |
| 362 | + MockHelper.addToCollectionIfNotNull( annotationValueList, |
| 363 | + AnnotationValue.createArrayValue( "parameters", filterParamAnnotations ) ); |
| 364 | + } |
| 365 | + } |
| 366 | + |
| 367 | + private void parseFetchProfiles(Collection<JaxbHbmFetchProfile> fetchProfiles) { |
| 368 | + if (! fetchProfiles.isEmpty() ) { |
| 369 | + AnnotationValue[] fetchProfileAnnotations = new AnnotationValue[fetchProfiles.size()]; |
| 370 | + int i = 0; |
| 371 | + for ( JaxbHbmFetchProfile fetchProfile : fetchProfiles ) { |
| 372 | + AnnotationInstance annotationInstance = parseFetchProfile( fetchProfile ); |
| 373 | + fetchProfileAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); |
| 374 | + } |
| 375 | + |
| 376 | + List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>(); |
| 377 | + MockHelper.addToCollectionIfNotNull( annotationValueList, |
| 378 | + AnnotationValue.createArrayValue( "value", fetchProfileAnnotations ) ); |
| 379 | + |
| 380 | + create( HibernateDotNames.FETCH_PROFILES, null, annotationValueList ); |
| 381 | + } |
| 382 | + } |
| 383 | + |
| 384 | + private AnnotationInstance parseFetchProfile(JaxbHbmFetchProfile fetchProfile) { |
| 385 | + List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>(); |
| 386 | + MockHelper.stringValue( "name", fetchProfile.getName(), annotationValueList ); |
| 387 | + |
| 388 | + AnnotationValue[] fetchAnnotations = new AnnotationValue[fetchProfile.getFetch().size()]; |
| 389 | + int i = 0; |
| 390 | + for ( JaxbFetch fetch : fetchProfile.getFetch() ) { |
| 391 | + List<AnnotationValue> fetchAnnotationValueList = new ArrayList<AnnotationValue>(); |
| 392 | + MockHelper.stringValue( "association", fetch.getAssociation(), fetchAnnotationValueList ); |
| 393 | + MockHelper.classValue( "entity", fetch.getEntity(), fetchAnnotationValueList, getDefaults(), |
| 394 | + indexBuilder.getServiceRegistry() ); |
| 395 | + MockHelper.enumValue( "mode", HibernateDotNames.FETCH_MODE, convertFetchMode( fetch.getStyle() ), |
| 396 | + fetchAnnotationValueList ); |
| 397 | + AnnotationInstance annotationInstance = create( |
| 398 | + HibernateDotNames.FETCH_OVERRIDE, null, fetchAnnotationValueList ); |
| 399 | + fetchAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance ); |
| 400 | + } |
| 401 | + |
| 402 | + MockHelper.addToCollectionIfNotNull( annotationValueList, |
| 403 | + AnnotationValue.createArrayValue( "fetchOverrides", fetchAnnotations ) ); |
| 404 | + |
| 405 | + return create(HibernateDotNames.FETCH_PROFILE, null, annotationValueList ); |
| 406 | + } |
| 407 | + |
| 408 | + private FetchMode convertFetchMode(String fetchMode) { |
| 409 | + if (fetchMode.equalsIgnoreCase( "join" )) { |
| 410 | + return FetchMode.JOIN; |
| 411 | + } |
| 412 | + else if (fetchMode.equalsIgnoreCase( "subselect" )) { |
| 413 | + return FetchMode.SUBSELECT; |
| 414 | + } |
| 415 | + else { |
| 416 | + return FetchMode.SELECT; |
| 417 | + } |
| 418 | + } |
312 | 419 |
|
313 | 420 | @Override
|
314 | 421 | protected AnnotationInstance push(AnnotationInstance annotationInstance) {
|
|
0 commit comments