diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedCallableQueryMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedCallableQueryMappingImpl.java index 30877dc26d..ab156cd27e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedCallableQueryMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedCallableQueryMappingImpl.java @@ -6,6 +6,8 @@ */ package org.hibernate.boot.internal; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; @@ -14,12 +16,14 @@ import javax.persistence.StoredProcedureParameter; import org.hibernate.CacheMode; import org.hibernate.FlushMode; +import org.hibernate.HibernateException; import org.hibernate.LockOptions; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.AbstractNamedQueryMapping; import org.hibernate.boot.spi.NamedCallableQueryMapping; -import org.hibernate.boot.spi.NamedQueryParameterMapping; import org.hibernate.cfg.BinderHelper; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.procedure.internal.NamedCallableQueryMementoImpl; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ParameterStrategy; @@ -29,17 +33,20 @@ import org.hibernate.query.procedure.internal.ProcedureParameterImpl; * @author Steve Ebersole */ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping implements NamedCallableQueryMapping { + private static final Class[] NO_CLASSES = new Class[0]; + private final String callableName; + private final List parameterMappings; private final List resultSetMappingNames; - private final List resultClasses; + private final List resultSetMappingClassNames; private final Set querySpaces; public NamedCallableQueryMappingImpl( String name, String callableName, - List parameterMappings, - List resultClasses, + List parameterMappings, List resultSetMappingNames, + List resultSetMappingClassNames, Set querySpaces, Boolean cacheable, String cacheRegion, @@ -53,7 +60,6 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp Map hints) { super( name, - parameterMappings, cacheable, cacheRegion, cacheMode, @@ -67,8 +73,9 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp ); this.callableName = callableName; + this.parameterMappings = parameterMappings; this.resultSetMappingNames = resultSetMappingNames; - this.resultClasses = resultClasses; + this.resultSetMappingClassNames = resultSetMappingClassNames; this.querySpaces = querySpaces; } @@ -79,15 +86,14 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp callableName, ParameterStrategy.UNKNOWN, resolveParameterMappings( factory ), - resultClasses, - resultSetMappingNames, + (String[]) resultSetMappingNames.toArray(), + toResultClasses( resultSetMappingClassNames, factory ), querySpaces, getCacheable(), getCacheRegion(), getCacheMode(), getFlushMode(), getReadOnly(), - getLockOptions(), getTimeout(), getFetchSize(), getComment(), @@ -95,20 +101,45 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp ); } - @Override - protected List resolveParameterMappings(SessionFactoryImplementor factory) { - //noinspection unchecked - return (List) super.resolveParameterMappings( factory ); + protected List resolveParameterMappings(SessionFactoryImplementor factory) { + if ( parameterMappings == null || parameterMappings.isEmpty() ) { + return Collections.emptyList(); + } + + final ArrayList mementos = CollectionHelper.arrayList( parameterMappings.size() ); + parameterMappings.forEach( mapping -> mementos.add( mapping.resolve( factory ) ) ); + return mementos; + } + + private static Class[] toResultClasses(List classNames, SessionFactoryImplementor factory) { + if ( classNames == null || classNames.isEmpty() ) { + return NO_CLASSES; + } + + final ClassLoaderService classLoaderService = factory.getServiceRegistry().getService( ClassLoaderService.class ); + + final Class[] classes = new Class[ classNames.size() ]; + int i = 0; + for ( String className : classNames ) { + try { + classes[ i++ ] = classLoaderService.classForName( className ); + } + catch (Exception e) { + throw new HibernateException( "Could not resolve class name given as procedure-call result class: " + className, e ); + } + } + + return classes; } public static class Builder extends AbstractBuilder { private String callableName; - private List resultClasses; + private List resultSetMappingClassNames; private List resultSetMappingNames; private ParameterStrategy parameterStrategy = ParameterStrategy.UNKNOWN; - private List parameterMappings; + private List parameterMappings; public Builder(String name) { super( name ); @@ -119,6 +150,21 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp return this; } + public Builder setCallableName(String callableName) { + this.callableName = callableName; + return this; + } + + public Builder setResultSetMappingClassNames(List resultSetMappingClassNames) { + this.resultSetMappingClassNames = resultSetMappingClassNames; + return this; + } + + public Builder setResultSetMappingNames(List resultSetMappingNames) { + this.resultSetMappingNames = resultSetMappingNames; + return this; + } + public Builder consume(StoredProcedureParameter[] parameters) { if ( parameters != null && parameters.length > 0 ) { for ( StoredProcedureParameter parameter : parameters ) { @@ -132,11 +178,12 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp if ( BinderHelper.isEmptyAnnotationValue( parameter.name() ) ) { consumeNamedParameter( parameter.name(), parameter.type(), parameter.mode() ); } - if ( parameter.name() != null ) { + else { + consumePositionalParameter( parameter.type(), parameter.mode() ); } } - private void consumeNamedParameter(String name, Class type, ParameterMode mode) { + private void consumeNamedParameter(String name, Class javaType, ParameterMode mode) { if ( parameterStrategy == ParameterStrategy.POSITIONAL ) { throw new IllegalArgumentException( "Named queries cannot mix named and positional parameters: " + getName() @@ -144,50 +191,44 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp } parameterStrategy = ParameterStrategy.NAMED; - final NamedCallableQueryParameterMapping namedParameter = new NamedCallableQueryParameterMapping() { - @Override - public ParameterMemento resolve(SessionFactoryImplementor factory) { - return session -> new ProcedureParameterImpl( - label, - mode, - javaType, - factory.getMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ), - factory.getSessionFactoryOptions().isProcedureParameterNullPassingEnabled() - ); - } - }; - parameterMappings.add( namedParameter ); - } - @Override - protected NamedCallableQueryParameterMapping createPositionalParameter(int label, Class javaType, ParameterMode mode) { - return - } - - @Override - protected NamedCallableQueryParameterMapping createNamedParameter(String name, Class javaType, ParameterMode mode) { - //noinspection Convert2Lambda - return new NamedQueryParameterMapping() { - @Override - @SuppressWarnings("unchecked") - public ParameterMemento resolve(SessionFactoryImplementor factory) { - return session -> new ProcedureParameterImpl( + parameterMappings.add( + (ParameterMapping) factory -> session -> new ProcedureParameterImpl( name, mode, javaType, factory.getMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ), factory.getSessionFactoryOptions().isProcedureParameterNullPassingEnabled() - ); - } - }; + ) + ); + } + + private void consumePositionalParameter(Class javaType, ParameterMode mode) { + if ( parameterStrategy == ParameterStrategy.POSITIONAL ) { + throw new IllegalArgumentException( + "Named queries cannot mix named and positional parameters: " + getName() + ); + } + + parameterStrategy = ParameterStrategy.POSITIONAL; + + parameterMappings.add( + (ParameterMapping) factory -> session -> new ProcedureParameterImpl( + parameterMappings.size(), + mode, + javaType, + factory.getMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ), + factory.getSessionFactoryOptions().isProcedureParameterNullPassingEnabled() + ) + } public NamedCallableQueryMapping build() { return new NamedCallableQueryMappingImpl( getName(), callableName, - getParameterMappings(), - resultClasses, + parameterMappings, + resultSetMappingClassNames, resultSetMappingNames, getQuerySpaces(), getCacheable(), @@ -202,18 +243,5 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp getHints() ); } - - public Builder setCallableName(String callableName) { - this.callableName = callableName; - return this; - } - } - - private static class NamedCallableQueryParameterMapping implements NamedQueryParameterMapping { - - @Override - public ParameterMemento resolve(SessionFactoryImplementor factory) { - return null; - } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedHqlQueryMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedHqlQueryMappingImpl.java index 4d26dcdc90..df729777d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedHqlQueryMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedHqlQueryMappingImpl.java @@ -6,17 +6,13 @@ */ package org.hibernate.boot.internal; -import java.util.List; import java.util.Map; -import javax.persistence.ParameterMode; import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.LockOptions; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.boot.spi.AbstractNamedQueryMapping; import org.hibernate.boot.spi.NamedHqlQueryMapping; -import org.hibernate.boot.spi.NamedQueryParameterMapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.hql.internal.NamedHqlQueryMementoImpl; import org.hibernate.query.hql.spi.NamedHqlQueryMemento; @@ -28,11 +24,11 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen private final String hqlString; private final Integer firstResult; private final Integer maxResults; + private final Map parameterTypes; public NamedHqlQueryMappingImpl( String name, String hqlString, - List parameterMappings, Integer firstResult, Integer maxResults, Boolean cacheable, @@ -44,10 +40,10 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen Integer timeout, Integer fetchSize, String comment, + Map parameterTypes, Map hints) { super( name, - parameterMappings, cacheable, cacheRegion, cacheMode, @@ -62,6 +58,7 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen this.hqlString = hqlString; this.firstResult = firstResult; this.maxResults = maxResults; + this.parameterTypes = parameterTypes; } @Override @@ -74,7 +71,6 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen return new NamedHqlQueryMementoImpl( getName(), hqlString, - resolveParameterMappings( factory ), firstResult, maxResults, getCacheable(), @@ -86,6 +82,7 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen getTimeout(), getFetchSize(), getComment(), + parameterTypes, getHints() ); } @@ -96,6 +93,8 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen private Integer firstResult; private Integer maxResults; + private Map parameterTypes; + public Builder(String name, String hqlString) { super( name ); this.hqlString = hqlString; @@ -116,33 +115,10 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen return getThis(); } - @Override - protected NamedQueryParameterMapping createPositionalParameter(int i, Class javaType, ParameterMode mode) { - /// todo (6.0) : this really ought to just adjust the type, if one... - throw new NotYetImplementedFor6Exception(); -// return new ParameterDefinition() { -// @Override -// public ParameterDescriptor resolve(SessionFactoryImplementor factory) { -// return new ParameterDescriptor() { -// @Override -// public QueryParameter toQueryParameter(SharedSessionContractImplementor session) { -// return new QueryParameterPositionalImpl( i, ); -// } -// }; -// } -// }; - } - - @Override - protected NamedQueryParameterMapping createNamedParameter(String name, Class javaType, ParameterMode mode) { - throw new NotYetImplementedFor6Exception(); - } - public NamedHqlQueryMappingImpl build() { return new NamedHqlQueryMappingImpl( getName(), hqlString, - getParameterMappings(), firstResult, maxResults, getCacheable(), @@ -154,6 +130,7 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen getTimeout(), getFetchSize(), getComment(), + parameterTypes, getHints() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryMappingImpl.java index fe1519d8d7..fb0408e6a6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryMappingImpl.java @@ -16,7 +16,6 @@ import org.hibernate.FlushMode; import org.hibernate.LockOptions; import org.hibernate.boot.spi.AbstractNamedQueryMapping; import org.hibernate.boot.spi.NamedNativeQueryMapping; -import org.hibernate.boot.spi.NamedQueryParameterMapping; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.sql.internal.NamedNativeQueryMementoImpl; import org.hibernate.query.sql.spi.NamedNativeQueryMemento; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractNamedQueryMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractNamedQueryMapping.java index d981950c15..b910f72e44 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractNamedQueryMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractNamedQueryMapping.java @@ -9,7 +9,6 @@ package org.hibernate.boot.spi; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import javax.persistence.ParameterMode; @@ -17,7 +16,6 @@ import javax.persistence.ParameterMode; import org.hibernate.CacheMode; import org.hibernate.FlushMode; import org.hibernate.LockOptions; -import org.hibernate.engine.spi.SessionFactoryImplementor; /** * @author Steve Ebersole @@ -25,8 +23,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { private final String name; - private final List parameterMappings; - private final Boolean cacheable; private final String cacheRegion; private final CacheMode cacheMode; @@ -45,7 +41,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { public AbstractNamedQueryMapping( String name, - List parameterMappings, Boolean cacheable, String cacheRegion, CacheMode cacheMode, @@ -57,9 +52,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { String comment, Map hints) { this.name = name; - this.parameterMappings = parameterMappings == null - ? new ArrayList<>() - : new ArrayList<>( parameterMappings ); this.cacheable = cacheable; this.cacheRegion = cacheRegion; this.cacheMode = cacheMode; @@ -117,16 +109,11 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { return hints; } - protected List resolveParameterMappings(SessionFactoryImplementor factory) { - final ArrayList descriptors = new ArrayList<>(); - parameterMappings.forEach( parameterMapping -> descriptors.add( parameterMapping.resolve( factory ) ) ); - return descriptors; - } - protected static abstract class AbstractBuilder { private final String name; private Set querySpaces; + private Boolean cacheable; private String cacheRegion; private CacheMode cacheMode; @@ -153,40 +140,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { protected abstract T getThis(); - public T addParameter(Class javaType, ParameterMode mode) { - return addParameter( - createPositionalParameter( - parameterMappings.size() + 1, - javaType, - mode - ) - ); - } - - protected abstract NamedQueryParameterMapping createPositionalParameter(int i, Class javaType, ParameterMode mode); - - public

T addParameter(P parameterMapping) { - if ( parameterMappings == null ) { - parameterMappings = new ArrayList<>(); - } - - parameterMappings.add( (P) parameterMapping ); - - return getThis(); - } - - public T addParameter(String name, Class javaType, ParameterMode mode) { - if ( parameterMappings == null ) { - parameterMappings = new ArrayList<>(); - } - - parameterMappings.add( createNamedParameter( name, javaType, mode ) ); - - return getThis(); - } - - protected abstract

P createNamedParameter(String name, Class javaType, ParameterMode mode); - public T addQuerySpaces(Set querySpaces) { if ( querySpaces == null || querySpaces.isEmpty() ) { @@ -298,10 +251,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping { return comment; } - protected List getParameterMappings() { - return parameterMappings; - } - public void addHint(String name, Object value) { if ( hints == null ) { hints = new HashMap<>(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedCallableQueryMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedCallableQueryMapping.java index a55d24d067..2e5d61ef8b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedCallableQueryMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedCallableQueryMapping.java @@ -6,9 +6,8 @@ */ package org.hibernate.boot.spi; -import java.util.List; - import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.procedure.internal.NamedCallableQueryMementoImpl; import org.hibernate.procedure.spi.NamedCallableQueryMemento; /** @@ -18,9 +17,10 @@ import org.hibernate.procedure.spi.NamedCallableQueryMemento; * @author Gavin King */ public interface NamedCallableQueryMapping extends NamedQueryMapping { - List getResultSetMappingNames(); - List getResultSetMappingClasses(); - @Override NamedCallableQueryMemento resolve(SessionFactoryImplementor factory); + + interface ParameterMapping { + NamedCallableQueryMementoImpl.ParameterMementoImpl resolve(SessionFactoryImplementor factory); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedQueryParameterMapping.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedQueryParameterMapping.java deleted file mode 100644 index cd8376c0f5..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/NamedQueryParameterMapping.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.boot.spi; - -import org.hibernate.engine.spi.SessionFactoryImplementor; - -/** - * Describes a parameter defined in the mapping of a {@link NamedQueryMapping} - * - * @author Steve Ebersole - * @author Gavin King - */ -public interface NamedQueryParameterMapping { - /** - * Resolve the mapping definition into its run-time memento form - */ - ParameterMemento resolve(SessionFactoryImplementor factory); -} diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java index 4969db8c14..490c9a0b72 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/NamedCallableQueryMementoImpl.java @@ -13,15 +13,14 @@ import javax.persistence.ParameterMode; import org.hibernate.CacheMode; import org.hibernate.FlushMode; -import org.hibernate.LockOptions; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.procedure.spi.ParameterRegistrationImplementor; import org.hibernate.procedure.spi.ParameterStrategy; -import org.hibernate.query.QueryParameter; import org.hibernate.query.spi.AbstractNamedQueryMemento; +import org.hibernate.query.spi.NamedQueryMemento; import org.hibernate.type.Type; /** @@ -31,9 +30,13 @@ import org.hibernate.type.Type; */ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento implements NamedCallableQueryMemento { private final String callableName; + private final ParameterStrategy parameterStrategy; - private final Class[] resultClasses; + private final List parameterMementos; + private final String[] resultSetMappingNames; + private final Class[] resultSetMappingClasses; + private final Set querySpaces; @@ -44,29 +47,26 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp String name, String callableName, ParameterStrategy parameterStrategy, - List parameterMementos, - Class[] resultClasses, + List parameterMementos, String[] resultSetMappingNames, + Class[] resultSetMappingClasses, Set querySpaces, Boolean cacheable, String cacheRegion, CacheMode cacheMode, FlushMode flushMode, Boolean readOnly, - LockOptions lockOptions, Integer timeout, Integer fetchSize, String comment, Map hints) { super( name, - parameterMementos, cacheable, cacheRegion, cacheMode, flushMode, readOnly, - lockOptions, timeout, fetchSize, comment, @@ -74,45 +74,48 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp ); this.callableName = callableName; this.parameterStrategy = parameterStrategy; - this.resultClasses = resultClasses; + this.parameterMementos = parameterMementos; this.resultSetMappingNames = resultSetMappingNames; + this.resultSetMappingClasses = resultSetMappingClasses; this.querySpaces = querySpaces; } + @Override + public String getCallableName() { + return callableName; + } + @Override public ProcedureCall makeProcedureCall(SharedSessionContractImplementor session) { return new ProcedureCallImpl( session, this ); } - public String getCallableName() { - return callableName; - } - - public NativeSQLQueryReturn[] getQueryReturns() { - return queryReturns; - } - - public ParameterStrategy getParameterStrategy() { - return parameterStrategy; - } - - public List getParameterDeclarations() { - return parameterDeclarations; - } - - public Set getSynchronizedQuerySpaces() { - return synchronizedQuerySpaces; - } - @Override - public Map getHintsMap() { - return hintsMap; + public NamedQueryMemento makeCopy(String name) { + return new NamedCallableQueryMementoImpl( + name, + callableName, + parameterStrategy, + parameterMementos, + resultSetMappingNames, + resultSetMappingClasses, + querySpaces, + cacheable, + cacheRegion, + cacheMode, + flushMode, + readOnly, + timeout, + fetchSize, + comment, + hints + ); } /** * A "disconnected" copy of the metadata for a parameter, that can be used in ProcedureCallMementoImpl. */ - public static class CallableParameterMemento implements ParameterMemento { + public static class ParameterMementoImpl implements ParameterMemento { private final Integer position; private final String name; private final ParameterMode mode; @@ -130,7 +133,7 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp * @param hibernateType The Hibernate Type. * @param passNulls Should NULL values to passed to the database? */ - public CallableParameterMemento( + public ParameterMementoImpl( int position, String name, ParameterMode mode, @@ -170,8 +173,8 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp } @Override - public QueryParameter toQueryParameter(SharedSessionContractImplementor session) { - return null; + public ParameterRegistrationImplementor resolve(SharedSessionContractImplementor session) { + throw new NotYetImplementedFor6Exception(); } /** @@ -181,8 +184,8 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp * * @return The memento */ - public static ParameterMemento fromRegistration(ParameterRegistrationImplementor registration) { - return new ParameterMemento( + public static ParameterMementoImpl fromRegistration(ParameterRegistrationImplementor registration) { + return new ParameterMementoImpl( registration.getPosition(), registration.getName(), registration.getMode(), diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/spi/NamedCallableQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/procedure/spi/NamedCallableQueryMemento.java index 0859556421..d21d332645 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/spi/NamedCallableQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/spi/NamedCallableQueryMemento.java @@ -6,8 +6,6 @@ */ package org.hibernate.procedure.spi; -import java.util.Map; - import org.hibernate.Incubating; import org.hibernate.Session; import org.hibernate.engine.spi.SessionImplementor; @@ -22,16 +20,8 @@ import org.hibernate.query.spi.NamedQueryMemento; */ @Incubating public interface NamedCallableQueryMemento extends NamedQueryMemento { - @Override - default String getQueryString() { - return getCallableName(); - } - /** - * The name of the database callable to execute. Whereas {@link #getName()} - * describes the name under which the named query is registered with the - * SessionFactory, the callable name is the actual database procedure/function - * name + * Informational access to the name of the database function or procedure */ String getCallableName(); @@ -66,12 +56,7 @@ public interface NamedCallableQueryMemento extends NamedQueryMemento { */ ProcedureCall makeProcedureCall(SharedSessionContractImplementor session); - /** - * Access to any hints associated with the memento. - *

- * IMPL NOTE : exposed separately because only HEM needs access to this. - * - * @return The hints. - */ - Map getHintsMap(); + interface ParameterMemento { + ParameterRegistrationImplementor resolve(SharedSessionContractImplementor session); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/spi/NamedHqlQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/hql/spi/NamedHqlQueryMemento.java index e15361ba2e..0ce6db9ffb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/spi/NamedHqlQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/spi/NamedHqlQueryMemento.java @@ -9,11 +9,10 @@ package org.hibernate.query.hql.spi; import java.util.HashMap; import java.util.Map; -import org.hibernate.CacheMode; -import org.hibernate.FlushMode; import org.hibernate.LockOptions; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.query.hql.internal.NamedHqlQueryMementoImpl; +import org.hibernate.query.spi.AbstractNamedQueryMemento; import org.hibernate.query.spi.NamedQueryMemento; /** @@ -22,11 +21,18 @@ import org.hibernate.query.spi.NamedQueryMemento; * @author Steve Ebersole */ public interface NamedHqlQueryMemento extends NamedQueryMemento { - @Override - NamedHqlQueryMemento makeCopy(String name); + /** + * Informational access to the HQL query string + */ + String getHqlString(); + + /** + * Convert the memento into an executable query + */ + HqlQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); @Override - HqlQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); + NamedHqlQueryMemento makeCopy(String name); /** * Delegate used in creating named HQL query mementos. @@ -34,67 +40,20 @@ public interface NamedHqlQueryMemento extends NamedQueryMemento { * @see org.hibernate.boot.spi.NamedHqlQueryMapping * @see HqlQueryImplementor#toMemento */ - class Builder { - protected String name; - protected String queryString; - protected boolean cacheable; - protected String cacheRegion; - protected CacheMode cacheMode; - protected Integer timeout; - protected Integer fetchSize; - protected FlushMode flushMode; - protected boolean readOnly; - protected String comment; + class Builder extends AbstractNamedQueryMemento.AbstractBuilder { + protected String hqlString; protected LockOptions lockOptions; protected Integer firstResult; protected Integer maxResults; protected Map parameterTypes; - protected Map hints; - public Builder() { - } public Builder(String name) { - this.name = name; + super( name ); } - public Builder setName(String name) { - this.name = name; - return this; - } - - public Builder setQuery(String queryString) { - this.queryString = queryString; - return this; - } - - public Builder setCacheable(boolean cacheable) { - this.cacheable = cacheable; - return this; - } - - public Builder setCacheRegion(String cacheRegion) { - this.cacheRegion = cacheRegion; - return this; - } - - public Builder setTimeout(Integer timeout) { - this.timeout = timeout; - return this; - } - - public Builder setFetchSize(Integer fetchSize) { - this.fetchSize = fetchSize; - return this; - } - - public Builder setFlushMode(FlushMode flushMode) { - this.flushMode = flushMode; - return this; - } - - public Builder setCacheMode(CacheMode cacheMode) { - this.cacheMode = cacheMode; + @Override + protected Builder getThis() { return this; } @@ -103,11 +62,6 @@ public interface NamedHqlQueryMemento extends NamedQueryMemento { return this; } - public Builder setComment(String comment) { - this.comment = comment; - return this; - } - public Builder addParameterType(String name, String typeName) { if ( this.parameterTypes == null ) { this.parameterTypes = new HashMap<>(); @@ -139,7 +93,7 @@ public interface NamedHqlQueryMemento extends NamedQueryMemento { public NamedHqlQueryMemento createNamedQueryDefinition() { return new NamedHqlQueryMementoImpl( name, - queryString, + hqlString, firstResult, maxResults, cacheable, diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java index f502a56957..da878dd9bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/NamedQueryRepositoryImpl.java @@ -140,7 +140,7 @@ public class NamedQueryRepositoryImpl implements NamedQueryRepository { // this will throw an error if there's something wrong. try { log.debugf( "Checking named query: %s", hqlMemento.getName() ); - final SqmStatement sqmStatement = sqmProducer.interpret( hqlMemento.getQueryString() ); + final SqmStatement sqmStatement = sqmProducer.interpret( hqlMemento.getHqlString() ); if ( cachingEnabled ) { // todo (6.0) : need to cache these; however atm that requires producing a SqmQueryImpl diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractNamedQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractNamedQueryMemento.java index 76bfa46274..ee957d629a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractNamedQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractNamedQueryMemento.java @@ -6,17 +6,13 @@ */ package org.hibernate.query.spi; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; -import javax.persistence.ParameterMode; import org.hibernate.CacheMode; import org.hibernate.FlushMode; -import org.hibernate.LockOptions; import org.hibernate.engine.spi.SharedSessionContractImplementor; /** @@ -106,23 +102,23 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento { } } - protected static abstract class AbstractBuilder { - private final String name; + public static abstract class AbstractBuilder { + protected final String name; - private Set querySpaces; - private Boolean cacheable; - private String cacheRegion; - private CacheMode cacheMode; + protected Set querySpaces; + protected Boolean cacheable; + protected String cacheRegion; + protected CacheMode cacheMode; - private FlushMode flushMode; - private Boolean readOnly; + protected FlushMode flushMode; + protected Boolean readOnly; - private Integer timeout; - private Integer fetchSize; + protected Integer timeout; + protected Integer fetchSize; - private String comment; + protected String comment; - private Map hints; + protected Map hints; public AbstractBuilder(String name) { this.name = name; @@ -170,11 +166,6 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento { return getThis(); } - public T setLockOptions(LockOptions lockOptions) { - this.lockOptions = lockOptions; - return getThis(); - } - public T setTimeout(Integer timeout) { this.timeout = timeout; return getThis(); @@ -190,6 +181,11 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento { return getThis(); } + public T setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + return getThis(); + } + public T setFetchSize(Integer fetchSize) { this.fetchSize = fetchSize; return getThis(); @@ -224,10 +220,6 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento { return readOnly; } - public LockOptions getLockOptions() { - return lockOptions; - } - public Integer getTimeout() { return timeout; } @@ -240,19 +232,11 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento { return comment; } - protected List getParameterDescriptors() { - return parameterDescriptors; - } - public void addHint(String name, Object value) { if ( hints == null ) { hints = new HashMap<>(); } hints.put( name, value ); } - - public Map getHints() { - return hints; - } } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java index b87a7100c2..ccf98aef5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryMemento.java @@ -6,8 +6,6 @@ */ package org.hibernate.query.spi; -import org.hibernate.engine.spi.SharedSessionContractImplementor; - /** * Base contract for all named query mementos * @@ -23,9 +21,4 @@ public interface NamedQueryMemento { * Makes a copy of the memento */ NamedQueryMemento makeCopy(String name); - - /** - * Convert the memento into an executable query - */ - QueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java index 491f1bac37..404d518339 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java @@ -24,13 +24,17 @@ import org.hibernate.query.sql.spi.NativeQueryImplementor; */ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento implements NamedNativeQueryMemento { private final String sqlString; - private final String resultSetMappingName; + + private String resultSetMappingName; + private String resultSetMappingClassName; + private final Set querySpaces; public NamedNativeQueryMementoImpl( String name, String sqlString, String resultSetMappingName, + String resultSetMappingClassName, Set querySpaces, Boolean cacheable, String cacheRegion, @@ -55,6 +59,7 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple ); this.sqlString = sqlString; this.resultSetMappingName = resultSetMappingName; + this.resultSetMappingClassName = resultSetMappingClassName; this.querySpaces = querySpaces; } @@ -67,20 +72,19 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple public NamedNativeQueryMemento makeCopy(String name) { return new NamedNativeQueryMementoImpl( name, - getParameterMementos(), sqlString, resultSetMappingName, - getQuerySpaces(), - getCacheable(), - getCacheRegion(), - getCacheMode(), - getFlushMode(), - getReadOnly(), - getLockOptions(), - getTimeout(), - getFetchSize(), - getComment(), - getHints() + resultSetMappingClassName, + querySpaces, + cacheable, + cacheRegion, + cacheMode, + flushMode, + readOnly, + timeout, + fetchSize, + comment, + hints ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java index 85f9890267..eacea636ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java @@ -6,11 +6,10 @@ */ package org.hibernate.query.sql.spi; -import java.util.Collection; +import java.util.Set; -import org.hibernate.CacheMode; -import org.hibernate.FlushMode; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.query.spi.AbstractNamedQueryMemento; import org.hibernate.query.spi.NamedQueryMemento; import org.hibernate.query.sql.internal.NamedNativeQueryMementoImpl; @@ -20,48 +19,42 @@ import org.hibernate.query.sql.internal.NamedNativeQueryMementoImpl; * @author Steve Ebersole */ public interface NamedNativeQueryMemento extends NamedQueryMemento { + /** + * Informational access to the SQL query string + */ String getSqlString(); + /** + * Convert the memento into an executable query + */ + NativeQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); + @Override NamedNativeQueryMemento makeCopy(String name); - @Override - NativeQueryImplementor toQuery(SharedSessionContractImplementor session, Class resultType); - - /** * Delegate used in creating named HQL query mementos. * * @see org.hibernate.boot.spi.NamedNativeQueryMapping */ - class Builder { - protected String name; + class Builder extends AbstractNamedQueryMemento.AbstractBuilder { protected String queryString; - protected boolean cacheable; - protected String cacheRegion; - protected CacheMode cacheMode; - protected Integer timeout; - protected Integer fetchSize; - protected FlushMode flushMode; - protected boolean readOnly; - protected String comment; + protected Integer firstResult; protected Integer maxResults; - private Collection querySpaces; - private String resultSetMappingName; - private String resultSetMappingClassName; + protected Set querySpaces; + protected String resultSetMappingName; + protected String resultSetMappingClassName; - public Builder() { - } public Builder(String name) { - this.name = name; + super( name ); } - public Builder setName(String name) { - this.name = name; + @Override + protected Builder getThis() { return this; } @@ -75,41 +68,6 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento { return this; } - public Builder setCacheRegion(String cacheRegion) { - this.cacheRegion = cacheRegion; - return this; - } - - public Builder setCacheMode(CacheMode cacheMode) { - this.cacheMode = cacheMode; - return this; - } - - public Builder setTimeout(Integer timeout) { - this.timeout = timeout; - return this; - } - - public Builder setFetchSize(Integer fetchSize) { - this.fetchSize = fetchSize; - return this; - } - - public Builder setFlushMode(FlushMode flushMode) { - this.flushMode = flushMode; - return this; - } - - public Builder setReadOnly(boolean readOnly) { - this.readOnly = readOnly; - return this; - } - - public Builder setComment(String comment) { - this.comment = comment; - return this; - } - public Builder setFirstResult(Integer firstResult) { this.firstResult = firstResult; return this; @@ -120,7 +78,7 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento { return this; } - public void setQuerySpaces(Collection querySpaces) { + public void setQuerySpaces(Set querySpaces) { this.querySpaces = querySpaces; } @@ -132,20 +90,22 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento { this.resultSetMappingClassName = resultSetMappingClassName; } - public NamedNativeQueryMemento createNamedQueryDefinition() { + public NamedNativeQueryMemento build() { return new NamedNativeQueryMementoImpl( name, queryString, + resultSetMappingName, + resultSetMappingClassName, + querySpaces, cacheable, cacheRegion, + cacheMode, + flushMode, + readOnly, timeout, fetchSize, - flushMode, - cacheMode, - readOnly, comment, - firstResult, - maxResults + hints ); } }