cls) {
+ return delegate().unwrap( cls );
+ }
+
+ /**
+ * This is an implementation of EntityManager#getDelegate(). It returns the current session and not the delegate()
+ * session as it is what we want. The name of the method is misleading here but, as it is part of JPA, we cannot do
+ * anything about it.
+ *
+ * To get the underlying delegate(), use {@link #delegate()} instead.
+ *
+ * @see SessionLazyDelegatorBaseImpl#delegate()
+ */
+ @Override
+ public Object getDelegate() {
+ return this;
+ }
+
+ @Override
+ public ProcedureCall getNamedProcedureCall(String name) {
+ return delegate().getNamedProcedureCall( name );
+ }
+
+ @Override
+ public ProcedureCall createStoredProcedureCall(String procedureName) {
+ return delegate().createStoredProcedureCall( procedureName );
+ }
+
+ @Override
+ public ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses) {
+ return delegate().createStoredProcedureCall( procedureName, resultClasses );
+ }
+
+ @Override
+ public ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings) {
+ return delegate().createStoredProcedureCall( procedureName, resultSetMappings );
+ }
+
+ @Override
+ public SharedSessionBuilder sessionWithOptions() {
+ return delegate().sessionWithOptions();
+ }
+
+ @Override
+ public SessionFactoryImplementor getSessionFactory() {
+ return delegate().getSessionFactory();
+ }
+
+ @Override
+ public void close() throws HibernateException {
+ delegate().close();
+ }
+
+ @Override
+ public void cancelQuery() throws HibernateException {
+ delegate().cancelQuery();
+ }
+
+ @Override
+ public boolean isDirty() throws HibernateException {
+ return delegate().isDirty();
+ }
+
+ @Override
+ public boolean isDefaultReadOnly() {
+ return delegate().isDefaultReadOnly();
+ }
+
+ @Override
+ public void setDefaultReadOnly(boolean readOnly) {
+ delegate().setDefaultReadOnly( readOnly );
+ }
+
+ @Override
+ public Object getIdentifier(Object object) {
+ return delegate().getIdentifier( object );
+ }
+
+ @Override
+ public boolean contains(String entityName, Object object) {
+ return delegate().contains( entityName, object );
+ }
+
+ @Override
+ public boolean contains(Object object) {
+ return delegate().contains( object );
+ }
+
+ @Override
+ public LockModeType getLockMode(Object entity) {
+ return delegate().getLockMode( entity );
+ }
+
+ @Override
+ public void setProperty(String propertyName, Object value) {
+ delegate().setProperty( propertyName, value );
+ }
+
+ @Override
+ public Map getProperties() {
+ return delegate().getProperties();
+ }
+
+ @Override
+ public void evict(Object object) {
+ delegate().evict( object );
+ }
+
+ @Override
+ public T load(Class theClass, Object id, LockMode lockMode) {
+ return delegate().load( theClass, id, lockMode );
+ }
+
+ @Override
+ public T load(Class theClass, Object id, LockOptions lockOptions) {
+ return delegate().load( theClass, id, lockOptions );
+ }
+
+ @Override
+ public Object load(String entityName, Object id, LockMode lockMode) {
+ return delegate().load( entityName, id, lockMode );
+ }
+
+ @Override
+ public Object load(String entityName, Object id, LockOptions lockOptions) {
+ return delegate().load( entityName, id, lockOptions );
+ }
+
+ @Override
+ public T load(Class theClass, Object id) {
+ return delegate().load( theClass, id );
+ }
+
+ @Override
+ public Object load(String entityName, Object id) {
+ return delegate().load( entityName, id );
+ }
+
+ @Override
+ public void load(Object object, Object id) {
+ delegate().load( object, id );
+ }
+
+ @Override
+ public void replicate(Object object, ReplicationMode replicationMode) {
+ delegate().replicate( object, replicationMode );
+ }
+
+ @Override
+ public void replicate(String entityName, Object object, ReplicationMode replicationMode) {
+ delegate().replicate( entityName, object, replicationMode );
+ }
+
+ @Override
+ public Object save(Object object) {
+ return delegate().save( object );
+ }
+
+ @Override
+ public Object save(String entityName, Object object) {
+ return delegate().save( entityName, object );
+ }
+
+ @Override
+ public void saveOrUpdate(Object object) {
+ delegate().saveOrUpdate( object );
+ }
+
+ @Override
+ public void saveOrUpdate(String entityName, Object object) {
+ delegate().saveOrUpdate( entityName, object );
+ }
+
+ @Override
+ public void update(Object object) {
+ delegate().update( object );
+ }
+
+ @Override
+ public void update(String entityName, Object object) {
+ delegate().update( entityName, object );
+ }
+
+ @Override
+ public Object merge(Object object) {
+ return delegate().merge( object );
+ }
+
+ @Override
+ public Object merge(String entityName, Object object) {
+ return delegate().merge( entityName, object );
+ }
+
+ @Override
+ public void persist(Object object) {
+ delegate().persist( object );
+ }
+
+ @Override
+ public void remove(Object entity) {
+ delegate().remove( entity );
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey) {
+ return delegate().find( entityClass, primaryKey );
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey, Map properties) {
+ return delegate().find( entityClass, primaryKey, properties );
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey, LockModeType lockMode) {
+ return delegate().find( entityClass, primaryKey, lockMode );
+ }
+
+ @Override
+ public T find(Class entityClass, Object primaryKey, LockModeType lockMode, Map properties) {
+ return delegate().find( entityClass, primaryKey, lockMode, properties );
+ }
+
+ @Override
+ public T getReference(Class entityClass, Object primaryKey) {
+ return delegate().getReference( entityClass, primaryKey );
+ }
+
+ @Override
+ public void persist(String entityName, Object object) {
+ delegate().persist( entityName, object );
+ }
+
+ @Override
+ public void delete(Object object) {
+ delegate().delete( object );
+ }
+
+ @Override
+ public void delete(String entityName, Object object) {
+ delegate().delete( entityName, object );
+ }
+
+ @Override
+ public void lock(Object object, LockMode lockMode) {
+ delegate().lock( object, lockMode );
+ }
+
+ @Override
+ public void lock(String entityName, Object object, LockMode lockMode) {
+ delegate().lock( entityName, object, lockMode );
+ }
+
+ @Override
+ public LockRequest buildLockRequest(LockOptions lockOptions) {
+ return delegate().buildLockRequest( lockOptions );
+ }
+
+ @Override
+ public void refresh(Object object) {
+ delegate().refresh( object );
+ }
+
+ @Override
+ public void refresh(Object entity, Map properties) {
+ delegate().refresh( entity, properties );
+ }
+
+ @Override
+ public void refresh(Object entity, LockModeType lockMode) {
+ delegate().refresh( entity, lockMode );
+ }
+
+ @Override
+ public void refresh(Object entity, LockModeType lockMode, Map properties) {
+ delegate().refresh( entity, lockMode, properties );
+ }
+
+ @Override
+ public void refresh(String entityName, Object object) {
+ delegate().refresh( entityName, object );
+ }
+
+ @Override
+ public void refresh(Object object, LockMode lockMode) {
+ delegate().refresh( object, lockMode );
+ }
+
+ @Override
+ public void refresh(Object object, LockOptions lockOptions) {
+ delegate().refresh( object, lockOptions );
+ }
+
+ @Override
+ public void refresh(String entityName, Object object, LockOptions lockOptions) {
+ delegate().refresh( entityName, object, lockOptions );
+ }
+
+ @Override
+ public LockMode getCurrentLockMode(Object object) {
+ return delegate().getCurrentLockMode( object );
+ }
+
+ @Override
+ public void clear() {
+ delegate().clear();
+ }
+
+ @Override
+ public void detach(Object entity) {
+ delegate().detach( entity );
+ }
+
+ @Override
+ public T get(Class theClass, Object id) {
+ return delegate().get( theClass, id );
+ }
+
+ @Override
+ public T get(Class theClass, Object id, LockMode lockMode) {
+ return delegate().get( theClass, id, lockMode );
+ }
+
+ @Override
+ public T get(Class theClass, Object id, LockOptions lockOptions) {
+ return delegate().get( theClass, id, lockOptions );
+ }
+
+ @Override
+ public Object get(String entityName, Object id) {
+ return delegate().get( entityName, id );
+ }
+
+ @Override
+ public Object get(String entityName, Serializable id, LockMode lockMode) {
+ return delegate().get( entityName, id, lockMode );
+ }
+
+ @Override
+ public Object get(String entityName, Object id, LockOptions lockOptions) {
+ return delegate().get( entityName, id, lockOptions );
+ }
+
+ @Override
+ public String getEntityName(Object object) {
+ return delegate().getEntityName( object );
+ }
+
+ @Override
+ public IdentifierLoadAccess byId(String entityName) {
+ return delegate().byId( entityName );
+ }
+
+ @Override
+ public MultiIdentifierLoadAccess byMultipleIds(Class entityClass) {
+ return delegate().byMultipleIds( entityClass );
+ }
+
+ @Override
+ public MultiIdentifierLoadAccess byMultipleIds(String entityName) {
+ return delegate().byMultipleIds( entityName );
+ }
+
+ @Override
+ public IdentifierLoadAccess byId(Class entityClass) {
+ return delegate().byId( entityClass );
+ }
+
+ @Override
+ public NaturalIdLoadAccess byNaturalId(String entityName) {
+ return delegate().byNaturalId( entityName );
+ }
+
+ @Override
+ public NaturalIdLoadAccess byNaturalId(Class entityClass) {
+ return delegate().byNaturalId( entityClass );
+ }
+
+ @Override
+ public SimpleNaturalIdLoadAccess bySimpleNaturalId(String entityName) {
+ return delegate().bySimpleNaturalId( entityName );
+ }
+
+ @Override
+ public SimpleNaturalIdLoadAccess bySimpleNaturalId(Class entityClass) {
+ return delegate().bySimpleNaturalId( entityClass );
+ }
+
+ @Override
+ public NaturalIdMultiLoadAccess byMultipleNaturalId(Class entityClass) {
+ return delegate().byMultipleNaturalId( entityClass );
+ }
+
+ @Override
+ public NaturalIdMultiLoadAccess byMultipleNaturalId(String entityName) {
+ return delegate().byMultipleNaturalId( entityName );
+ }
+
+ @Override
+ public Filter enableFilter(String filterName) {
+ return delegate().enableFilter( filterName );
+ }
+
+ @Override
+ public Filter getEnabledFilter(String filterName) {
+ return delegate().getEnabledFilter( filterName );
+ }
+
+ @Override
+ public void disableFilter(String filterName) {
+ delegate().disableFilter( filterName );
+ }
+
+ @Override
+ public SessionStatistics getStatistics() {
+ return delegate().getStatistics();
+ }
+
+ @Override
+ public boolean isReadOnly(Object entityOrProxy) {
+ return delegate().isReadOnly( entityOrProxy );
+ }
+
+ @Override
+ public void setReadOnly(Object entityOrProxy, boolean readOnly) {
+ delegate().setReadOnly( entityOrProxy, readOnly );
+ }
+
+ @Override
+ public void doWork(Work work) throws HibernateException {
+ delegate().doWork( work );
+ }
+
+ @Override
+ public T doReturningWork(ReturningWork work) throws HibernateException {
+ return delegate().doReturningWork( work );
+ }
+
+ @Override
+ public Connection disconnect() {
+ return delegate().disconnect();
+ }
+
+ @Override
+ public void reconnect(Connection connection) {
+ delegate().reconnect( connection );
+ }
+
+ @Override
+ public boolean isFetchProfileEnabled(String name) throws UnknownProfileException {
+ return delegate().isFetchProfileEnabled( name );
+ }
+
+ @Override
+ public void enableFetchProfile(String name) throws UnknownProfileException {
+ delegate().enableFetchProfile( name );
+ }
+
+ @Override
+ public void disableFetchProfile(String name) throws UnknownProfileException {
+ delegate().disableFetchProfile( name );
+ }
+
+ @Override
+ public LobHelper getLobHelper() {
+ return delegate().getLobHelper();
+ }
+
+ @Override
+ public void addEventListeners(SessionEventListener... listeners) {
+ delegate().addEventListeners( listeners );
+ }
+
+ @Override
+ public boolean isFlushBeforeCompletionEnabled() {
+ return delegate().isFlushBeforeCompletionEnabled();
+ }
+
+ @Override
+ public ActionQueue getActionQueue() {
+ return delegate().getActionQueue();
+ }
+
+ @Override
+ public Object instantiate(EntityPersister persister, Object id) throws HibernateException {
+ return delegate().instantiate( persister, id );
+ }
+
+ @Override
+ public void forceFlush(EntityEntry e) throws HibernateException {
+ delegate().forceFlush( e );
+ }
+
+ @Override
+ public void merge(String entityName, Object object, Map copiedAlready) throws HibernateException {
+ delegate().merge( entityName, object, copiedAlready );
+ }
+
+ @Override
+ public void persist(String entityName, Object object, Map createdAlready) throws HibernateException {
+ delegate().persist( entityName, object, createdAlready );
+ }
+
+ @Override
+ public void persistOnFlush(String entityName, Object object, Map copiedAlready) {
+ delegate().persistOnFlush( entityName, object, copiedAlready );
+ }
+
+ @Override
+ public void refresh(String entityName, Object object, Map refreshedAlready) throws HibernateException {
+ delegate().refresh( entityName, object, refreshedAlready );
+ }
+
+ @Override
+ public void delete(String entityName, Object child, boolean isCascadeDeleteEnabled, Set transientEntities) {
+ delegate().delete( entityName, child, isCascadeDeleteEnabled, transientEntities );
+ }
+
+ @Override
+ public void removeOrphanBeforeUpdates(String entityName, Object child) {
+ delegate().removeOrphanBeforeUpdates( entityName, child );
+ }
+
+ @Override
+ public SessionImplementor getSession() {
+ return this;
+ }
+
+ @Override
+ public boolean useStreamForLobBinding() {
+ return delegate().useStreamForLobBinding();
+ }
+
+ @Override
+ public LobCreator getLobCreator() {
+ return delegate().getLobCreator();
+ }
+
+ @Override
+ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
+ return delegate().remapSqlTypeDescriptor( sqlTypeDescriptor );
+ }
+
+ @Override
+ public Integer getJdbcBatchSize() {
+ return delegate().getJdbcBatchSize();
+ }
+
+ @Override
+ public void setJdbcBatchSize(Integer jdbcBatchSize) {
+ delegate().setJdbcBatchSize( jdbcBatchSize );
+ }
+
+ @Override
+ public TimeZone getJdbcTimeZone() {
+ return delegate().getJdbcTimeZone();
+ }
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java
index 6406d956d2..bcc9684066 100644
--- a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java
+++ b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java
@@ -200,7 +200,7 @@ public final class FastSessionServices {
return elr.getEventListenerGroup( type );
}
- SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
+ public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( !sqlTypeDescriptor.canBeRemapped() ) {
return sqlTypeDescriptor;
}
@@ -288,6 +288,10 @@ public final class FastSessionServices {
return defaultJdbcObservers;
}
+ public boolean useStreamForLobBinding() {
+ return useStreamForLobBinding;
+ }
+
public void firePostLoadEvent(final PostLoadEvent postLoadEvent) {
eventListenerGroup_POST_LOAD.fireEventOnEachListener( postLoadEvent, PostLoadEventListener::onPostLoad );
}
diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
index 465f3e74a0..bbe1ffedf5 100644
--- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
@@ -221,7 +221,7 @@ public class SessionImpl
//There might be custom properties for this session that affect the LockOptions state
LockOptionsHelper.applyPropertiesToLockOptions( this.properties, this::getLockOptionsForWrite );
}
- getSession().setCacheMode( fastSessionServices.initialSessionCacheMode );
+ setCacheMode( fastSessionServices.initialSessionCacheMode );
// NOTE : pulse() already handles auto-join-ability correctly
getTransactionCoordinator().pulse();
@@ -235,7 +235,7 @@ public class SessionImpl
else {
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
}
- getSession().setHibernateFlushMode( initialMode );
+ setHibernateFlushMode( initialMode );
}
if ( log.isTraceEnabled() ) {
@@ -2872,7 +2872,7 @@ public class SessionImpl
LockOptionsHelper.applyPropertiesToLockOptions( properties, this::getLockOptionsForWrite );
}
else if ( JPA_SHARED_CACHE_RETRIEVE_MODE.equals( propertyName ) || JPA_SHARED_CACHE_STORE_MODE.equals( propertyName ) ) {
- getSession().setCacheMode(
+ setCacheMode(
CacheModeHelper.interpretCacheMode(
determineCacheStoreMode( properties ),
determineCacheRetrieveMode( properties )
diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiNaturalIdLoadingBatcher.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiNaturalIdLoadingBatcher.java
index 8b2a5b63a8..a060b23457 100644
--- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiNaturalIdLoadingBatcher.java
+++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/MultiNaturalIdLoadingBatcher.java
@@ -37,7 +37,6 @@ import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.exec.spi.JdbcSelect;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.RowTransformerPassThruImpl;
-import org.hibernate.type.SerializableType;
/**
* Batch support for natural-id multi loading
@@ -139,10 +138,17 @@ public class MultiNaturalIdLoadingBatcher {
if ( needsExecution ) {
while ( jdbcParamItr.hasNext() ) {
+ final JdbcParameterBindings jdbcParamBindingsRef = jdbcParamBindings;
+ final Iterator jdbcParamItrRef = jdbcParamItr;
// pad the remaining parameters with null
- jdbcParamBindings.addBinding(
- jdbcParamItr.next(),
- new JdbcParameterBindingImpl( SerializableType.INSTANCE, null )
+ entityDescriptor.getNaturalIdMapping().visitJdbcValues(
+ null,
+ Clause.IRRELEVANT,
+ (jdbcValue, jdbcMapping) -> jdbcParamBindingsRef.addBinding(
+ jdbcParamItrRef.next(),
+ new JdbcParameterBindingImpl( jdbcMapping, jdbcValue )
+ ),
+ session
);
}
final List batchResults = performLoad( jdbcParamBindings, session );
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java
index 3843e36601..80c886a88c 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java
@@ -241,7 +241,7 @@ public abstract class AbstractCompositeIdentifierMapping
}
@Override
- public Expression toSqlExpression(
+ public SqlTuple toSqlExpression(
TableGroup tableGroup,
Clause clause,
SqmToSqlAstConverter walker,
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java
index d6c7ed9482..8081a6e07a 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/EmbeddableValuedModelPart.java
@@ -13,6 +13,7 @@ import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.tree.expression.Expression;
+import org.hibernate.sql.ast.tree.expression.SqlTuple;
import org.hibernate.sql.ast.tree.from.TableGroup;
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
import org.hibernate.sql.results.graph.Fetchable;
@@ -54,7 +55,7 @@ public interface EmbeddableValuedModelPart extends ModelPart, Fetchable, Fetchab
return null;
}
- Expression toSqlExpression(
+ SqlTuple toSqlExpression(
TableGroup tableGroup,
Clause clause,
SqmToSqlAstConverter walker,
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java
index f4edd0c7f1..bfda29445a 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelHelper.java
@@ -27,36 +27,7 @@ public class MappingModelHelper {
SessionFactoryImplementor sessionFactory) {
final int jdbcTypeCount = modelPart.getJdbcTypeCount( sessionFactory.getTypeConfiguration() );
- if ( jdbcTypeCount == 1 ) {
- assert modelPart instanceof BasicValuedModelPart;
- final BasicValuedModelPart basicPart = (BasicValuedModelPart) modelPart;
- if ( sqlExpressionResolver == null ) {
- return new ColumnReference(
- basicPart.getContainingTableExpression(),
- basicPart.getMappedColumnExpression(),
- basicPart.isMappedColumnExpressionFormula(),
- basicPart.getCustomReadExpression(),
- basicPart.getCustomWriteExpression(),
- basicPart.getJdbcMapping(),
- sessionFactory
- );
- }
- else {
- return sqlExpressionResolver.resolveSqlExpression(
- createColumnReferenceKey( basicPart.getContainingTableExpression(), basicPart.getMappedColumnExpression() ),
- sqlAstProcessingState -> new ColumnReference(
- basicPart.getContainingTableExpression(),
- basicPart.getMappedColumnExpression(),
- basicPart.isMappedColumnExpressionFormula(),
- basicPart.getCustomReadExpression(),
- basicPart.getCustomWriteExpression(),
- basicPart.getJdbcMapping(),
- sessionFactory
- )
- );
- }
- }
- else {
+ if ( modelPart instanceof EmbeddableValuedModelPart ) {
final List columnReferences = new ArrayList<>( jdbcTypeCount );
modelPart.visitColumns(
(table, column, isFormula, readFragment, writeFragment, jdbcMapping) -> {
@@ -91,6 +62,35 @@ public class MappingModelHelper {
);
return new SqlTuple( columnReferences, modelPart );
}
+ else {
+ assert modelPart instanceof BasicValuedModelPart;
+ final BasicValuedModelPart basicPart = (BasicValuedModelPart) modelPart;
+ if ( sqlExpressionResolver == null ) {
+ return new ColumnReference(
+ basicPart.getContainingTableExpression(),
+ basicPart.getMappedColumnExpression(),
+ basicPart.isMappedColumnExpressionFormula(),
+ basicPart.getCustomReadExpression(),
+ basicPart.getCustomWriteExpression(),
+ basicPart.getJdbcMapping(),
+ sessionFactory
+ );
+ }
+ else {
+ return sqlExpressionResolver.resolveSqlExpression(
+ createColumnReferenceKey( basicPart.getContainingTableExpression(), basicPart.getMappedColumnExpression() ),
+ sqlAstProcessingState -> new ColumnReference(
+ basicPart.getContainingTableExpression(),
+ basicPart.getMappedColumnExpression(),
+ basicPart.isMappedColumnExpressionFormula(),
+ basicPart.getCustomReadExpression(),
+ basicPart.getCustomWriteExpression(),
+ basicPart.getJdbcMapping(),
+ sessionFactory
+ )
+ );
+ }
+ }
}
private MappingModelHelper() {
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
index 9bbcb77058..92376603ac 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java
@@ -223,7 +223,7 @@ public class EmbeddedAttributeMapping
}
@Override
- public Expression toSqlExpression(
+ public SqlTuple toSqlExpression(
TableGroup tableGroup,
Clause clause,
SqmToSqlAstConverter walker,
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java
index f731db19a5..524ffb0c18 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedCollectionPart.java
@@ -210,7 +210,7 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
}
@Override
- public Expression toSqlExpression(
+ public SqlTuple toSqlExpression(
TableGroup tableGroup,
Clause clause,
SqmToSqlAstConverter walker,
diff --git a/hibernate-core/src/main/java/org/hibernate/query/CastType.java b/hibernate-core/src/main/java/org/hibernate/query/CastType.java
index c3ef5505d0..1bb71ded49 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/CastType.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/CastType.java
@@ -33,13 +33,23 @@ import java.time.*;
* @author Gavin King
*/
public enum CastType {
- STRING,
- BOOLEAN,
- INTEGER, LONG, FLOAT, DOUBLE, FIXED,
- DATE, TIME, TIMESTAMP,
- OFFSET_TIMESTAMP, ZONE_TIMESTAMP,
- NULL,
- OTHER;
+ STRING(CastTypeKind.TEXT),
+ BOOLEAN(CastTypeKind.BOOLEAN),
+ INTEGER(CastTypeKind.NUMERIC), LONG(CastTypeKind.NUMERIC), FLOAT(CastTypeKind.NUMERIC), DOUBLE(CastTypeKind.NUMERIC), FIXED(CastTypeKind.NUMERIC),
+ DATE(CastTypeKind.TEMPORAL), TIME(CastTypeKind.TEMPORAL), TIMESTAMP(CastTypeKind.TEMPORAL),
+ OFFSET_TIMESTAMP(CastTypeKind.TEMPORAL), ZONE_TIMESTAMP(CastTypeKind.TEMPORAL),
+ NULL(null),
+ OTHER(null);
+
+ private final CastTypeKind kind;
+
+ CastType(CastTypeKind kind) {
+ this.kind = kind;
+ }
+
+ public CastTypeKind getKind() {
+ return kind;
+ }
public static CastType from(Class javaClass) {
if (String.class.equals(javaClass)) {
diff --git a/hibernate-core/src/main/java/org/hibernate/query/CastTypeKind.java b/hibernate-core/src/main/java/org/hibernate/query/CastTypeKind.java
new file mode 100644
index 0000000000..e0d86961f1
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/query/CastTypeKind.java
@@ -0,0 +1,21 @@
+/*
+ * 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.query;
+
+/**
+ * The kind of type of a cast target.
+ *
+ * @see CastType
+ *
+ * @author Christian Beikov
+ */
+public enum CastTypeKind {
+ BOOLEAN,
+ NUMERIC,
+ TEMPORAL,
+ TEXT
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/ComparisonOperator.java b/hibernate-core/src/main/java/org/hibernate/query/ComparisonOperator.java
index 1ff9e3d46c..fbe0421856 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/ComparisonOperator.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/ComparisonOperator.java
@@ -12,10 +12,16 @@ package org.hibernate.query;
*/
public enum ComparisonOperator {
EQUAL {
+ @Override
public ComparisonOperator negated() {
return NOT_EQUAL;
}
+ @Override
+ public ComparisonOperator invert() {
+ return EQUAL;
+ }
+
@Override
public String sqlText() {
return "=";
@@ -23,10 +29,16 @@ public enum ComparisonOperator {
},
NOT_EQUAL {
+ @Override
public ComparisonOperator negated() {
return EQUAL;
}
+ @Override
+ public ComparisonOperator invert() {
+ return NOT_EQUAL;
+ }
+
@Override
public String sqlText() {
return "!=";
@@ -34,10 +46,16 @@ public enum ComparisonOperator {
},
LESS_THAN {
+ @Override
public ComparisonOperator negated() {
return GREATER_THAN_OR_EQUAL;
}
+ @Override
+ public ComparisonOperator invert() {
+ return GREATER_THAN;
+ }
+
@Override
public String sqlText() {
return "<";
@@ -45,10 +63,16 @@ public enum ComparisonOperator {
},
LESS_THAN_OR_EQUAL {
+ @Override
public ComparisonOperator negated() {
return GREATER_THAN;
}
+ @Override
+ public ComparisonOperator invert() {
+ return GREATER_THAN_OR_EQUAL;
+ }
+
@Override
public String sqlText() {
return "<=";
@@ -56,10 +80,16 @@ public enum ComparisonOperator {
},
GREATER_THAN {
+ @Override
public ComparisonOperator negated() {
return LESS_THAN_OR_EQUAL;
}
+ @Override
+ public ComparisonOperator invert() {
+ return LESS_THAN;
+ }
+
@Override
public String sqlText() {
return ">";
@@ -67,10 +97,16 @@ public enum ComparisonOperator {
},
GREATER_THAN_OR_EQUAL {
+ @Override
public ComparisonOperator negated() {
return LESS_THAN;
}
+ @Override
+ public ComparisonOperator invert() {
+ return LESS_THAN_OR_EQUAL;
+ }
+
@Override
public String sqlText() {
return ">=";
@@ -78,5 +114,6 @@ public enum ComparisonOperator {
};
public abstract ComparisonOperator negated();
+ public abstract ComparisonOperator invert();
public abstract String sqlText();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
index 25c0c1489c..0e90a977a3 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java
@@ -32,6 +32,7 @@ import javax.persistence.criteria.Subquery;
import org.hibernate.NullPrecedence;
import org.hibernate.SortOrder;
import org.hibernate.metamodel.model.domain.DomainType;
+import org.hibernate.query.sqm.tree.expression.SqmExpression;
/**
* Hibernate extensions to the JPA CriteriaBuilder.
@@ -330,6 +331,8 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder {
> JpaExpression> indexes(L list);
+ SqmExpression value(T value);
+
> JpaExpression> values(C collection);
@Override
diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java
index ffca9f2fa7..41437862a6 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaQueryStructure.java
@@ -94,5 +94,5 @@ public interface JpaQueryStructure extends JpaCriteriaNode {
JpaExpression getOffset();
- JpaQueryStructure setOffset(JpaExpression offset);
+ JpaQueryStructure setOffset(JpaExpression> offset);
}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java
index 1b0a47c1d9..56c6a58946 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java
@@ -6,7 +6,9 @@
*/
package org.hibernate.query.hql.internal;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.hibernate.NotYetImplementedFor6Exception;
@@ -58,8 +60,6 @@ import org.hibernate.query.sqm.tree.predicate.SqmWhereClause;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationArgument;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiationTarget;
-import org.hibernate.query.sqm.tree.select.SqmGroupByClause;
-import org.hibernate.query.sqm.tree.select.SqmHavingClause;
import org.hibernate.query.sqm.tree.select.SqmOrderByClause;
import org.hibernate.query.sqm.tree.select.SqmQuerySpec;
import org.hibernate.query.sqm.tree.select.SqmSelectClause;
@@ -188,7 +188,8 @@ public class QuerySplitter {
sqmQuerySpec.setFromClause( visitFromClause( querySpec.getFromClause() ) );
sqmQuerySpec.setSelectClause( visitSelectClause( querySpec.getSelectClause() ) );
sqmQuerySpec.setWhereClause( visitWhereClause( querySpec.getWhereClause() ) );
- sqmQuerySpec.setGroupByClause( visitGroupByClause( querySpec.getGroupByClause() ) );
+ sqmQuerySpec.setGroupByClauseExpressions( visitGroupByClause( querySpec.getGroupByClauseExpressions() ) );
+ sqmQuerySpec.setHavingClausePredicate( visitHavingClause( querySpec.getHavingClausePredicate() ) );
sqmQuerySpec.setOrderByClause( visitOrderByClause( querySpec.getOrderByClause() ) );
if ( querySpec.getLimitExpression() != null ) {
sqmQuerySpec.setLimitExpression( (SqmExpression) querySpec.getLimitExpression().accept( this ) );
@@ -218,33 +219,23 @@ public class QuerySplitter {
}
@Override
- public SqmGroupByClause visitGroupByClause(SqmGroupByClause clause) {
- if ( clause == null ) {
- return null;
+ public List> visitGroupByClause(List> groupByClauseExpressions) {
+ if ( groupByClauseExpressions.isEmpty() ) {
+ return groupByClauseExpressions;
}
- final SqmGroupByClause result = new SqmGroupByClause();
- clause.visitGroupings(
- grouping -> result.addGrouping(
- (SqmExpression) grouping.getExpression().accept( this ),
- grouping.getCollation()
- )
- );
- return result;
+ List> expressions = new ArrayList<>( groupByClauseExpressions.size() );
+ for ( SqmExpression> groupByClauseExpression : groupByClauseExpressions ) {
+ expressions.add( (SqmExpression>) groupByClauseExpression.accept( this ) );
+ }
+ return expressions;
}
@Override
- public SqmGroupByClause.SqmGrouping visitGrouping(SqmGroupByClause.SqmGrouping grouping) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SqmHavingClause visitHavingClause(SqmHavingClause clause) {
- if ( clause == null || clause.getPredicate() == null ) {
+ public SqmPredicate visitHavingClause(SqmPredicate sqmPredicate) {
+ if ( sqmPredicate == null ) {
return null;
}
- return new SqmHavingClause(
- (SqmPredicate) clause.getPredicate().accept( this )
- );
+ return (SqmPredicate) sqmPredicate.accept( this );
}
@Override
@@ -598,7 +589,6 @@ public class QuerySplitter {
public SqmSortSpecification visitSortSpecification(SqmSortSpecification sortSpecification) {
return new SqmSortSpecification(
(SqmExpression) sortSpecification.getSortExpression().accept( this ),
- sortSpecification.getCollation(),
sortSpecification.getSortOrder(),
sortSpecification.getNullPrecedence()
);
@@ -638,7 +628,7 @@ public class QuerySplitter {
}
@Override
- public SqmLiteral visitLiteral(SqmLiteral literal) {
+ public SqmLiteral visitLiteral(SqmLiteral> literal) {
return new SqmLiteral(
literal.getLiteralValue(),
literal.getNodeType(),
diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
index 3e5a3388e6..8e7765cabd 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java
@@ -36,6 +36,7 @@ import org.hibernate.QueryException;
import org.hibernate.SortOrder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
+import org.hibernate.grammars.hql.HqlLexer;
import org.hibernate.grammars.hql.HqlParser;
import org.hibernate.grammars.hql.HqlParserBaseVisitor;
import org.hibernate.internal.util.collections.Stack;
@@ -101,6 +102,7 @@ import org.hibernate.query.sqm.tree.expression.SqmByUnit;
import org.hibernate.query.sqm.tree.expression.SqmCaseSearched;
import org.hibernate.query.sqm.tree.expression.SqmCaseSimple;
import org.hibernate.query.sqm.tree.expression.SqmCastTarget;
+import org.hibernate.query.sqm.tree.expression.SqmCollate;
import org.hibernate.query.sqm.tree.expression.SqmCollectionSize;
import org.hibernate.query.sqm.tree.expression.SqmDistinct;
import org.hibernate.query.sqm.tree.expression.SqmDurationUnit;
@@ -470,8 +472,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
// Query spec
@Override
- public SqmQuerySpec visitQuerySpec(HqlParser.QuerySpecContext ctx) {
- final SqmQuerySpec sqmQuerySpec = new SqmQuerySpec( creationContext.getNodeBuilder() );
+ public SqmQuerySpec> visitQuerySpec(HqlParser.QuerySpecContext ctx) {
+ final SqmQuerySpec> sqmQuerySpec = new SqmQuerySpec<>( creationContext.getNodeBuilder() );
// visit from-clause first!!!
treatHandlerStack.push( new TreatHandlerFromClause() );
@@ -504,15 +506,25 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
sqmQuerySpec.setWhereClause( whereClause );
+ final HqlParser.GroupByClauseContext groupByClauseContext = ctx.groupByClause();
+ if ( groupByClauseContext != null ) {
+ sqmQuerySpec.setGroupByClauseExpressions( visitGroupByClause( groupByClauseContext ) );
+ }
+ final HqlParser.HavingClauseContext havingClauseContext = ctx.havingClause();
+ if ( havingClauseContext != null ) {
+ sqmQuerySpec.setHavingClausePredicate( visitHavingClause( havingClauseContext ) );
+ }
+
final SqmOrderByClause orderByClause;
- if ( ctx.orderByClause() != null ) {
+ final HqlParser.OrderByClauseContext orderByClauseContext = ctx.orderByClause();
+ if ( orderByClauseContext != null ) {
if ( creationOptions.useStrictJpaCompliance() && processingStateStack.depth() > 1 ) {
throw new StrictJpaComplianceViolation(
StrictJpaComplianceViolation.Type.SUBQUERY_ORDER_BY
);
}
- orderByClause = visitOrderByClause( ctx.orderByClause() );
+ orderByClause = visitOrderByClause( orderByClauseContext );
}
else {
orderByClause = new SqmOrderByClause();
@@ -743,13 +755,18 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public Object visitGroupByClause(HqlParser.GroupByClauseContext ctx) {
- return super.visitGroupByClause( ctx );
+ public List> visitGroupByClause(HqlParser.GroupByClauseContext ctx) {
+ final List expressionContexts = ctx.expression();
+ final List> expressions = new ArrayList<>( expressionContexts.size() );
+ for ( HqlParser.ExpressionContext expressionContext : expressionContexts ) {
+ expressions.add( (SqmExpression>) expressionContext.accept( this ) );
+ }
+ return expressions;
}
@Override
- public Object visitHavingClause(HqlParser.HavingClauseContext ctx) {
- return super.visitHavingClause( ctx );
+ public SqmPredicate visitHavingClause(HqlParser.HavingClauseContext ctx) {
+ return (SqmPredicate) ctx.predicate().accept( this );
}
@Override
@@ -763,7 +780,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public SqmSortSpecification visitSortSpecification(HqlParser.SortSpecificationContext ctx) {
- final SqmExpression sortExpression = visitSortExpression( ctx.sortExpression() );
+ final SqmExpression> sortExpression = visitSortExpression( ctx.sortExpression() );
if ( sortExpression == null ) {
throw new ParsingException( "Could not resolve sort-expression : " + ctx.sortExpression().getText() );
}
@@ -772,14 +789,6 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
HqlLogging.QUERY_LOGGER.debugf( "Questionable sorting by constant value : %s", sortExpression );
}
- final String collation;
- if ( ctx.collationSpecification() != null && ctx.collationSpecification().collateName() != null ) {
- collation = ctx.collationSpecification().collateName().dotIdentifierSequence().getText();
- }
- else {
- collation = null;
- }
-
final SortOrder sortOrder;
if ( ctx.orderingSpecification() != null ) {
final String ordering = ctx.orderingSpecification().getText();
@@ -802,76 +811,107 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
nullPrecedence = null;
}
- return new SqmSortSpecification( sortExpression, collation, sortOrder, nullPrecedence );
+ return new SqmSortSpecification( sortExpression, sortOrder, nullPrecedence );
+ }
+
+ private SqmExpression> wrapCollate(SqmExpression> expression, HqlParser.CollationSpecificationContext collationSpecificationContext) {
+ if ( collationSpecificationContext == null ) {
+ return expression;
+ }
+ return new SqmCollate<>( expression, collationSpecificationContext.collateName().getText() );
}
@Override
- public SqmExpression visitSortExpression(HqlParser.SortExpressionContext ctx) {
+ public SqmExpression> visitSortExpression(HqlParser.SortExpressionContext ctx) {
if ( ctx.INTEGER_LITERAL() != null ) {
+ final HqlParser.CollationSpecificationContext collationSpecificationContext = ctx.collationSpecification();
final int position = Integer.parseInt( ctx.INTEGER_LITERAL().getText() );
final SqmSelection selection = getCurrentProcessingState().getPathRegistry().findSelectionByPosition( position );
if ( selection != null ) {
final SqmSelectableNode selectableNode = selection.getSelectableNode();
if ( selectableNode instanceof SqmExpression ) {
- return (SqmExpression) selectableNode;
+ return wrapCollate( (SqmExpression) selectableNode, collationSpecificationContext );
}
}
- return new SqmLiteral<>( position, resolveExpressableTypeBasic( Integer.class ), creationContext.getNodeBuilder() );
+ return wrapCollate(
+ new SqmLiteral<>(
+ position,
+ resolveExpressableTypeBasic( Integer.class ),
+ creationContext.getNodeBuilder()
+ ),
+ collationSpecificationContext
+ );
}
if ( ctx.identifier() != null ) {
+ final HqlParser.CollationSpecificationContext collationSpecificationContext = ctx.collationSpecification();
final SqmSelection selection = getCurrentProcessingState().getPathRegistry().findSelectionByAlias( ctx.identifier().getText() );
if ( selection != null ) {
final SqmSelectableNode selectableNode = selection.getSelectableNode();
if ( selectableNode instanceof SqmExpression ) {
- return (SqmExpression) selectableNode;
+ return wrapCollate( (SqmExpression) selectableNode, collationSpecificationContext );
}
}
final SqmFrom sqmFrom = getCurrentProcessingState().getPathRegistry().findFromByAlias( ctx.identifier().getText() );
if ( sqmFrom != null ) {
+ assert collationSpecificationContext == null;
return sqmFrom;
}
final DotIdentifierConsumer dotIdentifierConsumer = dotIdentifierConsumerStack.getCurrent();
dotIdentifierConsumer.consumeIdentifier( ctx.getText(), true, true );
- return (SqmExpression) dotIdentifierConsumer.getConsumedPart();
+ return wrapCollate(
+ (SqmExpression>) dotIdentifierConsumer.getConsumedPart(),
+ collationSpecificationContext
+ );
}
- return (SqmExpression) ctx.expression().accept( this );
+ return (SqmExpression>) ctx.expression().accept( this );
}
@Override
- public SqmExpression visitLimitClause(HqlParser.LimitClauseContext ctx) {
+ public SqmExpression> visitLimitClause(HqlParser.LimitClauseContext ctx) {
if ( ctx == null ) {
return null;
}
- return (SqmExpression) ctx.parameterOrNumberLiteral().accept( this );
+ return (SqmExpression>) ctx.parameterOrNumberLiteral().accept( this );
}
@Override
- public SqmExpression visitOffsetClause(HqlParser.OffsetClauseContext ctx) {
+ public SqmExpression> visitOffsetClause(HqlParser.OffsetClauseContext ctx) {
if ( ctx == null ) {
return null;
}
- return (SqmExpression) ctx.parameterOrNumberLiteral().accept( this );
+ return (SqmExpression>) ctx.parameterOrNumberLiteral().accept( this );
}
@Override
- public Object visitPathExpression(HqlParser.PathExpressionContext ctx) {
- return ctx.path().accept( this );
+ public SqmExpression> visitPathExpression(HqlParser.PathExpressionContext ctx) {
+ return wrapCollate(
+ (SqmExpression>) ctx.path().accept( this ),
+ ctx.collationSpecification()
+ );
}
@Override
- public SqmExpression visitParameterOrNumberLiteral(HqlParser.ParameterOrNumberLiteralContext ctx) {
+ public SqmExpression> visitFunctionExpression(HqlParser.FunctionExpressionContext ctx) {
+ return wrapCollate(
+ (SqmExpression>) ctx.function().accept( this ),
+ ctx.collationSpecification()
+ );
+ }
+
+ @Override
+ public SqmExpression> visitParameterOrNumberLiteral(HqlParser.ParameterOrNumberLiteralContext ctx) {
if ( ctx.INTEGER_LITERAL() != null ) {
return integerLiteral( ctx.INTEGER_LITERAL().getText() );
}
if ( ctx.parameter() != null ) {
- return (SqmExpression) ctx.parameter().accept( this );
+ return (SqmExpression>) ctx.parameter().accept( this );
}
return null;
@@ -1501,8 +1541,11 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmPath visitEntityIdExpression(HqlParser.EntityIdExpressionContext ctx) {
- return visitEntityIdReference( ctx.entityIdReference() );
+ public SqmExpression> visitEntityIdExpression(HqlParser.EntityIdExpressionContext ctx) {
+ return wrapCollate(
+ visitEntityIdReference( ctx.entityIdReference() ),
+ ctx.collationSpecification()
+ );
}
@Override
@@ -1528,8 +1571,11 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmPath visitEntityVersionExpression(HqlParser.EntityVersionExpressionContext ctx) {
- return visitEntityVersionReference( ctx.entityVersionReference() );
+ public SqmExpression> visitEntityVersionExpression(HqlParser.EntityVersionExpressionContext ctx) {
+ return wrapCollate(
+ visitEntityVersionReference( ctx.entityVersionReference() ),
+ ctx.collationSpecification()
+ );
}
@Override
@@ -1716,6 +1762,16 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
return ctx.expression().accept(this);
}
+ @Override
+ public Object visitCaseExpression(HqlParser.CaseExpressionContext ctx) {
+ final SqmExpression> expression = (SqmExpression>) ctx.caseList().accept( this );
+ final HqlParser.CollationSpecificationContext collationSpecificationContext = ctx.collationSpecification();
+ if ( collationSpecificationContext == null ) {
+ return expression;
+ }
+ return new SqmCollate<>( expression, collationSpecificationContext.collateName().getText() );
+ }
+
@Override
public SqmCaseSimple visitSimpleCaseList(HqlParser.SimpleCaseListContext ctx) {
//noinspection unchecked
@@ -1933,145 +1989,180 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmLiteral visitLiteralExpression(HqlParser.LiteralExpressionContext ctx) {
- if ( ctx.literal().STRING_LITERAL() != null ) {
- return stringLiteral( ctx.literal().STRING_LITERAL().getText() );
- }
- else if ( ctx.literal().INTEGER_LITERAL() != null ) {
- return integerLiteral( ctx.literal().INTEGER_LITERAL().getText() );
- }
- else if ( ctx.literal().LONG_LITERAL() != null ) {
- return longLiteral( ctx.literal().LONG_LITERAL().getText() );
- }
- else if ( ctx.literal().BIG_INTEGER_LITERAL() != null ) {
- return bigIntegerLiteral( ctx.literal().BIG_INTEGER_LITERAL().getText() );
- }
- else if ( ctx.literal().HEX_LITERAL() != null ) {
- return hexLiteral( ctx.literal().HEX_LITERAL().getText() );
- }
- else if ( ctx.literal().FLOAT_LITERAL() != null ) {
- return floatLiteral( ctx.literal().FLOAT_LITERAL().getText() );
- }
- else if ( ctx.literal().DOUBLE_LITERAL() != null ) {
- return doubleLiteral( ctx.literal().DOUBLE_LITERAL().getText() );
- }
- else if ( ctx.literal().BIG_DECIMAL_LITERAL() != null ) {
- return bigDecimalLiteral( ctx.literal().BIG_DECIMAL_LITERAL().getText() );
- }
- else if ( ctx.literal().FALSE() != null ) {
- return booleanLiteral( false );
- }
- else if ( ctx.literal().TRUE() != null ) {
- return booleanLiteral( true );
- }
- else if ( ctx.literal().NULL() != null ) {
- return new SqmLiteralNull( creationContext.getQueryEngine().getCriteriaBuilder() );
- }
+ public SqmExpression> visitLiteralExpression(HqlParser.LiteralExpressionContext ctx) {
+ return wrapCollate(
+ (SqmExpression>) ctx.literal().accept( this ),
+ ctx.collationSpecification()
+ );
+ }
- if ( ctx.literal().binaryLiteral() != null ) {
- if ( ctx.literal().binaryLiteral().BINARY_LITERAL() != null ) {
- return binaryLiteral( ctx.literal().binaryLiteral().BINARY_LITERAL().getText() );
- }
- else {
- StringBuilder text = new StringBuilder("x'");
- for ( TerminalNode hex : ctx.literal().binaryLiteral().HEX_LITERAL() ) {
- if ( hex.getText().length()!=4 ) {
- throw new LiteralNumberFormatException( "not a byte: " + hex.getText() );
- }
- text.append( hex.getText().substring(2) );
+ @Override
+ public Object visitBinaryLiteral(HqlParser.BinaryLiteralContext ctx) {
+ final TerminalNode binaryLiteral = ctx.BINARY_LITERAL();
+ if ( binaryLiteral != null ) {
+ return binaryLiteral( binaryLiteral.getText() );
+ }
+ else {
+ final StringBuilder text = new StringBuilder( "x'" );
+ for ( TerminalNode hex : ctx.HEX_LITERAL() ) {
+ final String hexText = hex.getText();
+ if ( hexText.length() != 4 ) {
+ throw new LiteralNumberFormatException( "not a byte: " + hexText );
}
- return binaryLiteral( text.append("'").toString() );
+ text.append( hexText.substring( 2 ) );
}
+ return binaryLiteral( text.append( "'" ).toString() );
}
-
- if ( ctx.literal().temporalLiteral() != null ) {
- return interpretTemporalLiteral( ctx.literal().temporalLiteral() );
- }
-
- if ( ctx.literal().generalizedLiteral() != null ) {
- throw new NotYetImplementedFor6Exception( getClass() );
- }
-
- // otherwise we have a problem
- throw new ParsingException("Unexpected literal expression type [" + ctx.getText() + "]");
}
- private SqmLiteral interpretTemporalLiteral(HqlParser.TemporalLiteralContext temporalLiteral) {
- if ( temporalLiteral.dateTimeLiteral() != null ) {
- if ( temporalLiteral.dateTimeLiteral().dateTime().offset()==null ) {
- return dateTimeLiteralFrom(
- temporalLiteral.dateTimeLiteral().dateTime().date(),
- temporalLiteral.dateTimeLiteral().dateTime().time(),
- temporalLiteral.dateTimeLiteral().dateTime().zoneId()
- );
- }
- else {
- return offsetDatetimeLiteralFrom(
- temporalLiteral.dateTimeLiteral().dateTime().date(),
- temporalLiteral.dateTimeLiteral().dateTime().time(),
- temporalLiteral.dateTimeLiteral().dateTime().offset()
- );
- }
+ @Override
+ public Object visitGeneralizedLiteral(HqlParser.GeneralizedLiteralContext ctx) {
+ throw new NotYetImplementedFor6Exception( getClass() );
+ }
+
+ @Override
+ public SqmExpression> visitTerminal(TerminalNode node) {
+ if ( node.getSymbol().getType() == HqlLexer.EOF ) {
+ return null;
}
- else if ( temporalLiteral.dateLiteral() != null ) {
- return dateLiteralFrom( temporalLiteral.dateLiteral().date() );
+ switch ( node.getSymbol().getType() ) {
+ case HqlParser.STRING_LITERAL:
+ return stringLiteral( node.getText() );
+ case HqlParser.INTEGER_LITERAL:
+ return integerLiteral( node.getText() );
+ case HqlParser.LONG_LITERAL:
+ return longLiteral( node.getText() );
+ case HqlParser.BIG_INTEGER_LITERAL:
+ return bigIntegerLiteral( node.getText() );
+ case HqlParser.HEX_LITERAL:
+ return hexLiteral( node.getText() );
+ case HqlParser.FLOAT_LITERAL:
+ return floatLiteral( node.getText() );
+ case HqlParser.DOUBLE_LITERAL:
+ return doubleLiteral( node.getText() );
+ case HqlParser.BIG_DECIMAL_LITERAL:
+ return bigDecimalLiteral( node.getText() );
+ case HqlParser.FALSE:
+ return booleanLiteral( false );
+ case HqlParser.TRUE:
+ return booleanLiteral( true );
+ case HqlParser.NULL:
+ return new SqmLiteralNull<>( creationContext.getQueryEngine().getCriteriaBuilder() );
+ case HqlParser.BINARY_LITERAL:
+ return binaryLiteral( node.getText() );
+ default:
+ throw new ParsingException("Unexpected terminal node [" + node.getText() + "]");
}
- else if ( temporalLiteral.timeLiteral() != null ) {
- return timeLiteralFrom( temporalLiteral.timeLiteral().time() );
- }
- // literals for javax.sql Date/Time/Timestamp using JDBC escape syntax
- else if ( temporalLiteral.jdbcTimestampLiteral() != null ) {
- if ( temporalLiteral.jdbcTimestampLiteral().genericTemporalLiteralText()!=null ) {
- return sqlTimestampLiteralFrom( temporalLiteral.jdbcTimestampLiteral().genericTemporalLiteralText().getText() );
- }
- else {
- return dateTimeLiteralFrom(
- temporalLiteral.jdbcTimestampLiteral().dateTime().date(),
- temporalLiteral.jdbcTimestampLiteral().dateTime().time(),
- temporalLiteral.jdbcTimestampLiteral().dateTime().zoneId()
- );
- }
- }
- else if ( temporalLiteral.jdbcDateLiteral() != null ) {
- if ( temporalLiteral.jdbcDateLiteral().genericTemporalLiteralText()!=null ) {
- return sqlDateLiteralFrom( temporalLiteral.jdbcDateLiteral().genericTemporalLiteralText().getText() );
- }
- else {
- return dateLiteralFrom( temporalLiteral.jdbcDateLiteral().date() );
- }
- }
- else if ( temporalLiteral.jdbcTimeLiteral() != null ) {
- if ( temporalLiteral.jdbcTimeLiteral().genericTemporalLiteralText()!=null ) {
- return sqlTimeLiteralFrom( temporalLiteral.jdbcTimeLiteral().genericTemporalLiteralText().getText() );
- }
- else {
- return timeLiteralFrom( temporalLiteral.jdbcTimeLiteral().time() );
- }
+ }
+
+ @Override
+ public Object visitDateTimeLiteral(HqlParser.DateTimeLiteralContext dateTimeLiteralContext) {
+ final HqlParser.DateTimeContext dateTimeContext = dateTimeLiteralContext.dateTime();
+ if ( dateTimeContext.offset() == null ) {
+ return dateTimeLiteralFrom(
+ dateTimeContext.date(),
+ dateTimeContext.time(),
+ dateTimeContext.zoneId()
+ );
}
else {
- // otherwise we have a problem
- throw new ParsingException("Unexpected literal expression type [" + temporalLiteral.getText() + "]");
+ return offsetDatetimeLiteralFrom(
+ dateTimeContext.date(),
+ dateTimeContext.time(),
+ dateTimeContext.offset()
+ );
}
}
- private SqmLiteral> dateTimeLiteralFrom(HqlParser.DateContext date, HqlParser.TimeContext time, HqlParser.ZoneIdContext timezone) {
- if (timezone == null) {
+ @Override
+ public Object visitDateLiteral(HqlParser.DateLiteralContext ctx) {
+ return ctx.date().accept( this );
+ }
+
+ @Override
+ public Object visitTimeLiteral(HqlParser.TimeLiteralContext ctx) {
+ return ctx.time().accept( this );
+ }
+
+ @Override
+ public Object visitJdbcTimestampLiteral(HqlParser.JdbcTimestampLiteralContext ctx) {
+ final HqlParser.GenericTemporalLiteralTextContext genericTemporalLiteralTextContext = ctx.genericTemporalLiteralText();
+ if ( genericTemporalLiteralTextContext == null ) {
+ return ctx.dateTime().accept( this );
+ }
+ else {
+ return sqlTimestampLiteralFrom( genericTemporalLiteralTextContext.getText() );
+ }
+ }
+
+ @Override
+ public Object visitJdbcDateLiteral(HqlParser.JdbcDateLiteralContext ctx) {
+ final HqlParser.GenericTemporalLiteralTextContext genericTemporalLiteralTextContext = ctx.genericTemporalLiteralText();
+ if ( genericTemporalLiteralTextContext == null ) {
+ return ctx.date().accept( this );
+ }
+ else {
+ return sqlDateLiteralFrom( genericTemporalLiteralTextContext.getText() );
+ }
+ }
+
+ @Override
+ public Object visitJdbcTimeLiteral(HqlParser.JdbcTimeLiteralContext ctx) {
+ final HqlParser.GenericTemporalLiteralTextContext genericTemporalLiteralTextContext = ctx.genericTemporalLiteralText();
+ if ( genericTemporalLiteralTextContext == null ) {
+ return ctx.time().accept( this );
+ }
+ else {
+ return sqlTimeLiteralFrom( genericTemporalLiteralTextContext.getText() );
+ }
+ }
+
+ @Override
+ public Object visitDateTime(HqlParser.DateTimeContext ctx) {
+ return dateTimeLiteralFrom(
+ ctx.date(),
+ ctx.time(),
+ ctx.zoneId()
+ );
+ }
+
+ private SqmLiteral> dateTimeLiteralFrom(
+ HqlParser.DateContext date,
+ HqlParser.TimeContext time,
+ HqlParser.ZoneIdContext timezone) {
+ if ( timezone == null ) {
return new SqmLiteral<>(
- LocalDateTime.of(localDate(date), localTime(time)),
- resolveExpressableTypeBasic(LocalDateTime.class),
+ LocalDateTime.of( localDate( date ), localTime( time ) ),
+ resolveExpressableTypeBasic( LocalDateTime.class ),
creationContext.getNodeBuilder()
);
}
else {
+ final ZoneId zoneId = visitZoneId( timezone );
return new SqmLiteral<>(
- ZonedDateTime.of(localDate(date), localTime(time), ZoneId.of(timezone.getText())),
- resolveExpressableTypeBasic(ZonedDateTime.class),
+ ZonedDateTime.of( localDate( date ), localTime( time ), zoneId ),
+ resolveExpressableTypeBasic( ZonedDateTime.class ),
creationContext.getNodeBuilder()
);
}
}
- private SqmLiteral> offsetDatetimeLiteralFrom(HqlParser.DateContext date, HqlParser.TimeContext time, HqlParser.OffsetContext offset) {
+ @Override
+ public ZoneId visitZoneId(HqlParser.ZoneIdContext ctx) {
+ final String timezoneText = ctx.getText();
+ final String timezoneFullName = ZoneId.SHORT_IDS.get( timezoneText );
+ if ( timezoneFullName == null ) {
+ return ZoneId.of( timezoneText );
+ }
+ else {
+ return ZoneId.of( timezoneFullName );
+ }
+ }
+
+ private SqmLiteral> offsetDatetimeLiteralFrom(
+ HqlParser.DateContext date,
+ HqlParser.TimeContext time,
+ HqlParser.OffsetContext offset) {
return new SqmLiteral<>(
OffsetDateTime.of( localDate( date ), localTime( time ), zoneOffset( offset ) ),
resolveExpressableTypeBasic( OffsetDateTime.class ),
@@ -2079,38 +2170,42 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
);
}
- private SqmLiteral> dateLiteralFrom(HqlParser.DateContext date) {
+ @Override
+ public Object visitDate(HqlParser.DateContext ctx) {
return new SqmLiteral<>(
- localDate( date ),
+ localDate( ctx ),
resolveExpressableTypeBasic( LocalDate.class ),
creationContext.getNodeBuilder()
);
}
- private SqmLiteral> timeLiteralFrom(HqlParser.TimeContext time) {
+ @Override
+ public Object visitTime(HqlParser.TimeContext ctx) {
return new SqmLiteral<>(
- localTime( time ),
+ localTime( ctx ),
resolveExpressableTypeBasic( LocalTime.class ),
creationContext.getNodeBuilder()
);
}
private static LocalTime localTime(HqlParser.TimeContext ctx) {
- if ( ctx.second() != null ) {
- int index = ctx.second().getText().indexOf('.');
+ final HqlParser.SecondContext second = ctx.second();
+ if ( second != null ) {
+ final String secondText = second.getText();
+ final int index = secondText.indexOf( '.');
if ( index < 0 ) {
return LocalTime.of(
Integer.parseInt( ctx.hour().getText() ),
Integer.parseInt( ctx.minute().getText() ),
- Integer.parseInt( ctx.second().getText() )
+ Integer.parseInt( secondText )
);
}
else {
return LocalTime.of(
Integer.parseInt( ctx.hour().getText() ),
Integer.parseInt( ctx.minute().getText() ),
- Integer.parseInt( ctx.second().getText().substring( 0, index ) ),
- Integer.parseInt( ctx.second().getText().substring( index + 1 ) )
+ Integer.parseInt( secondText.substring( 0, index ) ),
+ Integer.parseInt( secondText.substring( index + 1 ) )
);
}
}
@@ -2131,11 +2226,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
private static ZoneOffset zoneOffset(HqlParser.OffsetContext offset) {
- return offset.minute() == null
+ final HqlParser.MinuteContext minute = offset.minute();
+ return minute == null
? ZoneOffset.ofHours( Integer.parseInt( offset.hour().getText() ) )
: ZoneOffset.ofHoursMinutes(
Integer.parseInt( offset.hour().getText() ),
- Integer.parseInt( offset.minute().getText() )
+ Integer.parseInt( minute.getText() )
);
}
@@ -2242,7 +2338,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
private SqmLiteral binaryLiteral(String text) {
- return new SqmLiteral(
+ return new SqmLiteral<>(
StandardBasicTypes.BINARY.fromStringValue( text.substring( 2, text.length()-1 ) ),
resolveExpressableTypeBasic( byte[].class ),
creationContext.getNodeBuilder()
@@ -2287,12 +2383,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
}
- private SqmLiteral hexLiteral(String text) {
+ private SqmLiteral extends Number> hexLiteral(String text) {
final String originalText = text;
text = text.substring( 2 );
try {
final Number value;
- final BasicDomainType type;
+ final BasicDomainType extends Number> type;
if ( text.endsWith( "l" ) || text.endsWith( "L" ) ) {
text = text.substring( 0, text.length() - 1 );
value = Long.parseUnsignedLong( text, 16 );
@@ -2304,7 +2400,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
return new SqmLiteral<>(
value,
- type,
+ (SqmExpressable) type,
creationContext.getNodeBuilder()
);
}
@@ -2395,13 +2491,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitParameterExpression(HqlParser.ParameterExpressionContext ctx) {
- return ctx.parameter().accept( this );
+ return wrapCollate( (SqmExpression>) ctx.parameter().accept( this ), ctx.collationSpecification() );
}
@Override
- public SqmNamedParameter visitNamedParameter(HqlParser.NamedParameterContext ctx) {
-
- final SqmNamedParameter> param = new SqmNamedParameter(
+ public SqmNamedParameter> visitNamedParameter(HqlParser.NamedParameterContext ctx) {
+ final SqmNamedParameter> param = new SqmNamedParameter<>(
ctx.identifier().getText(),
parameterDeclarationContextStack.getCurrent().isMultiValuedBindingAllowed(),
creationContext.getNodeBuilder()
@@ -2411,7 +2506,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmPositionalParameter visitPositionalParameter(HqlParser.PositionalParameterContext ctx) {
+ public SqmPositionalParameter> visitPositionalParameter(HqlParser.PositionalParameterContext ctx) {
if ( ctx.INTEGER_LITERAL() == null ) {
throw new SemanticException( "Encountered positional parameter which did not declare position (? instead of, e.g., ?1)" );
}
@@ -2429,7 +2524,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
// Functions
@Override
- public SqmExpression visitJpaNonStandardFunction(HqlParser.JpaNonStandardFunctionContext ctx) {
+ public SqmExpression> visitJpaNonStandardFunction(HqlParser.JpaNonStandardFunctionContext ctx) {
final String functionName = ctx.jpaNonStandardFunctionName().STRING_LITERAL().getText().toLowerCase();
List> functionArguments =
ctx.nonStandardFunctionArguments() == null ? emptyList() :
@@ -2449,7 +2544,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitNonStandardFunction(HqlParser.NonStandardFunctionContext ctx) {
+ public SqmExpression> visitNonStandardFunction(HqlParser.NonStandardFunctionContext ctx) {
if ( creationOptions.useStrictJpaCompliance() ) {
throw new StrictJpaComplianceViolation(
"Encountered non-compliant non-standard function call [" +
@@ -2497,12 +2592,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
return arguments;
}
- private SqmExpression visitFinalFunctionArgument(HqlParser.ExpressionContext expression) {
+ private SqmExpression> visitFinalFunctionArgument(HqlParser.ExpressionContext expression) {
// the final argument to a function may accept multi-value parameter (varargs),
// but only if we are operating in non-strict JPA mode
parameterDeclarationContextStack.push( creationOptions::useStrictJpaCompliance );
try {
- return (SqmExpression) expression.accept( this );
+ return (SqmExpression>) expression.accept( this );
}
finally {
parameterDeclarationContextStack.pop();
@@ -2510,8 +2605,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitCeilingFunction(HqlParser.CeilingFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitCeilingFunction(HqlParser.CeilingFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("ceiling").generateSqmExpression(
arg,
@@ -2522,8 +2617,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitFloorFunction(HqlParser.FloorFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitFloorFunction(HqlParser.FloorFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("floor").generateSqmExpression(
arg,
@@ -2538,20 +2633,20 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitAbsFunction(HqlParser.AbsFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitAbsFunction(HqlParser.AbsFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("abs").generateSqmExpression(
arg,
- (AllowableFunctionReturnType) arg.getNodeType(),
+ (AllowableFunctionReturnType>) arg.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitSignFunction(HqlParser.SignFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitSignFunction(HqlParser.SignFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("sign").generateSqmExpression(
arg,
@@ -2562,34 +2657,34 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitModFunction(HqlParser.ModFunctionContext ctx) {
- final SqmExpression dividend = (SqmExpression) ctx.modDividendArgument().accept( this );
- final SqmExpression divisor = (SqmExpression) ctx.modDivisorArgument().accept( this );
+ public SqmExpression> visitModFunction(HqlParser.ModFunctionContext ctx) {
+ final SqmExpression> dividend = (SqmExpression>) ctx.modDividendArgument().accept( this );
+ final SqmExpression> divisor = (SqmExpression>) ctx.modDivisorArgument().accept( this );
return getFunctionDescriptor("mod").generateSqmExpression(
asList( dividend, divisor ),
- (AllowableFunctionReturnType) dividend.getNodeType(),
+ (AllowableFunctionReturnType>) dividend.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitPowerFunction(HqlParser.PowerFunctionContext ctx) {
- final SqmExpression base = (SqmExpression) ctx.powerBaseArgument().accept( this );
- final SqmExpression power = (SqmExpression) ctx.powerPowerArgument().accept( this );
+ public SqmExpression> visitPowerFunction(HqlParser.PowerFunctionContext ctx) {
+ final SqmExpression> base = (SqmExpression>) ctx.powerBaseArgument().accept( this );
+ final SqmExpression> power = (SqmExpression>) ctx.powerPowerArgument().accept( this );
return getFunctionDescriptor("power").generateSqmExpression(
asList( base, power ),
- (AllowableFunctionReturnType) base.getNodeType(),
+ (AllowableFunctionReturnType>) base.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitTrigFunction(HqlParser.TrigFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitTrigFunction(HqlParser.TrigFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor( ctx.trigFunctionName().getText() ).generateSqmExpression(
arg,
@@ -2600,50 +2695,50 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitSqrtFunction(HqlParser.SqrtFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitSqrtFunction(HqlParser.SqrtFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("sqrt").generateSqmExpression(
arg,
- (AllowableFunctionReturnType) arg.getNodeType(),
+ (AllowableFunctionReturnType>) arg.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitRoundFunction(HqlParser.RoundFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
- final SqmExpression precision = (SqmExpression) ctx.roundFunctionPrecision().expression().accept( this );
+ public SqmExpression> visitRoundFunction(HqlParser.RoundFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
+ final SqmExpression> precision = (SqmExpression>) ctx.roundFunctionPrecision().expression().accept( this );
return getFunctionDescriptor("round").generateSqmExpression(
asList(arg, precision),
- (AllowableFunctionReturnType) arg.getNodeType(),
+ (AllowableFunctionReturnType>) arg.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitAtan2Function(HqlParser.Atan2FunctionContext ctx) {
- final SqmExpression sin = (SqmExpression) ctx.expression().get(0).accept( this );
- final SqmExpression cos = (SqmExpression) ctx.expression().get(1).accept( this );
+ public SqmExpression> visitAtan2Function(HqlParser.Atan2FunctionContext ctx) {
+ final SqmExpression> sin = (SqmExpression>) ctx.expression().get(0).accept( this );
+ final SqmExpression> cos = (SqmExpression>) ctx.expression().get(1).accept( this );
return getFunctionDescriptor("atan2").generateSqmExpression(
asList(sin, cos),
- (AllowableFunctionReturnType) sin.getNodeType(),
+ (AllowableFunctionReturnType>) sin.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitLnFunction(HqlParser.LnFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitLnFunction(HqlParser.LnFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("ln").generateSqmExpression(
arg,
- (AllowableFunctionReturnType) arg.getNodeType(),
+ (AllowableFunctionReturnType>) arg.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
@@ -2651,12 +2746,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitExpFunction(HqlParser.ExpFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitExpFunction(HqlParser.ExpFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("exp").generateSqmExpression(
arg,
- (AllowableFunctionReturnType) arg.getNodeType(),
+ (AllowableFunctionReturnType>) arg.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
@@ -2798,7 +2893,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitExtractFunction(HqlParser.ExtractFunctionContext ctx) {
- final SqmExpression> expressionToExtract = (SqmExpression) ctx.expression().accept( this );
+ final SqmExpression> expressionToExtract = (SqmExpression>) ctx.expression().accept( this );
// visitDateOrTimeField() needs to know if we're extracting from a
// JDBC Timestamp or from a java.time LocalDateTime/OffsetDateTime
@@ -2861,9 +2956,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitFormatFunction(HqlParser.FormatFunctionContext ctx) {
- final SqmExpression> expressionToCast = (SqmExpression) ctx.expression().accept( this );
- final SqmLiteral> format = (SqmLiteral) ctx.format().accept( this );
+ public SqmExpression> visitFormatFunction(HqlParser.FormatFunctionContext ctx) {
+ final SqmExpression> expressionToCast = (SqmExpression>) ctx.expression().accept( this );
+ final SqmLiteral> format = (SqmLiteral>) ctx.format().accept( this );
return getFunctionDescriptor("format").generateSqmExpression(
asList( expressionToCast, format ),
@@ -2874,9 +2969,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitCastFunction(HqlParser.CastFunctionContext ctx) {
- final SqmExpression> expressionToCast = (SqmExpression) ctx.expression().accept( this );
- final SqmCastTarget> castTargetExpression = (SqmCastTarget) ctx.castTarget().accept( this );
+ public SqmExpression> visitCastFunction(HqlParser.CastFunctionContext ctx) {
+ final SqmExpression> expressionToCast = (SqmExpression>) ctx.expression().accept( this );
+ final SqmCastTarget> castTargetExpression = (SqmCastTarget>) ctx.castTarget().accept( this );
return getFunctionDescriptor("cast").generateSqmExpression(
asList( expressionToCast, castTargetExpression ),
@@ -2907,31 +3002,31 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitUpperFunction(HqlParser.UpperFunctionContext ctx) {
- final SqmExpression expression = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitUpperFunction(HqlParser.UpperFunctionContext ctx) {
+ final SqmExpression> expression = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("upper").generateSqmExpression(
expression,
- (AllowableFunctionReturnType) expression.getNodeType(),
+ (AllowableFunctionReturnType>) expression.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitLowerFunction(HqlParser.LowerFunctionContext ctx) {
+ public SqmExpression> visitLowerFunction(HqlParser.LowerFunctionContext ctx) {
// todo (6.0) : why pass both the expression and its expression-type?
// can't we just pass the expression?
- final SqmExpression expression = (SqmExpression) ctx.expression().accept( this );
+ final SqmExpression> expression = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("lower").generateSqmExpression(
expression,
- (AllowableFunctionReturnType) expression.getNodeType(),
+ (AllowableFunctionReturnType>) expression.getNodeType(),
creationContext.getQueryEngine(),
creationContext.getJpaMetamodel().getTypeConfiguration()
);
}
@Override
- public SqmExpression visitConcatFunction(HqlParser.ConcatFunctionContext ctx) {
+ public SqmExpression> visitConcatFunction(HqlParser.ConcatFunctionContext ctx) {
final List> arguments = new ArrayList<>();
for ( HqlParser.ExpressionContext argument : ctx.expression() ) {
arguments.add( (SqmTypedNode>) argument.accept( this ) );
@@ -2947,7 +3042,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitLengthFunction(HqlParser.LengthFunctionContext ctx) {
- final SqmExpression arg = (SqmExpression) ctx.expression().accept( this );
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("length").generateSqmExpression(
arg,
@@ -2959,8 +3054,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitPositionFunction(HqlParser.PositionFunctionContext ctx) {
- final SqmExpression> string = (SqmExpression) ctx.positionFunctionStringArgument().accept( this );
- final SqmExpression> pattern = (SqmExpression) ctx.positionFunctionPatternArgument().accept( this );
+ final SqmExpression> string = (SqmExpression>) ctx.positionFunctionStringArgument().accept( this );
+ final SqmExpression> pattern = (SqmExpression>) ctx.positionFunctionPatternArgument().accept( this );
return getFunctionDescriptor("position").generateSqmExpression(
asList( pattern, string ),
@@ -2972,8 +3067,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitLocateFunction(HqlParser.LocateFunctionContext ctx) {
- final SqmExpression> string = (SqmExpression) ctx.locateFunctionStringArgument().accept( this );
- final SqmExpression> pattern = (SqmExpression) ctx.locateFunctionPatternArgument().accept( this );
+ final SqmExpression> string = (SqmExpression>) ctx.locateFunctionStringArgument().accept( this );
+ final SqmExpression> pattern = (SqmExpression>) ctx.locateFunctionPatternArgument().accept( this );
final SqmExpression> start = ctx.locateFunctionStartArgument() == null
? null
: (SqmExpression) ctx.locateFunctionStartArgument().accept( this );
@@ -2991,12 +3086,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitOverlayFunction(HqlParser.OverlayFunctionContext ctx) {
- final SqmExpression> string = (SqmExpression) ctx.overlayFunctionStringArgument().accept( this );
- final SqmExpression> replacement = (SqmExpression) ctx.overlayFunctionReplacementArgument().accept( this );
- final SqmExpression> start = (SqmExpression) ctx.overlayFunctionStartArgument().accept( this );
+ final SqmExpression> string = (SqmExpression>) ctx.overlayFunctionStringArgument().accept( this );
+ final SqmExpression> replacement = (SqmExpression>) ctx.overlayFunctionReplacementArgument().accept( this );
+ final SqmExpression> start = (SqmExpression>) ctx.overlayFunctionStartArgument().accept( this );
final SqmExpression> length = ctx.overlayFunctionLengthArgument() == null
? null
- : (SqmExpression) ctx.overlayFunctionLengthArgument().accept( this );
+ : (SqmExpression>) ctx.overlayFunctionLengthArgument().accept( this );
return getFunctionDescriptor("overlay").generateSqmExpression(
length == null
@@ -3011,9 +3106,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitReplaceFunction(HqlParser.ReplaceFunctionContext ctx) {
- final SqmExpression> string = (SqmExpression) ctx.replaceFunctionStringArgument().accept( this );
- final SqmExpression> pattern = (SqmExpression) ctx.replaceFunctionPatternArgument().accept( this );
- final SqmExpression> replacement = (SqmExpression) ctx.replaceFunctionReplacementArgument().accept( this );
+ final SqmExpression> string = (SqmExpression>) ctx.replaceFunctionStringArgument().accept( this );
+ final SqmExpression> pattern = (SqmExpression>) ctx.replaceFunctionPatternArgument().accept( this );
+ final SqmExpression> replacement = (SqmExpression>) ctx.replaceFunctionReplacementArgument().accept( this );
return getFunctionDescriptor("replace").generateSqmExpression(
asList( string, pattern, replacement ),
@@ -3025,7 +3120,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public Object visitStrFunction(HqlParser.StrFunctionContext ctx) {
- final SqmExpression> arg = (SqmExpression) ctx.expression().accept( this );
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
return getFunctionDescriptor("str").generateSqmExpression(
singletonList( arg ),
resolveExpressableTypeBasic( String.class ),
@@ -3035,8 +3130,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitMaxFunction(HqlParser.MaxFunctionContext ctx) {
- final SqmExpression> arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitMaxFunction(HqlParser.MaxFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
//ignore DISTINCT
return getFunctionDescriptor("max").generateSqmExpression(
arg,
@@ -3047,8 +3142,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitMinFunction(HqlParser.MinFunctionContext ctx) {
- final SqmExpression> arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitMinFunction(HqlParser.MinFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
//ignore DISTINCT
return getFunctionDescriptor("min").generateSqmExpression(
arg,
@@ -3059,8 +3154,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitSumFunction(HqlParser.SumFunctionContext ctx) {
- final SqmExpression> arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitSumFunction(HqlParser.SumFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
final SqmTypedNode> argument = ctx.DISTINCT() != null
? new SqmDistinct<>(arg, getCreationContext().getNodeBuilder())
: arg;
@@ -3074,14 +3169,14 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
+ public SqmExpression> visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
if ( ctx.subQuery()!=null ) {
SqmSubQuery> subquery = (SqmSubQuery>) ctx.subQuery().accept(this);
- return new SqmEvery( subquery, subquery.getNodeType(), creationContext.getNodeBuilder() );
+ return new SqmEvery<>( subquery, creationContext.getNodeBuilder() );
}
- final SqmExpression> argument = (SqmExpression) ctx.predicate().accept( this );
+ final SqmExpression> argument = (SqmExpression>) ctx.predicate().accept( this );
return getFunctionDescriptor("every").generateSqmExpression(
argument,
@@ -3092,14 +3187,14 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
+ public SqmExpression> visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
if ( ctx.subQuery()!=null ) {
SqmSubQuery> subquery = (SqmSubQuery>) ctx.subQuery().accept(this);
- return new SqmAny( subquery, subquery.getNodeType(), creationContext.getNodeBuilder() );
+ return new SqmAny<>( subquery, creationContext.getNodeBuilder() );
}
- final SqmExpression> argument = (SqmExpression) ctx.predicate().accept( this );
+ final SqmExpression> argument = (SqmExpression>) ctx.predicate().accept( this );
return getFunctionDescriptor("any").generateSqmExpression(
argument,
@@ -3110,8 +3205,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitAvgFunction(HqlParser.AvgFunctionContext ctx) {
- final SqmExpression> arg = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitAvgFunction(HqlParser.AvgFunctionContext ctx) {
+ final SqmExpression> arg = (SqmExpression>) ctx.expression().accept( this );
final SqmTypedNode> argument = ctx.DISTINCT() != null
? new SqmDistinct<>( arg, getCreationContext().getNodeBuilder() )
: arg;
@@ -3125,10 +3220,10 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitCountFunction(HqlParser.CountFunctionContext ctx) {
+ public SqmExpression> visitCountFunction(HqlParser.CountFunctionContext ctx) {
final SqmExpression> arg = ctx.ASTERISK() != null
? new SqmStar( getCreationContext().getNodeBuilder() )
- : (SqmExpression) ctx.expression().accept( this );
+ : (SqmExpression>) ctx.expression().accept( this );
final SqmTypedNode> argument = ctx.DISTINCT() != null
? new SqmDistinct<>( arg, getCreationContext().getNodeBuilder() )
: arg;
@@ -3142,10 +3237,10 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitCube(HqlParser.CubeContext ctx) {
+ public SqmExpression> visitCube(HqlParser.CubeContext ctx) {
List> args = new ArrayList<>();
for ( HqlParser.ExpressionContext arg: ctx.expression() ) {
- args.add( (SqmExpression) arg.accept( this ) );
+ args.add( (SqmExpression>) arg.accept( this ) );
}
//ignore DISTINCT
return getFunctionDescriptor("cube").generateSqmExpression(
@@ -3157,10 +3252,10 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitRollup(HqlParser.RollupContext ctx) {
+ public SqmExpression> visitRollup(HqlParser.RollupContext ctx) {
List> args = new ArrayList<>();
for ( HqlParser.ExpressionContext arg: ctx.expression() ) {
- args.add( (SqmExpression) arg.accept( this ) );
+ args.add( (SqmExpression>) arg.accept( this ) );
}
//ignore DISTINCT
return getFunctionDescriptor("rollup").generateSqmExpression(
@@ -3172,12 +3267,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitSubstringFunction(HqlParser.SubstringFunctionContext ctx) {
- final SqmExpression source = (SqmExpression) ctx.expression().accept( this );
- final SqmExpression start = (SqmExpression) ctx.substringFunctionStartArgument().accept( this );
- final SqmExpression length = ctx.substringFunctionLengthArgument() == null
+ public SqmExpression> visitSubstringFunction(HqlParser.SubstringFunctionContext ctx) {
+ final SqmExpression> source = (SqmExpression>) ctx.expression().accept( this );
+ final SqmExpression> start = (SqmExpression>) ctx.substringFunctionStartArgument().accept( this );
+ final SqmExpression> length = ctx.substringFunctionLengthArgument() == null
? null
- : (SqmExpression) ctx.substringFunctionLengthArgument().accept( this );
+ : (SqmExpression>) ctx.substringFunctionLengthArgument().accept( this );
return getFunctionDescriptor("substring").generateSqmExpression(
length==null ? asList( source, start ) : asList( source, start, length ),
@@ -3188,9 +3283,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitLeftFunction(HqlParser.LeftFunctionContext ctx) {
- final SqmExpression source = (SqmExpression) ctx.expression(0).accept( this );
- final SqmExpression length = (SqmExpression) ctx.expression(1).accept( this );
+ public SqmExpression> visitLeftFunction(HqlParser.LeftFunctionContext ctx) {
+ final SqmExpression> source = (SqmExpression>) ctx.expression(0).accept( this );
+ final SqmExpression> length = (SqmExpression>) ctx.expression(1).accept( this );
return getFunctionDescriptor("left").generateSqmExpression(
asList( source, length ),
@@ -3201,9 +3296,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitRightFunction(HqlParser.RightFunctionContext ctx) {
- final SqmExpression source = (SqmExpression) ctx.expression(0).accept( this );
- final SqmExpression length = (SqmExpression) ctx.expression(1).accept( this );
+ public SqmExpression> visitRightFunction(HqlParser.RightFunctionContext ctx) {
+ final SqmExpression> source = (SqmExpression>) ctx.expression(0).accept( this );
+ final SqmExpression> length = (SqmExpression>) ctx.expression(1).accept( this );
return getFunctionDescriptor("right").generateSqmExpression(
asList( source, length ),
@@ -3215,8 +3310,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
@Override
public SqmExpression visitPadFunction(HqlParser.PadFunctionContext ctx) {
- final SqmExpression source = (SqmExpression) ctx.expression().accept( this );
- SqmExpression length = (SqmExpression) ctx.padLength().accept(this);
+ final SqmExpression> source = (SqmExpression>) ctx.expression().accept( this );
+ SqmExpression> length = (SqmExpression>) ctx.padLength().accept(this);
SqmTrimSpecification padSpec = visitPadSpecification( ctx.padSpecification() );
SqmLiteral padChar = ctx.padCharacter() == null
? null
@@ -3264,8 +3359,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmExpression visitTrimFunction(HqlParser.TrimFunctionContext ctx) {
- final SqmExpression source = (SqmExpression) ctx.expression().accept( this );
+ public SqmExpression> visitTrimFunction(HqlParser.TrimFunctionContext ctx) {
+ final SqmExpression> source = (SqmExpression>) ctx.expression().accept( this );
SqmTrimSpecification trimSpec = visitTrimSpecification( ctx.trimSpecification() );
SqmLiteral trimChar = visitTrimCharacter( ctx.trimCharacter() );
@@ -3327,7 +3422,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmPath visitCollectionIndexFunction(HqlParser.CollectionIndexFunctionContext ctx) {
+ public SqmPath> visitCollectionIndexFunction(HqlParser.CollectionIndexFunctionContext ctx) {
final String alias = ctx.identifier().getText();
final SqmFrom,?> sqmFrom = processingStateStack.getCurrent().getPathRegistry().findFromByAlias( alias );
@@ -3343,14 +3438,14 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
//noinspection unchecked
- return ( (PluralPersistentAttribute) pluralAttribute ).getIndexPathSource().createSqmPath(
+ return ( (PluralPersistentAttribute, ?, ?>) pluralAttribute ).getIndexPathSource().createSqmPath(
sqmFrom,
this
);
}
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
- private boolean isIndexedPluralAttribute(SqmPath path) {
+ private boolean isIndexedPluralAttribute(SqmPath> path) {
return path.getReferencedPathSource() instanceof PluralPersistentAttribute;
}
@@ -3413,12 +3508,12 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
}
@Override
- public SqmSubQuery visitSubQueryExpression(HqlParser.SubQueryExpressionContext ctx) {
+ public SqmSubQuery> visitSubQueryExpression(HqlParser.SubQueryExpressionContext ctx) {
return visitSubQuery( ctx.subQuery() );
}
@Override
- public SqmSubQuery visitSubQuery(HqlParser.SubQueryContext ctx) {
+ public SqmSubQuery> visitSubQuery(HqlParser.SubQueryContext ctx) {
if ( ctx.querySpec().selectClause() == null ) {
throw new SemanticException( "Sub-query cannot use implicit select-clause : " + ctx.getText() );
}
@@ -3438,7 +3533,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre
try {
//noinspection unchecked
- subQuery.setQuerySpec( visitQuerySpec( ctx.querySpec() ) );
+ subQuery.setQuerySpec( (SqmQuerySpec) visitQuerySpec( ctx.querySpec() ) );
return subQuery;
}
finally {
diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java
index 857e792ef3..f7db74ca3f 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java
@@ -6,23 +6,23 @@
*/
package org.hibernate.query.internal;
+import java.util.Arrays;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import org.hibernate.Incubating;
-import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.QueryException;
import org.hibernate.QueryParameterException;
import org.hibernate.cache.spi.QueryKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
-import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.query.QueryParameter;
import org.hibernate.query.spi.ParameterMetadataImplementor;
import org.hibernate.query.spi.QueryParameterBinding;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.query.spi.QueryParameterImplementor;
+import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
/**
* Manages the group of QueryParameterBinding for a particular query.
@@ -179,21 +179,50 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
@Override
public QueryKey.ParameterBindingsMemento generateQueryKeyMemento() {
- // todo (6.0) : need to decide how to handle
- if ( parameterMetadata.getParameterCount() == 0 && CollectionHelper.isEmpty( parameterBindingMap ) ) {
- return new QueryKey.ParameterBindingsMemento() {
- @Override
- public int hashCode() {
- return QueryParameterBindingsImpl.class.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj instanceof QueryKey.ParameterBindingsMemento;
- }
- };
+ final int size = parameterBindingMap.size();
+ final Object[] values = new Object[size];
+ int i = 0;
+ int hashCode = 0;
+ for ( QueryParameterBinding binding : parameterBindingMap.values() ) {
+ JavaTypeDescriptor javaTypeDescriptor = binding.getBindType().getExpressableJavaTypeDescriptor();
+ final Object value = javaTypeDescriptor.getMutabilityPlan().deepCopy( binding.getBindValue() );
+ hashCode = 31 * hashCode + javaTypeDescriptor.extractHashCode( value );
+ values[i] = value;
}
- throw new NotYetImplementedFor6Exception( getClass() );
+ return new ParameterBindingsMementoImpl( values, hashCode);
+ }
+
+ private static class ParameterBindingsMementoImpl implements QueryKey.ParameterBindingsMemento {
+ private final Object[] values;
+ private final int hashCode;
+
+ private ParameterBindingsMementoImpl(Object[] values, int hashCode) {
+ this.values = values;
+ this.hashCode = hashCode;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ ParameterBindingsMementoImpl queryKey = (ParameterBindingsMementoImpl) o;
+
+ if ( hashCode != queryKey.hashCode ) {
+ return false;
+ }
+ // Probably incorrect - comparing Object[] arrays with Arrays.equals
+ return Arrays.equals( values, queryKey.values );
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
}
}
diff --git a/hibernate-core/src/main/java/org/hibernate/query/results/SqlSelectionImpl.java b/hibernate-core/src/main/java/org/hibernate/query/results/SqlSelectionImpl.java
index 6b47d862e1..9e238ff6ce 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/results/SqlSelectionImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/results/SqlSelectionImpl.java
@@ -60,6 +60,11 @@ public class SqlSelectionImpl implements SqlSelection, Expression, SqlExpression
return valuesArrayPosition;
}
+ @Override
+ public Expression getExpression() {
+ return this;
+ }
+
@Override
public MappingModelExpressable getExpressionType() {
return valueMapping;
diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
index 410c7592d7..658b700c71 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/spi/QueryEngine.java
@@ -10,6 +10,7 @@ import org.hibernate.HibernateException;
import org.hibernate.Incubating;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataImplementor;
+import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
@@ -19,6 +20,7 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.query.QueryLogging;
+import org.hibernate.query.criteria.LiteralHandlingMode;
import org.hibernate.query.hql.HqlTranslator;
import org.hibernate.query.hql.internal.StandardHqlTranslator;
import org.hibernate.query.hql.spi.SqmCreationOptions;
@@ -68,6 +70,7 @@ public class QueryEngine {
return new QueryEngine(
() -> sessionFactory.getRuntimeMetamodels().getJpaMetamodel(),
+ sessionFactory.getSessionFactoryOptions().getCriteriaLiteralHandlingMode(),
metadata.buildNamedQueryRepository( sessionFactory ),
hqlTranslator,
sqmTranslatorFactory,
@@ -89,6 +92,7 @@ public class QueryEngine {
public QueryEngine(
Supplier jpaMetamodelAccess,
+ LiteralHandlingMode criteriaLiteralHandlingMode,
NamedObjectRepository namedObjectRepository,
HqlTranslator hqlTranslator,
SqmTranslatorFactory sqmTranslatorFactory,
@@ -106,7 +110,8 @@ public class QueryEngine {
this.criteriaBuilder = new SqmCriteriaNodeBuilder(
this,
jpaMetamodelAccess,
- serviceRegistry
+ serviceRegistry,
+ criteriaLiteralHandlingMode
);
this.sqmFunctionRegistry = new SqmFunctionRegistry();
@@ -132,6 +137,7 @@ public class QueryEngine {
*/
public QueryEngine(
JpaMetamodel jpaMetamodel,
+ LiteralHandlingMode criteriaLiteralHandlingMode,
boolean useStrictJpaCompliance,
NamedObjectRepository namedObjectRepository,
NativeQueryInterpreter nativeQueryInterpreter,
@@ -147,7 +153,8 @@ public class QueryEngine {
this.criteriaBuilder = new SqmCriteriaNodeBuilder(
this,
() -> jpaMetamodel,
- serviceRegistry
+ serviceRegistry,
+ criteriaLiteralHandlingMode
);
final SqmCreationContext sqmCreationContext = new SqmCreationContext() {
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java
index cc5f13fac3..600b1373a8 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java
@@ -6,6 +6,8 @@
*/
package org.hibernate.query.sqm;
+import java.util.List;
+
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.query.sqm.tree.cte.SqmCteConsumer;
import org.hibernate.query.sqm.tree.cte.SqmCteStatement;
@@ -30,6 +32,7 @@ import org.hibernate.query.sqm.tree.expression.SqmCaseSearched;
import org.hibernate.query.sqm.tree.expression.SqmCaseSimple;
import org.hibernate.query.sqm.tree.expression.SqmCastTarget;
import org.hibernate.query.sqm.tree.expression.SqmCoalesce;
+import org.hibernate.query.sqm.tree.expression.SqmCollate;
import org.hibernate.query.sqm.tree.expression.SqmCollectionSize;
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
import org.hibernate.query.sqm.tree.expression.SqmDurationUnit;
@@ -75,10 +78,9 @@ import org.hibernate.query.sqm.tree.predicate.SqmMemberOfPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmNegatedPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmOrPredicate;
+import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.query.sqm.tree.predicate.SqmWhereClause;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation;
-import org.hibernate.query.sqm.tree.select.SqmGroupByClause;
-import org.hibernate.query.sqm.tree.select.SqmHavingClause;
import org.hibernate.query.sqm.tree.select.SqmJpaCompoundSelection;
import org.hibernate.query.sqm.tree.select.SqmOrderByClause;
import org.hibernate.query.sqm.tree.select.SqmQuerySpec;
@@ -165,11 +167,9 @@ public interface SemanticQueryWalker {
T visitValues(SqmValues values);
- T visitGroupByClause(SqmGroupByClause clause);
+ T visitGroupByClause(List> groupByClauseExpressions);
- T visitGrouping(SqmGroupByClause.SqmGrouping grouping);
-
- T visitHavingClause(SqmHavingClause clause);
+ T visitHavingClause(SqmPredicate clause);
T visitDynamicInstantiation(SqmDynamicInstantiation> sqmDynamicInstantiation);
@@ -189,6 +189,8 @@ public interface SemanticQueryWalker {
T visitTuple(SqmTuple> sqmTuple);
+ T visitCollate(SqmCollate> sqmCollate);
+
T visitBinaryArithmeticExpression(SqmBinaryArithmetic> expression);
T visitSubQueryExpression(SqmSubQuery> expression);
@@ -200,6 +202,7 @@ public interface SemanticQueryWalker {
T visitSearchedCaseExpression(SqmCaseSearched> expression);
T visitAny(SqmAny> sqmAny);
+
T visitEvery(SqmEvery> sqmEvery);
T visitPositionalParameterExpression(SqmPositionalParameter> expression);
diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java
index 5b72d48610..8cb191654b 100644
--- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java
+++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java
@@ -52,6 +52,8 @@ import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy;
import org.hibernate.query.sqm.tree.SqmDmlStatement;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
+import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
+import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.from.SqmRoot;
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
@@ -230,6 +232,17 @@ public class QuerySqmImpl
}
this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
+ // Parameters might be created through HibernateCriteriaBuilder.value which we need to bind here
+ for ( SqmParameter> sqmParameter : this.domainParameterXref.getParameterResolutions().getSqmParameters() ) {
+ if ( sqmParameter instanceof SqmJpaCriteriaParameterWrapper> ) {
+ final JpaCriteriaParameter