Skip to content

Commit e540089

Browse files
committed
HHH-6480 - Develop component binding for new metamodel
1 parent 605ce4b commit e540089

39 files changed

+968
-209
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/CacheDataDescriptionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public static CacheDataDescriptionImpl decode(Collection model) {
8787
public static CacheDataDescriptionImpl decode(AbstractPluralAttributeBinding model) {
8888
return new CacheDataDescriptionImpl(
8989
model.isMutable(),
90-
model.getEntityBinding().isVersioned(),
91-
getVersionComparator( model.getEntityBinding() )
90+
model.getContainer().seekEntityBinding().isVersioned(),
91+
getVersionComparator( model.getContainer().seekEntityBinding() )
9292
);
9393
}
9494

hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractAttributeBinding.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @author Steve Ebersole
3737
*/
3838
public abstract class AbstractAttributeBinding implements AttributeBinding {
39-
private final EntityBinding entityBinding;
39+
private final AttributeBindingContainer container;
4040
private final Attribute attribute;
4141

4242
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
@@ -50,14 +50,14 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
5050

5151
private MetaAttributeContext metaAttributeContext;
5252

53-
protected AbstractAttributeBinding(EntityBinding entityBinding, Attribute attribute) {
54-
this.entityBinding = entityBinding;
53+
protected AbstractAttributeBinding(AttributeBindingContainer container, Attribute attribute) {
54+
this.container = container;
5555
this.attribute = attribute;
5656
}
5757

5858
@Override
59-
public EntityBinding getEntityBinding() {
60-
return entityBinding;
59+
public AttributeBindingContainer getContainer() {
60+
return container;
6161
}
6262

6363
@Override
@@ -93,18 +93,6 @@ public void setIncludedInOptimisticLocking(boolean includedInOptimisticLocking)
9393
this.includedInOptimisticLocking = includedInOptimisticLocking;
9494
}
9595

96-
protected boolean forceNonNullable() {
97-
return false;
98-
}
99-
100-
protected boolean forceUnique() {
101-
return false;
102-
}
103-
104-
protected final boolean isPrimaryKey() {
105-
return this == getEntityBinding().getHierarchyDetails().getEntityIdentifier().getValueBinding();
106-
}
107-
10896
@Override
10997
public MetaAttributeContext getMetaAttributeContext() {
11098
return metaAttributeContext;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.binding;
25+
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
29+
import org.hibernate.metamodel.domain.PluralAttribute;
30+
import org.hibernate.metamodel.domain.SingularAttribute;
31+
32+
/**
33+
* @author Steve Ebersole
34+
*/
35+
public abstract class AbstractAttributeBindingContainer implements AttributeBindingContainer {
36+
private Map<String, AttributeBinding> attributeBindingMap = new HashMap<String, AttributeBinding>();
37+
38+
protected void registerAttributeBinding(String name, AttributeBinding attributeBinding) {
39+
attributeBindingMap.put( name, attributeBinding );
40+
}
41+
42+
@Override
43+
public SimpleSingularAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute) {
44+
return makeSimpleAttributeBinding( attribute, false, false );
45+
}
46+
47+
private SimpleSingularAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute, boolean forceNonNullable, boolean forceUnique) {
48+
final SimpleSingularAttributeBinding binding = new SimpleSingularAttributeBinding(
49+
this,
50+
attribute,
51+
forceNonNullable,
52+
forceUnique
53+
);
54+
registerAttributeBinding( attribute.getName(), binding );
55+
return binding;
56+
}
57+
58+
@Override
59+
public ComponentAttributeBinding makeComponentAttributeBinding(SingularAttribute attribute) {
60+
final ComponentAttributeBinding binding = new ComponentAttributeBinding( this, attribute );
61+
registerAttributeBinding( attribute.getName(), binding );
62+
return binding;
63+
}
64+
65+
@Override
66+
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(SingularAttribute attribute) {
67+
final ManyToOneAttributeBinding binding = new ManyToOneAttributeBinding( this, attribute );
68+
registerAttributeBinding( attribute.getName(), binding );
69+
return binding;
70+
}
71+
72+
@Override
73+
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature) {
74+
final BagBinding binding = new BagBinding( this, attribute, nature );
75+
registerAttributeBinding( attribute.getName(), binding );
76+
return binding;
77+
}
78+
79+
@Override
80+
public AttributeBinding locateAttributeBinding(String name) {
81+
return attributeBindingMap.get( name );
82+
}
83+
84+
@Override
85+
public Iterable<AttributeBinding> attributeBindings() {
86+
return attributeBindingMap.values();
87+
}
88+
89+
/**
90+
* Gets the number of attribute bindings defined on this class, including the
91+
* identifier attribute binding and attribute bindings defined
92+
* as part of a join.
93+
*
94+
* @return The number of attribute bindings
95+
*/
96+
public int getAttributeBindingClosureSpan() {
97+
// TODO: fix this after HHH-6337 is fixed; for now just return size of attributeBindingMap
98+
// if this is not a root, then need to include the superclass attribute bindings
99+
return attributeBindingMap.size();
100+
}
101+
102+
/**
103+
* Gets the attribute bindings defined on this class, including the
104+
* identifier attribute binding and attribute bindings defined
105+
* as part of a join.
106+
*
107+
* @return The attribute bindings.
108+
*/
109+
public Iterable<AttributeBinding> getAttributeBindingClosure() {
110+
// TODO: fix this after HHH-6337 is fixed. for now, just return attributeBindings
111+
// if this is not a root, then need to include the superclass attribute bindings
112+
return attributeBindings();
113+
}
114+
}

hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractPluralAttributeBinding.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public abstract class AbstractPluralAttributeBinding extends AbstractAttributeBi
7777
private String loaderName;
7878

7979
protected AbstractPluralAttributeBinding(
80-
EntityBinding entityBinding,
80+
AttributeBindingContainer container,
8181
PluralAttribute attribute,
8282
CollectionElementNature collectionElementNature) {
83-
super( entityBinding, attribute );
83+
super( container, attribute );
8484
this.collectionElement = interpretNature( collectionElementNature );
8585
}
8686

hibernate-core/src/main/java/org/hibernate/metamodel/binding/AbstractSingularAttributeBinding.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public abstract class AbstractSingularAttributeBinding
4545
private boolean hasDerivedValue;
4646
private boolean isNullable = true;
4747

48-
protected AbstractSingularAttributeBinding(EntityBinding entityBinding, SingularAttribute attribute) {
49-
super( entityBinding, attribute );
48+
protected AbstractSingularAttributeBinding(AttributeBindingContainer container, SingularAttribute attribute) {
49+
super( container, attribute );
5050
}
5151

5252
@Override
@@ -79,7 +79,7 @@ public void setSimpleValueBindings(Iterable<SimpleValueBinding> simpleValueBindi
7979
}
8080

8181
private String getRole() {
82-
return getEntityBinding().getEntity().getName() + '.' + getAttribute().getName();
82+
return getContainer().getPathBase() + '.' + getAttribute().getName();
8383
}
8484

8585
@Override
@@ -88,7 +88,7 @@ public int getSimpleValueSpan() {
8888
return simpleValueBindings.size();
8989
}
9090

91-
private void checkValueBinding() {
91+
protected void checkValueBinding() {
9292
if ( value == null ) {
9393
throw new AssertionFailure( "No values yet bound!" );
9494
}

hibernate-core/src/main/java/org/hibernate/metamodel/binding/AttributeBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public interface AttributeBinding {
3939
*
4040
* @return The entity binding.
4141
*/
42-
public EntityBinding getEntityBinding();
42+
public AttributeBindingContainer getContainer();
4343

4444
/**
4545
* Obtain the attribute bound.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.binding;
25+
26+
import org.hibernate.metamodel.domain.AttributeContainer;
27+
import org.hibernate.metamodel.domain.PluralAttribute;
28+
import org.hibernate.metamodel.domain.SingularAttribute;
29+
import org.hibernate.metamodel.relational.TableSpecification;
30+
import org.hibernate.metamodel.source.MetaAttributeContext;
31+
32+
/**
33+
* @author Steve Ebersole
34+
*/
35+
public interface AttributeBindingContainer {
36+
public String getPathBase();
37+
38+
public AttributeContainer getAttributeContainer();
39+
40+
public Iterable<AttributeBinding> attributeBindings();
41+
42+
public AttributeBinding locateAttributeBinding(String name);
43+
44+
public SimpleSingularAttributeBinding makeSimpleAttributeBinding(SingularAttribute attribute);
45+
46+
public ComponentAttributeBinding makeComponentAttributeBinding(SingularAttribute attribute);
47+
48+
public ManyToOneAttributeBinding makeManyToOneAttributeBinding(SingularAttribute attribute);
49+
50+
public BagBinding makeBagAttributeBinding(PluralAttribute attribute, CollectionElementNature nature);
51+
52+
public EntityBinding seekEntityBinding();
53+
54+
public TableSpecification getPrimaryTable();
55+
56+
public TableSpecification locateTable(String containingTableName);
57+
58+
public Class<?> getClassReference();
59+
60+
public MetaAttributeContext getMetaAttributeContext();
61+
}

hibernate-core/src/main/java/org/hibernate/metamodel/binding/BagBinding.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Steve Ebersole
3232
*/
3333
public class BagBinding extends AbstractPluralAttributeBinding {
34-
protected BagBinding(EntityBinding entityBinding, PluralAttribute attribute, CollectionElementNature nature) {
35-
super( entityBinding, attribute, nature );
34+
protected BagBinding(AttributeBindingContainer container, PluralAttribute attribute, CollectionElementNature nature) {
35+
super( container, attribute, nature );
3636
}
3737
}

0 commit comments

Comments
 (0)