Skip to content

Commit e1f7ee8

Browse files
committed
HHH-6480 - Develop component binding for new metamodel
1 parent 91f84c2 commit e1f7ee8

File tree

9 files changed

+396
-98
lines changed

9 files changed

+396
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.metamodel.source.annotations.entity;
25+
26+
import java.util.List;
27+
28+
import org.hibernate.internal.util.Value;
29+
import org.hibernate.mapping.PropertyGeneration;
30+
import org.hibernate.metamodel.source.LocalBindingContext;
31+
import org.hibernate.metamodel.source.binder.AttributeSource;
32+
import org.hibernate.metamodel.source.binder.ComponentAttributeSource;
33+
import org.hibernate.metamodel.source.binder.ExplicitHibernateTypeSource;
34+
import org.hibernate.metamodel.source.binder.MetaAttributeSource;
35+
import org.hibernate.metamodel.source.binder.RelationalValueSource;
36+
import org.hibernate.metamodel.source.binder.SingularAttributeNature;
37+
38+
/**
39+
* @author Steve Ebersole
40+
*/
41+
public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
42+
private final EmbeddableClass component;
43+
private final ConfiguredClass parent;
44+
45+
private final Value<Class<?>> classReference;
46+
47+
public ComponentAttributeSourceImpl(EmbeddableClass component, ConfiguredClass parent) {
48+
this.component = component;
49+
this.parent = parent;
50+
51+
this.classReference = new Value<Class<?>>( component.getClass() );
52+
}
53+
54+
@Override
55+
public String getClassName() {
56+
return component.getClass().getName();
57+
}
58+
59+
@Override
60+
public Value<Class<?>> getClassReference() {
61+
return classReference;
62+
}
63+
64+
@Override
65+
public String getParentReferenceAttributeName() {
66+
// todo : do annotations support this?
67+
return null;
68+
}
69+
70+
@Override
71+
public String getPath() {
72+
// todo : implement
73+
// do not see how this is possible currently given how annotations currently handle components
74+
return null;
75+
}
76+
77+
@Override
78+
public Iterable<AttributeSource> attributeSources() {
79+
// todo : implement
80+
return null;
81+
}
82+
83+
@Override
84+
public LocalBindingContext getLocalBindingContext() {
85+
return component.getLocalBindingContext();
86+
}
87+
88+
@Override
89+
public boolean isVirtualAttribute() {
90+
// todo : verify
91+
return false;
92+
}
93+
94+
@Override
95+
public SingularAttributeNature getNature() {
96+
return SingularAttributeNature.COMPONENT;
97+
}
98+
99+
@Override
100+
public ExplicitHibernateTypeSource getTypeInformation() {
101+
return null; //To change body of implemented methods use File | Settings | File Templates.
102+
}
103+
104+
@Override
105+
public String getName() {
106+
// todo : implement
107+
// do not see how this is possible currently given how annotations currently handle components
108+
return null;
109+
}
110+
111+
@Override
112+
public boolean isSingular() {
113+
return true;
114+
}
115+
116+
@Override
117+
public String getPropertyAccessorName() {
118+
// todo : implement
119+
return null;
120+
}
121+
122+
@Override
123+
public boolean isInsertable() {
124+
// todo : implement
125+
return true;
126+
}
127+
128+
@Override
129+
public boolean isUpdatable() {
130+
// todo : implement
131+
return true;
132+
}
133+
134+
@Override
135+
public PropertyGeneration getGeneration() {
136+
// todo : implement
137+
return null;
138+
}
139+
140+
@Override
141+
public boolean isLazy() {
142+
// todo : implement
143+
return false;
144+
}
145+
146+
@Override
147+
public boolean isIncludedInOptimisticLocking() {
148+
// todo : implement
149+
return true;
150+
}
151+
152+
@Override
153+
public Iterable<MetaAttributeSource> metaAttributes() {
154+
return null; //To change body of implemented methods use File | Settings | File Templates.
155+
}
156+
157+
@Override
158+
public boolean areValuesIncludedInInsertByDefault() {
159+
// todo : implement
160+
return true;
161+
}
162+
163+
@Override
164+
public boolean areValuesIncludedInUpdateByDefault() {
165+
// todo : implement
166+
return true;
167+
}
168+
169+
@Override
170+
public boolean areValuesNullableByDefault() {
171+
// todo : implement
172+
return true;
173+
}
174+
175+
@Override
176+
public List<RelationalValueSource> relationalValueSources() {
177+
return null;
178+
}
179+
}

hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/ConfiguredClass.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ public class ConfiguredClass {
130130
private final Set<String> transientFieldNames = new HashSet<String>();
131131
private final Set<String> transientMethodNames = new HashSet<String>();
132132

133-
private final AnnotationBindingContext context;
133+
private final LocalBindingContextImpl localBindingContext;
134134

135135
public ConfiguredClass(
136136
ClassInfo classInfo,
137137
AccessType defaultAccessType,
138138
ConfiguredClass parent,
139139
AnnotationBindingContext context) {
140140
this.parent = parent;
141-
this.context = context;
142141
this.classInfo = classInfo;
143142
this.clazz = context.locateClassByName( classInfo.toString() );
144143
this.configuredClassType = determineType();
@@ -147,6 +146,8 @@ public ConfiguredClass(
147146
this.idAttributeMap = new TreeMap<String, BasicAttribute>();
148147
this.associationAttributeMap = new TreeMap<String, AssociationAttribute>();
149148

149+
this.localBindingContext = new LocalBindingContextImpl( context, this );
150+
150151
collectAttributes();
151152
attributeOverrideMap = Collections.unmodifiableMap( findAttributeOverrides() );
152153
}
@@ -167,8 +168,8 @@ public ConfiguredClass getParent() {
167168
return parent;
168169
}
169170

170-
public AnnotationBindingContext getContext() {
171-
return context;
171+
public LocalBindingContextImpl getLocalBindingContext() {
172+
return localBindingContext;
172173
}
173174

174175
public ConfiguredClassType getConfiguredClassType() {
@@ -260,10 +261,10 @@ private void collectAttributes() {
260261
findTransientFieldAndMethodNames();
261262

262263
// use the class mate library to generic types
263-
ResolvedTypeWithMembers resolvedType = context.resolveMemberTypes( context.getResolvedType( clazz ) );
264+
ResolvedTypeWithMembers resolvedType = localBindingContext.resolveMemberTypes( localBindingContext.getResolvedType( clazz ) );
264265
for ( HierarchicType hierarchicType : resolvedType.allTypesAndOverrides() ) {
265266
if ( hierarchicType.getType().getErasedType().equals( clazz ) ) {
266-
resolvedType = context.resolveMemberTypes( hierarchicType.getType() );
267+
resolvedType = localBindingContext.resolveMemberTypes( hierarchicType.getType() );
267268
break;
268269
}
269270
}
@@ -446,7 +447,7 @@ private void createMappedAttribute(Member member, ResolvedTypeWithMembers resolv
446447
switch ( attributeNature ) {
447448
case BASIC: {
448449
BasicAttribute attribute = BasicAttribute.createSimpleAttribute(
449-
attributeName, attributeType, annotations, accessTypeString, getContext()
450+
attributeName, attributeType, annotations, accessTypeString, getLocalBindingContext()
450451
);
451452
if ( attribute.isId() ) {
452453
idAttributeMap.put( attributeName, attribute );
@@ -469,15 +470,15 @@ else if ( attribute.isVersioned() ) {
469470
// TODO handle the different association types
470471
default: {
471472
AssociationAttribute attribute = AssociationAttribute.createAssociationAttribute(
472-
attributeName, attributeType, attributeNature, accessTypeString, annotations, getContext()
473+
attributeName, attributeType, attributeNature, accessTypeString, annotations, getLocalBindingContext()
473474
);
474475
associationAttributeMap.put( attributeName, attribute );
475476
}
476477
}
477478
}
478479

479480
private void resolveEmbeddable(String attributeName, Class<?> type) {
480-
ClassInfo embeddableClassInfo = context.getClassInfo( type.getName() );
481+
ClassInfo embeddableClassInfo = localBindingContext.getClassInfo( type.getName() );
481482
if ( classInfo == null ) {
482483
String msg = String.format(
483484
"Attribute %s of entity %s is annotated with @Embedded, but no embeddable configuration for type %s can be found.",
@@ -488,11 +489,11 @@ private void resolveEmbeddable(String attributeName, Class<?> type) {
488489
throw new AnnotationException( msg );
489490
}
490491

491-
context.resolveAllTypes( type.getName() );
492+
localBindingContext.resolveAllTypes( type.getName() );
492493
EmbeddableHierarchy<EmbeddableClass> hierarchy = ConfiguredClassHierarchyBuilder.createEmbeddableHierarchy(
493-
context.<Object>locateClassByName( embeddableClassInfo.toString() ),
494+
localBindingContext.<Object>locateClassByName( embeddableClassInfo.toString() ),
494495
classAccessType,
495-
context
496+
localBindingContext
496497
);
497498
embeddedClasses.put( attributeName, hierarchy.getLeaf() );
498499
}

hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityClass.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ private Caching determineCachingSettings() {
492492
);
493493
if ( hibernateCacheAnnotation != null ) {
494494
final org.hibernate.cache.spi.access.AccessType accessType = hibernateCacheAnnotation.value( "usage" ) == null
495-
? getContext().getMappingDefaults().getCacheAccessType()
495+
? getLocalBindingContext().getMappingDefaults().getCacheAccessType()
496496
: CacheConcurrencyStrategy.parse( hibernateCacheAnnotation.value( "usage" ).asEnum() )
497497
.toAccessType();
498498
return new Caching(
@@ -515,7 +515,7 @@ private Caching determineCachingSettings() {
515515
}
516516

517517
final boolean doCaching;
518-
switch ( getContext().getMetadataImplementor().getOptions().getSharedCacheMode() ) {
518+
switch ( getLocalBindingContext().getMetadataImplementor().getOptions().getSharedCacheMode() ) {
519519
case ALL: {
520520
doCaching = true;
521521
break;
@@ -541,7 +541,7 @@ private Caching determineCachingSettings() {
541541

542542
return new Caching(
543543
getName(),
544-
getContext().getMappingDefaults().getCacheAccessType(),
544+
getLocalBindingContext().getMappingDefaults().getCacheAccessType(),
545545
true
546546
);
547547
}
@@ -552,8 +552,8 @@ private Caching determineCachingSettings() {
552552
* @return A table source for the specified annotation instance
553553
*/
554554
private TableSource createTableSource(AnnotationInstance tableAnnotation) {
555-
String schema = getContext().getMappingDefaults().getSchemaName();
556-
String catalog = getContext().getMappingDefaults().getCatalogName();
555+
String schema = getLocalBindingContext().getMappingDefaults().getSchemaName();
556+
String catalog = getLocalBindingContext().getMappingDefaults().getCatalogName();
557557

558558

559559
if ( tableAnnotation != null ) {
@@ -568,7 +568,7 @@ private TableSource createTableSource(AnnotationInstance tableAnnotation) {
568568
}
569569
}
570570

571-
if ( getContext().isGloballyQuotedIdentifiers() ) {
571+
if ( getLocalBindingContext().isGloballyQuotedIdentifiers() ) {
572572
schema = StringHelper.quote( schema );
573573
catalog = StringHelper.quote( catalog );
574574
}
@@ -580,8 +580,8 @@ private TableSource createTableSource(AnnotationInstance tableAnnotation) {
580580
if ( tableAnnotation != null ) {
581581
explicitTableName = JandexHelper.getValue( tableAnnotation, "name", String.class );
582582
if ( StringHelper.isNotEmpty( explicitTableName ) ) {
583-
tableName = getContext().getNamingStrategy().tableName( explicitTableName );
584-
if ( getContext().isGloballyQuotedIdentifiers() && !Identifier.isQuoted( explicitTableName ) ) {
583+
tableName = getLocalBindingContext().getNamingStrategy().tableName( explicitTableName );
584+
if ( getLocalBindingContext().isGloballyQuotedIdentifiers() && !Identifier.isQuoted( explicitTableName ) ) {
585585
tableName = StringHelper.quote( tableName );
586586
}
587587
}

0 commit comments

Comments
 (0)