Skip to content

Commit 681bd09

Browse files
committed
squash warnings in bean LifecycleStrategy stuff
Signed-off-by: Gavin King <[email protected]>
1 parent 7b8c403 commit 681bd09

File tree

4 files changed

+52
-60
lines changed

4 files changed

+52
-60
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
4646
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
4747
import org.hibernate.service.ServiceRegistry;
48-
import org.hibernate.type.Type;
4948

5049
import java.lang.annotation.Annotation;
5150
import java.lang.reflect.InvocationTargetException;

hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
/**
2121
* A {@link BeanLifecycleStrategy} to use when CDI compliance is required
2222
* (i.e. when the bean lifecycle is to be managed by the CDI runtime, not the JPA runtime).
23-
*
23+
* <p>
2424
* The main characteristic of this strategy is that every create/destroy operation is delegated
2525
* to the CDI runtime.
26-
*
26+
* <p>
2727
* In particular, @Singleton-scoped or @ApplicationScoped beans are retrieved from the CDI context,
2828
* and are not duplicated, in contrast to {@link JpaCompliantLifecycleStrategy}.
2929
*/
@@ -89,16 +89,16 @@ public void initialize() {
8989
}
9090

9191
try {
92-
this.instance = resolveContainerInstance();
93-
this.beanInstance = this.instance.get();
92+
instance = resolveContainerInstance();
93+
beanInstance = instance.get();
9494
}
9595
catch (NotYetReadyException e) {
9696
throw e;
9797
}
9898
catch (Exception e) {
9999
log.debug( "Error resolving CDI bean - using fallback" );
100-
this.beanInstance = produceFallbackInstance();
101-
this.instance = null;
100+
beanInstance = produceFallbackInstance();
101+
instance = null;
102102
}
103103

104104
this.beanManager = null;
@@ -154,8 +154,8 @@ protected Instance<B> resolveContainerInstance() {
154154
root = beanManager.createInstance();
155155
}
156156
catch (Exception e) {
157-
// this indicates that the BeanManager is not yet ready to use, which
158-
// should be consider an error
157+
// this indicates that the BeanManager is not yet ready to use,
158+
// which should be considered an error
159159
throw new NotYetReadyException( e );
160160
}
161161

@@ -186,15 +186,14 @@ private NamedBeanImpl(
186186
}
187187

