Skip to content

Commit 51d09c5

Browse files
committed
HHH-8893 HBM transform/mock
asdf
1 parent 3e1d73c commit 51d09c5

File tree

93 files changed

+1089
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1089
-358
lines changed

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/HibernateTypeSourceImpl.java

+3-17
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,9 @@ public HibernateTypeSourceImpl(String name) {
6464
}
6565

6666
public HibernateTypeSourceImpl(final PluralAttributeElementDetails element) {
67-
this.nameHolder = new ValueHolder<String>(
68-
new ValueHolder.DeferredInitializer<String>() {
69-
@Override
70-
public String initialize() {
71-
return element.getTypeResolver().getExplicitHibernateTypeName();
72-
}
73-
}
74-
);
75-
this.parameterHolder = new ValueHolder<Map<String, String>>(
76-
new ValueHolder.DeferredInitializer<Map<String, String>>() {
77-
@Override
78-
public Map<String, String> initialize() {
79-
return element.getTypeResolver().getExplicitHibernateTypeParameters();
80-
}
81-
}
82-
);
83-
this.javaType = element.getJavaType();
67+
this.name = element.getTypeResolver().getExplicitHibernateTypeName();
68+
this.parameters = element.getTypeResolver().getExplicitHibernateTypeParameters();
69+
this.javaTypeDescriptor = element.getJavaType();
8470
}
8571

