Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
MetadataBuildingContext buildingContext,
PersistentClass persistentClass,
Property property) {
String value = accessor.value();
Class<?> type = accessor.strategy();
final String value = accessor.value();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
AttributeAccessor.value
should be avoided because it has been deprecated.
final Class<?> type = accessor.strategy();
if ( !value.isEmpty() ) {
property.setPropertyAccessorName( value );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class CollateBinder implements AttributeBinder<Collate> {
@Override
public void bind(Collate collate, MetadataBuildingContext context, PersistentClass entity, Property property) {
Value value = property.getValue();
final Value value = property.getValue();
if ( value instanceof OneToMany ) {
throw new AnnotationException( "One to many association '" + property.getName()
+ "' was annotated '@Collate'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
public class CommentBinder implements AttributeBinder<Comment>, TypeBinder<Comment> {
@Override
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity, Property property) {
String text = comment.value();
String on = comment.on();
Value value = property.getValue();
final String text = comment.value();
final String on = comment.on();
final Value value = property.getValue();
if ( value instanceof OneToMany ) {
throw new AnnotationException( "One to many association '" + property.getName()
+ "' was annotated '@Comment'");
Expand Down Expand Up @@ -64,17 +64,17 @@ else if ( value instanceof Collection collection ) {

@Override
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity) {
String text = comment.value();
String on = comment.on();
Table primary = entity.getTable();
final String text = comment.value();
final String on = comment.on();
final Table primary = entity.getTable();
// by default, the comment goes on the primary table
if ( on.isEmpty() || primary.getName().equalsIgnoreCase( on ) ) {
primary.setComment( text );
}
else {
// but if 'on' is explicit, it can go on a secondary table
for ( Join join : entity.getJoins() ) {
Table secondary = join.getTable();
final Table secondary = join.getTable();
if ( secondary.getName().equalsIgnoreCase( on ) ) {
secondary.setComment( text );
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.hibernate.binder.internal;

import org.hibernate.AnnotationException;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Comments;
import org.hibernate.binder.AttributeBinder;
import org.hibernate.binder.TypeBinder;
Expand All @@ -25,9 +24,9 @@
public class CommentsBinder implements TypeBinder<Comments>, AttributeBinder<Comments> {
@Override
public void bind(Comments comments, MetadataBuildingContext context, PersistentClass entity, Property property) {
final CommentBinder commentBinder = new CommentBinder();
final var commentBinder = new CommentBinder();
final Set<String> ons = new HashSet<>( comments.value().length );
for ( Comment comment : comments.value() ) {
for ( var comment : comments.value() ) {
if ( !ons.add( comment.on() ) ) {
throw new AnnotationException( "Multiple '@Comment' annotations of '"
+ property.getName() + "' had the same 'on'" );
Expand All @@ -38,9 +37,9 @@ public void bind(Comments comments, MetadataBuildingContext context, PersistentC

@Override
public void bind(Comments comments, MetadataBuildingContext context, PersistentClass entity) {
final CommentBinder commentBinder = new CommentBinder();
final var commentBinder = new CommentBinder();
final Set<String> ons = new HashSet<>( comments.value().length );
for ( Comment comment : comments.value() ) {
for ( var comment : comments.value() ) {
if ( !ons.add( comment.on() ) ) {
throw new AnnotationException( "Multiple '@Comment' annotations of entity '"
+ entity.getEntityName() + "' had the same 'on'" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import org.hibernate.MappingException;
import org.hibernate.annotations.TenantId;
import org.hibernate.binder.AttributeBinder;
import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Formula;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JavaType;

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

final String returnedClassName = property.getReturnedClassName();
final BasicType<Object> tenantIdType =
final var tenantIdType =
collector.getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType( returnedClassName );

final FilterDefinition filterDefinition = collector.getFilterDefinition( FILTER_NAME );
final var filterDefinition = collector.getFilterDefinition( FILTER_NAME );
if ( filterDefinition == null ) {
collector.addFilterDefinition(
new FilterDefinition(
Expand Down Expand Up @@ -93,7 +90,7 @@ private String columnNameOrFormula(Property property) {
if ( property.getColumnSpan() != 1 ) {
throw new MappingException( "@TenantId attribute must be mapped to a single column or formula" );
}
final Selectable selectable = property.getSelectables().get( 0 );
final var selectable = property.getSelectables().get( 0 );
if ( selectable instanceof Formula formula ) {
return formula.getFormula();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory, SessionCre
batchSize = options.getDefaultBatchFetchSize();
subselectFetchEnabled = options.isSubselectFetchEnabled();
effectiveEntityGraph = new EffectiveEntityGraph();
for ( FilterDefinition filterDefinition : sessionFactory.getAutoEnabledFilters() ) {
final FilterImpl filter = new FilterImpl( filterDefinition );
for ( var filterDefinition : sessionFactory.getAutoEnabledFilters() ) {
final var filter = new FilterImpl( filterDefinition );
if ( enabledFilters == null ) {
enabledFilters = new TreeMap<>();
}
Expand All @@ -84,7 +84,7 @@ public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory, SessionCre
}

public EffectiveEntityGraph applyEntityGraph(@Nullable RootGraphImplementor<?> rootGraph, @Nullable GraphSemantic graphSemantic) {
final EffectiveEntityGraph effectiveEntityGraph = getEffectiveEntityGraph();
final var effectiveEntityGraph = getEffectiveEntityGraph();
if ( graphSemantic != null ) {
if ( rootGraph == null ) {
throw new IllegalArgumentException( "Graph semantic specified, but no RootGraph was supplied" );
Expand Down Expand Up @@ -141,13 +141,13 @@ public boolean hasEnabledFilters() {
}

public Map<String,Filter> getEnabledFilters() {
final TreeMap<String, Filter> enabledFilters = this.enabledFilters;
final var enabledFilters = this.enabledFilters;
if ( enabledFilters == null ) {
return emptyMap();
}
else {
// First, validate all the enabled filters...
for ( Filter filter : enabledFilters.values() ) {
for ( var filter : enabledFilters.values() ) {
//TODO: this implementation has bad performance
filter.validate();
}
Expand Down Expand Up @@ -187,15 +187,15 @@ public Object getFilterParameterValue(String filterParameterName) {
if ( enabledFilters == null ) {
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
}
final FilterImpl filter = (FilterImpl) enabledFilters.get( parsed[0] );
final var filter = (FilterImpl) enabledFilters.get( parsed[0] );
if ( filter == null ) {
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
}
return filter.getParameter( parsed[1] );
}

public static String [] parseFilterParameterName(String filterParameterName) {
int dot = filterParameterName.lastIndexOf( '.' );
final int dot = filterParameterName.lastIndexOf( '.' );
if ( dot <= 0 ) {
throw new IllegalArgumentException(
"Invalid filter-parameter name format [" + filterParameterName + "]; expecting {filter-name}.{param-name}"
Expand Down Expand Up @@ -246,14 +246,10 @@ public void disableFetchProfile(String name) throws UnknownProfileException {
@Internal
public @Nullable HashSet<String> adjustFetchProfiles(
@Nullable Set<String> disabledFetchProfiles, @Nullable Set<String> enabledFetchProfiles) {
final HashSet<String> currentEnabledFetchProfileNames = this.enabledFetchProfileNames;
final HashSet<String> oldFetchProfiles;
if ( currentEnabledFetchProfileNames == null || currentEnabledFetchProfileNames.isEmpty() ) {
oldFetchProfiles = null;
}
else {
oldFetchProfiles = new HashSet<>( currentEnabledFetchProfileNames );
}
final var oldFetchProfiles =
enabledFetchProfileNames != null && !enabledFetchProfileNames.isEmpty()
? new HashSet<>( enabledFetchProfileNames )
: null;
if ( disabledFetchProfiles != null && enabledFetchProfileNames != null ) {
enabledFetchProfileNames.removeAll( disabledFetchProfiles );
}
Expand Down Expand Up @@ -292,7 +288,7 @@ public void setBatchSize(int batchSize) {
}

public int effectiveBatchSize(CollectionPersister persister) {
int persisterBatchSize = persister.getBatchSize();
final int persisterBatchSize = persister.getBatchSize();
// persister-specific batch size overrides global setting
// (note that due to legacy, -1 means no explicit setting)
return persisterBatchSize >= 0 ? persisterBatchSize : batchSize;
Expand All @@ -303,7 +299,7 @@ public boolean effectivelyBatchLoadable(CollectionPersister persister) {
}

public int effectiveBatchSize(EntityPersister persister) {
int persisterBatchSize = persister.getBatchSize();
final int persisterBatchSize = persister.getBatchSize();
// persister-specific batch size overrides global setting
// (note that due to legacy, -1 means no explicit setting)
return persisterBatchSize >= 0 ? persisterBatchSize : batchSize;
Expand Down Expand Up @@ -331,7 +327,8 @@ private boolean isSubselectFetchEnabledInProfile(CollectionPersister persister)
if ( hasEnabledFetchProfiles() ) {
for ( String profile : getEnabledFetchProfileNames() ) {
final FetchProfile fetchProfile =
persister.getFactory().getSqlTranslationEngine().getFetchProfile( profile ) ;
persister.getFactory().getSqlTranslationEngine()
.getFetchProfile( profile ) ;
if ( fetchProfile != null ) {
final Fetch fetch = fetchProfile.getFetchByRole( persister.getRole() );
if ( fetch != null && fetch.getMethod() == SUBSELECT) {
Expand Down
Loading