6 - SQM based on JPA type system

- further work on `org.hibernate.query` (especially `NamedQueryRepository` and friends)
- initial work on `org.hibernate.sql.exec`
- initial work on `org.hibernate.sql.results`
- SemanticPathPart handling
- NamedQueryMemento
This commit is contained in:
Steve Ebersole 2019-05-29 08:10:38 -05:00 committed by Andrea Boriero
parent 43c738ec4e
commit 0be0d06b1d
14 changed files with 227 additions and 413 deletions

View File

@ -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<ParameterMapping> parameterMappings;
private final List<String> resultSetMappingNames;
private final List<Class> resultClasses;
private final List<String> resultSetMappingClassNames;
private final Set<String> querySpaces;
public NamedCallableQueryMappingImpl(
String name,
String callableName,
List<NamedQueryParameterMapping> parameterMappings,
List<Class> resultClasses,
List<ParameterMapping> parameterMappings,
List<String> resultSetMappingNames,
List<String> resultSetMappingClassNames,
Set<String> querySpaces,
Boolean cacheable,
String cacheRegion,
@ -53,7 +60,6 @@ public class NamedCallableQueryMappingImpl extends AbstractNamedQueryMapping imp
Map<String,Object> 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<? extends NamedCallableQueryMementoImpl.CallableParameterMemento> resolveParameterMappings(SessionFactoryImplementor factory) {
//noinspection unchecked
return (List) super.resolveParameterMappings( factory );
protected List<NamedCallableQueryMemento.ParameterMemento> resolveParameterMappings(SessionFactoryImplementor factory) {
if ( parameterMappings == null || parameterMappings.isEmpty() ) {
return Collections.emptyList();
}
final ArrayList<NamedCallableQueryMemento.ParameterMemento> mementos = CollectionHelper.arrayList( parameterMappings.size() );
parameterMappings.forEach( mapping -> mementos.add( mapping.resolve( factory ) ) );
return mementos;
}
private static Class<?>[] toResultClasses(List<String> 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<Builder> {
private String callableName;
private List<Class> resultClasses;
private List<String> resultSetMappingClassNames;
private List<String> resultSetMappingNames;
private ParameterStrategy parameterStrategy = ParameterStrategy.UNKNOWN;
private List<NamedCallableQueryParameterMapping> parameterMappings;
private List<ParameterMapping> 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<String> resultSetMappingClassNames) {
this.resultSetMappingClassNames = resultSetMappingClassNames;
return this;
}
public Builder setResultSetMappingNames(List<String> 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;
}
}
}

View File

@ -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<String, String> parameterTypes;
public NamedHqlQueryMappingImpl(
String name,
String hqlString,
List<NamedQueryParameterMapping> parameterMappings,
Integer firstResult,
Integer maxResults,
Boolean cacheable,
@ -44,10 +40,10 @@ public class NamedHqlQueryMappingImpl extends AbstractNamedQueryMapping implemen
Integer timeout,
Integer fetchSize,
String comment,
Map<String,String> parameterTypes,
Map<String,Object> 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<String,String> 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()
);
}

View File

@ -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;

View File