8672
@Override

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/util/HibernateDotNames.java

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.hibernate.annotations.DynamicInsert;
4444
import org.hibernate.annotations.DynamicUpdate;
4545
import org.hibernate.annotations.Fetch;
46+
import org.hibernate.annotations.FetchMode;
4647
import org.hibernate.annotations.FetchProfile;
4748
import org.hibernate.annotations.FetchProfiles;
4849
import org.hibernate.annotations.Filter;
@@ -138,6 +139,7 @@ public interface HibernateDotNames {
138139
DotName DYNAMIC_INSERT = DotName.createSimple( DynamicInsert.class.getName() );
139140
DotName DYNAMIC_UPDATE = DotName.createSimple( DynamicUpdate.class.getName() );
140141
DotName FETCH = DotName.createSimple( Fetch.class.getName() );
142+
DotName FETCH_MODE = DotName.createSimple( FetchMode.class.getName() );
141143
DotName FETCH_PROFILE = DotName.createSimple( FetchProfile.class.getName() );
142144
DotName FETCH_PROFILES = DotName.createSimple( FetchProfiles.class.getName() );
143145
DotName FETCH_OVERRIDE = DotName.createSimple( FetchProfile.FetchOverride.class.getName() );

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AbstractMocker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
import java.util.ArrayList;
2727
import java.util.List;
28+
2829
import javax.persistence.AccessType;
2930

3031
import org.hibernate.internal.util.collections.CollectionHelper;
3132
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
3233
import org.hibernate.metamodel.source.internal.jaxb.JaxbIndex;
3334
import org.hibernate.metamodel.source.internal.jaxb.JaxbUniqueConstraint;
34-
3535
import org.jboss.jandex.AnnotationInstance;
3636
import org.jboss.jandex.AnnotationTarget;
3737
import org.jboss.jandex.AnnotationValue;

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AnnotationMocker.java

+8
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ protected AnnotationInstance parseColumn(JaxbColumn column, AnnotationTarget tar
162162
if ( column == null ) {
163163
return null;
164164
}
165+
166+
// TODO: Not sure if this should be here...
165167
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
168+
MockHelper.stringValue( "forColumn", column.getName(), annotationValueList );
169+
MockHelper.stringValue( "read", column.getRead(), annotationValueList );
170+
MockHelper.stringValue( "write", column.getWrite(), annotationValueList );
171+
create( HibernateDotNames.COLUMN_TRANSFORMER, target, annotationValueList );
172+
173+
annotationValueList = new ArrayList<AnnotationValue>();
166174
MockHelper.stringValue( "name", column.getName(), annotationValueList );
167175
MockHelper.stringValue( "columnDefinition", column.getColumnDefinition(), annotationValueList );
168176
MockHelper.stringValue( "table", column.getTable(), annotationValueList );

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/AttributesBuilder.java

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class AttributesBuilder extends AbstractAttributesBuilder {
5959

6060
@Override
6161
protected void parse() {
62+
if (getAttributesContainer() == null) {
63+
return;
64+
}
65+
6266
super.parse();
6367

6468
if ( attributes.getNaturalId() != null ) {

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/ElementCollectionMocker.java

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected void doProcess() {
8484
parseMapKey( elementCollection.getMapKey(), getTarget() );
8585
parseMapKeyColumn( elementCollection.getMapKeyColumn(), getTarget() );
8686
parseMapKeyClass( elementCollection.getMapKeyClass(), getTarget() );
87+
parseMapKeyType( elementCollection.getMapKeyType(), getTarget() );
8788
parseMapKeyEnumerated( elementCollection.getMapKeyEnumerated(), getTarget() );
8889
parseMapKeyTemporal( elementCollection.getMapKeyTemporal(), getTarget() );
8990
}

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/EntityMocker.java

+56-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.hibernate.metamodel.source.internal.jandex;
2525

26+
import java.io.Serializable;
2627
import java.util.ArrayList;
2728
import java.util.List;
2829
import java.util.Map;
@@ -38,6 +39,7 @@
3839
import org.hibernate.metamodel.source.internal.jaxb.JaxbDiscriminatorColumn;
3940
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntity;
4041
import org.hibernate.metamodel.source.internal.jaxb.JaxbEntityListeners;
42+
import org.hibernate.metamodel.source.internal.jaxb.JaxbHbmFilter;
4143
import org.hibernate.metamodel.source.internal.jaxb.JaxbIdClass;
4244
import org.hibernate.metamodel.source.internal.jaxb.JaxbInheritance;
4345
import org.hibernate.metamodel.source.internal.jaxb.JaxbPostLoad;
@@ -103,7 +105,13 @@ protected void doProcess() {
103105
parseSecondaryTableList( entity.getSecondaryTable(), getTarget() );
104106

105107
//@Cache
106-
parseCache( entity.getCache() );
108+
parseCache( entity.getCache(), getTarget() );
109+
110+
// @Filters
111+
parseFilters( entity.getFilter(), getTarget() );
112+
113+
// @BatchSize
114+
parseBatchSize( entity.getBatchSize(), getTarget() );
107115
}
108116

109117
//@Table (entity only)
@@ -295,7 +303,7 @@ protected AnnotationValue[] nestedSecondaryTableList(String name, List<JaxbSecon
295303

296304
}
297305

298-
private void parseCache(JaxbCacheElement cache) {
306+
private void parseCache(JaxbCacheElement cache, AnnotationTarget target) {
299307
if ( cache == null ) {
300308
return;
301309
}
@@ -304,6 +312,51 @@ private void parseCache(JaxbCacheElement cache) {
304312
MockHelper.stringValue( "include", cache.getInclude(), annotationValueList );
305313
MockHelper.enumValue( "usage", HibernateDotNames.CACHE_CONCURRENCY_STRATEGY,
306314
CacheConcurrencyStrategy.parse( cache.getUsage() ), annotationValueList );
307-
create( HibernateDotNames.CACHE, annotationValueList );
315+
create( HibernateDotNames.CACHE, target, annotationValueList );
316+
}
317+
318+
private void parseFilters(List<JaxbHbmFilter> filters, AnnotationTarget target) {
319+
if (! filters.isEmpty() ) {
320+
AnnotationValue[] filterAnnotations = new AnnotationValue[filters.size()];
321+
int i = 0;
322+
for ( JaxbHbmFilter filter : filters ) {
323+
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
324+
MockHelper.stringValue( "name", filter.getName(), annotationValueList );
325+
326+
String condition = "";
327+
if (! StringHelper.isEmpty( filter.getConditionAttribute() )) {
328+
condition = filter.getConditionAttribute();
329+
}
330+
331+
for (Serializable contentElement : filter.getContent()) {
332+
if ( String.class.isInstance( contentElement ) ) {
333+
String s = (String) contentElement;
334+
condition = s.trim();
335+
}
336+
// TODO: Could be aliases -- see xsd
337+
}
338+
339+
MockHelper.stringValue( "condition", condition, annotationValueList );
340+
341+
AnnotationInstance annotationInstance = create(
342+
HibernateDotNames.FILTER, null, annotationValueList );
343+
filterAnnotations[i++] = MockHelper.nestedAnnotationValue( "", annotationInstance );
344+
}
345+
346+
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
347+
MockHelper.addToCollectionIfNotNull( annotationValueList,
348+
AnnotationValue.createArrayValue( "value", filterAnnotations ) );
349+
350+
create( HibernateDotNames.FILTERS, target, annotationValueList );
351+
}
352+
}
353+
354+
private void parseBatchSize(Integer batchSize, AnnotationTarget target) {
355+
if ( batchSize == null ) {
356+
return;
357+
}
358+
List<AnnotationValue> annotationValueList = new ArrayList<AnnotationValue>();
359+
MockHelper.integerValue( "size", batchSize, annotationValueList );
360+
create( HibernateDotNames.BATCH_SIZE, target, annotationValueList );
308361
}
309362
}

Diff for: hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/jandex/GlobalAnnotationMocker.java

+107
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
import java.util.Collection;
2828
import java.util.List;
2929

30+
import org.hibernate.annotations.FetchMode;
31+
import org.hibernate.internal.util.StringHelper;
3032
import org.hibernate.internal.util.collections.CollectionHelper;
3133
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;
3238
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedNativeQuery;
3339
import org.hibernate.metamodel.source.internal.jaxb.JaxbNamedQuery;
3440
import org.hibernate.metamodel.source.internal.jaxb.JaxbQueryHint;
@@ -39,6 +45,7 @@
3945
import org.hibernate.metamodel.source.internal.jaxb.JaxbSqlResultSetMappingFieldResult;
4046
import org.hibernate.metamodel.source.internal.jaxb.JaxbTableGenerator;
4147
import org.jboss.jandex.AnnotationInstance;
48+
import org.jboss.jandex.AnnotationTarget;
4249
import org.jboss.jandex.AnnotationValue;
4350

4451
/**
@@ -73,6 +80,12 @@ void process() {
7380
if ( !globalAnnotations.getSqlResultSetMappingMap().isEmpty() ) {
7481
parseSqlResultSetMappings( globalAnnotations.getSqlResultSetMappingMap().values() );
7582
}
83+
if ( !globalAnnotations.getFilterDefMap().isEmpty() ) {
84+
parseFilterDefs( globalAnnotations.getFilterDefMap().values() );
85+
}
86+
if ( !globalAnnotations.getFetchProfileMap().isEmpty() ) {
87+
parseFetchProfiles( globalAnnotations.getFetchProfileMap().values() );
88+
}
7689
indexBuilder.finishGlobalConfigurationMocking( globalAnnotations );
7790
}
7891

@@ -309,6 +322,100 @@ private AnnotationInstance parseTableGenerator(JaxbTableGenerator generator) {
309322

310323
);
311324
}
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+
}
312419

313420
@Override
314421
protected AnnotationInstance push(AnnotationInstance annotationInstance) {

0 commit comments

Comments
 (0)