introduce UnknownFilterException for consistency with UnknownProfileException

This commit is contained in:
Gavin King 2023-06-14 10:25:35 +02:00
parent d63323cb63
commit b971b1e377
5 changed files with 52 additions and 4 deletions

View File

@ -1271,6 +1271,8 @@ public interface Session extends SharedSessionContract, EntityManager {
* *
* @return the {@link Filter} instance representing the enabled filter. * @return the {@link Filter} instance representing the enabled filter.
* *
* @throws UnknownFilterException if there is no such filter
*
* @see org.hibernate.annotations.FilterDef * @see org.hibernate.annotations.FilterDef
*/ */
Filter enableFilter(String filterName); Filter enableFilter(String filterName);

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate;
/**
* Indicates a request against an unknown filter name.
*
* @author Gavin King
*
* @see org.hibernate.annotations.FilterDef
* @see Session#enableFilter(String)
*/
public class UnknownFilterException extends HibernateException {
private final String name;
/**
* Constructs an {@code UnknownFilterException} for the given name.
*
* @param name The filter that was unknown.
*/
public UnknownFilterException(String name) {
super( "No filter named '" + name + "'" );
this.name = name;
}
/**
* The unknown filter name.
*
* @return The unknown filter name.
*/
public String getName() {
return name;
}
}

View File

@ -7,9 +7,12 @@
package org.hibernate; package org.hibernate;
/** /**
* Used to indicate a request against an unknown profile name. * Indicates a request against an unknown fetch profile name.
* *
* @author Steve Ebersole * @author Steve Ebersole
*
* @see org.hibernate.annotations.FetchProfile
* @see Session#enableFetchProfile(String)
*/ */
public class UnknownProfileException extends HibernateException { public class UnknownProfileException extends HibernateException {
private final String name; private final String name;
@ -20,7 +23,7 @@ public class UnknownProfileException extends HibernateException {
* @param name The profile name that was unknown. * @param name The profile name that was unknown.
*/ */
public UnknownProfileException(String name) { public UnknownProfileException(String name) {
super( "Unknown fetch profile [" + name + "]" ); super( "No fetch profile named '" + name + "'" );
this.name = name; this.name = name;
} }

View File

@ -36,6 +36,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver; import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession; import org.hibernate.StatelessSession;
import org.hibernate.StatelessSessionBuilder; import org.hibernate.StatelessSessionBuilder;
import org.hibernate.UnknownFilterException;
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
@ -1033,7 +1034,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException { public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
FilterDefinition def = filters.get( filterName ); FilterDefinition def = filters.get( filterName );
if ( def == null ) { if ( def == null ) {
throw new HibernateException( "No such filter configured [" + filterName + "]" ); throw new UnknownFilterException( filterName );
} }
return def; return def;
} }

View File

@ -15,9 +15,13 @@ import org.hibernate.QueryException;
* @author Steve Ebersole * @author Steve Ebersole
* *
* @see org.hibernate.query.named.NamedObjectRepository * @see org.hibernate.query.named.NamedObjectRepository
* @see jakarta.persistence.NamedQuery
* @see jakarta.persistence.NamedNativeQuery
* @see org.hibernate.annotations.NamedQuery
* @see org.hibernate.annotations.NamedNativeQuery
*/ */
public class UnknownNamedQueryException extends QueryException { public class UnknownNamedQueryException extends QueryException {
public UnknownNamedQueryException(String queryName) { public UnknownNamedQueryException(String queryName) {
super( "No query is registered under the name '" + queryName + "'" ); super( "No query named '" + queryName + "'" );
} }
} }