Skip to content

Commit d2295d1

Browse files
committed
use of var and final in the TypeBinders and AttributeBinders
1 parent 76c4b3f commit d2295d1

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

hibernate-core/src/main/java/org/hibernate/binder/internal/AttributeAccessorBinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public void bind(
2424
MetadataBuildingContext buildingContext,
2525
PersistentClass persistentClass,
2626
Property property) {
27-
String value = accessor.value();
28-
Class<?> type = accessor.strategy();
27+
final String value = accessor.value();
28+
final Class<?> type = accessor.strategy();
2929
if ( !value.isEmpty() ) {
3030
property.setPropertyAccessorName( value );
3131
}

hibernate-core/src/main/java/org/hibernate/binder/internal/CollateBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class CollateBinder implements AttributeBinder<Collate> {
2424
@Override
2525
public void bind(Collate collate, MetadataBuildingContext context, PersistentClass entity, Property property) {
26-
Value value = property.getValue();
26+
final Value value = property.getValue();
2727
if ( value instanceof OneToMany ) {
2828
throw new AnnotationException( "One to many association '" + property.getName()
2929
+ "' was annotated '@Collate'");

hibernate-core/src/main/java/org/hibernate/binder/internal/CommentBinder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
public class CommentBinder implements AttributeBinder<Comment>, TypeBinder<Comment> {
2828
@Override
2929
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity, Property property) {
30-
String text = comment.value();
31-
String on = comment.on();
32-
Value value = property.getValue();
30+
final String text = comment.value();
31+
final String on = comment.on();
32+
final Value value = property.getValue();
3333
if ( value instanceof OneToMany ) {
3434
throw new AnnotationException( "One to many association '" + property.getName()
3535
+ "' was annotated '@Comment'");
@@ -64,17 +64,17 @@ else if ( value instanceof Collection collection ) {
6464

6565
@Override
6666
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity) {
67-
String text = comment.value();
68-
String on = comment.on();
69-
Table primary = entity.getTable();
67+
final String text = comment.value();
68+
final String on = comment.on();
69+
final Table primary = entity.getTable();
7070
// by default, the comment goes on the primary table
7171
if ( on.isEmpty() || primary.getName().equalsIgnoreCase( on ) ) {
7272
primary.setComment( text );
7373
}
7474
else {
7575
// but if 'on' is explicit, it can go on a secondary table
7676
for ( Join join : entity.getJoins() ) {
77-
Table secondary = join.getTable();
77+
final Table secondary = join.getTable();
7878
if ( secondary.getName().equalsIgnoreCase( on ) ) {
7979
secondary.setComment( text );
8080
return;

hibernate-core/src/main/java/org/hibernate/binder/internal/CommentsBinder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.hibernate.binder.internal;
66

77
import org.hibernate.AnnotationException;
8-
import org.hibernate.annotations.Comment;
98
import org.hibernate.annotations.Comments;
109
import org.hibernate.binder.AttributeBinder;
1110
import org.hibernate.binder.TypeBinder;
@@ -25,9 +24,9 @@
2524
public class CommentsBinder implements TypeBinder<Comments>, AttributeBinder<Comments> {
2625
@Override
2726
public void bind(Comments comments, MetadataBuildingContext context, PersistentClass entity, Property property) {
28-
final CommentBinder commentBinder = new CommentBinder();
27+
final var commentBinder = new CommentBinder();
2928
final Set<String> ons = new HashSet<>( comments.value().length );
30-
for ( Comment comment : comments.value() ) {
29+
for ( var comment : comments.value() ) {
3130
if ( !ons.add( comment.on() ) ) {
3231
throw new AnnotationException( "Multiple '@Comment' annotations of '"
3332
+ property.getName() + "' had the same 'on'" );
@@ -38,9 +37,9 @@ public void bind(Comments comments, MetadataBuildingContext context, PersistentC
3837

3938
@Override
4039
public void bind(Comments comments, MetadataBuildingContext context, PersistentClass entity) {
41-
final CommentBinder commentBinder = new CommentBinder();
40+
final var commentBinder = new CommentBinder();
4241
final Set<String> ons = new HashSet<>( comments.value().length );
43-
for ( Comment comment : comments.value() ) {
42+
for ( var comment : comments.value() ) {
4443
if ( !ons.add( comment.on() ) ) {
4544
throw new AnnotationException( "Multiple '@Comment' annotations of entity '"
4645
+ entity.getEntityName() + "' had the same 'on'" );

hibernate-core/src/main/java/org/hibernate/binder/internal/TenantIdBinder.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import org.hibernate.MappingException;
1111
import org.hibernate.annotations.TenantId;
1212
import org.hibernate.binder.AttributeBinder;
13-
import org.hibernate.boot.spi.InFlightMetadataCollector;
1413
import org.hibernate.boot.spi.MetadataBuildingContext;
1514
import org.hibernate.engine.spi.FilterDefinition;
1615
import org.hibernate.mapping.Column;
1716
import org.hibernate.mapping.Formula;
1817
import org.hibernate.mapping.PersistentClass;
1918
import org.hibernate.mapping.Property;
20-
import org.hibernate.mapping.Selectable;
2119
import org.hibernate.metamodel.mapping.JdbcMapping;
22-
import org.hibernate.type.BasicType;
2320
import org.hibernate.type.descriptor.java.JavaType;
2421

2522
import static java.util.Collections.emptyMap;
@@ -41,14 +38,14 @@ public void bind(
4138
MetadataBuildingContext buildingContext,
4239
PersistentClass persistentClass,
4340
Property property) {
44-
final InFlightMetadataCollector collector = buildingContext.getMetadataCollector();
41+
final var collector = buildingContext.getMetadataCollector();
4542

4643
final String returnedClassName = property.getReturnedClassName();
47-
final BasicType<Object> tenantIdType =
44+
final var tenantIdType =
4845
collector.getTypeConfiguration().getBasicTypeRegistry()
4946
.getRegisteredType( returnedClassName );
5047

51-
final FilterDefinition filterDefinition = collector.getFilterDefinition( FILTER_NAME );
48+
final var filterDefinition = collector.getFilterDefinition( FILTER_NAME );
5249
if ( filterDefinition == null ) {
5350
collector.addFilterDefinition(
5451
new FilterDefinition(
@@ -93,7 +90,7 @@ private String columnNameOrFormula(Property property) {
9390
if ( property.getColumnSpan() != 1 ) {
9491
throw new MappingException( "@TenantId attribute must be mapped to a single column or formula" );
9592
}
96-
final Selectable selectable = property.getSelectables().get( 0 );
93+
final var selectable = property.getSelectables().get( 0 );
9794
if ( selectable instanceof Formula formula ) {
9895
return formula.getFormula();
9996
}

0 commit comments

Comments
 (0)