188188
@Override
189-
@SuppressWarnings("unchecked")
190189
protected Instance<B> resolveContainerInstance() {
191-
final Instance root;
190+
final Instance<Object> root;
192191
try {
193192
root = beanManager.createInstance();
194193
}
195194
catch (Exception e) {
196-
// this indicates that the BeanManager is not yet ready to use, which
197-
// should be consider an error
195+
// this indicates that the BeanManager is not yet ready to use,
196+
// which should be considered an error
198197
throw new NotYetReadyException( e );
199198
}
200199

hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate.resource.beans.container.internal;
88

9-
import java.util.Set;
109
import jakarta.enterprise.context.spi.CreationalContext;
1110
import jakarta.enterprise.inject.spi.AnnotatedType;
1211
import jakarta.enterprise.inject.spi.Bean;
@@ -23,12 +22,12 @@
2322
/**
2423
* A {@link BeanLifecycleStrategy} to use when JPA compliance is required
2524
* (i.e. when the bean lifecycle is to be managed by the JPA runtime, not the CDI runtime).
26-
*
25+
* <p>
2726
* The main characteristic of this strategy is that each requested bean is instantiated directly
2827
* and guaranteed to not be shared in the CDI context.
29-
*
30-
* In particular, @Singleton-scoped or @ApplicationScoped beans are instantiated directly by this strategy,
31-
* even if there is already an instance in the CDI context.
28+
* <p>
29+
* In particular, {@code @Singleton}-scoped or {@code @ApplicationScoped} beans are instantiated
30+
* directly by this strategy, even if there is already an instance in the CDI context.
3231
* This means singletons are not really singletons, but this seems to be the behavior required by
3332
* the JPA 2.2 spec.
3433
*/
@@ -128,10 +127,10 @@ public void initialize() {
128127
}
129128

130129
try {
131-
this.injectionTarget = beanManager.getInjectionTargetFactory( annotatedType ).createInjectionTarget( (Bean) null );
132-
this.creationalContext = beanManager.createCreationalContext( null );
130+
injectionTarget = beanManager.getInjectionTargetFactory( annotatedType ).createInjectionTarget( null );
131+
creationalContext = beanManager.createCreationalContext( null );
133132

134-
this.beanInstance = this.injectionTarget.produce( creationalContext );
133+
beanInstance = injectionTarget.produce( creationalContext );
135134
injectionTarget.inject( beanInstance, creationalContext );
136135

137136
injectionTarget.postConstruct( beanInstance );
@@ -141,7 +140,7 @@ public void initialize() {
141140
}
142141
catch (Exception e) {
143142
log.debugf( "Error resolving CDI bean [%s] - using fallback", beanType.getName() );
144-
this.beanInstance = fallbackProducer.produceBeanInstance( beanType );
143+
beanInstance = fallbackProducer.produceBeanInstance( beanType );
145144

146145
try {
147146
if ( this.creationalContext != null ) {
@@ -151,11 +150,11 @@ public void initialize() {
151150
catch (Exception ignore) {
152151
}
153152

154-
this.creationalContext = null;
155-
this.injectionTarget = null;
153+
creationalContext = null;
154+
injectionTarget = null;
156155
}
157156

158-
this.beanManager = null;
157+
beanManager = null;
159158
}
160159

161160
@Override
@@ -171,15 +170,15 @@ public void release() {
171170
}
172171
injectionTarget.preDestroy( beanInstance );
173172
injectionTarget.dispose( beanInstance );
174-
this.creationalContext.release();
173+
creationalContext.release();
175174
}
176175
catch (Exception ignore) {
177176

178177
}
179178
finally {
180-
this.beanInstance = null;
181-
this.creationalContext = null;
182-
this.injectionTarget = null;
179+
beanInstance = null;
180+
creationalContext = null;
181+
injectionTarget = null;
183182
}
184183
}
185184
}
@@ -239,31 +238,31 @@ public void initialize() {
239238
}
240239

241240
try {
242-
this.creationalContext = beanManager.createCreationalContext( null );
241+
creationalContext = beanManager.createCreationalContext( null );
243242
}
244243
catch (Exception e) {
245244
throw new NotYetReadyException( e );
246245
}
247246

248247
try {
249-
Set<Bean<?>> beans = beanManager.getBeans( beanType, new NamedBeanQualifier( beanName ) );
250-
this.bean = (Bean<B>) beanManager.resolve( beans );
251-
this.beanInstance = bean.create( creationalContext );
248+
bean = (Bean<B>) beanManager.resolve( beanManager.getBeans( beanType,
249+
new NamedBeanQualifier( beanName ) ) );
250+
beanInstance = bean.create( creationalContext );
252251
}
253252
catch (Exception e) {
254253
log.debugf( "Error resolving CDI bean [%s] - using fallback", beanName );
255-
this.beanInstance = fallbackProducer.produceBeanInstance( beanName, beanType );
254+
beanInstance = fallbackProducer.produceBeanInstance( beanName, beanType );
256255

257256
try {
258-
if ( this.creationalContext != null ) {
259-
this.creationalContext.release();
257+
if ( creationalContext != null ) {
258+
creationalContext.release();
260259
}
261260
}
262261
catch (Exception ignore) {
263262
}
264263

265-
this.creationalContext = null;
266-
this.bean = null;
264+
creationalContext = null;
265+
bean = null;
267266
}
268267
}
269268

@@ -291,10 +290,10 @@ public void release() {
291290
}
292291
}
293292

294-
this.beanInstance = null;
295-
this.creationalContext = null;
296-
this.bean = null;
297-
this.beanManager = null;
293+
beanInstance = null;
294+
creationalContext = null;
295+
bean = null;
296+
beanManager = null;
298297
}
299298
}
300299

