Skip to content

Commit 5657347

Browse files
committed
clean up org.hibernate.internal package
- delete obsolete internal ExceptionMapper stuff - move FilterAliasGenerator to its own package near to its clients - disable out obsolete code in LoadQueryInfluencers - make some internal classes package-private - more misc changes
1 parent 2fb4775 commit 5657347

30 files changed

+192
-312
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.hibernate.Filter;
1515
import org.hibernate.Internal;
1616
import org.hibernate.UnknownProfileException;
17-
import org.hibernate.engine.profile.Fetch;
18-
import org.hibernate.engine.profile.FetchProfile;
1917
import org.hibernate.graph.GraphSemantic;
2018
import org.hibernate.graph.spi.RootGraphImplementor;
2119
import org.hibernate.internal.FilterImpl;
@@ -182,29 +180,29 @@ public void disableFilter(String filterName) {
182180
}
183181
}
184182

185-
public Object getFilterParameterValue(String filterParameterName) {
186-
final String[] parsed = parseFilterParameterName( filterParameterName );
187-
if ( enabledFilters == null ) {
188-
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
189-
}
190-
final var filter = (FilterImpl) enabledFilters.get( parsed[0] );
191-
if ( filter == null ) {
192-
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
193-
}
194-
return filter.getParameter( parsed[1] );
195-
}
196-
197-
public static String [] parseFilterParameterName(String filterParameterName) {
198-
final int dot = filterParameterName.lastIndexOf( '.' );
199-
if ( dot <= 0 ) {
200-
throw new IllegalArgumentException(
201-
"Invalid filter-parameter name format [" + filterParameterName + "]; expecting {filter-name}.{param-name}"
202-
);
203-
}
204-
final String filterName = filterParameterName.substring( 0, dot );
205-
final String parameterName = filterParameterName.substring( dot + 1 );
206-
return new String[] { filterName, parameterName };
207-
}
183+
// public Object getFilterParameterValue(String filterParameterName) {
184+
// final String[] parsed = parseFilterParameterName( filterParameterName );
185+
// if ( enabledFilters == null ) {
186+
// throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
187+
// }
188+
// final var filter = (FilterImpl) enabledFilters.get( parsed[0] );
189+
// if ( filter == null ) {
190+
// throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
191+
// }
192+
// return filter.getParameter( parsed[1] );
193+
// }
194+
//
195+
// public static String[] parseFilterParameterName(String filterParameterName) {
196+
// final int dot = filterParameterName.lastIndexOf( '.' );
197+
// if ( dot <= 0 ) {
198+
// throw new IllegalArgumentException(
199+
// "Invalid filter-parameter name format [" + filterParameterName + "]; expecting {filter-name}.{param-name}"
200+
// );
201+
// }
202+
// final String filterName = filterParameterName.substring( 0, dot );
203+
// final String parameterName = filterParameterName.substring( dot + 1 );
204+
// return new String[] { filterName, parameterName };
205+
// }
208206

209207

