Skip to content

Commit e1c6f49

Browse files
committed
remove unnecessary logging
and add more 'var' usage
1 parent 2e38fb3 commit e1c6f49

File tree

3 files changed

+38
-74
lines changed

3 files changed

+38
-74
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch;
6666
import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch;
6767
import org.hibernate.sql.results.graph.collection.internal.SelectEagerCollectionFetch;
68-
import org.jboss.logging.Logger;
6968

7069
import java.util.function.BiConsumer;
7170
import java.util.function.Consumer;
@@ -80,7 +79,6 @@
8079
public class PluralAttributeMappingImpl
8180
extends AbstractAttributeMapping
8281
implements PluralAttributeMapping, FetchProfileAffectee, FetchOptions {
83-
private static final Logger log = Logger.getLogger( PluralAttributeMappingImpl.class );
8482

8583
/**
8684
* Allows callback after creation of the attribute mapping.
@@ -96,8 +94,7 @@ public interface Aware {
9694
void injectAttributeMapping(PluralAttributeMapping attributeMapping);
9795
}
9896

99-
@SuppressWarnings("rawtypes")
100-
private final CollectionMappingType collectionMappingType;
97+
private final CollectionMappingType<?> collectionMappingType;
10198
private final String referencedPropertyName;
10299
private final String mapKeyPropertyName;
103100

@@ -237,10 +234,11 @@ public boolean isBidirectionalAttributeName(NavigablePath fetchablePath, ToOneAt
237234
return fetchablePath.getLocalName().endsWith( bidirectionalAttributeName );
238235
}
239236

240-
@SuppressWarnings("unused")
241237
public void finishInitialization(
238+
@SuppressWarnings("unused")
242239
Property bootProperty,
243240
Collection bootDescriptor,
241+
@SuppressWarnings("unused")
244242
MappingModelCreationProcess creationProcess) {
245243
final boolean hasOrder = bootDescriptor.getOrderBy() != null;
246244
final boolean hasManyToManyOrder = bootDescriptor.getManyToManyOrdering() != null;
@@ -249,13 +247,6 @@ public void finishInitialization(
249247
final TranslationContext context = collectionDescriptor::getFactory;
250248

251249
if ( hasOrder ) {
252-
if ( log.isTraceEnabled() ) {
253-
log.tracef(
254-
"Translating order-by fragment [%s] for collection role: %s",
255-
bootDescriptor.getOrderBy(),
256-
collectionDescriptor.getRole()
257-
);
258-
}
259250
orderByFragment = OrderByFragmentTranslator.translate(
260251
bootDescriptor.getOrderBy(),
261252
this,
@@ -264,13 +255,6 @@ public void finishInitialization(
264255
}
265256

266257
if ( hasManyToManyOrder ) {
267-
if ( log.isTraceEnabled() ) {
268-
log.tracef(
269-
"Translating many-to-many order-by fragment [%s] for collection role: %s",
270-
bootDescriptor.getOrderBy(),
271-
collectionDescriptor.getRole()
272-
);
273-
}
274258
manyToManyOrderByFragment = OrderByFragmentTranslator.translate(
275259
bootDescriptor.getManyToManyOrdering(),
276260
this,
@@ -286,8 +270,7 @@ public NavigableRole getNavigableRole() {
286270
}
287271

288272
@Override
289-
@SuppressWarnings("rawtypes")
290-
public CollectionMappingType getMappedType() {
273+
public CollectionMappingType<?> getMappedType() {
291274
return collectionMappingType;
292275
}
293276

@@ -384,32 +367,34 @@ public boolean hasPartitionedSelectionMapping() {
384367

385368
@Override
386369
public void applySoftDeleteRestrictions(TableGroup tableGroup, PredicateConsumer predicateConsumer) {
387-
if ( !hasSoftDelete() ) {
388-
// short-circuit
389-
return;
390-
}
370+
if ( hasSoftDelete() ) {
371+
final var descriptor = getCollectionDescriptor();
372+
if ( descriptor.isOneToMany() || descriptor.isManyToMany() ) {
373+
// see if the associated entity has soft-delete defined
374+
final var elementDescriptor = (EntityCollectionPart) getElementDescriptor();
375+
final var associatedEntityDescriptor = elementDescriptor.getAssociatedEntityMappingType();
376+
final var softDeleteMapping = associatedEntityDescriptor.getSoftDeleteMapping();
377+
if ( softDeleteMapping != null ) {
378+
final String primaryTableName =
379+
associatedEntityDescriptor.getSoftDeleteTableDetails().getTableName();
380+
final TableReference primaryTableReference =
381+
tableGroup.resolveTableReference( primaryTableName );
382+
final Predicate softDeleteRestriction =
383+
softDeleteMapping.createNonDeletedRestriction( primaryTableReference );
384+
predicateConsumer.applyPredicate( softDeleteRestriction );
385+
}
386+
}
391387

392-
if ( getCollectionDescriptor().isOneToMany()
393-
|| getCollectionDescriptor().isManyToMany() ) {
394-
// see if the associated entity has soft-delete defined
395-
final EntityCollectionPart elementDescriptor = (EntityCollectionPart) getElementDescriptor();
396-
final EntityMappingType associatedEntityDescriptor = elementDescriptor.getAssociatedEntityMappingType();
397-
final SoftDeleteMapping softDeleteMapping = associatedEntityDescriptor.getSoftDeleteMapping();
388+
// apply the collection's soft-delete mapping, if one
389+
final var softDeleteMapping = getSoftDeleteMapping();
398390
if ( softDeleteMapping != null ) {
399-
final String primaryTableName = associatedEntityDescriptor.getSoftDeleteTableDetails().getTableName();
400-
final TableReference primaryTableReference = tableGroup.resolveTableReference( primaryTableName );
401-
final Predicate softDeleteRestriction = softDeleteMapping.createNonDeletedRestriction( primaryTableReference );
391+
final TableReference primaryTableReference =
392+
tableGroup.resolveTableReference( getSoftDeleteTableDetails().getTableName() );
393+
final Predicate softDeleteRestriction =
394+
softDeleteMapping.createNonDeletedRestriction( primaryTableReference );
402395
predicateConsumer.applyPredicate( softDeleteRestriction );
403396
}
404397
}
405-
406-
// apply the collection's soft-delete mapping, if one
407-
final SoftDeleteMapping softDeleteMapping = getSoftDeleteMapping();
408-
if ( softDeleteMapping != null ) {
409-
final TableReference primaryTableReference = tableGroup.resolveTableReference( getSoftDeleteTableDetails().getTableName() );
410-
final Predicate softDeleteRestriction = softDeleteMapping.createNonDeletedRestriction( primaryTableReference );
411-
predicateConsumer.applyPredicate( softDeleteRestriction );
412-
}
413398
}
414399

415400
@Override
@@ -418,9 +403,9 @@ public <T> DomainResult<T> createDomainResult(
418403
TableGroup tableGroup,
419404
String resultVariable,
420405
DomainResultCreationState creationState) {
421-
final TableGroup collectionTableGroup = creationState.getSqlAstCreationState()
422-
.getFromClauseAccess()
423-
.getTableGroup( navigablePath );
406+
final TableGroup collectionTableGroup =
407+
creationState.getSqlAstCreationState().getFromClauseAccess()
408+
.getTableGroup( navigablePath );
424409

425410
assert collectionTableGroup != null;
426411

@@ -440,7 +425,7 @@ public Fetch generateFetch(
440425
boolean selected,
441426
String resultVariable,
442427
DomainResultCreationState creationState) {
443-
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
428+
final var sqlAstCreationState = creationState.getSqlAstCreationState();
444429

445430
final boolean added = creationState.registerVisitedAssociationKey( fkDescriptor.getAssociationKey() );
446431

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/OrderByFragmentTranslator.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
1010
import org.hibernate.metamodel.mapping.ordering.ast.ParseTreeVisitor;
1111

12-
import org.jboss.logging.Logger;
1312

1413
import org.antlr.v4.runtime.BailErrorStrategy;
1514
import org.antlr.v4.runtime.BufferedTokenStream;
@@ -28,7 +27,6 @@
2827
* @see jakarta.persistence.OrderBy
2928
*/
3029
public class OrderByFragmentTranslator {
31-
private static final Logger LOG = Logger.getLogger( OrderByFragmentTranslator.class.getName() );
3230

3331
/**
3432
* Perform the translation of the user-supplied fragment, returning the translation.
@@ -43,28 +41,18 @@ public static OrderByFragment translate(
4341
String fragment,
4442
PluralAttributeMapping pluralAttributeMapping,
4543
TranslationContext context) {
46-
if ( LOG.isTraceEnabled() ) {
47-
LOG.tracef(
48-
"Beginning parsing of order-by fragment [%s] : %s",
49-
pluralAttributeMapping.getCollectionDescriptor().getRole(),
50-
fragment
51-
);
52-
}
53-
54-
final OrderingParser.OrderByFragmentContext parseTree = buildParseTree( context, fragment );
55-
56-
final ParseTreeVisitor visitor = new ParseTreeVisitor( pluralAttributeMapping, context );
57-
44+
final var parseTree = buildParseTree( fragment );
45+
final var visitor = new ParseTreeVisitor( pluralAttributeMapping, context );
5846
return new OrderByFragmentImpl( visitor.visitOrderByFragment( parseTree ) );
5947
}
6048

6149

62-
private static OrderingParser.OrderByFragmentContext buildParseTree(TranslationContext context, String fragment) {
63-
final OrderingLexer lexer = new OrderingLexer( CharStreams.fromString( fragment ) );
50+
private static OrderingParser.OrderByFragmentContext buildParseTree(String fragment) {
51+
final var lexer = new OrderingLexer( CharStreams.fromString( fragment ) );
6452

65-
final OrderingParser parser = new OrderingParser( new BufferedTokenStream( lexer ) );
53+
final var parser = new OrderingParser( new BufferedTokenStream( lexer ) );
6654

67-
// try to use SLL(k)-based parsing first - its faster
55+
// try to use SLL(k)-based parsing first - it's faster
6856
parser.getInterpreter().setPredictionMode( PredictionMode.SLL );
6957
parser.removeErrorListeners();
7058
parser.setErrorHandler( new BailErrorStrategy() );

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/PathConsumer.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* @author Steve Ebersole
1919
*/
2020
public class PathConsumer {
21-
private static final Logger log = Logger.getLogger( BasicDotIdentifierConsumer.class );
2221

2322
private final TranslationContext translationContext;
2423

@@ -48,19 +47,11 @@ public void consumeIdentifier(
4847
reset();
4948
}
5049

51-
if ( pathSoFar.length() != 0 ) {
50+
if ( !pathSoFar.isEmpty() ) {
5251
pathSoFar.append( '.' );
5352
}
5453
pathSoFar.append( unquotedIdentifier );
5554

56-
// log.tracef(
57-
// "BasicDotIdentifierHandler#consumeIdentifier( %s, %s, %s ) - %s",
58-
// unquotedIdentifier,
59-
// isBase,
60-
// isTerminal,
61-
// pathSoFar
62-
// );
63-
6455
currentPart = currentPart.resolvePathPart( unquotedIdentifier, identifier, isTerminal, translationContext );
6556
}
6657

0 commit comments

Comments
 (0)