Skip to content

Consolidate filter handling: applyFilters. #32655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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 @@ -163,7 +163,7 @@ protected final SessionFactory obtainSessionFactory() {
* operation and correspondingly disabled at the end of the operation.
* This will work for newly opened Sessions as well as for existing
* Sessions (for example, within a transaction).
* @see #enableFilters(Session)
* @see #applyFilters(Session, boolean)
* @see Session#enableFilter(String)
*/
public void setFilterNames(@Nullable String... filterNames) {
Expand Down Expand Up @@ -360,7 +360,7 @@ protected <T> T doExecute(HibernateCallback<T> action, boolean enforceNativeSess
}

try {
enableFilters(session);
applyFilters(session, true);
Session sessionToExpose =
(enforceNativeSession || isExposeNativeSession() ? session : createSessionProxy(session));
return action.doInHibernate(sessionToExpose);
Expand All @@ -383,7 +383,7 @@ protected <T> T doExecute(HibernateCallback<T> action, boolean enforceNativeSess
SessionFactoryUtils.closeSession(session);
}
else {
disableFilters(session);
applyFilters(session, false);
}
}
}
Expand All @@ -404,31 +404,25 @@ protected Session createSessionProxy(Session session) {
}

/**
* Enable the specified filters on the given Session.
* Apply the specified filters on the given Session.
* This method can enable or disable the specified filters based on the 'enable' parameter.
*
* @param session the current Hibernate Session
* @param enable true to enable filters, false to disable filters
* @see #setFilterNames
* @see Session#enableFilter(String)
*/
protected void enableFilters(Session session) {
String[] filterNames = getFilterNames();
if (filterNames != null) {
for (String filterName : filterNames) {
session.enableFilter(filterName);
}
}
}

/**
* Disable the specified filters on the given Session.
* @param session the current Hibernate Session
* @see #setFilterNames
* @see Session#disableFilter(String)
*/
protected void disableFilters(Session session) {
protected void applyFilters(Session session, boolean enable) {
String[] filterNames = getFilterNames();
if (filterNames != null) {
for (String filterName : filterNames) {
session.disableFilter(filterName);
if (enable) {
session.enableFilter(filterName);
}
else {
session.disableFilter(filterName);
}
}
}
}
Expand Down
Loading