210208
// fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -327,9 +325,9 @@ private boolean isSubselectFetchEnabledInProfile(CollectionPersister persister)
327325
if ( hasEnabledFetchProfiles() ) {
328326
final var sqlTranslationEngine = persister.getFactory().getSqlTranslationEngine();
329327
for ( String profile : getEnabledFetchProfileNames() ) {
330-
final FetchProfile fetchProfile = sqlTranslationEngine.getFetchProfile( profile ) ;
328+
final var fetchProfile = sqlTranslationEngine.getFetchProfile( profile ) ;
331329
if ( fetchProfile != null ) {
332-
final Fetch fetch = fetchProfile.getFetchByRole( persister.getRole() );
330+
final var fetch = fetchProfile.getFetchByRole( persister.getRole() );
333331
if ( fetch != null && fetch.getMethod() == SUBSELECT) {
334332
return true;
335333
}

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,33 @@
1111
/**
1212
* @author Steve Ebersole
1313
*/
14-
public class CoordinatingEntityNameResolver implements EntityNameResolver {
14+
class CoordinatingEntityNameResolver implements EntityNameResolver {
1515
private final SessionFactoryImplementor sessionFactory;
1616
private final Interceptor interceptor;
1717

18-
public CoordinatingEntityNameResolver(SessionFactoryImplementor sessionFactory, Interceptor interceptor) {
18+
CoordinatingEntityNameResolver(SessionFactoryImplementor sessionFactory, Interceptor interceptor) {
1919
this.sessionFactory = sessionFactory;
2020
this.interceptor = interceptor;
2121
}
2222

2323
@Override
2424
public String resolveEntityName(Object entity) {
25-
String entityName = interceptor.getEntityName( entity );
26-
if ( entityName != null ) {
27-
return entityName;
25+
final String interceptorEntityName = interceptor.getEntityName( entity );
26+
if ( interceptorEntityName != null ) {
27+
return interceptorEntityName;
2828
}
2929

30-
for ( EntityNameResolver resolver :
31-
sessionFactory.getSessionFactoryOptions().getEntityNameResolvers() ) {
32-
entityName = resolver.resolveEntityName( entity );
33-
if ( entityName != null ) {
34-
return entityName;
30+
for ( var resolver : sessionFactory.getSessionFactoryOptions().getEntityNameResolvers() ) {
31+
final String resolverEntityName = resolver.resolveEntityName( entity );
32+
if ( resolverEntityName != null ) {
33+
return resolverEntityName;
3534
}
3635
}
3736

38-
for ( EntityNameResolver resolver :
39-
sessionFactory.getMappingMetamodel().getEntityNameResolvers() ) {
40-
entityName = resolver.resolveEntityName( entity );
41-
if ( entityName != null ) {
42-
return entityName;
37+
for ( var resolver : sessionFactory.getMappingMetamodel().getEntityNameResolvers() ) {
38+
final String resolverEntityName = resolver.resolveEntityName( entity );
39+
if ( resolverEntityName != null ) {
40+
return resolverEntityName;
4341
}
4442
}
4543

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
/**
4646
* @author Andrea Boriero
4747
*/
48-
public class ExceptionConverterImpl implements ExceptionConverter {
48+
class ExceptionConverterImpl implements ExceptionConverter {
4949

5050
private final SharedSessionContractImplementor session;
5151
private final boolean isJpaBootstrap;
5252

53-
public ExceptionConverterImpl(SharedSessionContractImplementor session) {
53+
ExceptionConverterImpl(SharedSessionContractImplementor session) {
5454
this.session = session;
5555
isJpaBootstrap = session.getFactory().getSessionFactoryOptions().isJpaBootstrap();
5656
}
@@ -78,46 +78,46 @@ public RuntimeException convertCommitException(RuntimeException exception) {
7878
@Override
7979
public RuntimeException convert(HibernateException exception, LockOptions lockOptions) {
8080
if ( exception instanceof StaleStateException staleStateException ) {
81-
final PersistenceException converted = wrapStaleStateException( staleStateException );
81+
final var converted = wrapStaleStateException( staleStateException );
8282
rollbackIfNecessary( converted );
8383
return converted;
8484
}
8585
else if ( exception instanceof org.hibernate.PessimisticLockException pessimisticLockException ) {
86-
final PersistenceException converted = wrapLockException( pessimisticLockException, lockOptions );
86+
final var converted = wrapLockException( pessimisticLockException, lockOptions );
8787
rollbackIfNecessary( converted );
8888
return converted;
8989
}
9090
else if ( exception instanceof LockingStrategyException lockingStrategyException ) {
91-
final PersistenceException converted = wrapLockException( lockingStrategyException, lockOptions );
91+
final var converted = wrapLockException( lockingStrategyException, lockOptions );
9292
rollbackIfNecessary( converted );
9393
return converted;
9494
}
9595
else if ( exception instanceof SnapshotIsolationException ) {
9696
return new OptimisticLockException( exception.getMessage(), exception );
9797
}
9898
else if ( exception instanceof org.hibernate.QueryTimeoutException ) {
99-
final QueryTimeoutException converted = new QueryTimeoutException( exception.getMessage(), exception );
99+
final var converted = new QueryTimeoutException( exception.getMessage(), exception );
100100
rollbackIfNecessary( converted );
101101
return converted;
102102
}
103103
else if ( exception instanceof ObjectNotFoundException ) {
104-
final EntityNotFoundException converted = new EntityNotFoundException( exception.getMessage(), exception );
104+
final var converted = new EntityNotFoundException( exception.getMessage(), exception );
105105
rollbackIfNecessary( converted );
106106
return converted;
107107
}
108108
else if ( exception instanceof org.hibernate.NonUniqueObjectException
109109
|| exception instanceof PersistentObjectException) {
110-
final EntityExistsException converted = new EntityExistsException( exception.getMessage(), exception );
110+
final var converted = new EntityExistsException( exception.getMessage(), exception );
111111
rollbackIfNecessary( converted );
112112
return converted;
113113
}
114114
else if ( exception instanceof org.hibernate.NonUniqueResultException ) {
115-
final NonUniqueResultException converted = new NonUniqueResultException( exception.getMessage(), exception );
115+
final var converted = new NonUniqueResultException( exception.getMessage(), exception );
116116
rollbackIfNecessary( converted );
117117
return converted;
118118
}
119119
else if ( exception instanceof UnresolvableObjectException ) {
120-
final EntityNotFoundException converted = new EntityNotFoundException( exception.getMessage(), exception );
120+
final var converted = new EntityNotFoundException( exception.getMessage(), exception );
121121
rollbackIfNecessary( converted );
122122
return converted;
123123
}
@@ -141,7 +141,7 @@ else if ( exception instanceof TransientObjectException ) {
141141
return new IllegalStateException( exception );
142142
}
143143
else if ( exception instanceof TransactionSerializationException ) {
144-
final PersistenceException converted = new RollbackException( exception.getMessage(), exception );
144+
final var converted = new RollbackException( exception.getMessage(), exception );
145145
rollbackIfNecessary( converted );
146146
return converted;
147147
}
@@ -184,48 +184,52 @@ public JDBCException convert(SQLException e, String message) {
184184
}
185185

186186
protected PersistenceException wrapStaleStateException(StaleStateException exception) {
187+
final String message = exception.getMessage();
187188
if ( exception instanceof StaleObjectStateException staleStateException ) {
188189
final Object identifier = staleStateException.getIdentifier();
189190
final String entityName = staleStateException.getEntityName();
190191
if ( identifier != null ) {
191192
try {
192193
final Object entity = session.internalLoad( entityName, identifier, false, true );
193194
if ( entity instanceof Serializable ) { // avoid some user errors regarding boundary crossing
194-
return new OptimisticLockException( exception.getMessage(), exception, entity );
195+
return new OptimisticLockException( message, exception, entity );
195196
}
196197
}
197198
catch (EntityNotFoundException entityNotFoundException) {
198199
// swallow it;
199200
}
200201
}
201202
}
202-
return new OptimisticLockException( exception.getMessage(), exception );
203+
return new OptimisticLockException( message, exception );
203204
}
204205

205206
protected PersistenceException wrapLockException(LockingStrategyException exception, LockOptions lockOptions) {
207+
final String message = exception.getMessage();
208+
final Object entity = exception.getEntity();
206209
if ( exception instanceof OptimisticEntityLockException lockException ) {
207-
return new OptimisticLockException( lockException.getMessage(), lockException, lockException.getEntity() );
210+
return new OptimisticLockException( message, lockException, entity );
208211
}
209212
else if ( exception instanceof PessimisticEntityLockException lockException ) {
210213
// assume lock timeout occurred if a timeout or NO WAIT was specified
211214
return lockOptions != null && lockOptions.getTimeout().milliseconds() > -1
212-
? new LockTimeoutException( lockException.getMessage(), lockException, lockException.getEntity() )
213-
: new PessimisticLockException( lockException.getMessage(), lockException, lockException.getEntity() );
215+
? new LockTimeoutException( message, lockException, entity )
216+
: new PessimisticLockException( message, lockException, entity );
214217
}
215218
else {
216219
throw new AssertionFailure( "Unrecognized exception type" );
217220
}
218221
}
219222

220223
protected PersistenceException wrapLockException(org.hibernate.PessimisticLockException exception, LockOptions lockOptions) {
224+
final String message = exception.getMessage();
221225
if ( exception instanceof org.hibernate.exception.LockTimeoutException ) {
222-
return new LockTimeoutException( exception.getMessage(), exception );
226+
return new LockTimeoutException( message, exception );
223227
}
224228
else {
225229
// assume lock timeout occurred if a timeout or NO WAIT was specified
226230
return lockOptions != null && lockOptions.getTimeout().milliseconds() > -1
227-
? new LockTimeoutException( exception.getMessage(), exception )
228-
: new PessimisticLockException( exception.getMessage(), exception );
231+
? new LockTimeoutException( message, exception )
232+
: new PessimisticLockException( message, exception );
229233
}
230234
}
231235

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @author Gavin King
3333
*/
34-
public class FetchProfileHelper {
34+
class FetchProfileHelper {
3535

3636
@SuppressWarnings("unused")
3737
public static Map<String, FetchProfile> getFetchProfiles(
@@ -48,7 +48,7 @@ static void addFetchProfiles(
4848
Map<String, FetchProfile> fetchProfiles) {
4949
final MappingMetamodel mappingMetamodel = runtimeMetamodels.getMappingMetamodel();
5050
for ( var mappingProfile : bootMetamodel.getFetchProfiles() ) {
51-
final FetchProfile fetchProfile = createFetchProfile( mappingMetamodel, mappingProfile );
51+
final var fetchProfile = createFetchProfile( mappingMetamodel, mappingProfile );
5252
fetchProfiles.put( fetchProfile.getName(), fetchProfile );
5353
}
5454
fetchProfiles.put( HIBERNATE_DEFAULT_PROFILE, new DefaultFetchProfile( mappingMetamodel ) );
@@ -58,20 +58,20 @@ private static FetchProfile createFetchProfile(
5858
MappingMetamodel mappingMetamodel,
5959
org.hibernate.mapping.FetchProfile mappingProfile) {
6060
final String profileName = mappingProfile.getName();
61-
final FetchProfile fetchProfile = new FetchProfile( profileName );
61+
final var fetchProfile = new FetchProfile( profileName );
6262
for ( var mappingFetch : mappingProfile.getFetches() ) {
6363
// resolve the persister owning the fetch
64-
final EntityPersister owner = getEntityPersister( mappingMetamodel, fetchProfile, mappingFetch );
64+
final var owner = getEntityPersister( mappingMetamodel, fetchProfile, mappingFetch );
6565
if ( owner instanceof FetchProfileAffectee fetchProfileAffectee ) {
6666
fetchProfileAffectee.registerAffectingFetchProfile( profileName );
6767
}
6868

69-
final Association association = new Association( owner, mappingFetch.getAssociation() );
70-
final FetchStyle fetchStyle = fetchStyle( mappingFetch.getMethod() );
71-
final FetchTiming fetchTiming = FetchTiming.forType( mappingFetch.getType() );
69+
final var association = new Association( owner, mappingFetch.getAssociation() );
70+
final var fetchStyle = fetchStyle( mappingFetch.getMethod() );
71+
final var fetchTiming = FetchTiming.forType( mappingFetch.getType() );
7272

7373
// validate the specified association fetch
74-
final ModelPart fetchablePart = owner.findByPath( association.getAssociationPath() );
74+
final var fetchablePart = owner.findByPath( association.getAssociationPath() );
7575
validateFetchablePart( fetchablePart, profileName, association );
7676
if ( fetchablePart instanceof FetchProfileAffectee fetchProfileAffectee ) {
7777
fetchProfileAffectee.registerAffectingFetchProfile( profileName );
@@ -120,7 +120,7 @@ private static EntityPersister getEntityPersister(
120120
org.hibernate.mapping.FetchProfile.Fetch mappingFetch) {
121121
final String entityName = mappingMetamodel.getImportedName( mappingFetch.getEntity() );
122122
if ( entityName != null ) {
123-
final EntityPersister persister = mappingMetamodel.getEntityDescriptor( entityName );
123+
final var persister = mappingMetamodel.getEntityDescriptor( entityName );
124124
if ( persister != null ) {
125125
return persister;
126126
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.hibernate.HibernateException;
1616
import org.hibernate.engine.spi.FilterDefinition;
1717
import org.hibernate.engine.spi.SessionFactoryImplementor;
18-
import org.hibernate.metamodel.mapping.JdbcMapping;
1918

2019
import org.checkerframework.checker.nullness.qual.Nullable;
2120

@@ -106,7 +105,7 @@ public Filter setParameter(String name, Object value) throws IllegalArgumentExce
106105
final Object argument = definition.processArgument( value );
107106

108107
// Make sure this is a defined parameter and check the incoming value type
109-
final JdbcMapping type = definition.getParameterJdbcMapping( name );
108+
final var type = definition.getParameterJdbcMapping( name );
110109
if ( type == null ) {
111110
throw new IllegalArgumentException( "Undefined filter parameter '" + name + "'" );
112111
}
@@ -134,7 +133,7 @@ public Filter setParameterList(String name, Collection<?> values) throws Hiberna
134133
if ( values == null ) {
135134
throw new IllegalArgumentException( "Collection must be not null" );
136135
}
137-
final JdbcMapping type = definition.getParameterJdbcMapping( name );
136+
final var type = definition.getParameterJdbcMapping( name );
138137
if ( type == null ) {
139138
throw new HibernateException( "Undefined filter parameter '" + name + "'" );
140139
}
@@ -212,7 +211,7 @@ public Object getParameterValue(String paramName) {
212211
return value;
213212
}
214213
else {
215-
final Supplier<?> filterParamResolver = getParameterResolver( paramName );
214+
final var filterParamResolver = getParameterResolver( paramName );
216215
return filterParamResolver == null ? null : filterParamResolver.get();
217216
}
218217
}

0 commit comments

Comments
 (0)