-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
195 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...te-core/src/test/java/org/hibernate/orm/test/mapping/formula/SchemaSubstitutionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.mapping.formula; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import org.hibernate.annotations.Formula; | ||
import org.hibernate.cfg.MappingSettings; | ||
import org.hibernate.dialect.H2Dialect; | ||
import org.hibernate.engine.spi.SessionFactoryImplementor; | ||
import org.hibernate.metamodel.mapping.AttributeMapping; | ||
import org.hibernate.metamodel.mapping.SelectableMapping; | ||
import org.hibernate.persister.entity.EntityPersister; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.DomainModelScope; | ||
import org.hibernate.testing.orm.junit.Jira; | ||
import org.hibernate.testing.orm.junit.RequiresDialect; | ||
import org.hibernate.testing.orm.junit.ServiceRegistry; | ||
import org.hibernate.testing.orm.junit.Setting; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@Jira( "https://hibernate.atlassian.net/browse/HHH-12227" ) | ||
@RequiresDialect( value = H2Dialect.class, comment = "Not dialect specific" ) | ||
@SuppressWarnings("JUnitMalformedDeclaration") | ||
public class SchemaSubstitutionTests { | ||
@Test | ||
@ServiceRegistry( settings = @Setting( name = MappingSettings.DEFAULT_SCHEMA, value = "my_schema" ) ) | ||
@DomainModel( annotatedClasses = Thing.class ) | ||
void testWithSchema(DomainModelScope modelScope) { | ||
try (SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) modelScope.getDomainModel().buildSessionFactory()) { | ||
final EntityPersister persister = sessionFactory.getMappingMetamodel().getEntityDescriptor( Thing.class ); | ||
final AttributeMapping attributeMapping = persister.findAttributeMapping( "externalName" ); | ||
verifyFormula( attributeMapping, true ); | ||
} | ||
} | ||
|
||
@Test | ||
@ServiceRegistry | ||
@DomainModel( annotatedClasses = Thing.class ) | ||
void testWithoutSchema(DomainModelScope modelScope) { | ||
try (SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) modelScope.getDomainModel().buildSessionFactory()) { | ||
final EntityPersister persister = sessionFactory.getMappingMetamodel().getEntityDescriptor( Thing.class ); | ||
final AttributeMapping attributeMapping = persister.findAttributeMapping( "externalName" ); | ||
verifyFormula( attributeMapping, false ); | ||
} | ||
} | ||
|
||
private void verifyFormula(AttributeMapping attributeMapping, boolean expectSchema) { | ||
final SelectableMapping selectable = attributeMapping.getSelectable( 0 ); | ||
assertThat( selectable.isFormula() ).isTrue(); | ||
assertThat( selectable.getSelectionExpression() ).doesNotContain( "{h-schema}" ); | ||
assertThat( selectable.getSelectionExpression().contains( "my_schema" ) ).isEqualTo( expectSchema ); | ||
} | ||
|
||
@Entity(name="Thing") | ||
@Table(name="things") | ||
public static class Thing { | ||
@Id | ||
private Integer id; | ||
private String name; | ||
@Formula( "select name from {h-schema}externals" ) | ||
private String externalName; | ||
} | ||
} |
137 changes: 0 additions & 137 deletions
137
...t/java/org/hibernate/orm/test/persister/entity/AbstractSchemaSubstitutionFormulaTest.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
...a/org/hibernate/orm/test/persister/entity/FormulaTemplateEmptySchemaSubstitutionTest.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...t/java/org/hibernate/orm/test/persister/entity/FormulaTemplateSchemaSubstitutionTest.java
This file was deleted.
Oops, something went wrong.