Skip to content

Commit

Permalink
Rebase main -> 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed May 28, 2024
1 parent 1b90599 commit a7b4fe4
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TypeDetails getClassOrElementType() throws MappingException {
}

@Override
public XClass getClassOrPluralElement() throws MappingException {
public ClassDetails getClassOrPluralElement() throws MappingException {
return wrappedInferredData.getClassOrPluralElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected Object performSave(
processIfManagedEntity( entity, (managedEntity) -> managedEntity.$$_hibernate_setUseTracker( true ) );

final Generator generator = persister.getGenerator();
if ( generator instanceof Assigned || generator instanceof CompositeNestedGeneratedValueGenerator ) {
if ( !generator.generatesOnInsert() || generator instanceof CompositeNestedGeneratedValueGenerator ) {
id = persister.getIdentifier( entity, source );
if ( id == null ) {
throw new IdentifierGenerationException( "Identifier of entity '" + persister.getEntityName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hibernate.Internal;
import org.hibernate.MappingException;
import org.hibernate.Remove;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.QualifiedName;
Expand All @@ -34,6 +33,8 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.Generator;
import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerationException;
Expand All @@ -43,8 +44,6 @@
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.property.access.spi.Setter;
import org.hibernate.generator.Generator;
import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.type.ComponentType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.sqm;

import org.hibernate.HibernateException;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Indicates a problem with a TREAT usage
*
* @author Steve Ebersole
*/
public class TreatException extends HibernateException {
public TreatException(String message) {
super( message );
}

public TreatException(String message, @Nullable Throwable cause) {
super( message, cause );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.query.sqm.tree.domain;

import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.sqm.TreatException;
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.PathException;
Expand Down Expand Up @@ -59,33 +60,33 @@ public <X> X accept(SemanticQueryWalker<X> walker) {
}

@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(Class<S> treatJavaType) throws PathException {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
public <S extends T> SqmTreatedEntityValuedSimplePath<T, S> treatAs(Class<S> treatJavaType) throws PathException {
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(EntityDomainType<S> treatTarget) throws PathException {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(Class<S> treatJavaType, String alias) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedSimplePath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType, String alias, boolean fetch) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetch) {
throw new FunctionArgumentException( "Non-aggregate composite paths cannot be TREAT-ed" );
throw new TreatException( "Non-aggregate composite paths cannot be TREAT-ed" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.TreatException;
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.spi.NavigablePath;
Expand Down Expand Up @@ -104,7 +105,7 @@ public <S extends T> SqmTreatedPath<T, S> treatAs(Class<S> treatJavaType) throws

@Override
public <S extends T> SqmTreatedPath<T, S> treatAs(EntityDomainType<S> treatTarget) throws PathException {
throw new FunctionArgumentException( "Embeddable paths cannot be TREAT-ed to an entity type" );
throw new TreatException( "Embeddable paths cannot be TREAT-ed to an entity type" );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.TreatException;
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.spi.NavigablePath;
Expand Down Expand Up @@ -84,12 +85,12 @@ public SqmFkExpression<T> copy(SqmCopyContext context) {

@Override
public <S extends T> SqmTreatedPath<T,S> treatAs(Class<S> treatJavaType) {
throw new FunctionArgumentException( "Fk paths cannot be TREAT-ed" );
throw new TreatException( "Fk paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget) {
throw new FunctionArgumentException( "Fk paths cannot be TREAT-ed" );
throw new TreatException( "Fk paths cannot be TREAT-ed" );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.TreatException;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.produce.function.FunctionArgumentException;
import org.hibernate.query.sqm.tree.SqmCopyContext;
Expand Down Expand Up @@ -155,11 +156,11 @@ public void appendHqlString(StringBuilder sb) {

@Override
public <S extends T> SqmTreatedPath<T,S> treatAs(Class<S> treatJavaType) {
throw new FunctionArgumentException( "Embeddable paths cannot be TREAT-ed" );
throw new TreatException( "Embeddable paths cannot be TREAT-ed" );
}

@Override
public <S extends T> SqmTreatedPath<T,S> treatAs(EntityDomainType<S> treatTarget) {
throw new FunctionArgumentException( "Embeddable paths cannot be TREAT-ed" );
throw new TreatException( "Embeddable paths cannot be TREAT-ed" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,6 @@ public <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(EntityDomainType<S> t
return treat;
}

@Override
public <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(Class<S> treatJavaType, String alias, boolean fetched) {
return treatAs( nodeBuilder().getDomainModel().entity( treatJavaType ), alias, fetched );
}

@Override
public <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(EntityDomainType<S> treatTarget, String alias, boolean fetched) {
final SqmTreatedMapJoin<L, K, V, S> treat = findTreat( treatTarget, alias );
if ( treat == null ) {
return addTreat( new SqmTreatedMapJoin<>( this, treatTarget, alias ) );
}
return treat;
}

@Override
public SqmMapJoin<L, K, V> makeCopy(SqmCreationProcessingState creationProcessingState) {
return new SqmMapJoin<>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* 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.sqm.tree.domain;

import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.PathException;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.spi.NavigablePath;

/**
* @author Steve Ebersole
*/
public class SqmTreatedSimplePath<T, S extends T>
extends SqmEntityValuedSimplePath<S>
implements SqmSimplePath<S>, SqmTreatedPath<T,S> {

private final EntityDomainType<S> treatTarget;
private final SqmPath<T> wrappedPath;

public SqmTreatedSimplePath(
SqmPluralValuedSimplePath<T> wrappedPath,
EntityDomainType<S> treatTarget,
NodeBuilder nodeBuilder) {
//noinspection unchecked
super(
wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName()
),
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getLhs(),
nodeBuilder
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}

public SqmTreatedSimplePath(
SqmPath<T> wrappedPath,
EntityDomainType<S> treatTarget,
NodeBuilder nodeBuilder) {
//noinspection unchecked
super(
wrappedPath.getNavigablePath().treatAs(
treatTarget.getHibernateEntityName()
),
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getLhs(),
nodeBuilder
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}

private SqmTreatedSimplePath(
NavigablePath navigablePath,
SqmPath<T> wrappedPath,
EntityDomainType<S> treatTarget,
NodeBuilder nodeBuilder) {
//noinspection unchecked
super(
navigablePath,
(SqmPathSource<S>) wrappedPath.getReferencedPathSource(),
wrappedPath.getLhs(),
nodeBuilder
);
this.treatTarget = treatTarget;
this.wrappedPath = wrappedPath;
}

@Override
public SqmTreatedSimplePath<T, S> copy(SqmCopyContext context) {
final SqmTreatedSimplePath<T, S> existing = context.getCopy( this );
if ( existing != null ) {
return existing;
}

final SqmTreatedSimplePath<T, S> path = context.registerCopy(
this,
new SqmTreatedSimplePath<>(
getNavigablePath(),
wrappedPath.copy( context ),
getTreatTarget(),
nodeBuilder()
)
);
copyTo( path, context );
return path;
}

@Override
public EntityDomainType<S> getTreatTarget() {
return treatTarget;
}

@Override
public SqmPath<T> getWrappedPath() {
return wrappedPath;
}

@Override
public EntityDomainType<S> getNodeType() {
return treatTarget;
}

@Override
public SqmPathSource<S> getReferencedPathSource() {
return treatTarget;
}

@Override
public SqmPathSource<?> getResolvedModel() {
return treatTarget;
}

@Override
public <S1 extends S> SqmTreatedEntityValuedSimplePath<S,S1> treatAs(Class<S1> treatJavaType) throws PathException {
return super.treatAs( treatJavaType );
}

@Override
@SuppressWarnings("unchecked")
public SqmPath<?> get(String attributeName) {
return resolvePath( attributeName, treatTarget.getSubPathSource( attributeName ) );
}

@Override
public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitTreatedPath( this );
}

@Override
public void appendHqlString(StringBuilder sb) {
sb.append( "treat(" );
wrappedPath.appendHqlString( sb );
sb.append( " as " );
sb.append( treatTarget.getName() );
sb.append( ')' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void testJdbcPreparedStatementEventNoFired(SessionFactoryScope scope) {
@EnableEvent(JdbcPreparedStatementCreationEvent.NAME)
@EnableEvent(JdbcPreparedStatementExecutionEvent.NAME)
public void testJdbcPreparedStatementEventStoredProcedure(SessionFactoryScope scope) {
jfrEvents.reset();
scope.inTransaction(
session -> {
ProcedureCall call = session.createStoredProcedureCall("DB_OBJECT_SQL", String.class)
Expand Down Expand Up @@ -120,14 +121,12 @@ public void testJdbcPreparedStatementEventStoredProcedure(SessionFactoryScope sc
RecordedEvent preparedStatementCreationEvent = events.get( 0 );
assertThat( preparedStatementCreationEvent.getEventType().getName() )
.isEqualTo( JdbcPreparedStatementCreationEvent.NAME );
assertThat( preparedStatementCreationEvent.getLong( "executionTime" ) ).isGreaterThan( 0 );
assertThat( preparedStatementCreationEvent.getString( "sql" ).toLowerCase( Locale.ROOT ) )
.contains( "{call " );

RecordedEvent preparedStatementExecutionEvent = events.get( 1 );
assertThat( preparedStatementExecutionEvent.getEventType().getName() )
.isEqualTo( JdbcPreparedStatementExecutionEvent.NAME );
assertThat( preparedStatementExecutionEvent.getLong( "executionTime" ) ).isGreaterThan( 0 );
assertThat( preparedStatementExecutionEvent.getString( "sql" ) )
.isEqualTo( preparedStatementCreationEvent.getString( "sql" ) );
}
Expand Down

0 comments on commit a7b4fe4

Please sign in to comment.