Skip to content

Commit dc7cdf9

Browse files
committed
HHH-8276 - Integrate LoadPlans into UniqueEntityLoader (PoC)
1 parent 456d61b commit dc7cdf9

File tree

144 files changed

+7369
-2876
lines changed

Some content is hidden

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

144 files changed

+7369
-2876
lines changed

hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ public String getPropertyName() {
7171
return propertyName;
7272
}
7373

74+
protected String originalMessage() {
75+
return super.getMessage();
76+
}
77+
7478
@Override
7579
public String getMessage() {
76-
return super.getMessage()
80+
return originalMessage()
7781
+ ( wasSetter ? " setter of " : " getter of " )
7882
+ StringHelper.qualify( persistentClass.getName(), propertyName );
7983
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2013, 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;
25+
26+
/**
27+
* @author Steve Ebersole
28+
*/
29+
public class PropertySetterAccessException extends PropertyAccessException {
30+
/**
31+
* Constructs a PropertyAccessException using the specified information.
32+
*
33+
* @param cause The underlying cause
34+
* @param persistentClass The class which is supposed to contain the property in question
35+
* @param propertyName The name of the property.
36+
* @param expectedType The expected property type
37+
* @param target The target, which should be of type 'persistentClass'
38+
* @param value The property value we are trying to set
39+
*/
40+
public PropertySetterAccessException(
41+
Throwable cause,
42+
Class persistentClass,
43+
String propertyName,
44+
Class expectedType,
45+
Object target,
46+
Object value) {
47+
super(
48+
cause,
49+
String.format(
50+
"IllegalArgumentException occurred while calling setter for property [%s.%s (expected type = %s)]; " +
51+
"target = [%s], property value = [%s]",
52+
persistentClass.getName(),
53+
propertyName,
54+
expectedType.getName(),
55+
target,
56+
value
57+
),
58+
true,
59+
persistentClass,
60+
propertyName
61+
);
62+
}
63+
64+
@Override
65+
public String toString() {
66+
return super.originalMessage();
67+
}
68+
}

hibernate-core/src/main/java/org/hibernate/annotations/Any.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
*
5858
* @author Emmanuel Bernard
5959
* @author Steve Ebersole
60+
*
61+
* @see AnyMetaDef
6062
*/
6163
@java.lang.annotation.Target({METHOD, FIELD})
6264
@Retention(RUNTIME)

hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929

3030
import org.hibernate.CustomEntityDirtinessStrategy;
31+
import org.hibernate.EntityNameResolver;
3132
import org.hibernate.HibernateException;
3233
import org.hibernate.Interceptor;
3334
import org.hibernate.MappingException;
@@ -290,4 +291,6 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory {
290291
* @return
291292
*/
292293
public NamedQueryRepository getNamedQueryRepository();
294+
295+
Iterable<EntityNameResolver> iterateEntityNameResolvers();
293296
}

hibernate-core/src/main/java/org/hibernate/hql/internal/NameGenerator.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ public static String[][] generateColumnNames(Type[] types, SessionFactoryImpleme
5252
}
5353

5454
public static String scalarName(int x, int y) {
55-
return new StringBuilder()
56-
.append( "col_" )
57-
.append( x )
58-
.append( '_' )
59-
.append( y )
60-
.append( '_' )
61-
.toString();
55+
return scalarName( "col_" + x, y );
56+
}
57+
58+
public static String scalarName(String base, int num) {
59+
return base + '_' + num + '_';
60+
}
61+
62+
public static String[] scalarNames(String base, int count) {
63+
final String[] names = new String[count];
64+
for ( int j = 0; j < count; j++ ) {
65+
names[j] = scalarName( base, j );
66+
}
67+
return names;
68+
}
69+
70+
public static String[] scalarNames(int uniqueness, int count) {
71+
return scalarNames( "col_" + uniqueness, count );
6272
}
6373
}

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlSqlWalker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ protected void createFromJoinElement(
378378

379379
final FromElement fromElement;
380380
if ( dot.getDataType() != null && dot.getDataType().isComponentType() ) {
381+
if ( dot.getDataType().isAnyType() ) {
382+
throw new SemanticException( "An AnyType attribute cannot be join fetched" );
383+
// ^^ because the discriminator (aka, the "meta columns") must be known to the SQL in
384+
// a non-parameterized way.
385+
}
381386
FromElementFactory factory = new FromElementFactory(
382387
getCurrentFromClause(),
383388
dot.getLhs().getFromElement(),

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.HashMap;
3636
import java.util.HashSet;
3737
import java.util.Iterator;
38-
import java.util.List;
3938
import java.util.Map;
4039
import java.util.Properties;
4140
import java.util.Set;
@@ -268,7 +267,6 @@ public void handleEntityNotFound(String entityName, Serializable id) {
268267
this.jdbcServices = this.serviceRegistry.getService( JdbcServices.class );
269268
this.dialect = this.jdbcServices.getDialect();
270269
this.cacheAccess = this.serviceRegistry.getService( CacheImplementor.class );
271-
final RegionFactory regionFactory = cacheAccess.getRegionFactory();
272270
this.sqlFunctionRegistry = new SQLFunctionRegistry( getDialect(), cfg.getSqlFunctions() );
273271
if ( observer != null ) {
274272
this.observer.addObserver( observer );
@@ -329,15 +327,22 @@ public void sessionFactoryClosed(SessionFactory factory) {
329327
}
330328
}
331329

330+
imports = new HashMap<String,String>( cfg.getImports() );
332331

333332
///////////////////////////////////////////////////////////////////////
334333
// Prepare persisters and link them up with their cache
335334
// region/access-strategy
336335

336+
final RegionFactory regionFactory = cacheAccess.getRegionFactory();
337337
final String cacheRegionPrefix = settings.getCacheRegionPrefix() == null ? "" : settings.getCacheRegionPrefix() + ".";
338-
339338
final PersisterFactory persisterFactory = serviceRegistry.getService( PersisterFactory.class );
340339

340+
// todo : consider removing this silliness and just have EntityPersister directly implement ClassMetadata
341+
// EntityPersister.getClassMetadata() for the internal impls simply "return this";
342+
// collapsing those would allow us to remove this "extra" Map
343+
//
344+
// todo : similar for CollectionPersister/CollectionMetadata
345+
341346
entityPersisters = new HashMap();
342347
Map entityAccessStrategies = new HashMap();
343348
Map<String,ClassMetadata> classMeta = new HashMap<String,ClassMetadata>();
@@ -358,15 +363,15 @@ public void sessionFactoryClosed(SessionFactory factory) {
358363
cacheAccess.addCacheRegion( cacheRegionName, entityRegion );
359364
}
360365
}
361-
366+
362367
NaturalIdRegionAccessStrategy naturalIdAccessStrategy = null;
363368
if ( model.hasNaturalId() && model.getNaturalIdCacheRegionName() != null ) {
364369
final String naturalIdCacheRegionName = cacheRegionPrefix + model.getNaturalIdCacheRegionName();
365370
naturalIdAccessStrategy = ( NaturalIdRegionAccessStrategy ) entityAccessStrategies.get( naturalIdCacheRegionName );
366-
371+
367372
if ( naturalIdAccessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
368373
final CacheDataDescriptionImpl cacheDataDescription = CacheDataDescriptionImpl.decode( model );
369-
374+
370375
NaturalIdRegion naturalIdRegion = null;
371376
try {
372377
naturalIdRegion = regionFactory.buildNaturalIdRegion( naturalIdCacheRegionName, properties,
@@ -380,15 +385,15 @@ public void sessionFactoryClosed(SessionFactory factory) {
380385
model.getEntityName()
381386
);
382387
}
383-
388+
384389
if (naturalIdRegion != null) {
385390
naturalIdAccessStrategy = naturalIdRegion.buildAccessStrategy( regionFactory.getDefaultAccessType() );
386391
entityAccessStrategies.put( naturalIdCacheRegionName, naturalIdAccessStrategy );
387392
cacheAccess.addCacheRegion( naturalIdCacheRegionName, naturalIdRegion );
388393
}
389394
}
390395
}
391-
396+
392397
EntityPersister cp = persisterFactory.createEntityPersister(
393398
model,
394399
accessStrategy,
@@ -462,19 +467,13 @@ public void sessionFactoryClosed(SessionFactory factory) {
462467
cfg.getSqlResultSetMappings().values(),
463468
toProcedureCallMementos( cfg.getNamedProcedureCallMap(), cfg.getSqlResultSetMappings() )
464469
);
465-
imports = new HashMap<String,String>( cfg.getImports() );
466470

467471
// after *all* persisters and named queries are registered
468-
Iterator iter = entityPersisters.values().iterator();
469-
while ( iter.hasNext() ) {
470-
final EntityPersister persister = ( ( EntityPersister ) iter.next() );
472+
for ( EntityPersister persister : entityPersisters.values() ) {
471473
persister.postInstantiate();
472474
registerEntityNameResolvers( persister );
473-
474475
}
475-
iter = collectionPersisters.values().iterator();
476-
while ( iter.hasNext() ) {
477-
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
476+
for ( CollectionPersister persister : collectionPersisters.values() ) {
478477
persister.postInstantiate();
479478
}
480479

@@ -1070,6 +1069,7 @@ public void registerEntityNameResolver(EntityNameResolver resolver) {
10701069
entityNameResolvers.put( resolver, ENTITY_NAME_RESOLVER_MAP_VALUE );
10711070
}
10721071

1072+
@Override
10731073
public Iterable<EntityNameResolver> iterateEntityNameResolvers() {
10741074
return entityNameResolvers.keySet();
10751075
}

hibernate-core/src/main/java/org/hibernate/loader/GeneratedCollectionAliases.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ public GeneratedCollectionAliases(Map userProvidedAliases, CollectionPersister p
5151
this.keyAliases = getUserProvidedAliases(
5252
"key",
5353
persister.getKeyColumnAliases( suffix )
54-
);
54+
);
5555

5656
this.indexAliases = getUserProvidedAliases(
5757
"index",
5858
persister.getIndexColumnAliases( suffix )
59-
);
59+
);
6060

61-
this.elementAliases = getUserProvidedAliases( "element",
61+
this.elementAliases = getUserProvidedAliases(
62+
"element",
6263
persister.getElementColumnAliases( suffix )
63-
);
64+
);
6465

65-
this.identifierAlias = getUserProvidedAlias( "id",
66+
this.identifierAlias = getUserProvidedAlias(
67+
"id",
6668
persister.getIdentifierColumnAlias( suffix )
67-
);
69+
);
6870
}
6971

7072
public GeneratedCollectionAliases(CollectionPersister persister, String string) {

hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package org.hibernate.loader;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27+
import java.util.Collections;
2728
import java.util.HashSet;
2829
import java.util.Iterator;
2930
import java.util.List;
@@ -91,6 +92,9 @@ protected JoinWalker(
9192

9293
}
9394

95+
public List getAssociations() {
96+
return Collections.unmodifiableList( associations );
97+
}
9498

9599
public String[] getCollectionSuffixes() {
96100
return collectionSuffixes;

hibernate-core/src/main/java/org/hibernate/loader/entity/BatchingEntityLoaderBuilder.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ public UniqueEntityLoader buildLoader(
7272
LoadQueryInfluencers influencers) {
7373
if ( batchSize <= 1 ) {
7474
// no batching
75-
return new EntityLoader( persister, lockMode, factory, influencers );
75+
return buildNonBatchingLoader( persister, lockMode, factory, influencers );
7676
}
7777
return buildBatchingLoader( persister, batchSize, lockMode, factory, influencers );
7878
}
7979

80+
protected UniqueEntityLoader buildNonBatchingLoader(
81+
OuterJoinLoadable persister,
82+
LockMode lockMode,
83+
SessionFactoryImplementor factory,
84+
LoadQueryInfluencers influencers) {
85+
return new EntityLoader( persister, lockMode, factory, influencers );
86+
}
87+
8088
protected abstract UniqueEntityLoader buildBatchingLoader(
8189
OuterJoinLoadable persister,
8290
int batchSize,
@@ -103,11 +111,19 @@ public UniqueEntityLoader buildLoader(
103111
LoadQueryInfluencers influencers) {
104112
if ( batchSize <= 1 ) {
105113
// no batching
106-
return new EntityLoader( persister, lockOptions, factory, influencers );
114+
return buildNonBatchingLoader( persister, lockOptions, factory, influencers );
107115
}
108116
return buildBatchingLoader( persister, batchSize, lockOptions, factory, influencers );
109117
}
110118

119+
protected UniqueEntityLoader buildNonBatchingLoader(
120+
OuterJoinLoadable persister,
121+
LockOptions lockOptions,
122+
SessionFactoryImplementor factory,
123+
LoadQueryInfluencers influencers) {
124+
return new EntityLoader( persister, lockOptions, factory, influencers );
125+
}
126+
111127
protected abstract UniqueEntityLoader buildBatchingLoader(
112128
OuterJoinLoadable persister,
113129
int batchSize,

0 commit comments

Comments
 (0)