hibernate-core/src/main/java/org/hibernate/resource/beans/container/spi/AbstractCdiBeanContainer.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@
2323
* @author Steve Ebersole
2424
*/
2525
public abstract class AbstractCdiBeanContainer implements CdiBasedBeanContainer {
26-
private Map<String,ContainedBeanImplementor<?>> beanCache = new HashMap<>();
27-
private List<ContainedBeanImplementor<?>> registeredBeans = new ArrayList<>();
26+
private final Map<String,ContainedBeanImplementor<?>> beanCache = new HashMap<>();
27+
private final List<ContainedBeanImplementor<?>> registeredBeans = new ArrayList<>();
2828

2929
@Override
3030
public <B> ContainedBean<B> getBean(
3131
Class<B> beanType,
3232
LifecycleOptions lifecycleOptions,
3333
BeanInstanceProducer fallbackProducer) {
34-
if ( lifecycleOptions.canUseCachedReferences() ) {
35-
return getCacheableBean( beanType, lifecycleOptions, fallbackProducer );
36-
}
37-
else {
38-
return createBean( beanType, lifecycleOptions, fallbackProducer );
39-
}
34+
return lifecycleOptions.canUseCachedReferences()
35+
? getCacheableBean( beanType, lifecycleOptions, fallbackProducer )
36+
: createBean( beanType, lifecycleOptions, fallbackProducer );
4037
}
4138

4239
@SuppressWarnings("unchecked")
@@ -46,22 +43,21 @@ private <B> ContainedBean<B> getCacheableBean(
4643
BeanInstanceProducer fallbackProducer) {
4744
final String beanCacheKey = Helper.determineBeanCacheKey( beanType );
4845

49-
final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
46+
final ContainedBeanImplementor<?> existing = beanCache.get( beanCacheKey );
5047
if ( existing != null ) {
51-
return existing;
48+
return (ContainedBeanImplementor<B>) existing;
5249
}
5350

54-
final ContainedBeanImplementor bean = createBean( beanType, lifecycleOptions, fallbackProducer );
51+
final ContainedBeanImplementor<B> bean = createBean( beanType, lifecycleOptions, fallbackProducer );
5552
beanCache.put( beanCacheKey, bean );
5653
return bean;
5754
}
5855

59-
@SuppressWarnings("unchecked")
6056
private <B> ContainedBeanImplementor<B> createBean(
6157
Class<B> beanType,
6258
LifecycleOptions lifecycleOptions,
6359
BeanInstanceProducer fallbackProducer) {
64-
final ContainedBeanImplementor bean = createBean(
60+
final ContainedBeanImplementor<B> bean = createBean(
6561
beanType,
6662
lifecycleOptions.useJpaCompliantCreation()
6763
? JpaCompliantLifecycleStrategy.INSTANCE
@@ -99,23 +95,22 @@ private <B> ContainedBeanImplementor<B> getCacheableBean(
9995
BeanInstanceProducer fallbackProducer) {
10096
final String beanCacheKey = Helper.determineBeanCacheKey( beanName, beanType );
10197

102-
final ContainedBeanImplementor existing = beanCache.get( beanCacheKey );
98+
final ContainedBeanImplementor<?> existing = beanCache.get( beanCacheKey );
10399
if ( existing != null ) {
104-
return existing;
100+
return (ContainedBeanImplementor<B>) existing;
105101
}
106102

107-
final ContainedBeanImplementor bean = createBean( beanName, beanType, lifecycleOptions, fallbackProducer );
103+
final ContainedBeanImplementor<B> bean = createBean( beanName, beanType, lifecycleOptions, fallbackProducer );
108104
beanCache.put( beanCacheKey, bean );
109105
return bean;
110106
}
111107

112-
@SuppressWarnings("unchecked")
113108
private <B> ContainedBeanImplementor<B> createBean(
114109
String beanName,
115110
Class<B> beanType,
116111
LifecycleOptions lifecycleOptions,
117112
BeanInstanceProducer fallbackProducer) {
118-
final ContainedBeanImplementor bean = createBean(
113+
final ContainedBeanImplementor<B> bean = createBean(
119114
beanName,
120115
beanType,
121116
lifecycleOptions.useJpaCompliantCreation()

0 commit comments

Comments
 (0)