Skip to content

Commit 4a7d577

Browse files
committed
extract a method in AbstractEntityPersister
1 parent 6902a72 commit 4a7d577

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,9 +1889,10 @@ public String selectFragment(String alias, String suffix) {
18891889
for ( ; i < sqlSelections.size(); i++ ) {
18901890
final SqlSelection sqlSelection = sqlSelections.get( i );
18911891
final ColumnReference columnReference = (ColumnReference) sqlSelection.getExpression();
1892-
final String selectAlias = !columnReference.isColumnExpressionFormula()
1893-
? columnAliases[columnIndex++] + suffix
1894-
: formulaAliases[formulaIndex++] + suffix;
1892+
final String selectAlias =
1893+
columnReference.isColumnExpressionFormula()
1894+
? formulaAliases[formulaIndex++] + suffix
1895+
: columnAliases[columnIndex++] + suffix;
18951896
sqlSelections.set(
18961897
i,
18971898
new SqlSelectionImpl(
@@ -1916,50 +1917,48 @@ private ImmutableFetchList fetchProcessor(FetchParent fetchParent, LoaderSqlAstC
19161917
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
19171918
final int size = fetchableContainer.getNumberOfFetchables();
19181919
final ImmutableFetchList.Builder fetches = new ImmutableFetchList.Builder( fetchableContainer );
1919-
19201920
for ( int i = 0; i < size; i++ ) {
19211921
final Fetchable fetchable = fetchableContainer.getFetchable( i );
19221922
// Ignore plural attributes
19231923
if ( !( fetchable instanceof PluralAttributeMapping ) ) {
19241924
final FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming();
1925-
if ( fetchable.asBasicValuedModelPart() != null ) {
1926-
// Ignore lazy basic columns
1927-
if ( fetchTiming == FetchTiming.DELAYED ) {
1928-
continue;
1929-
}
1930-
}
1931-
else if ( fetchable instanceof Association association ) {
1932-
// Ignore the fetchable if the FK is on the other side
1933-
if ( association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET ) {
1934-
continue;
1925+
if ( !skipFetchable( fetchable, fetchTiming ) ) {
1926+
if ( fetchTiming == null ) {
1927+
throw new AssertionFailure( "fetchTiming was null" );
19351928
}
1936-
// Ensure the FK comes from the root table
1937-
if ( !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() ) ) {
1938-
continue;
1929+
if ( fetchable.isSelectable() ) {
1930+
final Fetch fetch = fetchParent.generateFetchableFetch(
1931+
fetchable,
1932+
fetchParent.resolveNavigablePath( fetchable ),
1933+
fetchTiming,
1934+
false,
1935+
null,
1936+
creationState
1937+
);
1938+
fetches.add( fetch );
19391939
}
19401940
}
1941-
1942-
if ( fetchTiming == null ) {
1943-
throw new AssertionFailure("fetchTiming was null");
1944-
}
1945-
1946-
if ( fetchable.isSelectable() ) {
1947-
final Fetch fetch = fetchParent.generateFetchableFetch(
1948-
fetchable,
1949-
fetchParent.resolveNavigablePath( fetchable ),
1950-
fetchTiming,
1951-
false,
1952-
null,
1953-
creationState
1954-
);
1955-
fetches.add( fetch );
1956-
}
19571941
}
19581942
}
1959-
19601943
return fetches.build();
19611944
}
19621945

1946+
private boolean skipFetchable(Fetchable fetchable, FetchTiming fetchTiming) {
1947+
if ( fetchable.asBasicValuedModelPart() != null ) {
1948+
// Ignore lazy basic columns
1949+
return fetchTiming == FetchTiming.DELAYED;
1950+
}
1951+
else if ( fetchable instanceof Association association ) {
1952+
// Ignore the fetchable if the FK is on the other side
1953+
return association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET
1954+
// Ensure the FK comes from the root table
1955+
|| !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() );
1956+
}
1957+
else {
1958+
return false;
1959+
}
1960+
}
1961+
19631962
@Override
19641963
public String[] getIdentifierAliases(String suffix) {
19651964
// NOTE: this assumes something about how propertySelectFragment is implemented by the subclass!

0 commit comments

Comments
 (0)