HHH-12917 Interning of strings for Filter definitions
This commit is contained in:
parent
6911efdfb7
commit
4fa0491341
|
@ -14,6 +14,8 @@ import org.hibernate.internal.util.StringHelper;
|
|||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.sql.Template;
|
||||
|
||||
import static org.hibernate.internal.util.StringHelper.safeInterning;
|
||||
|
||||
/**
|
||||
* Implementation of FilterHelper.
|
||||
*
|
||||
|
@ -44,23 +46,27 @@ public class FilterHelper {
|
|||
filterCount = 0;
|
||||
for ( final FilterConfiguration filter : filters ) {
|
||||
filterAutoAliasFlags[filterCount] = false;
|
||||
filterNames[filterCount] = filter.getName();
|
||||
filterConditions[filterCount] = filter.getCondition();
|
||||
filterNames[filterCount] = safeInterning( filter.getName() );
|
||||
filterConditions[filterCount] = safeInterning( filter.getCondition() );
|
||||
filterAliasTableMaps[filterCount] = filter.getAliasTableMap( factory );
|
||||
if ( ( filterAliasTableMaps[filterCount].isEmpty() || isTableFromPersistentClass( filterAliasTableMaps[filterCount] ) ) && filter
|
||||
.useAutoAliasInjection() ) {
|
||||
filterConditions[filterCount] = Template.renderWhereStringTemplate(
|
||||
filter.getCondition(),
|
||||
FilterImpl.MARKER,
|
||||
factory.getDialect(),
|
||||
factory.getSqlFunctionRegistry()
|
||||
filterConditions[filterCount] = safeInterning(
|
||||
Template.renderWhereStringTemplate(
|
||||
filter.getCondition(),
|
||||
FilterImpl.MARKER,
|
||||
factory.getDialect(),
|
||||
factory.getSqlFunctionRegistry()
|
||||
)
|
||||
);
|
||||
filterAutoAliasFlags[filterCount] = true;
|
||||
}
|
||||
filterConditions[filterCount] = StringHelper.replace(
|
||||
filterConditions[filterCount],
|
||||
":",
|
||||
":" + filterNames[filterCount] + "."
|
||||
filterConditions[filterCount] = safeInterning(
|
||||
StringHelper.replace(
|
||||
filterConditions[filterCount],
|
||||
":",
|
||||
":" + filterNames[filterCount] + "."
|
||||
)
|
||||
);
|
||||
filterCount++;
|
||||
}
|
||||
|
|
|
@ -886,4 +886,25 @@ public final class StringHelper {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the interned form of a String, or null if the parameter is null.
|
||||
* <p>
|
||||
* Use with caution: excessive interning is known to cause issues.
|
||||
* Best to use only with strings which are known to be long lived constants,
|
||||
* and for which the chances of being actual duplicates is proven.
|
||||
* (Even better: avoid needing interning by design changes such as reusing
|
||||
* the known reference)
|
||||
* @param string The string to intern.
|
||||
* @return The interned string.
|
||||
*/
|
||||
public static String safeInterning(final String string) {
|
||||
if ( string == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return string.intern();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue