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 @@ -326,15 +326,13 @@ public static Properties asProperties(Map<?,?> map) {
* @return will never return null, but might return an immutable collection.
*/
public static <T> Set<T> toSmallSet(Set<T> set) {
switch ( set.size() ) {
case 0:
return emptySet();
case 1:
return singleton( set.iterator().next() );
default:
//TODO assert tests pass even if this is set to return an unmodifiable Set
return set;
}
return switch ( set.size() ) {
case 0 -> emptySet();
case 1 -> singleton( set.iterator().next() );
//TODO assert tests pass even if this is set to return an unmodifiable Set
default -> set;

};
}

/**
Expand All @@ -345,16 +343,16 @@ public static <T> Set<T> toSmallSet(Set<T> set) {
* The goal is to save memory.
*/
public static <K, V> Map<K, V> toSmallMap(final Map<K, V> map) {
switch ( map.size() ) {
case 0:
return emptyMap();
case 1:
Map.Entry<K, V> entry = map.entrySet().iterator().next();
return singletonMap( entry.getKey(), entry.getValue() );
default:
//TODO assert tests pass even if this is set to return an unmodifiable Map
return map;
}
return switch ( map.size() ) {
case 0 -> emptyMap();
case 1 -> {
var entry = map.entrySet().iterator().next();
yield singletonMap( entry.getKey(), entry.getValue() );
}
//TODO assert tests pass even if this is set to return an unmodifiable Map
default -> map;

};
}

/**
Expand All @@ -365,15 +363,14 @@ public static <K, V> Map<K, V> toSmallMap(final Map<K, V> map) {
* The goal is to save memory.
*/
public static <V> List<V> toSmallList(ArrayList<V> arrayList) {
switch ( arrayList.size() ) {
case 0:
return emptyList();
case 1:
return singletonList( arrayList.get( 0 ) );
default:
return switch ( arrayList.size() ) {
case 0 -> emptyList();
case 1 -> singletonList( arrayList.get( 0 ) );
default -> {
arrayList.trimToSize();
return arrayList;
}
yield arrayList;
}
};
}

public static <O> List<O> combine(List<O> list1, List<O> list2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1889,9 +1889,10 @@ public String selectFragment(String alias, String suffix) {
for ( ; i < sqlSelections.size(); i++ ) {
final SqlSelection sqlSelection = sqlSelections.get( i );
final ColumnReference columnReference = (ColumnReference) sqlSelection.getExpression();
final String selectAlias = !columnReference.isColumnExpressionFormula()
? columnAliases[columnIndex++] + suffix
: formulaAliases[formulaIndex++] + suffix;
final String selectAlias =
columnReference.isColumnExpressionFormula()
? formulaAliases[formulaIndex++] + suffix
: columnAliases[columnIndex++] + suffix;
sqlSelections.set(
i,
new SqlSelectionImpl(
Expand All @@ -1916,50 +1917,48 @@ private ImmutableFetchList fetchProcessor(FetchParent fetchParent, LoaderSqlAstC
final FetchableContainer fetchableContainer = fetchParent.getReferencedMappingContainer();
final int size = fetchableContainer.getNumberOfFetchables();
final ImmutableFetchList.Builder fetches = new ImmutableFetchList.Builder( fetchableContainer );

for ( int i = 0; i < size; i++ ) {
final Fetchable fetchable = fetchableContainer.getFetchable( i );
// Ignore plural attributes
if ( !( fetchable instanceof PluralAttributeMapping ) ) {
final FetchTiming fetchTiming = fetchable.getMappedFetchOptions().getTiming();
if ( fetchable.asBasicValuedModelPart() != null ) {
// Ignore lazy basic columns
if ( fetchTiming == FetchTiming.DELAYED ) {
continue;
}
}
else if ( fetchable instanceof Association association ) {
// Ignore the fetchable if the FK is on the other side
if ( association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET ) {
continue;
if ( !skipFetchable( fetchable, fetchTiming ) ) {
if ( fetchTiming == null ) {
throw new AssertionFailure( "fetchTiming was null" );
}
// Ensure the FK comes from the root table
if ( !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() ) ) {
continue;
if ( fetchable.isSelectable() ) {
final Fetch fetch = fetchParent.generateFetchableFetch(
fetchable,
fetchParent.resolveNavigablePath( fetchable ),
fetchTiming,
false,
null,
creationState
);
fetches.add( fetch );
}
}

if ( fetchTiming == null ) {
throw new AssertionFailure("fetchTiming was null");
}

if ( fetchable.isSelectable() ) {
final Fetch fetch = fetchParent.generateFetchableFetch(
fetchable,
fetchParent.resolveNavigablePath( fetchable ),
fetchTiming,
false,
null,
creationState
);
fetches.add( fetch );
}
}
}

return fetches.build();
}

private boolean skipFetchable(Fetchable fetchable, FetchTiming fetchTiming) {
if ( fetchable.asBasicValuedModelPart() != null ) {
// Ignore lazy basic columns
return fetchTiming == FetchTiming.DELAYED;
}
else if ( fetchable instanceof Association association ) {
// Ignore the fetchable if the FK is on the other side
return association.getSideNature() == ForeignKeyDescriptor.Nature.TARGET
// Ensure the FK comes from the root table
|| !getRootTableName().equals( association.getForeignKeyDescriptor().getKeyTable() );
}
else {
return false;
}
}

@Override
public String[] getIdentifierAliases(String suffix) {
// NOTE: this assumes something about how propertySelectFragment is implemented by the subclass!
Expand Down