@ -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<? extends NamedQueryParameterMapping> 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<? extends NamedQueryParameterMapping> parameterMappings,
Boolean cacheable,
String cacheRegion,
CacheMode cacheMode,
@ -57,9 +52,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping {
String comment,
Map<String,Object> 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<? extends ParameterMemento> resolveParameterMappings(SessionFactoryImplementor factory) {
final ArrayList<ParameterMemento> descriptors = new ArrayList<>();
parameterMappings.forEach( parameterMapping -> descriptors.add( parameterMapping.resolve( factory ) ) );
return descriptors;
}
protected static abstract class AbstractBuilder<T extends AbstractBuilder> {
private final String name;
private Set<String> 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 <P extends NamedQueryParameterMapping> 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 extends NamedQueryParameterMapping> P createNamedParameter(String name, Class javaType, ParameterMode mode);
public T addQuerySpaces(Set<String> querySpaces) {
if ( querySpaces == null || querySpaces.isEmpty() ) {
@ -298,10 +251,6 @@ public abstract class AbstractNamedQueryMapping implements NamedQueryMapping {
return comment;
}
protected List<? extends NamedQueryParameterMapping> getParameterMappings() {
return parameterMappings;
}
public void addHint(String name, Object value) {
if ( hints == null ) {
hints = new HashMap<>();

View File

@ -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<String> getResultSetMappingNames();
List<Class> getResultSetMappingClasses();
@Override
NamedCallableQueryMemento resolve(SessionFactoryImplementor factory);
interface ParameterMapping {
NamedCallableQueryMementoImpl.ParameterMementoImpl resolve(SessionFactoryImplementor factory);
}
}

View File

@ -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);
}

View File

@ -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<ParameterMemento> parameterMementos;
private final String[] resultSetMappingNames;
private final Class[] resultSetMappingClasses;
private final Set<String> querySpaces;
@ -44,29 +47,26 @@ public class NamedCallableQueryMementoImpl extends AbstractNamedQueryMemento imp
String name,
String callableName,
ParameterStrategy parameterStrategy,
List<CallableParameterMemento> parameterMementos,
Class[] resultClasses,
List<ParameterMemento> parameterMementos,
String[] resultSetMappingNames,
Class[] resultSetMappingClasses,
Set<String> querySpaces,
Boolean cacheable,
String cacheRegion,
CacheMode cacheMode,
FlushMode flushMode,
Boolean readOnly,
LockOptions lockOptions,
Integer timeout,
Integer fetchSize,
String comment,
Map<String, Object> 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<ParameterMemento> getParameterDeclarations() {
return parameterDeclarations;
}
public Set<String> getSynchronizedQuerySpaces() {
return synchronizedQuerySpaces;
}
@Override
public Map<String, Object> 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(),

View File

@ -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.
* <p/>
* IMPL NOTE : exposed separately because only HEM needs access to this.
*
* @return The hints.
*/
Map<String, Object> getHintsMap();
interface ParameterMemento {
ParameterRegistrationImplementor resolve(SharedSessionContractImplementor session);
}
}

View File

@ -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
*/
<T> HqlQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType);
@Override
<T> HqlQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> 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<Builder> {
protected String hqlString;
protected LockOptions lockOptions;
protected Integer firstResult;
protected Integer maxResults;
protected Map<String,String> parameterTypes;
protected Map<String,Object> 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,

View File

@ -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

View File

@ -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<T extends AbstractBuilder> {
private final String name;
public static abstract class AbstractBuilder<T extends AbstractBuilder> {
protected final String name;
private Set<String> querySpaces;
private Boolean cacheable;
private String cacheRegion;
private CacheMode cacheMode;
protected Set<String> 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<String,Object> hints;
protected Map<String,Object> 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<ParameterDefinition> getParameterDescriptors() {
return parameterDescriptors;
}
public void addHint(String name, Object value) {
if ( hints == null ) {
hints = new HashMap<>();
}
hints.put( name, value );
}
public Map<String, Object> getHints() {
return hints;
}
}
}

View File

@ -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
*/
<T> QueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType);
}

View File

@ -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<String> querySpaces;
public NamedNativeQueryMementoImpl(
String name,
String sqlString,
String resultSetMappingName,
String resultSetMappingClassName,
Set<String> 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
);
}

View File

@ -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
*/
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType);
@Override
NamedNativeQueryMemento makeCopy(String name);
@Override
<T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> 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<Builder> {
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<String> querySpaces;
private String resultSetMappingName;
private String resultSetMappingClassName;
protected Set<String> 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<String> querySpaces) {
public void setQuerySpaces(Set<String> 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
);
}
}