Skip to content

Commit c607e30

Browse files
stliusebersole
authored andcommitted
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
1 parent 77d7deb commit c607e30

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,12 +1831,12 @@ public int getSize(Serializable key, SessionImplementor session) {
18311831
}
18321832
}
18331833
catch ( SQLException sqle ) {
1834-
throw getFactory().getSQLExceptionHelper().convert(
1834+
throw getSQLExceptionHelper().convert(
18351835
sqle,
18361836
"could not retrieve collection size: " +
18371837
MessageHelper.collectionInfoString( this, key, getFactory() ),
18381838
sqlSelectSizeString
1839-
);
1839+
);
18401840
}
18411841
}
18421842

@@ -1873,12 +1873,12 @@ private boolean exists(Serializable key, Object indexOrElement, Type indexOrElem
18731873
}
18741874
}
18751875
catch ( SQLException sqle ) {
1876-
throw getFactory().getSQLExceptionHelper().convert(
1876+
throw getSQLExceptionHelper().convert(
18771877
sqle,
18781878
"could not check row existence: " +
18791879
MessageHelper.collectionInfoString( this, key, getFactory() ),
18801880
sqlSelectSizeString
1881-
);
1881+
);
18821882
}
18831883
}
18841884

@@ -1909,12 +1909,12 @@ public Object getElementByIndex(Serializable key, Object index, SessionImplement
19091909
}
19101910
}
19111911
catch ( SQLException sqle ) {
1912-
throw getFactory().getSQLExceptionHelper().convert(
1912+
throw getSQLExceptionHelper().convert(
19131913
sqle,
19141914
"could not read row: " +
19151915
MessageHelper.collectionInfoString( this, key, getFactory() ),
19161916
sqlSelectSizeString
1917-
);
1917+
);
19181918
}
19191919
}
19201920

@@ -2002,8 +2002,38 @@ public CompositionDefinition toCompositeDefinition() {
20022002
if ( ! getType().isComponentType() ) {
20032003
throw new IllegalStateException( "Cannot treat entity collection index type as composite" );
20042004
}
2005-
// todo : implement
2006-
throw new NotYetImplementedException();
2005+
return new CompositeCollectionElementDefinition() {
2006+
@Override
2007+
public String getName() {
2008+
return "index";
2009+
}
2010+
2011+
@Override
2012+
public CompositeType getType() {
2013+
return (CompositeType) getIndexType();
2014+
}
2015+
2016+
@Override
2017+
public boolean isNullable() {
2018+
return false;
2019+
}
2020+
2021+
@Override
2022+
public AttributeSource getSource() {
2023+
// TODO: what if this is a collection w/in an encapsulated composition attribute?
2024+
// should return the encapsulated composition attribute instead???
2025+
return getOwnerEntityPersister();
2026+
}
2027+
2028+
@Override
2029+
public Iterable<AttributeDefinition> getAttributes() {
2030+
return CompositionSingularSubAttributesHelper.getCompositeCollectionIndexSubAttributes( this );
2031+
}
2032+
@Override
2033+
public CollectionDefinition getCollectionDefinition() {
2034+
return AbstractCollectionPersister.this;
2035+
}
2036+
};
20072037
}
20082038
};
20092039
}

hibernate-core/src/main/java/org/hibernate/persister/walking/internal/CompositionSingularSubAttributesHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ public static Iterable<AttributeDefinition> getCompositeCollectionElementSubAttr
100100
);
101101
}
102102

103+
public static Iterable<AttributeDefinition> getCompositeCollectionIndexSubAttributes(CompositeCollectionElementDefinition compositionElementDefinition){
104+
final QueryableCollection collectionPersister =
105+
(QueryableCollection) compositionElementDefinition.getCollectionDefinition().getCollectionPersister();
106+
return getSingularSubAttributes(
107+
compositionElementDefinition.getSource(),
108+
(OuterJoinLoadable) collectionPersister.getOwnerEntityPersister(),
109+
(CompositeType) collectionPersister.getIndexType(),
110+
collectionPersister.getTableName(),
111+
collectionPersister.getIndexColumnNames()
112+
);
113+
}
114+
103115
private static Iterable<AttributeDefinition> getSingularSubAttributes(
104116
final AttributeSource source,
105117
final OuterJoinLoadable ownerEntityPersister,

hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ else if ( aType.getForeignKeyDirection() == ForeignKeyDirection.FOREIGN_KEY_FROM
156156
}
157157

158158
final CompositeType cType = getType();
159-
final boolean nullable = cType.getPropertyNullability() == null
160-
? true
161-
: cType.getPropertyNullability()[ subAttributeNumber ];
159+
final boolean nullable = cType.getPropertyNullability() == null || cType.getPropertyNullability()[subAttributeNumber];
162160

163161
return new CompositeBasedAssociationAttribute(
164162
AbstractCompositionAttribute.this,
@@ -203,9 +201,7 @@ else if ( type.isComponentType() ) {
203201
}
204202
else {
205203
final CompositeType cType = getType();
206-
final boolean nullable = cType.getPropertyNullability() == null
207-
? true
208-
: cType.getPropertyNullability()[ subAttributeNumber ];
204+
final boolean nullable = cType.getPropertyNullability() == null || cType.getPropertyNullability()[subAttributeNumber];
209205

210206
return new CompositeBasedBasicAttribute(
211207
AbstractCompositionAttribute.this,

hibernate-core/src/main/java/org/hibernate/tuple/component/CompositionBasedCompositionAttribute.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
* @author Steve Ebersole
3333
*/
3434
public class CompositionBasedCompositionAttribute
35-
extends AbstractCompositionAttribute
36-
implements CompositionDefinition {
35+
extends AbstractCompositionAttribute {
3736
public CompositionBasedCompositionAttribute(
3837
CompositionDefinition source,
3938
SessionFactoryImplementor sessionFactory,

0 commit comments

Comments
 (0)