Skip to content

Commit c05d4b4

Browse files
committed
lots of use of 'var'
1 parent e8fa7e9 commit c05d4b4

File tree

20 files changed

+488
-615
lines changed

20 files changed

+488
-615
lines changed

hibernate-core/src/main/java/org/hibernate/boot/cfgxml/spi/LoadedConfig.java

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515

1616
import org.hibernate.boot.CacheRegionDefinition;
1717
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgCollectionCacheType;
18-
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType;
1918
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEntityCacheType;
20-
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType;
21-
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType;
2219
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgHibernateConfiguration;
23-
import org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType;
2420
import org.hibernate.event.spi.EventType;
2521

2622
import org.jboss.logging.Logger;
@@ -75,41 +71,41 @@ public Map<EventType<?>, Set<String>> getEventListenerMap() {
7571
* @return The parsed representation
7672
*/
7773
public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) {
78-
final LoadedConfig cfg = new LoadedConfig( jaxbCfg.getSessionFactory().getName() );
74+
final var cfg = new LoadedConfig( jaxbCfg.getSessionFactory().getName() );
7975

80-
for ( JaxbCfgConfigPropertyType jaxbProperty : jaxbCfg.getSessionFactory().getProperty() ) {
76+
for ( var jaxbProperty : jaxbCfg.getSessionFactory().getProperty() ) {
8177
cfg.addConfigurationValue( jaxbProperty.getName(), jaxbProperty.getValue() );
8278
}
8379

84-
for ( JaxbCfgMappingReferenceType jaxbMapping : jaxbCfg.getSessionFactory().getMapping() ) {
80+
for ( var jaxbMapping : jaxbCfg.getSessionFactory().getMapping() ) {
8581
cfg.addMappingReference( MappingReference.consume( jaxbMapping ) );
8682
}
8783

8884
for ( Object cacheDeclaration : jaxbCfg.getSessionFactory().getClassCacheOrCollectionCache() ) {
8985
cfg.addCacheRegionDefinition( parseCacheRegionDefinition( cacheDeclaration ) );
9086
}
9187

92-
if ( !jaxbCfg.getSessionFactory().getListener().isEmpty() ) {
93-
for ( JaxbCfgEventListenerType listener : jaxbCfg.getSessionFactory().getListener() ) {
94-
final EventType<?> eventType = EventType.resolveEventTypeByName( listener.getType().value() );
88+
final var eventListeners = jaxbCfg.getSessionFactory().getListener();
89+
if ( !eventListeners.isEmpty() ) {
90+
for ( var listener : eventListeners ) {
91+
final var eventType = EventType.resolveEventTypeByName( listener.getType().value() );
9592
cfg.addEventListener( eventType, listener.getClazz() );
9693
}
9794
}
9895

99-
if ( !jaxbCfg.getSessionFactory().getEvent().isEmpty() ) {
100-
for ( JaxbCfgEventListenerGroupType listenerGroup : jaxbCfg.getSessionFactory().getEvent() ) {
101-
if ( listenerGroup.getListener().isEmpty() ) {
102-
continue;
103-
}
104-
105-
final String eventTypeName = listenerGroup.getType().value();
106-
final EventType<?> eventType = EventType.resolveEventTypeByName( eventTypeName );
107-
108-
for ( JaxbCfgEventListenerType listener : listenerGroup.getListener() ) {
109-
if ( listener.getType() != null ) {
110-
LOG.debugf( "Listener [%s] defined as part of a group also defined event type", listener.getClazz() );
96+
final var listenerGroups = jaxbCfg.getSessionFactory().getEvent();
97+
if ( !listenerGroups.isEmpty() ) {
98+
for ( var listenerGroup : listenerGroups ) {
99+
if ( !listenerGroup.getListener().isEmpty() ) {
100+
final String eventTypeName = listenerGroup.getType().value();
101+
final var eventType = EventType.resolveEventTypeByName( eventTypeName );
102+
for ( var listener : listenerGroup.getListener() ) {
103+
if ( listener.getType() != null ) {
104+
LOG.debugf( "Listener [%s] defined as part of a group also defined event type",
105+
listener.getClazz() );
106+
}
107+
cfg.addEventListener( eventType, listener.getClazz() );
111108
}
112-
cfg.addEventListener( eventType, listener.getClazz() );
113109
}
114110
}
115111
}
@@ -118,17 +114,13 @@ public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) {
118114
}
119115

120116
private static String trim(String value) {
121-
if ( value == null ) {
122-
return null;
123-
}
117+
return value == null ? null : value.trim();
124118

125-
return value.trim();
126119
}
127120

128121
private void addConfigurationValue(String propertyName, String value) {
129122
value = trim( value );
130123
configurationValues.put( propertyName, value );
131-
132124
if ( !propertyName.startsWith( "hibernate." ) ) {
133125
configurationValues.put( "hibernate." + propertyName, value );
134126
}
@@ -138,7 +130,6 @@ private void addMappingReference(MappingReference mappingReference) {
138130
if ( mappingReferences == null ) {
139131
mappingReferences = new ArrayList<>();
140132
}
141-
142133
mappingReferences.add( mappingReference );
143134
}
144135

@@ -152,8 +143,7 @@ private static CacheRegionDefinition parseCacheRegionDefinition(Object cacheDecl
152143
"all".equals( jaxbClassCache.getInclude() )
153144
);
154145
}
155-
else {
156-
final JaxbCfgCollectionCacheType jaxbCollectionCache = (JaxbCfgCollectionCacheType) cacheDeclaration;
146+
else if ( cacheDeclaration instanceof JaxbCfgCollectionCacheType jaxbCollectionCache ) {
157147
return new CacheRegionDefinition(
158148
CacheRegionDefinition.CacheRegionType.COLLECTION,
159149
jaxbCollectionCache.getCollection(),
@@ -162,6 +152,9 @@ private static CacheRegionDefinition parseCacheRegionDefinition(Object cacheDecl
162152
false
163153
);
164154
}
155+
else {
156+
throw new IllegalArgumentException( "Unrecognized cache declaration" );
157+
}
165158
}
166159

167160
public void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
@@ -213,22 +206,18 @@ public void merge(LoadedConfig incoming) {
213206
}
214207

215208
protected void addConfigurationValues(Map<String,Object> configurationValues) {
216-
if ( configurationValues == null ) {
217-
return;
209+
if ( configurationValues != null ) {
210+
this.configurationValues.putAll( configurationValues );
218211
}
219-
220-
this.configurationValues.putAll( configurationValues );
221212
}
222213

223214
private void addMappingReferences(List<MappingReference> mappingReferences) {
224-
if ( mappingReferences == null ) {
225-
return;
226-
}
227-
228-
if ( this.mappingReferences == null ) {
229-
this.mappingReferences = new ArrayList<>();
215+
if ( mappingReferences != null ) {
216+
if ( this.mappingReferences == null ) {
217+
this.mappingReferences = new ArrayList<>();
218+
}
219+
this.mappingReferences.addAll( mappingReferences );
230220
}
231-
this.mappingReferences.addAll( mappingReferences );
232221
}
233222

234223
private void addCacheRegionDefinitions(List<CacheRegionDefinition> cacheRegionDefinitions) {
@@ -243,21 +232,19 @@ private void addCacheRegionDefinitions(List<CacheRegionDefinition> cacheRegionDe
243232
}
244233

245234
private void addEventListeners(Map<EventType<?>, Set<String>> eventListenerMap) {
246-
if ( eventListenerMap == null ) {
247-
return;
248-
}
249-
250-
if ( this.eventListenerMap == null ) {
251-
this.eventListenerMap = new HashMap<>();
252-
}
235+
if ( eventListenerMap != null ) {
236+
if ( this.eventListenerMap == null ) {
237+
this.eventListenerMap = new HashMap<>();
238+
}
253239

254-
for ( Map.Entry<EventType<?>, Set<String>> incomingEntry : eventListenerMap.entrySet() ) {
255-
Set<String> listenerClasses = this.eventListenerMap.get( incomingEntry.getKey() );
256-
if ( listenerClasses == null ) {
257-
listenerClasses = new HashSet<>();
258-
this.eventListenerMap.put( incomingEntry.getKey(), listenerClasses );
240+
for ( var incomingEntry : eventListenerMap.entrySet() ) {
241+
var listenerClasses = this.eventListenerMap.get( incomingEntry.getKey() );
242+
if ( listenerClasses == null ) {
243+
listenerClasses = new HashSet<>();
244+
this.eventListenerMap.put( incomingEntry.getKey(), listenerClasses );
245+
}
246+
listenerClasses.addAll( incomingEntry.getValue() );
259247
}
260-
listenerClasses.addAll( incomingEntry.getValue() );
261248
}
262249
}
263250

0 commit comments

Comments
 (0)