From f9fa2e6e5332ee6b57f16275dd9d9f47c1efc31a Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 18 Dec 2021 12:37:28 -0600 Subject: [PATCH] 6.0 Final tasks - general test_legacy dir clean-up At this point, everything left in test_legacy is something I think we want to account for in the test suite (move it, etc) --- ...ctDefaultMultiTableBulkIdStrategyTest.java | 28 - .../dialect/Oracle8iDialectTestCase.java | 39 - .../hibernate/id/hhh14407/ChildEntity.java | 23 - .../hibernate/id/hhh14407/ParentEntity.java | 34 - .../PersistentTableBulkIdStrategyNPETest.java | 58 - .../org/hibernate/sql/TemplateTest.java | 253 --- .../hibernate/test/ast/ASTIteratorTest.java | 111 -- .../org/hibernate/test/ast/ASTUtilTest.java | 68 - .../test/cid/CompositeIdCountEntityTest.java | 120 -- .../AggressiveReleaseQueryIterationTest.java | 99 - .../hibernate/test/criteria/AbstractFoo.java | 22 - .../org/hibernate/test/criteria/Address.java | 28 - .../hibernate/test/criteria/Animal.hbm.xml | 23 - .../org/hibernate/test/criteria/Bar.java | 30 - .../org/hibernate/test/criteria/Bid.java | 25 - .../hibernate/test/criteria/CityState.java | 41 - .../org/hibernate/test/criteria/Code.java | 14 - .../org/hibernate/test/criteria/Country.java | 38 - .../org/hibernate/test/criteria/Course.java | 46 - .../test/criteria/CourseMeeting.java | 36 - .../test/criteria/CourseMeetingId.java | 52 - .../hibernate/test/criteria/Enrolment.hbm.xml | 99 - .../hibernate/test/criteria/Enrolment.java | 69 - .../org/hibernate/test/criteria/Foo.hbm.xml | 28 - .../org/hibernate/test/criteria/GreatFoo.java | 12 - .../org/hibernate/test/criteria/Item.java | 25 - .../test/criteria/ListActionRole.java | 40 - .../org/hibernate/test/criteria/Man.java | 13 - .../org/hibernate/test/criteria/Order.hbm.xml | 59 - .../org/hibernate/test/criteria/Order.java | 56 - .../hibernate/test/criteria/OrderAddress.java | 43 - .../hibernate/test/criteria/OrderContact.java | 39 - .../hibernate/test/criteria/OrderLine.java | 41 - .../hibernate/test/criteria/Person.hbm.xml | 26 - .../org/hibernate/test/criteria/Person.java | 76 - .../org/hibernate/test/criteria/Role.java | 24 - .../test/criteria/StringExpression.java | 23 - .../org/hibernate/test/criteria/Student.java | 82 - .../test/criteria/StudentAddress.java | 96 - .../hibernate/test/criteria/StudentDTO.java | 34 - .../hibernate/test/criteria/StudyAbroad.java | 37 - .../test/criteria/TestObject.hbm.xml | 19 - .../hibernate/test/criteria/TestObject.java | 29 - .../test/criteria/VersionedRecord.java | 18 - .../org/hibernate/test/criteria/Woman.java | 13 - .../test/hql/ClassicTranslatorTest.java | 65 - .../CollectionPropertyDeprecationsTest.java | 201 -- .../org/hibernate/test/hql/EJBQLTest.java | 297 --- .../org/hibernate/test/hql/HQLTest.java | 1642 ----------------- .../HibernateFirstResultMaxResultsTest.java | 143 -- .../org/hibernate/test/hql/HqlParserTest.java | 1119 ----------- .../hibernate/test/hql/QuerySplitterTest.java | 127 -- .../test/hql/QueryTranslatorTestCase.java | 289 --- .../hibernate/test/iterate/IterateTest.java | 76 - .../tck2_2/OrderByAnnotationTests.java | 113 -- ...positeAttributeResultSetProcessorTest.java | 347 ---- ...atedCompositeIdResultSetProcessorTest.java | 407 ---- ...tityAssociationResultSetProcessorTest.java | 261 --- ...nLazyCollectionResultSetProcessorTest.java | 137 -- ...zyOneToManyListResultSetProcessorTest.java | 170 -- ...azyOneToManySetResultSetProcessorTest.java | 188 -- .../test/loadplans/process/Helper.java | 82 - ...atedCompositeIdResultSetProcessorTest.java | 185 -- .../process/SimpleResultSetProcessorTest.java | 126 -- .../process/inheritance/Contractor.java | 33 - .../process/inheritance/Department.java | 26 - .../process/inheritance/Employee.java | 30 - .../loadplans/process/inheritance/Test.java | 45 - .../loadplans/process/inheritance/User.java | 31 - .../loadplans/walking/BasicWalkingTest.java | 55 - .../walking/CompositesWalkingTest.java | 38 - .../walking/KeyManyToOneWalkingTest.java | 32 - .../LoggingAssociationVisitationStrategy.java | 228 --- .../walking/NestedCompositeElementTest.java | 31 - .../org/hibernate/test/locale/IAmAFoo.java | 41 - .../org/hibernate/test/locale/LocaleTest.java | 82 - .../test/queryplan/GetHqlQueryPlanTest.java | 137 -- .../NativeSQLQueryPlanEqualsTest.java | 52 - ...ativeQueryDoesNotSupportIterationTest.java | 46 - .../NamedNativeQueryMementoBuilderTest.java | 56 - ...redProcedureParameterRegistrationTest.java | 242 --- 81 files changed, 9369 deletions(-) delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/dialect/DerbyDialectDefaultMultiTableBulkIdStrategyTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/dialect/Oracle8iDialectTestCase.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ChildEntity.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ParentEntity.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/PersistentTableBulkIdStrategyNPETest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/sql/TemplateTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTIteratorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTUtilTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/cid/CompositeIdCountEntityTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/connections/AggressiveReleaseQueryIterationTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/AbstractFoo.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Address.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Animal.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bar.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bid.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/CityState.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Code.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Country.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Course.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeeting.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeetingId.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Foo.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/GreatFoo.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Item.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/ListActionRole.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Man.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderAddress.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderContact.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderLine.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Role.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/StringExpression.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Student.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentAddress.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentDTO.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudyAbroad.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.hbm.xml delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/VersionedRecord.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/criteria/Woman.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/ClassicTranslatorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/CollectionPropertyDeprecationsTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/EJBQLTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/HQLTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/HibernateFirstResultMaxResultsTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/HqlParserTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/QuerySplitterTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/hql/QueryTranslatorTestCase.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/iterate/IterateTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeAttributeResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeIdResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityAssociationResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyCollectionResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManyListResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManySetResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/Helper.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/SimpleResultSetProcessorTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Contractor.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Department.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Employee.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Test.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/User.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/BasicWalkingTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/CompositesWalkingTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/NestedCompositeElementTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/locale/IAmAFoo.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/locale/LocaleTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/queryplan/GetHqlQueryPlanTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/sql/hand/query/NamedNativeQueryMementoBuilderTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/sql/storedproc/StoredProcedureParameterRegistrationTest.java diff --git a/hibernate-core/src/test_legacy/org/hibernate/dialect/DerbyDialectDefaultMultiTableBulkIdStrategyTest.java b/hibernate-core/src/test_legacy/org/hibernate/dialect/DerbyDialectDefaultMultiTableBulkIdStrategyTest.java deleted file mode 100644 index a6774e26cf..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/dialect/DerbyDialectDefaultMultiTableBulkIdStrategyTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.dialect; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -/** - * @author Andrea Boriero - */ -public class DerbyDialectDefaultMultiTableBulkIdStrategyTest extends BaseUnitTestCase { - @Test - @TestForIssue(jiraKey = "HHH-10238") - public void testDefaultMultiTableBulkIdStrategyIsLocal() { - MultiTableBulkIdStrategy actual = new DerbyDialectTestCase.LocalDerbyDialect().getFallbackSqmMutationStrategy( - runtimeRootEntityDescriptor ); - assertThat(actual, is(instanceOf(LocalTemporaryTableBulkIdStrategy.class))); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/dialect/Oracle8iDialectTestCase.java b/hibernate-core/src/test_legacy/org/hibernate/dialect/Oracle8iDialectTestCase.java deleted file mode 100644 index 5acd0cec75..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/dialect/Oracle8iDialectTestCase.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.dialect; - -import org.junit.Test; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; - -public class Oracle8iDialectTestCase extends BaseUnitTestCase { - - @Test - @TestForIssue(jiraKey = "HHH-9290") - public void testTemporaryTableNameTruncation() throws Exception { - final AbstractMultiTableBulkIdStrategyImpl strategy = (AbstractMultiTableBulkIdStrategyImpl) new Oracle8iDialect().getFallbackSqmMutationStrategy( - runtimeRootEntityDescriptor ); - - String temporaryTableName = strategy.getIdTableSupport().generateIdTableName( - "TABLE_NAME_THAT_EXCEEDS_30_CHARACTERS" - ); - - assertEquals( - "Temporary table names should be truncated to 30 characters", - 30, - temporaryTableName.length() - ); - assertEquals( - "Temporary table names should start with HT_", - "HT_TABLE_NAME_THAT_EXCEEDS_30_", - temporaryTableName - ); - } -} \ No newline at end of file diff --git a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ChildEntity.java b/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ChildEntity.java deleted file mode 100644 index 5bcd13ea43..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ChildEntity.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.id.hhh14407; - -import jakarta.persistence.Basic; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; - -/** - * @author Sönke Reimer - */ -@Entity(name="ChildEntity") -class ChildEntity extends ParentEntity { - - @Basic - @Column(name="CHILD") - private String ivChild; - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ParentEntity.java b/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ParentEntity.java deleted file mode 100644 index fb67803a06..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/ParentEntity.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.id.hhh14407; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Version; - -/** - * @author Sönke Reimer - */ -@Entity(name="ParentEntity") -@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) -class ParentEntity { - - @Id - @Column(name = "ID", length = 32) - private String Id; - - @Version - @Column(name = "LOCK_VERSION") - private int Lock_Version; - public String getId() { - return Id; - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/PersistentTableBulkIdStrategyNPETest.java b/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/PersistentTableBulkIdStrategyNPETest.java deleted file mode 100644 index 85a2a64095..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/id/hhh14407/PersistentTableBulkIdStrategyNPETest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.id.hhh14407; - -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; -import org.hibernate.hql.spi.id.persistent.PersistentTableBulkIdStrategy; - -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -/** - * @author Nathan Xu - * @author Sönke Reimer - */ -@RequiresDialect( value = H2Dialect.class ) -@TestForIssue( jiraKey = "HHH14407" ) -public class PersistentTableBulkIdStrategyNPETest extends BaseCoreFunctionalTestCase { - - @Override - protected void configure(Configuration configuration) { - configuration.setProperty( - Environment.DIALECT, - PersistentTableBulkIdH2Dialect.class.getName() - ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - ParentEntity.class, - ChildEntity.class - }; - } - - @Test - public void hhh14407Test() { - // without fix of HHH14407, the test case will trigger exception due to NPE in PersistentTableBulkIdStrategy - } - - public static class PersistentTableBulkIdH2Dialect extends H2Dialect { - - @Override - public MultiTableBulkIdStrategy getDefaultMultiTableBulkIdStrategy() { - return new PersistentTableBulkIdStrategy(); - } - - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/sql/TemplateTest.java b/hibernate-core/src/test_legacy/org/hibernate/sql/TemplateTest.java deleted file mode 100644 index ae634bb336..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/sql/TemplateTest.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.sql; - -import java.util.Collections; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import org.hibernate.QueryException; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.HSQLDialect; -import org.hibernate.dialect.function.SQLFunctionRegistry; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.persister.entity.PropertyMapping; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.testing.ServiceRegistryBuilder; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.type.Type; - -import static org.junit.Assert.assertEquals; - -/** - * @author Steve Ebersole - */ -public class TemplateTest extends BaseUnitTestCase { - private static final PropertyMapping PROPERTY_MAPPING = new PropertyMapping() { - public String[] toColumns(String propertyName) throws QueryException, UnsupportedOperationException { - if ( "sql".equals( propertyName ) ) { - return new String[] { "sql" }; - } - else if ( "component".equals( propertyName ) ) { - return new String[] { "comp_1", "comp_2" }; - } - else if ( "component.prop1".equals( propertyName ) ) { - return new String[] { "comp_1" }; - } - else if ( "component.prop2".equals( propertyName ) ) { - return new String[] { "comp_2" }; - } - else if ( "property".equals( propertyName ) ) { - return new String[] { "prop" }; - } - throw new QueryException( "could not resolve property: " + propertyName ); - } - - public Type toType(String propertyName) throws QueryException { - return null; - } - - public String[] toColumns(String alias, String propertyName) throws QueryException { - return new String[0]; - } - - public Type getType() { - return null; - } - }; - - private static final ColumnMapper MAPPER = new ColumnMapper() { - public SqlValueReference[] map(String reference) { - final String[] columnNames = PROPERTY_MAPPING.toColumns( reference ); - final SqlValueReference[] result = new SqlValueReference[ columnNames.length ]; - int i = 0; - for ( final String columnName : columnNames ) { - result[i] = new ColumnReference() { - @Override - public String getColumnName() { - return columnName; - } - }; - i++; - } - return result; - } - }; - - private static final Dialect DIALECT = new HSQLDialect(); - - private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP ); - - private static SessionFactoryImplementor SESSION_FACTORY = null; // Required for ORDER BY rendering. - - @BeforeClass - public static void buildSessionFactory() { - Configuration cfg = new Configuration(); - cfg.setProperty( AvailableSettings.DIALECT, DIALECT.getClass().getName() ); - ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() ); - SESSION_FACTORY = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - } - - @AfterClass - public static void closeSessionFactory() { - if ( SESSION_FACTORY != null ) { - SESSION_FACTORY.close(); - SESSION_FACTORY = null; - } - } - - @Test - public void testSqlExtractFunction() { - String fragment = "extract( year from col )"; - String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - - assertEquals( "extract(year from " + Template.TEMPLATE + ".col)", template ); - } - - @Test - public void testSqlTrimFunction() { - String fragment = "trim( col )"; - String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(" + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(from " + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( both from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(both from " + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( leading from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(leading from " + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( TRAILING from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(TRAILING from " + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( 'b' from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim('b' from " + Template.TEMPLATE + ".col)", template ); - - fragment = "trim( both 'b' from col )"; - template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY ); - assertEquals( "trim(both 'b' from " + Template.TEMPLATE + ".col)", template ); - } - - @Test - public void testSQLReferences() { - String fragment = "sql asc, sql desc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".sql asc, " + Template.TEMPLATE + ".sql desc", template ); - } - - @Test - public void testQuotedSQLReferences() { - String fragment = "`sql` asc, `sql` desc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".\"sql\" asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); - } - - @Test - public void testPropertyReference() { - String fragment = "property asc, property desc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".prop asc, " + Template.TEMPLATE + ".prop desc", template ); - } - - @Test - public void testFunctionReference() { - String fragment = "upper(sql) asc, lower(sql) desc"; - String template = doStandardRendering( fragment ); - - assertEquals( "upper(" + Template.TEMPLATE + ".sql) asc, lower(" + Template.TEMPLATE + ".sql) desc", template ); - } - - @Test - public void testQualifiedFunctionReference() { - String fragment = "qual.upper(property) asc, qual.lower(property) desc"; - String template = doStandardRendering( fragment ); - - assertEquals( "qual.upper(" + Template.TEMPLATE + ".prop) asc, qual.lower(" + Template.TEMPLATE + ".prop) desc", template ); - } - - @Test - public void testDoubleQualifiedFunctionReference() { - String fragment = "qual1.qual2.upper(property) asc, qual1.qual2.lower(property) desc"; - String template = doStandardRendering( fragment ); - - assertEquals( "qual1.qual2.upper(" + Template.TEMPLATE + ".prop) asc, qual1.qual2.lower(" + Template.TEMPLATE + ".prop) desc", template ); - } - - @Test - public void testFunctionWithPropertyReferenceAsParam() { - String fragment = "upper(property) asc, lower(property) desc"; - String template = doStandardRendering( fragment ); - - assertEquals( "upper(" + Template.TEMPLATE + ".prop) asc, lower(" + Template.TEMPLATE + ".prop) desc", template ); - } - - @Test - public void testNestedFunctionReferences() { - String fragment = "upper(lower(sql)) asc, lower(upper(sql)) desc"; - String template = doStandardRendering( fragment ); - - assertEquals( "upper(lower(" + Template.TEMPLATE + ".sql)) asc, lower(upper(" + Template.TEMPLATE + ".sql)) desc", template ); - } - - @Test - public void testComplexNestedFunctionReferences() { - String fragment = "mod(mod(sql,2),3) asc"; - String template = doStandardRendering( fragment ); - - assertEquals( "mod(mod(" + Template.TEMPLATE + ".sql, 2), 3) asc", template ); - } - - @Test - public void testCollation() { - String fragment = "`sql` COLLATE my_collation, `sql` COLLATE your_collation"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".\"sql\" collate my_collation, " + Template.TEMPLATE + ".\"sql\" collate your_collation", template ); - } - - @Test - public void testCollationAndOrdering() { - String fragment = "sql COLLATE my_collation, upper(prop) COLLATE your_collation asc, `sql` desc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".sql collate my_collation, upper(" + Template.TEMPLATE + ".prop) collate your_collation asc, " + Template.TEMPLATE + ".\"sql\" desc", template ); - } - - @Test - public void testComponentReferences() { - String fragment = "component asc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".comp_1 asc, " + Template.TEMPLATE + ".comp_2 asc", template ); - } - - @Test - public void testComponentDerefReferences() { - String fragment = "component.prop1 asc"; - String template = doStandardRendering( fragment ); - - assertEquals( Template.TEMPLATE + ".comp_1 asc", template ); - } - - public String doStandardRendering(String fragment) { - return Template.renderOrderByStringTemplate( fragment, MAPPER, SESSION_FACTORY, DIALECT, FUNCTION_REGISTRY ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTIteratorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTIteratorTest.java deleted file mode 100644 index 1c278d718c..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTIteratorTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.ast; - -import java.io.PrintWriter; - -import antlr.ASTFactory; -import antlr.collections.AST; -import org.junit.Test; - -import org.hibernate.hql.internal.antlr.HqlTokenTypes; -import org.hibernate.hql.internal.ast.HqlParser; -import org.hibernate.hql.internal.ast.util.ASTIterator; -import org.hibernate.hql.internal.ast.util.ASTParentsFirstIterator; -import org.hibernate.hql.internal.ast.util.ASTPrinter; -import org.hibernate.hql.internal.ast.util.ASTUtil; -import org.hibernate.hql.internal.ast.util.TokenPrinters; - -import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Test ASTIterator. - */ -public class ASTIteratorTest extends BaseUnitTestCase { - private ASTFactory factory = new ASTFactory(); - - @Test - public void testSimpleTree() throws Exception { - String input = "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id"; - HqlParser parser = HqlParser.getInstance( input ); - parser.statement(); - AST ast = parser.getAST(); - ASTPrinter printer = TokenPrinters.HQL_TOKEN_PRINTER; - printer.showAst( ast, new PrintWriter( System.out ) ); - ASTIterator iterator = new ASTIterator( ast ); - int count = 0; - while ( iterator.hasNext() ) { - assertTrue( iterator.next() instanceof AST ); - count++; - } - assertEquals( 43, count ); - - UnsupportedOperationException uoe = null; - try { - iterator.remove(); - } - catch ( UnsupportedOperationException e ) { - uoe = e; - } - assertNotNull( uoe ); - } - - @Test - public void testParentsFirstIterator() throws Exception { - AST[] tree = new AST[4]; - AST grandparent = tree[0] = ASTUtil.create( factory, 1, "grandparent" ); - AST parent = tree[1] = ASTUtil.create( factory, 2, "parent" ); - AST child = tree[2] = ASTUtil.create( factory, 3, "child" ); - AST baby = tree[3] = ASTUtil.create( factory, 4, "baby" ); - AST t = ASTUtil.createTree( factory, tree ); - AST brother = ASTUtil.create( factory, 10, "brother" ); - child.setNextSibling( brother ); - AST sister = ASTUtil.create( factory, 11, "sister" ); - brother.setNextSibling( sister ); - AST uncle = factory.make( new AST[]{ - factory.create( 20, "uncle" ), - factory.create( 21, "cousin1" ), - factory.create( 22, "cousin2" ), - factory.create( 23, "cousin3" )} ); - parent.setNextSibling( uncle ); - System.out.println( t.toStringTree() ); - - System.out.println( "--- ASTParentsFirstIterator ---" ); - ASTParentsFirstIterator iter = new ASTParentsFirstIterator( t ); - int count = 0; - while ( iter.hasNext() ) { - AST n = iter.nextNode(); - count++; - System.out.println( n ); - } - assertEquals( 10, count ); - - System.out.println( "--- ASTIterator ---" ); - ASTIterator iter2 = new ASTIterator( t ); - int count2 = 0; - while ( iter2.hasNext() ) { - AST n = iter2.nextNode(); - count2++; - System.out.println( n ); - } - assertEquals( 10, count2 ); - - System.out.println( "--- ASTParentsFirstIterator (parent) ---" ); - ASTParentsFirstIterator iter3 = new ASTParentsFirstIterator( parent ); - int count3 = 0; - while ( iter3.hasNext() ) { - AST n = iter3.nextNode(); - count3++; - System.out.println( n ); - } - assertEquals( 5, count3 ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTUtilTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTUtilTest.java deleted file mode 100644 index 3a4cd090fe..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/ast/ASTUtilTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.ast; - -import antlr.ASTFactory; -import antlr.collections.AST; -import org.junit.Test; - -import org.hibernate.hql.internal.ast.util.ASTUtil; -import org.hibernate.testing.junit4.BaseUnitTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -/** - * Unit test for ASTUtil. - */ -public class ASTUtilTest extends BaseUnitTestCase { - private ASTFactory factory = new ASTFactory(); - - @Test - public void testCreate() throws Exception { - AST n = ASTUtil.create( factory, 1, "one"); - assertNull( n.getFirstChild() ); - assertEquals( "one", n.getText() ); - assertEquals( 1, n.getType() ); - } - - @Test - public void testCreateTree() throws Exception { - AST[] tree = new AST[4]; - AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent"); - AST parent = tree[1] = ASTUtil.create(factory,2,"parent"); - AST child = tree[2] = ASTUtil.create(factory,3,"child"); - AST baby = tree[3] = ASTUtil.create(factory,4,"baby"); - AST t = ASTUtil.createTree( factory, tree); - assertSame(t,grandparent); - assertSame(parent,t.getFirstChild()); - assertSame(child,t.getFirstChild().getFirstChild()); - assertSame( baby, t.getFirstChild().getFirstChild().getFirstChild() ); - } - - @Test - public void testFindPreviousSibling() throws Exception { - AST child1 = ASTUtil.create(factory,2, "child1"); - AST child2 = ASTUtil.create(factory,3, "child2"); - AST n = factory.make( new AST[] { - ASTUtil.create(factory, 1, "parent"), - child1, - child2, - }); - assertSame(child1,ASTUtil.findPreviousSibling( n,child2)); - Exception e = null; - try { - ASTUtil.findPreviousSibling(child1,null); - } - catch (Exception x) { - e = x; - } - assertNotNull(e); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/cid/CompositeIdCountEntityTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/cid/CompositeIdCountEntityTest.java deleted file mode 100644 index 3d6ee4fa31..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/cid/CompositeIdCountEntityTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.cid; - -import java.util.Calendar; -import java.util.Collections; -import jakarta.persistence.PersistenceException; - -import org.hibernate.Session; -import org.hibernate.dialect.Oracle8iDialect; -import org.hibernate.dialect.SQLServerDialect; -import org.hibernate.exception.SQLGrammarException; - -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Andrea Boriero - */ -public class CompositeIdCountEntityTest extends BaseCoreFunctionalTestCase { - @Override - public String[] getMappings() { - return new String[] { "cid/Customer.hbm.xml", "cid/Order.hbm.xml", "cid/LineItem.hbm.xml", "cid/Product.hbm.xml" }; - } - - @Test - public void testNonDistinctCountOfEntityWithCompositeId() { - // the check here is all based on whether we had commas in the expressions inside the count - final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan( - "select count(o) from Order o", - false, - Collections.EMPTY_MAP - ); - assertEquals( 1, plan.getTranslators().length ); - final QueryTranslator translator = plan.getTranslators()[0]; - final String generatedSql = translator.getSQLString(); - - final int countExpressionListStart = generatedSql.indexOf( "count(" ); - final int countExpressionListEnd = generatedSql.indexOf( ")", countExpressionListStart ); - final String countExpressionFragment = generatedSql.substring( countExpressionListStart+6, countExpressionListEnd+1 ); - final boolean hadCommas = countExpressionFragment.contains( "," ); - - // set up the expectation based on Dialect... - final boolean expectCommas = sessionFactory().getDialect().supportsTupleCounts(); - - assertEquals( expectCommas, hadCommas ); - } - - @Test - @SkipForDialect(value = Oracle8iDialect.class, comment = "Cannot count distinct over multiple columns in Oracle") - @SkipForDialect(value = SQLServerDialect.class, comment = "Cannot count distinct over multiple columns in SQL Server") - public void testDistinctCountOfEntityWithCompositeId() { - // today we do not account for Dialects supportsTupleDistinctCounts() is false. though really the only - // "option" there is to throw an error. - final HQLQueryPlan plan = sessionFactory().getQueryInterpretationCache().getHQLQueryPlan( - "select count(distinct o) from Order o", - false, - Collections.EMPTY_MAP - ); - assertEquals( 1, plan.getTranslators().length ); - final QueryTranslator translator = plan.getTranslators()[0]; - final String generatedSql = translator.getSQLString(); - System.out.println( "Generated SQL : " + generatedSql ); - - final int countExpressionListStart = generatedSql.indexOf( "count(" ); - final int countExpressionListEnd = generatedSql.indexOf( ")", countExpressionListStart ); - final String countExpressionFragment = generatedSql.substring( countExpressionListStart+6, countExpressionListEnd+1 ); - assertTrue( countExpressionFragment.startsWith( "distinct" ) ); - assertTrue( countExpressionFragment.contains( "," ) ); - - Session s = openSession(); - s.beginTransaction(); - Customer c = new Customer(); - c.setCustomerId( "1" ); - c.setAddress("123 somewhere"); - c.setName("Brett"); - Order o1 = new Order( c ); - o1.setOrderDate( Calendar.getInstance() ); - Order o2 = new Order( c ); - o2.setOrderDate( Calendar.getInstance() ); - s.persist( c ); - s.persist( o1 ); - s.persist( o2 ); - s.getTransaction().commit(); - s.clear(); - - s.beginTransaction(); - try { - long count = ( Long ) s.createQuery( "select count(distinct o) FROM Order o" ).uniqueResult(); - if ( ! getDialect().supportsTupleDistinctCounts() ) { - fail( "expected PersistenceException caused by SQLGrammarException" ); - } - assertEquals( 2l, count ); - } - catch ( PersistenceException e ) { - if ( ! (e.getCause() instanceof SQLGrammarException ) || getDialect().supportsTupleDistinctCounts() ) { - throw e; - } - } - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - s.createQuery("delete from Order").executeUpdate(); - s.createQuery("delete from Customer").executeUpdate(); - s.getTransaction().commit(); - s.close(); - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/connections/AggressiveReleaseQueryIterationTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/connections/AggressiveReleaseQueryIterationTest.java deleted file mode 100644 index a3198a364f..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/connections/AggressiveReleaseQueryIterationTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.connections; - -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.hibernate.ConnectionReleaseMode; -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Environment; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; - -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.jta.TestingJtaBootstrap; -import org.hibernate.testing.jta.TestingJtaPlatformImpl; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * @author Andrea Boriero - */ -@RequiresDialect(H2Dialect.class) -public class AggressiveReleaseQueryIterationTest extends ConnectionManagementTestCase { - @Override - @SuppressWarnings("unchecked") - protected void addSettings(Map settings) { - super.addSettings( settings ); - - TestingJtaBootstrap.prepare( settings ); -// settings.put( Environment.TRANSACTION_STRATEGY, CMTTransactionFactory.class.getName() ); - settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName() ); - settings.put( Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT.toString() ); - settings.put( Environment.GENERATE_STATISTICS, "true" ); - settings.put( Environment.STATEMENT_BATCH_SIZE, "0" ); - } - - @Override - protected Session getSessionUnderTest() throws Throwable { - return openSession(); - } - - @Override - protected void reconnect(Session session) { - } - - @Override - protected void prepare() throws Throwable { - TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin(); - } - - @Override - protected void done() throws Throwable { - TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit(); - } - - @Test - public void testQueryIteration() throws Throwable { - prepare(); - Session s = getSessionUnderTest(); - Silly silly = new Silly( "silly" ); - s.save( silly ); - s.flush(); - - List itr = s.createQuery( "from Silly" ).iterate(); - assertTrue( itr.hasNext() ); - Silly silly2 = ( Silly ) itr.next(); - assertEquals( silly, silly2 ); - Hibernate.close( itr ); - - itr = s.createQuery( "from Silly" ).iterate(); - Iterator itr2 = s.createQuery( "from Silly where name = 'silly'" ).iterate(); - - assertTrue( itr.hasNext() ); - assertEquals( silly, itr.next() ); - assertTrue( itr2.hasNext() ); - assertEquals( silly, itr2.next() ); - - Hibernate.close( itr ); - Hibernate.close( itr2 ); - - s.delete( silly ); - s.flush(); - - release( s ); - done(); - } - - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/AbstractFoo.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/AbstractFoo.java deleted file mode 100644 index e9085a51cf..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/AbstractFoo.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - - -public abstract class AbstractFoo { - - private Integer id; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Address.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Address.java deleted file mode 100644 index 6771855c17..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Address.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author Gail Badner - */ -public class Address { - private int addressId; - - public int getAddressId() { - return addressId; - } - - private String addressText; - - public String getAddressText() { - return addressText; - } - - public void setAddressText(String addressText) { - this.addressText = addressText; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Animal.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Animal.hbm.xml deleted file mode 100644 index 343f5f1d9a..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Animal.hbm.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bar.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bar.java deleted file mode 100644 index b8842da2c2..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bar.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - -public class Bar { - private Integer id; - - AbstractFoo myFoo; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public AbstractFoo getMyFoo() { - return myFoo; - } - - public void setMyFoo(AbstractFoo myFoo) { - this.myFoo = myFoo; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bid.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bid.java deleted file mode 100644 index ea80bc2377..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Bid.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import java.io.Serializable; - -/** - * @author tknowlton at iamhisfriend dot org - */ -@Entity -public class Bid implements Serializable { - @Id - float amount; - - @Id - @ManyToOne - Item item; -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CityState.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CityState.java deleted file mode 100644 index efd90ee801..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CityState.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - -/** - * @author Gail Badner - */ - -public class CityState { - private String city; - private String state; - - public CityState() {} - - public CityState(String city, String state) { - this.city = city; - this.state = state; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Code.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Code.java deleted file mode 100644 index 9d4e1d896e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Code.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** -* @author Strong Liu -*/ -public enum Code { - ADM, CEN, RPA, RPP, PRJ, HUB, RQS, OAD, ORP, ORQ -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Country.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Country.java deleted file mode 100644 index 4e0c2181ed..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Country.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author David Mansfield - */ -public class Country { - String code; - String name; - - public Country() {} - - public Country(String code, String name) { - this.code = code; - this.name = name; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Course.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Course.java deleted file mode 100644 index 2d3210f1cc..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Course.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ - -//$Id: Course.java 5686 2005-02-12 07:27:32Z steveebersole $ -package org.hibernate.test.criteria; -import java.util.HashSet; -import java.util.Set; - -/** - * @author Gavin King - */ -public class Course { - private String courseCode; - private String description; - private Set courseMeetings = new HashSet(); - private Set crossListedAs; - - public String getCourseCode() { - return courseCode; - } - public void setCourseCode(String courseCode) { - this.courseCode = courseCode; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public Set getCourseMeetings() { - return courseMeetings; - } - public void setCourseMeetings(Set courseMeetings) { - this.courseMeetings = courseMeetings; - } - public Set getCrossListedAs() { - return crossListedAs; - } - public void setCrossListedAs(Set crossListedAs) { - this.crossListedAs = crossListedAs; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeeting.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeeting.java deleted file mode 100644 index 50c6ed65ee..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeeting.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - -/** - * @author Gail Badner - */ -public class CourseMeeting { - private CourseMeetingId id; - private Course course; - - public CourseMeeting() {} - - public CourseMeeting(Course course, String day, int period, String location) { - this.id = new CourseMeetingId( course, day, period, location ); - this.course = course; - } - - public CourseMeetingId getId() { - return id; - } - public void setId(CourseMeetingId id) { - this.id = id; - } - public Course getCourse() { - return course; - } - public void setCourse(Course course) { - this.course = course; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeetingId.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeetingId.java deleted file mode 100644 index d1fca27b88..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/CourseMeetingId.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; -import java.io.Serializable; - -/** - * @author Gail Badner - */ -public class CourseMeetingId implements Serializable { - private String courseCode; - private String day; - private int period; - private String location; - - public CourseMeetingId() {} - - public CourseMeetingId(Course course, String day, int period, String location) { - this.courseCode = course.getCourseCode(); - this.day = day; - this.period = period; - this.location = location; - } - - public String getCourseCode() { - return courseCode; - } - public void setCourseCode(String courseCode) { - this.courseCode = courseCode; - } - public String getDay() { - return day; - } - public void setDay(String day) { - this.day = day; - } - public int getPeriod() { - return period; - } - public void setPeriod(int period) { - this.period = period; - } - public String getLocation() { - return location; - } - public void setLocation(String location) { - this.location = location; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.hbm.xml deleted file mode 100644 index e5dbcc482a..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.hbm.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.java deleted file mode 100644 index 9d85d9114d..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Enrolment.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ - -//$Id: Enrolment.java 6970 2005-05-31 20:24:41Z oneovthafew $ -package org.hibernate.test.criteria; -import java.io.Serializable; - -/** - * @author Gavin King - */ -public class Enrolment implements Serializable { - private Student student; - private Course course; - private long studentNumber; - private String courseCode; - private short year; - private short semester; - public String getCourseCode() { - return courseCode; - } - public void setCourseCode(String courseId) { - this.courseCode = courseId; - } - public long getStudentNumber() { - return studentNumber; - } - public void setStudentNumber(long studentId) { - this.studentNumber = studentId; - } - public Course getCourse() { - return course; - } - public void setCourse(Course course) { - this.course = course; - } - public Student getStudent() { - return student; - } - public void setStudent(Student student) { - this.student = student; - } - public short getSemester() { - return semester; - } - public void setSemester(short semester) { - this.semester = semester; - } - public short getYear() { - return year; - } - public void setYear(short year) { - this.year = year; - } - - public boolean equals(Object other) { - if ( !(other instanceof Enrolment) ) return false; - Enrolment that = (Enrolment) other; - return studentNumber==that.studentNumber && - courseCode.equals(that.courseCode); - } - - public int hashCode() { - return courseCode.hashCode(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Foo.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Foo.hbm.xml deleted file mode 100644 index 208df92c6c..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Foo.hbm.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/GreatFoo.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/GreatFoo.java deleted file mode 100644 index 42dd3ca85e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/GreatFoo.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - -public class GreatFoo extends AbstractFoo { - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Item.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Item.java deleted file mode 100644 index c8093ab347..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Item.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import jakarta.persistence.*; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; - -/** - * @author tknowlton at iamhisfriend dot org - */ -@Entity -public class Item implements Serializable { - @Id - String name; - - @OneToMany(mappedBy = "item", fetch = FetchType.EAGER) - @OrderBy("amount desc") - Set bids = new HashSet(); -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/ListActionRole.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/ListActionRole.java deleted file mode 100644 index bd145f6a79..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/ListActionRole.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Id; -import jakarta.persistence.IdClass; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; - -/** - * @author Strong Liu - */ -@Entity -@IdClass(ListActionRole.class) -public class ListActionRole extends VersionedRecord { - @Id - @Enumerated(EnumType.STRING) - Code roleCode; - - @ManyToOne(targetEntity = Role.class) - @JoinColumn(nullable = false) - Role role; - - @Override - public String toString() { - return "ListActionRole.Id(roleCode=" + roleCode + ")"; - } - - @Override - public int hashCode() { - return toString().hashCode(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Man.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Man.java deleted file mode 100644 index ee04dd3f80..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Man.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -public class Man extends Person { -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.hbm.xml deleted file mode 100644 index 1a60139202..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.hbm.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.java deleted file mode 100644 index 0cab5b39fa..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Order.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -public class Order { - - private int orderId; - - public int getOrderId() { - return orderId; - } - - private Set orderLines = new HashSet(); - - public Set getLines() { - return Collections.unmodifiableSet(orderLines); - } - - public void addLine(OrderLine orderLine){ - orderLine.setOrder(this); - this.orderLines.add(orderLine); - } - - private Set orderContacts = new HashSet(); - - public Set getContacts() { - return Collections.unmodifiableSet(orderContacts); - } - - public void addContact(OrderContact orderContact){ - orderContact.getOrders().add( this ); - this.orderContacts.add(orderContact); - } - - public OrderAddress orderAddress; - - public OrderAddress getOrderAddress() { - return orderAddress; - } - - public void setOrderAddress(OrderAddress orderAddress) { - this.orderAddress = orderAddress; - } - - public String toString() { - return "" + getOrderId() + " - " + getLines(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderAddress.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderAddress.java deleted file mode 100644 index 3c5b77e6f8..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderAddress.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import java.util.HashSet; -import java.util.Set; - -public class OrderAddress { - - private int orderAddressId; - - public int getOrderAddressId() { - return orderAddressId; - } - - private Address deliveryAddress; - - public Address getDeliveryAddress() { - return deliveryAddress; - } - - public void setDeliveryAddress(Address deliveryAddress) { - this.deliveryAddress = deliveryAddress; - } - - private Set
notifiedAddresses = new HashSet
(); - - public Set
getNotifiedAddresses() { - return notifiedAddresses; - } - - public void setNotifiedAddresses(Set
notifiedAddresses) { - this.notifiedAddresses = notifiedAddresses; - } - - public String toString() { - return "" + orderAddressId + " - " + getDeliveryAddress() + " - " + getNotifiedAddresses(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderContact.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderContact.java deleted file mode 100644 index 2fba35b433..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderContact.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import java.util.HashSet; -import java.util.Set; - -public class OrderContact { - - private int contactId = 0; - private Set orders = new HashSet(); - - private String contact; - - - public int getContactId() { - return contactId; - } - - public Set getOrders() { - return orders; - } - - public String getContact() { - return contact; - } - - public void setContact(String contact) { - this.contact = contact; - } - - public String toString() { - return "[" + getContactId() + ":" + getContact() + "]"; - } -} \ No newline at end of file diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderLine.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderLine.java deleted file mode 100644 index b87745f484..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/OrderLine.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -public class OrderLine { - - private int lineId = 0; - - private Order order; - - private String articleId; - - - public int getLineId() { - return lineId; - } - - public Order getOrder() { - return order; - } - - public String getArticleId() { - return articleId; - } - - public void setOrder(Order order) { - this.order = order; - } - - public void setArticleId(String articleId) { - this.articleId = articleId; - } - - public String toString() { - return "[" + getLineId() + ":" + getArticleId() + "]"; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.hbm.xml deleted file mode 100644 index cc9e26db4f..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.hbm.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.java deleted file mode 100644 index d940e803c2..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Person.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -public abstract class Person { - private Long id; - - private String name; - - private Integer weight; - - private Integer height; - - @Override - public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof Person ) ) return false; - - Person person = (Person) o; - - if ( height != null ? !height.equals( person.height ) : person.height != null ) return false; - if ( id != null ? !id.equals( person.id ) : person.id != null ) return false; - if ( name != null ? !name.equals( person.name ) : person.name != null ) return false; - if ( weight != null ? !weight.equals( person.weight ) : person.weight != null ) return false; - - return true; - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + ( name != null ? name.hashCode() : 0 ); - result = 31 * result + ( weight != null ? weight.hashCode() : 0 ); - result = 31 * result + ( height != null ? height.hashCode() : 0 ); - return result; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getWeight() { - return weight; - } - - public void setWeight(Integer weight) { - this.weight = weight; - } - - public Integer getHeight() { - return height; - } - - public void setHeight(Integer height) { - this.height = height; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Role.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Role.java deleted file mode 100644 index 70fca2803f..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Role.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -/** -* @author Strong Liu -*/ -@Entity -@Table(name = "roles") -public class Role extends VersionedRecord { - @Id - @Enumerated(EnumType.STRING) - Code code; -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StringExpression.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StringExpression.java deleted file mode 100644 index c9511c521e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StringExpression.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; -import org.hibernate.criterion.Criterion; -import org.hibernate.criterion.LikeExpression; - -public class StringExpression extends LikeExpression { - private final static Character ESCAPE_CODE = new Character( '\\' ); - - protected StringExpression( String property, String value, - boolean ignoreCase ) { - super( property, value, ESCAPE_CODE, ignoreCase ); - } - - public static Criterion stringExpression( String propertyName, - String value, boolean ignoreCase ) { - return new StringExpression( propertyName, value, ignoreCase ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Student.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Student.java deleted file mode 100644 index abfca38834..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Student.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -/** - * @author Gavin King - */ -public class Student { - private long studentNumber; - private String name; - private CityState cityState; - private Course preferredCourse; - private Set enrolments = new HashSet(); - private Map addresses; - private List studyAbroads; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public long getStudentNumber() { - return studentNumber; - } - - public void setStudentNumber(long studentNumber) { - this.studentNumber = studentNumber; - } - - public CityState getCityState() { - return cityState; - } - - public void setCityState(CityState cityState) { - this.cityState = cityState; - } - - public Course getPreferredCourse() { - return preferredCourse; - } - - public void setPreferredCourse(Course preferredCourse) { - this.preferredCourse = preferredCourse; - } - - public Set getEnrolments() { - return enrolments; - } - - public void setEnrolments(Set employments) { - this.enrolments = employments; - } - - public Map getAddresses() { - return addresses; - } - - public void setAddresses(Map addresses) { - this.addresses = addresses; - } - - public List getStudyAbroads() { - return studyAbroads; - } - - public void setStudyAbroads(List studyAbroads) { - this.studyAbroads = studyAbroads; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentAddress.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentAddress.java deleted file mode 100644 index 833c3dfcd0..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentAddress.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author David Mansfield - */ -public class StudentAddress { - private String line1; - private String line2; - private String city; - private String state; - private String zip; - - public String getLine1() { - return line1; - } - public void setLine1(String line1) { - this.line1 = line1; - } - public String getLine2() { - return line2; - } - public void setLine2(String line2) { - this.line2 = line2; - } - public String getCity() { - return city; - } - public void setCity(String city) { - this.city = city; - } - public String getState() { - return state; - } - public void setState(String state) { - this.state = state; - } - public String getZip() { - return zip; - } - public void setZip(String zip) { - this.zip = zip; - } - // @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((city == null) ? 0 : city.hashCode()); - result = prime * result + ((line1 == null) ? 0 : line1.hashCode()); - result = prime * result + ((line2 == null) ? 0 : line2.hashCode()); - result = prime * result + ((state == null) ? 0 : state.hashCode()); - result = prime * result + ((zip == null) ? 0 : zip.hashCode()); - return result; - } - // @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - StudentAddress other = (StudentAddress) obj; - if (city == null) { - if (other.city != null) - return false; - } else if (!city.equals(other.city)) - return false; - if (line1 == null) { - if (other.line1 != null) - return false; - } else if (!line1.equals(other.line1)) - return false; - if (line2 == null) { - if (other.line2 != null) - return false; - } else if (!line2.equals(other.line2)) - return false; - if (state == null) { - if (other.state != null) - return false; - } else if (!state.equals(other.state)) - return false; - if (zip == null) { - if (other.zip != null) - return false; - } else if (!zip.equals(other.zip)) - return false; - return true; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentDTO.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentDTO.java deleted file mode 100644 index 211d4360b7..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudentDTO.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ - -/* - * Created on 28-Jan-2005 - * - */ -package org.hibernate.test.criteria; - - -/** - * @author max - * - */ -public class StudentDTO { - - private String studentName; - private String courseDescription; - - public StudentDTO() { } - - public String getName() { - return studentName; - } - - public String getDescription() { - return courseDescription; - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudyAbroad.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudyAbroad.java deleted file mode 100644 index 4bcc3465ac..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/StudyAbroad.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import java.util.Date; - -public class StudyAbroad { - private Country country; - private Date date; - - public StudyAbroad() {} - - public StudyAbroad(Country country, Date date) { - this.country = country; - this.date = date; - } - - public Country getCountry() { - return country; - } - - public void setCountry(Country country) { - this.country = country; - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.hbm.xml b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.hbm.xml deleted file mode 100644 index ce150a4075..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.hbm.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.java deleted file mode 100644 index 7623e51fb2..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/TestObject.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - - -public class TestObject { - private Integer id; - private String text; - - public Integer getId() { - return id; - } - - public void setId( Integer id ) { - this.id = id; - } - - public String getText() { - return text; - } - - public void setText( String text ) { - this.text = text; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/VersionedRecord.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/VersionedRecord.java deleted file mode 100644 index fae5c51508..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/VersionedRecord.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -import jakarta.persistence.MappedSuperclass; - -/** -* @author Strong Liu -*/ -@MappedSuperclass -abstract class VersionedRecord implements java.io.Serializable { - Long recordVersion; - Boolean isDeleted; -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Woman.java b/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Woman.java deleted file mode 100644 index d6be5e7bb6..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/criteria/Woman.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.criteria; - -/** - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -public class Woman extends Person { -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/ClassicTranslatorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/ClassicTranslatorTest.java deleted file mode 100644 index 009a2ab4a8..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/ClassicTranslatorTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; - -import org.junit.Test; - -import org.hibernate.Session; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; - -/** - * Some simple test queries using the classic translator explicitly - * to ensure that code is not broken in changes for the new translator. - *

- * Only really checking translation and syntax, not results. - * - * @author Steve Ebersole - */ -@RequiresDialectFeature(DialectChecks.SupportsNoColumnInsert.class) -public class ClassicTranslatorTest extends QueryTranslatorTestCase { - @Override - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( Environment.QUERY_TRANSLATOR, ClassicQueryTranslatorFactory.class.getName() ); - cfg.setProperty( AvailableSettings.JDBC_TYLE_PARAMS_ZERO_BASE, "true" ); - } - - @Override - public boolean createSchema() { - return true; - } - - @Override - public boolean rebuildSessionFactoryOnError() { - return true; - } - - @Test - public void testQueries() { - Session session = openSession(); - session.beginTransaction(); - - session.createQuery( "from Animal" ).list(); - - session.createQuery( "select a from Animal as a" ).list(); - session.createQuery( "select a.mother from Animal as a" ).list(); - session.createQuery( "select m from Animal as a inner join a.mother as m" ).list(); - session.createQuery( "select a from Animal as a inner join fetch a.mother" ).list(); - - session.createQuery( "from Animal as a where a.description = ?" ).setString( 0, "jj" ).list(); - session.createQuery( "from Animal as a where a.description = :desc" ).setString( "desc", "jr" ).list(); - - session.getTransaction().commit(); - session.close(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/CollectionPropertyDeprecationsTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/CollectionPropertyDeprecationsTest.java deleted file mode 100644 index beb3323022..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/CollectionPropertyDeprecationsTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.hql; - -import java.util.Collections; - -import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; -import org.hibernate.hql.internal.ast.QueryTranslatorImpl; -import org.hibernate.hql.spi.QueryTranslatorFactory; -import org.hibernate.internal.log.DeprecationLogger; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.logger.LoggerInspectionRule; -import org.hibernate.testing.logger.Triggerable; -import org.junit.Rule; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Tests that the forms of referencing parts of and info about collections as a property - * gets logged as a deprecation warning. E.g. {@code `h.family.elements`} is - * deprecated in preference for {@code `elements(h.family)`} - * - * @author Steve Ebersole - */ -public class CollectionPropertyDeprecationsTest extends BaseCoreFunctionalTestCase { - @Rule - public LoggerInspectionRule logInspection = new LoggerInspectionRule( - DeprecationLogger.DEPRECATION_LOGGER - ); - - @Override - public String[] getMappings() { - return new String[] {"hql/Animal.hbm.xml"}; - } - - @Override - public boolean createSchema() { - return false; - } - - @Override - public boolean rebuildSessionFactoryOnError() { - return false; - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingBagElements() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select elements(h.friends) from Human h" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select h from Human h where h in elements(h.friends)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select h.friends.elements from Human h" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingSetElements() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select elements(h.nickNames) from Human h" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select h from Human h where h.name.first in elements(h.nickNames)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select h.nickNames.elements from Human h" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingListElements() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select elements(u.permissions) from User u" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select u from User u where u.userName in elements(u.permissions)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select u.permissions.elements from User u" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingListIndices() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select indices(u.permissions) from User u" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select u from User u where u.userName in indices(u.permissions)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select u.permissions.indices from User u" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingMapElements() { - // NOTE : JPA's VALUE ought to work fine as we never supported - // that in the legacy form... - - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select elements(h.family) from Human h" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select h from Human h where h.name.first in elements(h.family)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select h.family.elements from Human h" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingMapIndices() { - // NOTE : JPA's KEY ought to work fine as we never supported - // that in the legacy form... - - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select indices(h.family) from Human h" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select h from Human h where h.name.first in indices(h.family)" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select h.family.indices from Human h" ); - assertTrue( triggerable.wasTriggered() ); - } - - @Test - @TestForIssue( jiraKey = "HHH-11400" ) - public void testReferencingSize() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH90000016" ); - - // first the accepted ways - compileQuery( "select size(h.family) from Human h" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - compileQuery( "select h from Human h where size(h.family) = 1" ); - assertFalse( triggerable.wasTriggered() ); - triggerable.reset(); - - // then the deprecated way - compileQuery( "select h.family.size from Human h" ); - assertTrue( triggerable.wasTriggered() ); - } - - - - - private QueryTranslatorImpl compileQuery(String hql) { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - QueryTranslatorImpl newQueryTranslator = (QueryTranslatorImpl) ast.createQueryTranslator( - hql, - hql, - Collections.EMPTY_MAP, - sessionFactory(), - null - ); - newQueryTranslator.compile( Collections.emptyMap(), false ); - return newQueryTranslator; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/EJBQLTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/EJBQLTest.java deleted file mode 100644 index 64a82a9bd8..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/EJBQLTest.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Collections; -import java.util.List; - -import antlr.RecognitionException; -import antlr.TokenStreamException; -import antlr.collections.AST; -import org.junit.Test; - -import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes; -import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; -import org.hibernate.hql.internal.ast.HqlParser; -import org.hibernate.hql.internal.ast.QueryTranslatorImpl; -import org.hibernate.hql.internal.ast.util.ASTUtil; -import org.hibernate.hql.spi.QueryTranslator; -import org.hibernate.hql.spi.QueryTranslatorFactory; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; - -/** - * @author Alexey Loubyansky - */ -@RequiresDialectFeature(DialectChecks.SupportsNoColumnInsert.class) -public class EJBQLTest extends BaseCoreFunctionalTestCase { - @Override - public String[] getMappings() { - return new String[]{ - "hql/Animal.hbm.xml", - "/org/hibernate/orm/test/batchfetch/ProductLine.hbm.xml", - "cid/Customer.hbm.xml", - "cid/Order.hbm.xml", - "cid/LineItem.hbm.xml", - "cid/Product.hbm.xml", - "legacy/Glarch.hbm.xml", - "legacy/Fee.hbm.xml", - "legacy/Qux.hbm.xml", - "legacy/Fum.hbm.xml", - "legacy/Holder.hbm.xml", - "legacy/One.hbm.xml", - "legacy/FooBar.hbm.xml", - "legacy/Many.hbm.xml", - "legacy/Baz.hbm.xml", - "legacy/Simple.hbm.xml", - "legacy/Middle.hbm.xml", - "legacy/Category.hbm.xml", - "legacy/Multi.hbm.xml", - "legacy/Commento.hbm.xml", - "legacy/Marelo.hbm.xml", - "compositeelement/Parent.hbm.xml", - "legacy/Container.hbm.xml", - }; - } - - @Override - public boolean createSchema() { - return false; - } - - @Test - public void testEjb3PositionalParameters() throws Exception { - QueryTranslatorImpl qt = compile( "from Animal a where a.bodyWeight = ?1" ); - AST ast = ( AST ) qt.getSqlAST(); - - // make certain that the ejb3-positional param got recognized as a positional param - List namedParams = ASTUtil.collectChildren( - ast, - new ASTUtil.FilterPredicate() { - public boolean exclude(AST n) { - return n.getType() != HqlSqlTokenTypes.PARAM; - } - } - ); - assertTrue( "ejb3 positional param not recognized as a named param", namedParams.size() > 0 ); - } - - @Test - public void testSelectObjectClause() throws Exception { - //parse("select object(m) from Model m"); - assertEjbqlEqualsHql( "select object(m) from Model m", "from Model m" ); - } - - @Test - public void testCollectionMemberDeclaration() throws Exception { - String hql = "select o from Animal a inner join a.offspring o"; - String ejbql = "select object(o) from Animal a, in(a.offspring) o"; - //parse(hql); - //parse(ejbql); - assertEjbqlEqualsHql( ejbql, hql ); - } - - @Test - public void testIsEmpty() throws Exception { - //String hql = "from Animal a where not exists (from a.offspring)"; - String hql = "from Animal a where not exists elements(a.offspring)"; - String ejbql = "select object(a) from Animal a where a.offspring is empty"; - //parse(hql); - //parse(ejbql); - assertEjbqlEqualsHql(ejbql, hql); - - hql = "from Animal a where exists (from a.mother.father.offspring)"; - ejbql = "select object(a) from Animal a where a.mother.father.offspring is not empty"; - assertEjbqlEqualsHql( ejbql, hql ); - } - - @Test - public void testMemberOf() throws Exception { - String hql = "from Animal a where a.mother in (from a.offspring)"; - //String hql = "from Animal a where a.mother in elements(a.offspring)"; - String ejbql = "select object(a) from Animal a where a.mother member of a.offspring"; - //parse(hql); - //parse(ejbql); - assertEjbqlEqualsHql( ejbql, hql ); - - hql = "from Animal a where a.mother not in (from a.offspring)"; - //hql = "from Animal a where a.mother not in elements(a.offspring)"; - ejbql = "select object(a) from Animal a where a.mother not member of a.offspring"; - //parse(hql); - //parse(ejbql); - assertEjbqlEqualsHql( ejbql, hql ); - } - - @Test - public void testEJBQLFunctions() throws Exception { - String hql = "select object(a) from Animal a where a.description = concat('1', concat('2','3'), '4'||'5')||0"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "from Animal a where substring(a.description, 1, 3) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select substring(a.description, 1, 3) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "from Animal a where lower(a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select lower(a.description) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "from Animal a where upper(a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select upper(a.description) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "from Animal a where length(a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select length(a.description) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "from Animal a where locate(a.description, 'abc', 2) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select locate(a.description, :p1, 2) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where trim(trailing '_' from a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select trim(trailing '_' from a.description) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where trim(leading '_' from a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where trim(both a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where trim(a.description) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where abs(a.bodyWeight) = sqrt(a.bodyWeight)"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where mod(a.bodyWeight, a.mother.bodyWeight) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where BIT_LENGTH(a.bodyWeight) = :p1"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select BIT_LENGTH(a.bodyWeight) from Animal a"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where CURRENT_DATE = :p1 or CURRENT_TIME = :p2 or CURRENT_TIMESTAMP = :p3"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - // todo the following is not supported - //hql = "select CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP from Animal a"; - //parse(hql, true); - //System.out.println("sql: " + toSql(hql)); - - hql = "select object(a) from Animal a where a.bodyWeight like '%a%'"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where a.bodyWeight not like '%a%'"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - - hql = "select object(a) from Animal a where a.bodyWeight like '%a%' escape '%'"; - parse( hql, false ); - System.out.println( "sql: " + toSql( hql ) ); - } - - @Test - public void testTrueFalse() throws Exception { - assertEjbqlEqualsHql( "from Human h where h.pregnant is true", "from Human h where h.pregnant = true" ); - assertEjbqlEqualsHql( "from Human h where h.pregnant is false", "from Human h where h.pregnant = false" ); - assertEjbqlEqualsHql( "from Human h where not(h.pregnant is true)", "from Human h where not( h.pregnant=true )" ); - } - - - private void assertEjbqlEqualsHql(String ejbql, String hql) { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - - QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory(), null ); - queryTranslator.compile( Collections.EMPTY_MAP, true ); - String hqlSql = queryTranslator.getSQLString(); - - queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sessionFactory(), null ); - queryTranslator.compile( Collections.EMPTY_MAP, true ); - String ejbqlSql = queryTranslator.getSQLString(); - - assertEquals( hqlSql, ejbqlSql ); - } - - private QueryTranslatorImpl compile(String input) { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - QueryTranslator queryTranslator = ast.createQueryTranslator( input, input, Collections.EMPTY_MAP, sessionFactory(), null ); - queryTranslator.compile( Collections.EMPTY_MAP, true ); - - return ( QueryTranslatorImpl ) queryTranslator; - } - - private AST parse(String input, boolean logging) throws RecognitionException, TokenStreamException { - if ( logging ) { - System.out.println( "input: ->" + input + "<-" ); - } - - HqlParser parser = HqlParser.getInstance( input ); - parser.setFilter( false ); - parser.statement(); - AST ast = parser.getAST(); - - if ( logging ) { - System.out.println( "AST : " + ast.toStringTree() + "" ); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - parser.showAst( ast, new PrintStream( baos ) ); - System.out.println( baos.toString() ); - } - - assertEquals( "At least one error occurred during parsing!", 0, parser.getParseErrorHandler().getErrorCount() ); - - return ast; - } - - private String toSql(String hql) { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sessionFactory(), null ); - queryTranslator.compile( Collections.EMPTY_MAP, true ); - return queryTranslator.getSQLString(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HQLTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/HQLTest.java deleted file mode 100644 index a543183e5f..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HQLTest.java +++ /dev/null @@ -1,1642 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.QueryException; -import org.hibernate.Session; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.AbstractHANADialect; -import org.hibernate.dialect.DB2Dialect; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.dialect.HSQLDialect; -import org.hibernate.dialect.IngresDialect; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.Oracle8iDialect; -import org.hibernate.dialect.PostgreSQL81Dialect; -import org.hibernate.dialect.PostgreSQLDialect; -import org.hibernate.dialect.SQLServerDialect; -import org.hibernate.dialect.Sybase11Dialect; -import org.hibernate.dialect.SybaseASE15Dialect; -import org.hibernate.dialect.SybaseAnywhereDialect; -import org.hibernate.dialect.SybaseDialect; -import org.hibernate.dialect.TeradataDialect; -import org.hibernate.dialect.CockroachDialect; -import org.hibernate.dialect.function.SQLFunction; -import org.hibernate.engine.query.spi.HQLQueryPlan; -import org.hibernate.engine.query.spi.ReturnMetadata; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.hql.internal.antlr.HqlTokenTypes; -import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; -import org.hibernate.hql.internal.ast.DetailedSemanticException; -import org.hibernate.hql.internal.ast.QuerySyntaxException; -import org.hibernate.hql.internal.ast.QueryTranslatorImpl; -import org.hibernate.hql.internal.ast.SqlGenerator; -import org.hibernate.hql.internal.ast.tree.ConstructorNode; -import org.hibernate.hql.internal.ast.tree.DotNode; -import org.hibernate.hql.internal.ast.tree.FromReferenceNode; -import org.hibernate.hql.internal.ast.tree.IndexNode; -import org.hibernate.hql.internal.ast.tree.QueryNode; -import org.hibernate.hql.internal.ast.tree.SelectClause; -import org.hibernate.hql.internal.ast.util.ASTUtil; -import org.hibernate.hql.spi.QueryTranslator; -import org.hibernate.hql.spi.QueryTranslatorFactory; -import org.hibernate.type.CalendarDateType; -import org.hibernate.type.DoubleType; -import org.hibernate.type.StringType; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.FailureExpected; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.TestForIssue; -import org.junit.Ignore; -import org.junit.Test; - -import antlr.RecognitionException; -import antlr.collections.AST; - -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL. - * - * @author Gavin King - */ -@RequiresDialectFeature(DialectChecks.SupportsNoColumnInsert.class) -public class HQLTest extends QueryTranslatorTestCase { - @Override - public boolean createSchema() { - return false; - } - - @Override - public boolean rebuildSessionFactoryOnError() { - return false; - } - - @Override - protected void prepareTest() throws Exception { - super.prepareTest(); - SelectClause.VERSION2_SQL = true; - DotNode.regressionStyleJoinSuppression = true; - DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = new DotNode.IllegalCollectionDereferenceExceptionBuilder() { - public QueryException buildIllegalCollectionDereferenceException(String propertyName, FromReferenceNode lhs) { - throw new QueryException( "illegal syntax near collection: " + propertyName ); - } - }; - SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = true; - } - - @Override - protected void cleanupTest() throws Exception { - SelectClause.VERSION2_SQL = false; - DotNode.regressionStyleJoinSuppression = false; - DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER = DotNode.DEF_ILLEGAL_COLL_DEREF_EXCP_BUILDER; - SqlGenerator.REGRESSION_STYLE_CROSS_JOINS = false; - super.cleanupTest(); - } - - @Test - @TestForIssue(jiraKey = "HHH-2187") - public void testBogusQuery() { - try { - QueryTranslatorImpl translator = createNewQueryTranslator( "bogus" ); - fail( "This should have failed with a QueryException" ); - } - catch ( Throwable t ) { - assertTyping( QueryException.class, t ); - } - } - - @Test - @TestForIssue(jiraKey = "HHH-2187") - public void testBogusCreateQuery() { - Session session = openSession(); - try { - session.beginTransaction(); - session.createQuery( "Bogus" ); - fail( "This should have failed with an IllegalArgumentException" ); - } - catch ( IllegalArgumentException e ) { - if ( session.getTransaction().isActive() ) { - session.getTransaction().rollback(); - } - assertTyping( QueryException.class, e.getCause() ); - } - finally { - session.close(); - } - } - - @Test - public void testModulo() { - assertTranslation( "from Animal a where a.bodyWeight % 2 = 0" ); - } - - @Test - public void testInvalidCollectionDereferencesFail() { - // should fail with the same exceptions (because of the DotNode.ILLEGAL_COLL_DEREF_EXCP_BUILDER injection) - assertTranslation( "from Animal a where a.offspring.description = 'xyz'" ); - assertTranslation( "from Animal a where a.offspring.father.description = 'xyz'" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Lacking ClassicQueryTranslatorFactory support" ) - public void testRowValueConstructorSyntaxInInList2() { - assertTranslation( "from LineItem l where l.id in (:idList)" ); - assertTranslation( "from LineItem l where l.id in :idList" ); - } - - @Test - @SkipForDialect( value = { - Oracle8iDialect.class, - AbstractHANADialect.class, - PostgreSQL81Dialect.class, - MySQLDialect.class, - CockroachDialect.class - } ) - - public void testRowValueConstructorSyntaxInInListBeingTranslated() { - QueryTranslatorImpl translator = createNewQueryTranslator( "from LineItem l where l.id in (?1)" ); - assertInExist( "'in' should be translated to 'and'", false, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in ?1" ); - assertInExist( "'in' should be translated to 'and'", false, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))" ); - assertInExist( "'in' should be translated to 'and'", false, translator ); - translator = createNewQueryTranslator("from Animal a where a.id in (?1)" ); - assertInExist( "only translated tuple has 'in' syntax", true, translator ); - translator = createNewQueryTranslator("from Animal a where a.id in ?1" ); - assertInExist( "only translated tuple has 'in' syntax", true, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)" ); - assertInExist( "do not translate sub-queries", true, translator ); - } - - @Test - @RequiresDialectFeature( DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck.class ) - public void testRowValueConstructorSyntaxInInList() { - QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?1)" ); - assertInExist( " 'in' should be kept, since the dialect supports this syntax", true, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in ?1" ); - assertInExist( " 'in' should be kept, since the dialect supports this syntax", true, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))" ); - assertInExist( " 'in' should be kept, since the dialect supports this syntax", true, translator ); - translator = createNewQueryTranslator("from Animal a where a.id in (?1)" ); - assertInExist( "only translated tuple has 'in' syntax", true, translator ); - translator = createNewQueryTranslator("from Animal a where a.id in ?1" ); - assertInExist( "only translated tuple has 'in' syntax", true, translator ); - translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)" ); - assertInExist( "do not translate sub-queries", true, translator ); - } - - private void assertInExist( String message, boolean expected, QueryTranslatorImpl translator ) { - AST ast = translator.getSqlAST().getWalker().getAST(); - QueryNode queryNode = (QueryNode) ast; - AST whereNode = ASTUtil.findTypeInChildren( queryNode, HqlTokenTypes.WHERE ); - AST inNode = whereNode.getFirstChild(); - assertEquals( message, expected, inNode != null && inNode.getType() == HqlTokenTypes.IN ); - } - - @Test - public void testSubComponentReferences() { - assertTranslation( "select c.address.zip.code from ComponentContainer c" ); - assertTranslation( "select c.address.zip from ComponentContainer c" ); - assertTranslation( "select c.address from ComponentContainer c" ); - } - - @Test - public void testManyToAnyReferences() { - assertTranslation( "from PropertySet p where p.someSpecificProperty.id is not null" ); - assertTranslation( "from PropertySet p join p.generalProperties gp where gp.id is not null" ); - } - - @Test - public void testJoinFetchCollectionOfValues() { - assertTranslation( "select h from Human as h join fetch h.nickNames" ); - } - - @Test - public void testCollectionMemberDeclarations2() { - assertTranslation( "from Customer c, in(c.orders) o" ); - assertTranslation( "from Customer c, in(c.orders) as o" ); - assertTranslation( "select c.name from Customer c, in(c.orders) as o where c.id = o.id.customerId" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Lacking ClassicQueryTranslatorFactory support" ) - public void testCollectionMemberDeclarations(){ - // both these two query translators throw exeptions for this HQL since - // IN asks an alias, but the difference is that the error message from AST - // contains the error token location (by lines and columns), which is hardly - // to get from Classic query translator --stliu - assertTranslation( "from Customer c, in(c.orders)" ); - } - - @Test - public void testCollectionJoinsInSubselect() { - disableOmittingJoinOfSuperclassTables(); - - // caused by some goofiness in FromElementFactory that tries to - // handle correlated subqueries (but fails miserably) even though this - // is not a correlated subquery. HHH-1248 - assertTranslation( - "select a.id, a.description" + - " from Animal a" + - " left join a.offspring" + - " where a in (" + - " select a1 from Animal a1" + - " left join a1.offspring o" + - " where a1.id=1" + - ")" - ); - assertTranslation( - "select h.id, h.description" + - " from Human h" + - " left join h.friends" + - " where h in (" + - " select h1" + - " from Human h1" + - " left join h1.friends f" + - " where h1.id=1" + - ")" - ); - } - - @Test - @TestForIssue( jiraKey = "HHH-2045" ) - public void testEmptyInList() { - assertTranslation( "select a from Animal a where a.description in ()" ); - } - - @Test - public void testDateTimeArithmeticReturnTypesAndParameterGuessing() { - QueryTranslatorImpl translator = createNewQueryTranslator( "select o.orderDate - o.orderDate from Order o" ); - assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); - assertEquals( "incorrect return type", DoubleType.INSTANCE, translator.getReturnTypes()[0] ); - translator = createNewQueryTranslator( "select o.orderDate + 2 from Order o" ); - assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); - assertEquals( "incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0] ); - translator = createNewQueryTranslator( "select o.orderDate -2 from Order o" ); - assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); - assertEquals( "incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0] ); - - translator = createNewQueryTranslator( "from Order o where o.orderDate > ?1" ); - assertEquals( "incorrect expected param type", CalendarDateType.INSTANCE, translator.getParameterTranslations().getPositionalParameterInformation( 1 ).getExpectedType() ); - - translator = createNewQueryTranslator( "select o.orderDate + ?1 from Order o" ); - assertEquals( "incorrect return type count", 1, translator.getReturnTypes().length ); - assertEquals( "incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0] ); - assertEquals( "incorrect expected param type", DoubleType.INSTANCE, translator.getParameterTranslations().getPositionalParameterInformation( 1 ).getExpectedType() ); - - } - - @Test - public void testReturnMetadata() { - HQLQueryPlan plan = createQueryPlan( "from Animal a" ); - check( plan.getReturnMetadata(), false, true ); - - plan = createQueryPlan( "select a as animal from Animal a" ); - check( plan.getReturnMetadata(), false, false ); - - plan = createQueryPlan( "from java.lang.Object" ); - check( plan.getReturnMetadata(), true, true ); - - plan = createQueryPlan( "select o as entity from java.lang.Object o" ); - check( plan.getReturnMetadata(), true, false ); - } - - private void check( - ReturnMetadata returnMetadata, - boolean expectingEmptyTypes, - boolean expectingEmptyAliases) { - assertNotNull( "null return metadata", returnMetadata ); - assertNotNull( "null return metadata - types", returnMetadata ); - assertEquals( "unexpected return size", 1, returnMetadata.getReturnTypes().length ); - if ( expectingEmptyTypes ) { - assertNull( "non-empty types", returnMetadata.getReturnTypes()[0] ); - } - else { - assertNotNull( "empty types", returnMetadata.getReturnTypes()[0] ); - } - if ( expectingEmptyAliases ) { - assertNull( "non-empty aliases", returnMetadata.getReturnAliases() ); - } - else { - assertNotNull( "empty aliases", returnMetadata.getReturnAliases() ); - assertNotNull( "empty aliases", returnMetadata.getReturnAliases()[0] ); - } - } - - @Test - public void testImplicitJoinsAlongWithCartesianProduct() { - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("select foo.foo from Foo foo, Foo foo2"); - assertTranslation("select foo.foo.foo from Foo foo, Foo foo2"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - public void testSubselectBetween() { - assertTranslation( "from Animal x where (select max(a.bodyWeight) from Animal a) between :min and :max" ); - assertTranslation( "from Animal x where (select max(a.description) from Animal a) like 'big%'" ); - assertTranslation( "from Animal x where (select max(a.bodyWeight) from Animal a) is not null" ); - assertTranslation( "from Animal x where exists (select max(a.bodyWeight) from Animal a)" ); - assertTranslation( "from Animal x where (select max(a.bodyWeight) from Animal a) in (1,2,3)" ); - } - - @Test - public void testFetchOrderBy() { - assertTranslation( "from Animal a left outer join fetch a.offspring where a.mother.id = :mid order by a.description"); - } - - @Test - public void testCollectionOrderBy() { - assertTranslation( "from Animal a join a.offspring o order by a.description" ); - assertTranslation( "from Animal a join fetch a.offspring order by a.description" ); - assertTranslation( "from Animal a join fetch a.offspring o order by o.description" ); - assertTranslation( "from Animal a join a.offspring o order by a.description, o.description" ); - } - - @Test - public void testExpressionWithParamInFunction() { - assertTranslation("from Animal a where abs(a.bodyWeight-:param) < 2.0" ); - assertTranslation("from Animal a where abs(:param - a.bodyWeight) < 2.0" ); - assertTranslation("from Animal where abs(:x - :y) < 2.0" ); - assertTranslation("from Animal where lower(upper(:foo)) like 'f%'" ); - if ( ! ( getDialect() instanceof SybaseDialect ) && ! ( getDialect() instanceof Sybase11Dialect ) && ! ( getDialect() instanceof SybaseASE15Dialect ) && ! ( getDialect() instanceof SQLServerDialect ) && ! ( getDialect() instanceof TeradataDialect ) ) { - // Transact-SQL dialects (except SybaseAnywhereDialect) map the length function -> len; - // classic translator does not consider that *when nested*; - // SybaseAnywhereDialect supports the length function - - assertTranslation( "from Animal a where abs(abs(a.bodyWeight - 1.0 + :param) * abs(length('ffobar')-3)) = 3.0" ); - } - if ( !( getDialect() instanceof MySQLDialect ) && ! ( getDialect() instanceof SybaseDialect ) && ! ( getDialect() instanceof Sybase11Dialect ) && !( getDialect() instanceof SybaseASE15Dialect ) && ! ( getDialect() instanceof SybaseAnywhereDialect ) && ! ( getDialect() instanceof SQLServerDialect ) && ! ( getDialect() instanceof TeradataDialect ) ) { - assertTranslation( "from Animal where lower(upper('foo') || upper(:bar)) like 'f%'" ); - } - if ( getDialect() instanceof PostgreSQLDialect || getDialect() instanceof PostgreSQL81Dialect || getDialect() instanceof TeradataDialect) { - return; - } - if ( getDialect() instanceof AbstractHANADialect ) { - // HANA returns - // ...al0_7_.mammal where [abs(cast(1 as float(19))-cast(? as float(19)))=1.0] - return; - } - if ( getDialect() instanceof MySQLDialect ) { - // MySQL dialects are smarter now wrt cast targets. For example, float (as a db type) is not - // valid as a cast target for MySQL. The new parser uses the dialect handling for casts, the old - // parser does not; so the outputs do not match here... - return; - } - if ( getDialect() instanceof CockroachDialect ) { - // CockroachDB turns "float" into "float4" so the outputs won't match. - return; - } - assertTranslation( "from Animal where abs(cast(1 as float) - cast(:param as float)) = 1.0" ); - } - - @Test - public void testCompositeKeysWithPropertyNamedId() { - assertTranslation( "select e.id.id from EntityWithCrazyCompositeKey e" ); - assertTranslation( "select max(e.id.id) from EntityWithCrazyCompositeKey e" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Lacking ClassicQueryTranslatorFactory support" ) - public void testMaxindexHqlFunctionInElementAccessor() { - //TODO: broken SQL - // steve (2005.10.06) - this is perfect SQL, but fairly different from the old parser - // tested : HSQLDB (1.8), Oracle8i - assertTranslation( "select c from ContainerX c where c.manyToMany[ maxindex(c.manyToMany) ].count = 2" ); - assertTranslation( "select c from Container c where c.manyToMany[ maxIndex(c.manyToMany) ].count = 2" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Lacking ClassicQueryTranslatorFactory support" ) - public void testMultipleElementAccessorOperators() throws Exception { - //TODO: broken SQL - // steve (2005.10.06) - Yes, this is all hosed ;) - assertTranslation( "select c from ContainerX c where c.oneToMany[ c.manyToMany[0].count ].name = 's'" ); - assertTranslation( "select c from ContainerX c where c.manyToMany[ c.oneToMany[0].count ].name = 's'" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Parser output mismatch" ) - public void testKeyManyToOneJoin() { - //TODO: new parser generates unnecessary joins (though the query results are correct) - assertTranslation( "from Order o left join fetch o.lineItems li left join fetch li.product p" ); - assertTranslation( "from Outer o where o.id.root.id.sup.dudu is not null" ); - assertTranslation( "from Outer o where o.id.root.id.sup.dudu is not null" ); - } - - @Test - @FailureExpected( jiraKey = "N/A", message = "Parser output mismatch" ) - public void testDuplicateExplicitJoin() throws Exception { - //very minor issue with select clause: - assertTranslation( "from Animal a join a.mother m1 join a.mother m2" ); - assertTranslation( "from Zoo zoo join zoo.animals an join zoo.mammals m" ); - assertTranslation( "from Zoo zoo join zoo.mammals an join zoo.mammals m" ); - } - - @Test - public void testIndexWithExplicitJoin() throws Exception { - //TODO: broken on dialects with theta-style outerjoins: - // steve (2005.10.06) - this works perfectly for me on Oracle8i - assertTranslation( "from Zoo zoo join zoo.animals an where zoo.mammals[ index(an) ] = an" ); - assertTranslation( "from Zoo zoo join zoo.mammals dog where zoo.mammals[ index(dog) ] = dog" ); - assertTranslation( "from Zoo zoo join zoo.mammals dog where dog = zoo.mammals[ index(dog) ]" ); - } - - @Test - public void testOneToManyMapIndex() throws Exception { - //TODO: this breaks on dialects with theta-style outerjoins: - // steve (2005.10.06) - this works perfectly for me on Oracle8i - assertTranslation( "from Zoo zoo where zoo.mammals['dog'].description like '%black%'" ); - assertTranslation( "from Zoo zoo where zoo.mammals['dog'].father.description like '%black%'" ); - assertTranslation( "from Zoo zoo where zoo.mammals['dog'].father.id = 1234" ); - assertTranslation( "from Zoo zoo where zoo.animals['1234'].description like '%black%'" ); - } - - @Test - public void testExplicitJoinMapIndex() throws Exception { - //TODO: this breaks on dialects with theta-style outerjoins: - // steve (2005.10.06) - this works perfectly for me on Oracle8i - assertTranslation( "from Zoo zoo, Dog dog where zoo.mammals['dog'] = dog" ); - assertTranslation( "from Zoo zoo join zoo.mammals dog where zoo.mammals['dog'] = dog" ); - } - - @Test - public void testIndexFunction() throws Exception { - // Instead of doing the pre-processor trick like the existing QueryTranslator, this - // is handled by MethodNode. - // steve (2005.10.06) - this works perfectly for me on Oracle8i - //TODO: broken on dialects with theta-style outerjoins: - assertTranslation( "from Zoo zoo join zoo.mammals dog where index(dog) = 'dog'" ); - assertTranslation( "from Zoo zoo join zoo.animals an where index(an) = '1234'" ); - } - - @Test - public void testSelectCollectionOfValues() throws Exception { - //TODO: broken on dialects with theta-style joins - ///old parser had a bug where the collection element was not included in return types! - // steve (2005.10.06) - this works perfectly for me on Oracle8i - assertTranslation( "select baz, date from Baz baz join baz.stringDateMap date where index(date) = 'foo'" ); - } - - @Test - public void testCollectionOfValues() throws Exception { - //old parser had a bug where the collection element was not returned! - //TODO: broken on dialects with theta-style joins - // steve (2005.10.06) - this works perfectly for me on Oracle8i - assertTranslation( "from Baz baz join baz.stringDateMap date where index(date) = 'foo'" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-719" ) - public void testHHH719() throws Exception { - assertTranslation("from Baz b order by org.bazco.SpecialFunction(b.id)"); - assertTranslation("from Baz b order by anypackage.anyFunction(b.id)"); - } - - @Test - public void testParameterListExpansion() { - assertTranslation( "from Animal as animal where animal.id in (:idList_1, :idList_2)" ); - } - - @Test - public void testComponentManyToOneDereferenceShortcut() { - assertTranslation( "from Zoo z where z.address.stateProvince.id is null" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-770" ) - public void testNestedCollectionImplicitJoins() { - assertTranslation( "select h.friends.offspring from Human h" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-557" ) - public void testExplicitJoinsInSubquery() { - assertTranslation( - "from org.hibernate.test.hql.Animal as animal " + - "where animal.id in (" + - " select a.id " + - " from org.hibernate.test.hql.Animal as a " + - " left join a.mother as mo" + - ")" - ); - } - - @Test - public void testImplicitJoinsInGroupBy() { - assertTranslation( - "select o.mother.bodyWeight, count(distinct o) " + - "from Animal an " + - " join an.offspring as o " + - "group by o.mother.bodyWeight" - ); - } - - @Test - public void testCrazyIdFieldNames() { - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - // only regress against non-scalar forms as there appears to be a bug in the classic translator - // in regards to this issue also. Specifically, it interprets the wrong return type, though it gets - // the sql "correct" :/ - - String hql = "select e.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e where e.heresAnotherCrazyIdFieldName is not null"; - assertTranslation(hql, new HashMap(), false, null); - - hql = "select e.heresAnotherCrazyIdFieldName.heresAnotherCrazyIdFieldName from MoreCrazyIdFieldNameStuffEntity e where e.heresAnotherCrazyIdFieldName is not null"; - assertTranslation(hql, new HashMap(), false, null); - - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - @Ignore( "Old parser generated incorrect SQL for `size()`") - public void testSizeFunctionAndProperty() { - assertTranslation("from Animal a where a.offspring.size > 0"); - assertTranslation("from Animal a join a.offspring where a.offspring.size > 1"); - assertTranslation("from Animal a where size(a.offspring) > 0"); - assertTranslation("from Animal a join a.offspring o where size(a.offspring) > 1"); - assertTranslation("from Animal a where size(a.offspring) > 1 and size(a.offspring) < 100"); - - assertTranslation("from Human a where a.family.size > 0"); - assertTranslation("from Human a join a.family where a.family.size > 1"); - assertTranslation("from Human a where size(a.family) > 0"); - assertTranslation("from Human a join a.family o where size(a.family) > 1"); - assertTranslation("from Human a where a.family.size > 0 and a.family.size < 100"); - } - - @Test - public void testFromOnly() throws Exception { - // 2004-06-21 [jsd] This test now works with the new AST based QueryTranslatorImpl. - assertTranslation( "from Animal" ); - assertTranslation( "from Model" ); - } - - @Test - public void testJoinPathEndingInValueCollection() { - assertTranslation( "select h from Human as h join h.nickNames as nn where h.nickName=:nn1 and (nn=:nn2 or nn=:nn3)" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-242" ) - public void testSerialJoinPathEndingInValueCollection() { - assertTranslation( "select h from Human as h join h.friends as f join f.nickNames as nn where h.nickName=:nn1 and (nn=:nn2 or nn=:nn3)" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-281" ) - public void testImplicitJoinContainedByCollectionFunction() { - assertTranslation( "from Human as h where 'shipping' in indices(h.father.addresses)" ); - assertTranslation( "from Human as h where 'shipping' in indices(h.father.father.addresses)" ); - assertTranslation( "from Human as h where 'sparky' in elements(h.father.nickNames)" ); - assertTranslation( "from Human as h where 'sparky' in elements(h.father.father.nickNames)" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-276" ) - public void testImpliedJoinInSubselectFrom() { - assertTranslation( "from Animal a where exists( from a.mother.offspring )" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-276" ) - public void testSubselectImplicitJoins() { - assertTranslation( "from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count )" ); - } - - @Test - public void testCollectionFunctions() throws Exception { - //these are both broken, a join that belongs in the subselect finds its way into the main query - assertTranslation( "from Zoo zoo where maxindex(zoo.mammals) = 'dog'" ); - } - - @Test - public void testImplicitJoinInExplicitJoin() throws Exception { - assertTranslation( "from Animal an inner join an.mother.mother gm" ); - assertTranslation( "from Animal an inner join an.mother.mother.mother ggm" ); - assertTranslation( "from Animal an inner join an.mother.mother.mother.mother gggm" ); - } - - @Test - public void testImpliedManyToManyProperty() throws Exception { - //missing a table join (SQL correct for a one-to-many, not for a many-to-many) - assertTranslation( "select c from ContainerX c where c.manyToMany[0].name = 's'" ); - } - - @Test - @Ignore( "The old parser generated incorrect SQL for selection of size functions" ) - public void testCollectionSizeSelection() throws Exception { - assertTranslation( "select size(zoo.animals) from Zoo zoo" ); - assertTranslation( "select size(baz.stringDateMap) from org.hibernate.test.legacy.Baz baz" ); - } - - @Test - public void testFetchCollectionOfValues() throws Exception { - assertTranslation( "from Baz baz left join fetch baz.stringSet" ); - } - - @Test - public void testFetchList() throws Exception { - assertTranslation( "from User u join fetch u.permissions" ); - } - - @Test - public void testCollectionFetchWithExplicitThetaJoin() { - assertTranslation( "select m from Root m1, Root m left join fetch m.details where m.name=m1.name" ); - } - - @Test - public void testListElementFunctionInWhere() throws Exception { - assertTranslation( "from User u where 'read' in elements(u.permissions)" ); - assertTranslation( "from User u where 'write' <> all elements(u.permissions)" ); - } - - @Test - public void testManyToManyMaxElementFunctionInWhere() throws Exception { - assertTranslation( "from Human human where 5 = maxelement(human.friends)" ); - } - - @Test - public void testCollectionIndexFunctionsInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 4 = maxindex(zoo.animals)" ); - assertTranslation( "from Zoo zoo where 2 = minindex(zoo.animals)" ); - } - - @Test - public void testCollectionIndicesInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 4 > some indices(zoo.animals)" ); - assertTranslation( "from Zoo zoo where 4 > all indices(zoo.animals)" ); - } - - @Test - public void testIndicesInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 4 in indices(zoo.animals)" ); - assertTranslation( "from Zoo zoo where exists indices(zoo.animals)" ); - } - - @Test - public void testCollectionElementInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 4 > some elements(zoo.animals)" ); - assertTranslation( "from Zoo zoo where 4 > all elements(zoo.animals)" ); - } - - @Test - public void testElementsInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 4 in elements(zoo.animals)" ); - assertTranslation( "from Zoo zoo where exists elements(zoo.animals)" ); - } - - @Test - public void testNull() throws Exception { - assertTranslation( "from Human h where h.nickName is null" ); - assertTranslation( "from Human h where h.nickName is not null" ); - } - - @Test - @SuppressWarnings( {"unchecked"}) - public void testSubstitutions() throws Exception { - Map replacements = buildTrueFalseReplacementMapForDialect(); - replacements.put("yes", "'Y'"); - assertTranslation( "from Human h where h.pregnant = true", replacements ); - assertTranslation( "from Human h where h.pregnant = yes", replacements ); - assertTranslation( "from Human h where h.pregnant = foo", replacements ); - } - - @Test - public void testWhere() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight > 10" ); - // 2004-06-26 [jsd] This one requires NOT GT => LE transform. - assertTranslation( "from Animal an where not an.bodyWeight > 10" ); - assertTranslation( "from Animal an where an.bodyWeight between 0 and 10" ); - assertTranslation( "from Animal an where an.bodyWeight not between 0 and 10" ); - assertTranslation( "from Animal an where sqrt(an.bodyWeight)/2 > 10" ); - // 2004-06-27 [jsd] Recognize 'is null' properly. Generate 'and' and 'or' as well. - assertTranslation( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" ); - } - - @Test - public void testEscapedQuote() throws Exception { - assertTranslation( "from Human h where h.nickName='1 ov''tha''few'"); - } - - @Test - public void testCaseWhenElse() { - assertTranslation( - "from Human h where case when h.nickName='1ovthafew' then 'Gavin' when h.nickName='turin' then 'Christian' else h.nickName end = h.name.first" - ); - } - - @Test - public void testCaseExprWhenElse() { - assertTranslation( "from Human h where case h.nickName when '1ovthafew' then 'Gavin' when 'turin' then 'Christian' else h.nickName end = h.name.first" ); - } - - @Test - @SuppressWarnings( {"ThrowableResultOfMethodCallIgnored"}) - public void testInvalidHql() throws Exception { - Exception newException = compileBadHql( "from Animal foo where an.bodyWeight > 10", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "select an.name from Animal foo", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "from Animal foo where an.verybogus > 10", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "select an.boguspropertyname from Animal foo", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "select an.name", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "from Animal an where (((an.bodyWeight > 10 and an.bodyWeight < 100)) or an.bodyWeight is null", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "from Animal an where an.bodyWeight is null where an.bodyWeight is null", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "from where name='foo'", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "from NonexistentClass where name='foo'", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "select new FOO_BOGUS_Animal(an.description, an.bodyWeight) from Animal an", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - newException = compileBadHql( "select new Animal(an.description, an.bodyWeight, 666) from Animal an", false ); - assertTrue( "Wrong exception type!", newException instanceof QuerySyntaxException ); - - } - - @Test - public void testWhereBetween() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight between 1 and 10" ); - } - - @Test - public void testConcatenation() { - if ( getDialect() instanceof MySQLDialect || getDialect() instanceof SybaseDialect - || getDialect() instanceof Sybase11Dialect - || getDialect() instanceof SybaseASE15Dialect - || getDialect() instanceof SybaseAnywhereDialect - || getDialect() instanceof SQLServerDialect - || getDialect() instanceof IngresDialect - ) { - // SybaseASE15Dialect and SybaseAnywhereDialect support '||' - // MySQL uses concat(x, y, z) - // SQL Server replaces '||' with '+' - // - // this is syntax checked in {@link ASTParserLoadingTest#testConcatenation} - // Ingres supports both "||" and '+' but IngresDialect originally - // uses '+' operator; updated Ingres9Dialect to use "||". - return; - } - assertTranslation("from Human h where h.nickName = '1' || 'ov' || 'tha' || 'few'" ); - } - - @Test - public void testWhereLike() throws Exception { - assertTranslation( "from Animal a where a.description like '%black%'" ); - assertTranslation( "from Animal an where an.description like '%fat%'" ); - assertTranslation( "from Animal an where lower(an.description) like '%fat%'" ); - } - - @Test - public void testWhereIn() throws Exception { - assertTranslation( "from Animal an where an.description in ('fat', 'skinny')" ); - } - - @Test - public void testLiteralInFunction() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight > abs(5)" ); - assertTranslation( "from Animal an where an.bodyWeight > abs(-5)" ); - } - - @SuppressWarnings( {"unchecked"}) - @Test - public void testExpressionInFunction() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight > abs(3-5)" ); - assertTranslation( "from Animal an where an.bodyWeight > abs(3/5)" ); - assertTranslation( "from Animal an where an.bodyWeight > abs(3+5)" ); - assertTranslation( "from Animal an where an.bodyWeight > abs(3*5)" ); - SQLFunction concat = sessionFactory().getSqlFunctionRegistry().findSQLFunction( "concat" ); - List list = new ArrayList(); - list.add( "'fat'" ); - list.add( "'skinny'" ); - assertTranslation( - "from Animal an where an.description = " + - concat.render( StringType.INSTANCE, list, sessionFactory() ) - ); - } - - @Test - public void testNotOrWhereClause() { - assertTranslation( "from Simple s where 'foo'='bar' or not 'foo'='foo'" ); - assertTranslation( "from Simple s where 'foo'='bar' or not ('foo'='foo')" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' or 'foo'='foo' )" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' and 'foo'='foo' )" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' and 'foo'='foo' ) or not ('x'='y')" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' or 'foo'='foo' ) and not ('x'='y')" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' or 'foo'='foo' ) and 'x'='y'" ); - assertTranslation( "from Simple s where not ( 'foo'='bar' and 'foo'='foo' ) or 'x'='y'" ); - assertTranslation( "from Simple s where 'foo'='bar' and 'foo'='foo' or not 'x'='y'" ); - assertTranslation( "from Simple s where 'foo'='bar' or 'foo'='foo' and not 'x'='y'" ); - assertTranslation( "from Simple s where ('foo'='bar' and 'foo'='foo') or 'x'='y'" ); - assertTranslation( "from Simple s where ('foo'='bar' or 'foo'='foo') and 'x'='y'" ); - assertTranslation( "from Simple s where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )" ); - } - - @Test - public void testComplexExpressionInFunction() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight > abs((3-5)/4)" ); - } - - @Test - public void testStandardFunctions() throws Exception { - assertTranslation( "from Animal where current_date = current_time" ); - assertTranslation( "from Animal a where upper(a.description) = 'FAT'" ); - assertTranslation( "select lower(a.description) from Animal a" ); - } - - @Test - public void testOrderBy() throws Exception { - assertTranslation( "from Animal an order by an.bodyWeight" ); - assertTranslation( "from Animal an order by an.bodyWeight asc" ); - assertTranslation( "from Animal an order by an.bodyWeight desc" ); - assertTranslation( "from Animal an order by sqrt(an.bodyWeight*4)/2" ); - assertTranslation( "from Animal an order by an.mother.bodyWeight" ); - assertTranslation( "from Animal an order by an.bodyWeight, an.description" ); - assertTranslation( "from Animal an order by an.bodyWeight asc, an.description desc" ); - if ( getDialect() instanceof HSQLDialect || getDialect() instanceof DB2Dialect ) { - assertTranslation( "from Human h order by sqrt(h.bodyWeight), year(h.birthdate)" ); - } - } - - @Test - public void testGroupByFunction() { - disableOmittingJoinOfSuperclassTables(); - - if ( getDialect() instanceof Oracle8iDialect ) return; // the new hiearchy... - if ( getDialect() instanceof PostgreSQLDialect || getDialect() instanceof PostgreSQL81Dialect ) return; - if ( getDialect() instanceof CockroachDB192Dialect ) return; - if ( getDialect() instanceof TeradataDialect) return; - if ( ! H2Dialect.class.isInstance( getDialect() ) ) { - // H2 has no year function - assertTranslation( "select count(*) from Human h group by year(h.birthdate)" ); - assertTranslation( "select count(*) from Human h group by year(sysdate)" ); - } - assertTranslation( "select count(*) from Human h group by trunc( sqrt(h.bodyWeight*4)/2 )" ); - } - - @Test - public void testPolymorphism() throws Exception { - Map replacements = buildTrueFalseReplacementMapForDialect(); - assertTranslation( "from Mammal" ); - assertTranslation( "from Dog" ); - assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements ); - assertTranslation( "from Dog d where d.pregnant = false and d.bodyWeight > 10", replacements ); - } - - private Map buildTrueFalseReplacementMapForDialect() { - HashMap replacements = new HashMap(); - try { - String dialectTrueRepresentation = getDialect().toBooleanValueString( true ); - // if this call succeeds, then the dialect is saying to represent true/false as int values... - Integer.parseInt( dialectTrueRepresentation ); - replacements.put( "true", "1" ); - replacements.put( "false", "0" ); - } - catch( NumberFormatException nfe ) { - // the Integer#parseInt call failed... - } - return replacements; - } - - @Test - public void testTokenReplacement() throws Exception { - Map replacements = buildTrueFalseReplacementMapForDialect(); - assertTranslation( "from Mammal m where m.pregnant = false and m.bodyWeight > 10", replacements ); - } - - @Test - public void testProduct() throws Exception { - Map replacements = buildTrueFalseReplacementMapForDialect(); - assertTranslation( "from Animal, Animal" ); - assertTranslation( "from Animal x, Animal y where x.bodyWeight = y.bodyWeight" ); - assertTranslation( "from Animal x, Mammal y where x.bodyWeight = y.bodyWeight and not y.pregnant = true", replacements ); - assertTranslation( "from Mammal, Mammal" ); - } - - @Test - public void testJoinedSubclassProduct() throws Exception { - assertTranslation( "from PettingZoo, PettingZoo" ); //product of two subclasses - } - - @Test - public void testProjectProduct() throws Exception { - assertTranslation( "select x from Human x, Human y where x.nickName = y.nickName" ); - assertTranslation( "select x, y from Human x, Human y where x.nickName = y.nickName" ); - } - - @Test - public void testExplicitEntityJoins() throws Exception { - assertTranslation( "from Animal an inner join an.mother mo" ); - assertTranslation( "from Animal an left outer join an.mother mo" ); - assertTranslation( "from Animal an left outer join fetch an.mother" ); - } - - @Test - public void testMultipleExplicitEntityJoins() throws Exception { - assertTranslation( "from Animal an inner join an.mother mo inner join mo.mother gm" ); - assertTranslation( "from Animal an left outer join an.mother mo left outer join mo.mother gm" ); - assertTranslation( "from Animal an inner join an.mother m inner join an.father f" ); - assertTranslation( "from Animal an left join fetch an.mother m left join fetch an.father f" ); - } - - @Test - public void testMultipleExplicitJoins() throws Exception { - assertTranslation( "from Animal an inner join an.mother mo inner join an.offspring os" ); - assertTranslation( "from Animal an left outer join an.mother mo left outer join an.offspring os" ); - } - - @Test - public void testExplicitEntityJoinsWithRestriction() throws Exception { - assertTranslation( "from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - } - - @Test - public void testIdProperty() throws Exception { - assertTranslation( "from Animal a where a.mother.id = 12" ); - } - - @Test - public void testSubclassAssociation() throws Exception { - assertTranslation( "from DomesticAnimal da join da.owner o where o.nickName = 'Gavin'" ); - assertTranslation( "from DomesticAnimal da left join fetch da.owner" ); - assertTranslation( "from Human h join h.pets p where p.pregnant = 1" ); - assertTranslation( "from Human h join h.pets p where p.bodyWeight > 100" ); - assertTranslation( "from Human h left join fetch h.pets" ); - } - - @Test - public void testExplicitCollectionJoins() throws Exception { - assertTranslation( "from Animal an inner join an.offspring os" ); - assertTranslation( "from Animal an left outer join an.offspring os" ); - } - - @Test - public void testExplicitOuterJoinFetch() throws Exception { - assertTranslation( "from Animal an left outer join fetch an.offspring" ); - } - - @Test - public void testExplicitOuterJoinFetchWithSelect() throws Exception { - assertTranslation( "select an from Animal an left outer join fetch an.offspring" ); - } - - @Test - public void testExplicitJoins() throws Exception { - Map replacements = buildTrueFalseReplacementMapForDialect(); - assertTranslation( "from Zoo zoo join zoo.mammals mam where mam.pregnant = true and mam.description like '%white%'", replacements ); - assertTranslation( "from Zoo zoo join zoo.animals an where an.description like '%white%'" ); - } - - @Test - @TestForIssue( jiraKey = "HHH-559" ) - public void testMultibyteCharacterConstant() throws Exception { - assertTranslation( "from Zoo zoo join zoo.animals an where an.description like '%\u4e2d%'" ); - } - - @Test - public void testImplicitJoins() throws Exception { - // Two dots... - assertTranslation( "from Animal an where an.mother.bodyWeight > ?1" ); - assertTranslation( "from Animal an where an.mother.bodyWeight > 10" ); - assertTranslation( "from Dog dog where dog.mother.bodyWeight > 10" ); - // Three dots... - assertTranslation( "from Animal an where an.mother.mother.bodyWeight > 10" ); - // The new QT doesn't throw an exception here, so this belongs in ASTQueryTranslator test. [jsd] -// assertTranslation( "from Animal an where an.offspring.mother.bodyWeight > 10" ); - // Is not null (unary postfix operator) - assertTranslation( "from Animal an where an.mother is not null" ); - // ID property shortut (no implicit join) - assertTranslation( "from Animal an where an.mother.id = 123" ); - } - - @Test - public void testImplicitJoinInSelect() { - assertTranslation( "select foo, foo.long from Foo foo" ); - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("select foo.foo from Foo foo"); - assertTranslation("select foo, foo.foo from Foo foo"); - assertTranslation("select foo.foo from Foo foo where foo.foo is not null"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - public void testSelectExpressions() { - disableOmittingJoinOfSuperclassTables(); - - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("select an.mother.mother from Animal an"); - assertTranslation("select an.mother.mother.mother from Animal an"); - assertTranslation("select an.mother.mother.bodyWeight from Animal an"); - assertTranslation("select an.mother.zoo.id from Animal an"); - assertTranslation("select user.human.zoo.id from User user"); - assertTranslation("select u.userName, u.human.name.first from User u"); - assertTranslation("select u.human.name.last, u.human.name.first from User u"); - assertTranslation("select bar.baz.name from Bar bar"); - assertTranslation("select bar.baz.name, bar.baz.count from Bar bar"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - @SkipForDialect(CockroachDialect.class) - public void testSelectStandardFunctionsNoParens() throws Exception { - assertTranslation( "select current_date, current_time, current_timestamp from Animal" ); - } - - @Test - public void testMapIndex() throws Exception { - assertTranslation( "from User u where u.permissions['hibernate']='read'" ); - } - - @Test - public void testNamedParameters() throws Exception { - assertTranslation( "from Animal an where an.mother.bodyWeight > :weight" ); - } - - @Test - @SkipForDialect( Oracle8iDialect.class ) - public void testClassProperty() throws Exception { - assertTranslation( "from Animal a where a.mother.class = Reptile" ); - } - - @Test - public void testComponent() throws Exception { - assertTranslation( "from Human h where h.name.first = 'Gavin'" ); - } - - @Test - public void testSelectEntity() throws Exception { - assertTranslation( "select an from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - assertTranslation( "select mo, an from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - } - - @Test - public void testValueAggregate() { - assertTranslation( "select max(p), min(p) from User u join u.permissions p" ); - } - - @Test - public void testAggregation() throws Exception { - assertTranslation( "select count(an) from Animal an" ); - assertTranslation( "select count(*) from Animal an" ); - assertTranslation( "select count(distinct an) from Animal an" ); - assertTranslation( "select count(distinct an.id) from Animal an" ); - assertTranslation( "select count(all an.id) from Animal an" ); - } - - @Test - public void testSelectProperty() throws Exception { - assertTranslation( "select an.bodyWeight, mo.bodyWeight from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - } - - @Test - public void testSelectEntityProperty() throws Exception { - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("select an.mother from Animal an"); - assertTranslation("select an, an.mother from Animal an"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - public void testSelectDistinctAll() throws Exception { - assertTranslation( "select distinct an.description, an.bodyWeight from Animal an" ); - assertTranslation( "select all an from Animal an" ); - } - - @Test - public void testSelectAssociatedEntityId() throws Exception { - assertTranslation( "select an.mother.id from Animal an" ); - } - - @Test - public void testGroupBy() throws Exception { - assertTranslation( "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id" ); - assertTranslation( "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id having max(an.bodyWeight)>1.0" ); - } - - @Test - public void testGroupByMultiple() throws Exception { - assertTranslation( "select s.id, s.count, count(t), max(t.date) from org.hibernate.test.legacy.Simple s, org.hibernate.test.legacy.Simple t where s.count = t.count group by s.id, s.count order by s.count" ); - } - - @Test - public void testManyToMany() throws Exception { - assertTranslation( "from Human h join h.friends f where f.nickName = 'Gavin'" ); - assertTranslation( "from Human h join h.friends f where f.bodyWeight > 100" ); - } - - @Test - public void testManyToManyElementFunctionInWhere() throws Exception { - assertTranslation( "from Human human where human in elements(human.friends)" ); - assertTranslation( "from Human human where human = some elements(human.friends)" ); - } - - @Test - public void testManyToManyElementFunctionInWhere2() throws Exception { - assertTranslation( "from Human h1, Human h2 where h2 in elements(h1.family)" ); - assertTranslation( "from Human h1, Human h2 where 'father' in indices(h1.family)" ); - } - - @Test - public void testManyToManyFetch() throws Exception { - assertTranslation( "from Human h left join fetch h.friends" ); - } - - @Test - public void testManyToManyIndexAccessor() throws Exception { - assertTranslation( "select c from ContainerX c, Simple s where c.manyToMany[2] = s" ); - assertTranslation( "select s from ContainerX c, Simple s where c.manyToMany[2] = s" ); - assertTranslation( "from ContainerX c, Simple s where c.manyToMany[2] = s" ); - } - - @Test - public void testSelectNew() throws Exception { - assertTranslation( "select new Animal(an.description, an.bodyWeight) from Animal an" ); - assertTranslation( "select new org.hibernate.test.hql.Animal(an.description, an.bodyWeight) from Animal an" ); - } - - @Test - public void testSimpleCorrelatedSubselect() throws Exception { - assertTranslation( "from Animal a where a.bodyWeight = (select o.bodyWeight from a.offspring o)" ); - assertTranslation( "from Animal a where a = (from a.offspring o)" ); - } - - @Test - public void testSimpleUncorrelatedSubselect() throws Exception { - assertTranslation( "from Animal a where a.bodyWeight = (select an.bodyWeight from Animal an)" ); - assertTranslation( "from Animal a where a = (from Animal an)" ); - } - - @Test - public void testSimpleCorrelatedSubselect2() throws Exception { - assertTranslation( "from Animal a where a = (select o from a.offspring o)" ); - assertTranslation( "from Animal a where a in (select o from a.offspring o)" ); - } - - @Test - public void testSimpleUncorrelatedSubselect2() throws Exception { - assertTranslation( "from Animal a where a = (select an from Animal an)" ); - assertTranslation( "from Animal a where a in (select an from Animal an)" ); - } - - @Test - public void testUncorrelatedSubselect2() throws Exception { - assertTranslation( "from Animal a where a.bodyWeight = (select max(an.bodyWeight) from Animal an)" ); - } - - @Test - public void testCorrelatedSubselect2() throws Exception { - assertTranslation( "from Animal a where a.bodyWeight > (select max(o.bodyWeight) from a.offspring o)" ); - } - - @Test - public void testManyToManyJoinInSubselect() throws Exception { - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("select foo from Foo foo where foo in (select elt from Baz baz join baz.fooArray elt)"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - public void testImplicitJoinInSubselect() throws Exception { - assertTranslation( "from Animal a where a = (select an.mother from Animal an)" ); - assertTranslation( "from Animal a where a.id = (select an.mother.id from Animal an)" ); - } - - @Test - public void testManyToOneSubselect() { - //TODO: the join in the subselect also shows up in the outer query! - assertTranslation( "from Animal a where 'foo' in (select m.description from a.mother m)" ); - } - - @Test - public void testPositionalParameters() throws Exception { - assertTranslation( "from Animal an where an.bodyWeight > ?1" ); - } - - @Test - public void testKeywordPropertyName() throws Exception { - assertTranslation( "from Glarch g order by g.order asc" ); - assertTranslation( "select g.order from Glarch g where g.order = 3" ); - } - - @Test - public void testJavaConstant() throws Exception { - assertTranslation( "from org.hibernate.test.legacy.Category c where c.name = org.hibernate.test.legacy.Category.ROOT_CATEGORY" ); - assertTranslation( "from org.hibernate.test.legacy.Category c where c.id = org.hibernate.test.legacy.Category.ROOT_ID" ); - // todo : additional desired functionality - //assertTranslation( "from Category c where c.name = Category.ROOT_CATEGORY" ); - //assertTranslation( "select c.name, Category.ROOT_ID from Category as c"); - } - - @Test - public void testClassName() throws Exception { - // The Zoo reference is OK; Zoo is discriminator-based; - // the old parser could handle these correctly - // - // However, the Animal one ares not; Animal is joined subclassing; - // the old parser does not handle thee correctly. The new parser - // previously did not handle them correctly in that same way. So they - // used to pass regression even though the output was bogus SQL... - // - // I have moved the Animal ones (plus duplicating the Zoo one) - // to ASTParserLoadingTest for syntax checking. - assertTranslation( "from Zoo zoo where zoo.class = PettingZoo" ); -// assertTranslation( "from DomesticAnimal an where an.class = Dog" ); -// assertTranslation( "from Animal an where an.class = Dog" ); - } - - @Test - public void testSelectDialectFunction() throws Exception { - disableOmittingJoinOfSuperclassTables(); - - // From SQLFunctionsTest.testDialectSQLFunctions... - if ( getDialect() instanceof HSQLDialect ) { - assertTranslation( "select mod(s.count, 2) from org.hibernate.test.legacy.Simple as s where s.id = 10" ); - //assertTranslation( "from org.hibernate.test.legacy.Simple as s where mod(s.count, 2) = 0" ); - } - assertTranslation( "select upper(human.name.first) from Human human" ); - assertTranslation( "from Human human where lower(human.name.first) like 'gav%'" ); - assertTranslation( "select upper(a.description) from Animal a" ); - assertTranslation( "select max(a.bodyWeight) from Animal a" ); - } - - @Test - public void testTwoJoins() throws Exception { - assertTranslation( "from Human human join human.friends, Human h join h.mother" ); - assertTranslation( "from Human human join human.friends f, Animal an join an.mother m where f=m" ); - assertTranslation( "from Baz baz left join baz.fooToGlarch, Bar bar join bar.foo" ); - } - - @Test - public void testToOneToManyManyJoinSequence() throws Exception { - assertTranslation( "from Dog d join d.owner h join h.friends f where f.name.first like 'joe%'" ); - } - - @Test - public void testToOneToManyJoinSequence() throws Exception { - assertTranslation( "from Animal a join a.mother m join m.offspring" ); - assertTranslation( "from Dog d join d.owner m join m.offspring" ); - assertTranslation( "from Animal a join a.mother m join m.offspring o where o.bodyWeight > a.bodyWeight" ); - } - - @Test - public void testSubclassExplicitJoin() throws Exception { - assertTranslation( "from DomesticAnimal da join da.owner o where o.nickName = 'gavin'" ); - assertTranslation( "from DomesticAnimal da join da.owner o where o.bodyWeight > 0" ); - } - - @Test - public void testMultipleExplicitCollectionJoins() throws Exception { - assertTranslation( "from Animal an inner join an.offspring os join os.offspring gc" ); - assertTranslation( "from Animal an left outer join an.offspring os left outer join os.offspring gc" ); - } - - @Test - public void testSelectDistinctComposite() throws Exception { - // This is from CompositeElementTest.testHandSQL. - assertTranslation( "select distinct p from org.hibernate.test.compositeelement.Parent p join p.children c where c.name like 'Child%'" ); - } - - @Test - public void testDotComponent() throws Exception { - // from FumTest.testListIdentifiers() - assertTranslation( "select fum.id from org.hibernate.test.legacy.Fum as fum where not fum.fum='FRIEND'" ); - } - - @Test - public void testOrderByCount() throws Exception { - assertTranslation( "from Animal an group by an.zoo.id order by an.zoo.id, count(*)" ); - } - - @Test - public void testHavingCount() throws Exception { - assertTranslation( "from Animal an group by an.zoo.id having count(an.zoo.id) > 1" ); - } - - @Test - public void selectWhereElements() throws Exception { - assertTranslation( "select foo from Foo foo, Baz baz where foo in elements(baz.fooArray)" ); - } - - @Test - public void testCollectionOfComponents() throws Exception { - assertTranslation( "from Baz baz inner join baz.components comp where comp.name='foo'" ); - } - - @Test - public void testNestedComponentIsNull() { - // From MapTest... - assertTranslation( "from Commento c where c.marelo.commento.mcompr is null" ); - } - - @Test - public void testOneToOneJoinedFetch() throws Exception { - // From OneToOneTest.testOneToOneOnSubclass - assertTranslation( "from org.hibernate.orm.test.onetoone.joined.Person p join fetch p.address left join fetch p.mailingAddress" ); - } - - @Test - public void testSubclassImplicitJoin() throws Exception { - assertTranslation( "from DomesticAnimal da where da.owner.nickName like 'Gavin%'" ); - assertTranslation( "from DomesticAnimal da where da.owner.nickName = 'gavin'" ); - assertTranslation( "from DomesticAnimal da where da.owner.bodyWeight > 0" ); - } - - @Test - public void testComponent2() throws Exception { - assertTranslation( "from Dog dog where dog.owner.name.first = 'Gavin'" ); - } - - @Test - public void testOneToOne() throws Exception { - disableOmittingJoinOfSuperclassTables(); - - assertTranslation( "from User u where u.human.nickName='Steve'" ); - assertTranslation( "from User u where u.human.name.first='Steve'" ); - } - - @Test - public void testSelectClauseImplicitJoin() throws Exception { - disableOmittingJoinOfSuperclassTables(); - - //assertTranslation( "select d.owner.mother from Dog d" ); //bug in old qt - assertTranslation( "select d.owner.mother.description from Dog d" ); - //assertTranslation( "select d.owner.mother from Dog d, Dog h" ); - } - - @Test - public void testFromClauseImplicitJoin() throws Exception { - assertTranslation( "from DomesticAnimal da join da.owner.mother m where m.bodyWeight > 10" ); - } - - @Test - public void testJoinedSubclassWithOrCondition() { - assertTranslation( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" ); - } - - @Test - public void testImplicitJoinInFrom() { - assertTranslation( "from Human h join h.mother.mother.offspring o" ); - } - - @Test - @SkipForDialect( Oracle8iDialect.class ) - public void testDuplicateImplicitJoinInSelect() { - // This test causes failures on theta-join dialects because the SQL is different. The old parser - // duplicates the condition, whereas the new parser does not. The queries are semantically the - // same however. - -// the classic translator handles this incorrectly; the explicit join and the implicit ones should create separate physical SQL joins... -// assertTranslation( "select an.mother.bodyWeight from Animal an join an.mother m where an.mother.bodyWeight > 10" ); - assertTranslation( "select an.mother.bodyWeight from Animal an where an.mother.bodyWeight > 10" ); - //assertTranslation("select an.mother from Animal an where an.mother.bodyWeight is not null"); - assertTranslation( "select an.mother.bodyWeight from Animal an order by an.mother.bodyWeight" ); - } - - @Test - public void testConstructorNode() throws Exception { - ConstructorNode n = new ConstructorNode(); - assertNull( n.getFromElement() ); - assertFalse( n.isReturnableEntity() ); - } - - @Test - public void testIndexNode() throws Exception { - IndexNode n = new IndexNode(); - Exception ex = null; - try { - n.setScalarColumn( 0 ); - } - catch ( UnsupportedOperationException e ) { - ex = e; - } - assertNotNull( ex ); - } - - @Test - public void testExceptions() throws Exception { - DetailedSemanticException dse = new DetailedSemanticException( "test" ); - dse.printStackTrace(); - dse.printStackTrace( new PrintWriter( new StringWriter() ) ); - QuerySyntaxException qse = QuerySyntaxException.convert( new RecognitionException( "test" ), "from bozo b where b.clown = true" ); - assertNotNull( qse.getMessage() ); - } - - @Test - public void testSelectProperty2() throws Exception { - assertTranslation( "select an, mo.bodyWeight from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - assertTranslation( "select an, mo, an.bodyWeight, mo.bodyWeight from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); - } - - @Test - public void testSubclassWhere() throws Exception { - // TODO: The classic QT generates lots of extra parens, etc. - assertTranslation( "from PettingZoo pz1, PettingZoo pz2 where pz1.id = pz2.id" ); - assertTranslation( "from PettingZoo pz1, PettingZoo pz2 where pz1.id = pz2" ); - assertTranslation( "from PettingZoo pz where pz.id > 0 " ); - } - - @Test - public void testNestedImplicitJoinsInSelect() throws Exception { - // NOTE: This test is not likely to generate the exact SQL because of the where clause. The synthetic - // theta style joins come out differently in the new QT. - // From FooBarTest.testQuery() - // Missing the foo2_ join, and foo3_ should include subclasses, but it doesn't. -// assertTranslation("select foo.foo.foo.foo.string from org.hibernate.test.legacy.Foo foo where foo.foo.foo = 'bar'"); - assertTranslation( "select foo.foo.foo.foo.string from org.hibernate.test.legacy.Foo foo" ); - } - - @Test - public void testNestedComponent() throws Exception { - // From FooBarTest.testQuery() - //an extra set of parens in new SQL - assertTranslation( "from org.hibernate.test.legacy.Foo foo where foo.component.subcomponent.name='bar'" ); - } - - @Test - public void testNull2() throws Exception { - //old parser generates useless extra parens - assertTranslation( "from Human h where not( h.nickName is null )" ); - assertTranslation( "from Human h where not( h.nickName is not null )" ); - } - - @Test - public void testUnknownFailureFromMultiTableTest() { - assertTranslation( "from Lower s where s.yetanother.name='name'" ); - } - - @Test - public void testJoinInSubselect() throws Exception { - //new parser uses ANSI-style inner join syntax - boolean originalValue = DotNode.useThetaStyleImplicitJoins; - try { - DotNode.useThetaStyleImplicitJoins = true; - assertTranslation("from Animal a where a in (select m from Animal an join an.mother m)"); - assertTranslation("from Animal a where a in (select o from Animal an join an.offspring o)"); - } finally { - DotNode.useThetaStyleImplicitJoins = originalValue; - } - } - - @Test - public void testJoinedSubclassImplicitJoin() throws Exception { - // From MultiTableTest.testQueries() - // TODO: This produces the proper from clause now, but the parens in the where clause are different. - assertTranslation( "from org.hibernate.test.legacy.Lower s where s.yetanother.name='name'" ); - } - - @Test - public void testProjectProductJoinedSubclass() throws Exception { - // TODO: The old QT generates the discriminator and the theta join in a strange order, and with two extra sets of parens, this is okay, right? - assertTranslation( "select zoo from Zoo zoo, PettingZoo pz where zoo=pz" ); - assertTranslation( "select zoo, pz from Zoo zoo, PettingZoo pz where zoo=pz" ); - } - - @Test - public void testCorrelatedSubselect1() throws Exception { - // The old translator generates the theta join before the condition in the sub query. - // TODO: Decide if we want to bother generating the theta join in the same order (non simple). - assertTranslation( "from Animal a where exists (from a.offspring o where o.bodyWeight>10)" ); - } - - @Test - public void testOuterAliasInSubselect() { - assertTranslation( "from Human h where h = (from Animal an where an = h)" ); - } - - @Test - public void testFetch() throws Exception { - assertTranslation( "from Zoo zoo left join zoo.mammals" ); - assertTranslation( "from Zoo zoo left join fetch zoo.mammals" ); - } - - @Test - public void testOneToManyElementFunctionInWhere() throws Exception { - assertTranslation( "from Zoo zoo where 'dog' in indices(zoo.mammals)" ); - assertTranslation( "from Zoo zoo, Dog dog where dog in elements(zoo.mammals)" ); - } - - @Test - public void testManyToManyInJoin() throws Exception { - disableOmittingJoinOfSuperclassTables(); - - assertTranslation( "select x.id from Human h1 join h1.family x" ); - //assertTranslation("select index(h2) from Human h1 join h1.family h2"); - } - - @Test - public void testManyToManyInSubselect() throws Exception { - disableOmittingJoinOfSuperclassTables(); - - assertTranslation( "from Human h1, Human h2 where h2 in (select x.id from h1.family x)" ); - assertTranslation( "from Human h1, Human h2 where 'father' in indices(h1.family)" ); - } - - @Test - public void testOneToManyIndexAccess() throws Exception { - assertTranslation( "from Zoo zoo where zoo.mammals['dog'] is not null" ); - } - - @Test - public void testImpliedSelect() throws Exception { - assertTranslation( "select zoo from Zoo zoo" ); - assertTranslation( "from Zoo zoo" ); - assertTranslation( "from Zoo zoo join zoo.mammals m" ); - assertTranslation( "from Zoo" ); - assertTranslation( "from Zoo zoo join zoo.mammals" ); - } - - @Test - public void testVectorSubselect() { - assertTranslation( "from Animal a where ('foo', 'bar') in (select m.description, m.bodyWeight from a.mother m)" ); - } - - @Test - public void testWierdSubselectImplicitJoinStuff() { - //note that the new qt used to eliminate unnecessary join, but no more - assertTranslation("from Simple s where s = some( select sim from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0"); - } - - @Test - public void testCollectionsInSelect2() throws Exception { - // This one looks okay now, it just generates extra parens in the where clause. - assertTranslation( "select foo.string from Bar bar left join bar.baz.fooArray foo where bar.string = foo.string" ); - } - - @Test - public void testAssociationPropertyWithoutAlias() throws Exception { - // The classic translator doesn't do this right, so don't bother asserting. - compileWithAstQueryTranslator( "from Animal where zoo is null", false ); - } - - private void compileWithAstQueryTranslator(String hql, boolean scalar) { - Map replacements = new HashMap(); - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - SessionFactoryImplementor factory = getSessionFactoryImplementor(); - QueryTranslator newQueryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory, null ); - newQueryTranslator.compile( replacements, scalar ); - } - - @Test - public void testComponentNoAlias() throws Exception { - // The classic translator doesn't do this right, so don't bother asserting. - compileWithAstQueryTranslator( "from Human where name.first = 'Gavin'", false ); - } - - private void disableOmittingJoinOfSuperclassTables() { - // Disable this feature because of Lacking ClassicQueryTranslatorFactory support - rebuildSessionFactory( c -> c.setProperty( - AvailableSettings.OMIT_JOIN_OF_SUPERCLASS_TABLES, - Boolean.FALSE.toString() - ) ); - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HibernateFirstResultMaxResultsTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/HibernateFirstResultMaxResultsTest.java deleted file mode 100644 index 4123cd7f20..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HibernateFirstResultMaxResultsTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; - -import java.util.List; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; - -import org.hibernate.query.Query; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * @author Gail Badner - */ -@TestForIssue( jiraKey = "HHH-12729") -public class HibernateFirstResultMaxResultsTest extends BaseNonConfigCoreFunctionalTestCase { - - protected Class[] getAnnotatedClasses() { - return new Class[] { Employee.class }; - } - - @Test - public void testFirstResult() { - doInHibernate( - this::sessionFactory, - session -> { - - Query query = session.createQuery( "from Employee" ); - - // not initialized yet - assertNull( query.getHibernateFirstResult() ); - - // the following is special case; when initialized to -1, getHibernateFirstResult returns 0 - assertEquals( 0 , query.setFirstResult( -1 ).getFirstResult() ); - - assertEquals( Integer.valueOf( 0 ), query.setFirstResult( 0 ).getHibernateFirstResult() ); - assertEquals( Integer.valueOf( 1 ), query.setFirstResult( 1 ).getHibernateFirstResult() ); - - assertEquals( Integer.valueOf( 10 ), query.setFirstResult( 10 ).getHibernateFirstResult() ); - } - ); - } - - @Test - public void testMaxResults() { - doInHibernate( - this::sessionFactory, - session -> { - - Query query = session.createQuery( "from Employee" ); - - // not initialized yet - assertNull( query.getHibernateMaxResults() ); - - // values <= 0 are considered uninitialized; - assertNull( query.setHibernateMaxResults( -1 ).getHibernateMaxResults() ); - assertNull( query.setHibernateMaxResults( 0 ).getHibernateMaxResults() ); - - assertEquals( Integer.valueOf( 1 ), query.setHibernateMaxResults( 1 ).getHibernateMaxResults() ); - - assertEquals( Integer.valueOf( 0 ), query.setMaxResults( 0 ).getHibernateMaxResults() ); - - assertEquals( Integer.valueOf( 2 ), query.setMaxResults( 2 ).getHibernateMaxResults() ); - } - ); - } - - @Test - public void testPagination() { - doInHibernate( - this::sessionFactory, - session -> { - for ( int i = 0; i < 5; i++ ) { - session.persist( new Employee( i ) ); - } - } - ); - - final String query = "from Employee order by id"; - checkResults( executeQuery( query, null, null ), 0, 4 ); - checkResults( executeQuery( query, 0, null ), 0, 4 ); - checkResults( executeQuery( query, -1, null ), 0, 4 ); - checkResults( executeQuery( query, null, 0 ), 0, 4 ); - checkResults( executeQuery( query, null, -1 ), 0, 4 ); - checkResults( executeQuery( query, null, 2 ), 0, 1 ); - checkResults( executeQuery( query, -1, 0 ), 0, 4 ); - checkResults( executeQuery( query, -1, 3 ), 0, 2 ); - checkResults( executeQuery( query, 1, null ), 1, 4 ); - checkResults( executeQuery( query, 1, 0 ), 1, 4 ); - checkResults( executeQuery( query, 1, -1 ), 1, 4 ); - checkResults( executeQuery( query, 1, 1 ), 1, 1 ); - } - - public List executeQuery(String queryString, Integer firstResult, Integer maxResults) { - return doInHibernate( - this::sessionFactory, - session -> { - Query query = session.createQuery( queryString ); - if ( firstResult != null ) { - query.setHibernateFirstResult( firstResult ); - } - if ( maxResults != null ) { - query.setHibernateMaxResults( maxResults ); - } - return query.list(); - } - ); - } - - private void checkResults( List results, int firstIdExpected, int lastIdExpected ) { - int resultIndex = 0; - for( int i = firstIdExpected ; i <= lastIdExpected ; i++, resultIndex++ ) { - assertEquals( i, ( (Employee) results.get( resultIndex ) ).id ); - } - } - - @Entity(name = "Employee") - public static class Employee { - @Id - private long id; - - private String name; - - public Employee() { - } - - public Employee(long id) { - this.id = id; - } - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HqlParserTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/HqlParserTest.java deleted file mode 100644 index ff92dc0f9e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/HqlParserTest.java +++ /dev/null @@ -1,1119 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ - -// $Id: HqlParserTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ -package org.hibernate.test.hql; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Stack; - -import org.hibernate.hql.internal.antlr.HqlTokenTypes; -import org.hibernate.hql.internal.ast.HqlParser; -import org.hibernate.hql.internal.ast.tree.Node; -import org.hibernate.hql.internal.ast.util.ASTIterator; -import org.hibernate.hql.internal.ast.util.ASTPrinter; - -import org.junit.Test; - -import antlr.RecognitionException; -import antlr.TokenStreamException; -import antlr.collections.AST; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * Tests the HQL parser on various inputs, just makes sure that the first phase of the parser - * works properly (i.e. no unexpected syntax errors). - * todo this should be a unit test. - */ -public class HqlParserTest { - - /** - * Section 9.2 - from * - */ - @Test public void testDocoExamples92() throws Exception { - parse( "from eg.Cat" ); - parse( "from eg.Cat as cat" ); - parse( "from eg.Cat cat" ); - parse( "from Formula, Parameter" ); - parse( "from Formula as form, Parameter as param" ); - } - - /** - * Section 9.3 - Associations and joins * - */ - @Test public void testDocoExamples93() throws Exception { - parse( "from eg.Cat as cat inner join cat.mate as mate left outer join cat.kittens as kitten" ); - parse( "from eg.Cat as cat left join cat.mate.kittens as kittens" ); - parse( "from Formula form full join form.parameter param" ); - parse( "from eg.Cat as cat join cat.mate as mate left join cat.kittens as kitten" ); - parse( "from eg.Cat as cat\ninner join fetch cat.mate\nleft join fetch cat.kittens" ); - } - - /** - * Section 9.4 - Select * - */ - @Test public void testDocoExamples94() throws Exception { - parse( "select mate from eg.Cat as cat inner join cat.mate as mate" ); - parse( "select cat.mate from eg.Cat cat" ); - parse( "select elements(cat.kittens) from eg.Cat cat" ); - parse( "select cat.name from eg.DomesticCat cat where cat.name like 'fri%'" ); - parse( "select cust.name.firstName from Customer as cust" ); - parse( "select mother, offspr, mate.name from eg.DomesticCat\n" - + " as mother inner join mother.mate as mate left outer join\n" - + "mother.kittens as offspr" ); - parse( "select new Family(mother, mate, offspr)\n" - + "from eg.DomesticCat as mother\n" - + "join mother.mate as mate\n" - + "left join mother.kittens as offspr\n" ); - } - - /** - * Section 9.5 - Aggregate functions * - */ - @Test public void testDocoExamples95() throws Exception { - parse( "select avg(cat.weight), sum(cat.weight), max(cat.weight), count(cat)\n" - + "from eg.Cat cat" ); - parse( "select cat, count( elements(cat.kittens) )\n" - + " from eg.Cat cat group by cat" ); - parse( "select distinct cat.name from eg.Cat cat" ); - parse( "select count(distinct cat.name), count(cat) from eg.Cat cat" ); - } - - /** - * Section 9.6 - Polymorphism * - */ - @Test public void testDocoExamples96() throws Exception { - parse( "from eg.Cat as cat" ); - parse( "from java.lang.Object o" ); - parse( "from eg.Named n, eg.Named m where n.name = m.name" ); - } - - /** - * Section 9.7 - Where * - */ - @Test public void testDocoExamples97() throws Exception { - parse( "from eg.Cat as cat where cat.name='Fritz'" ); - parse( "select foo\n" - + "from eg.Foo foo, eg.Bar bar\n" - + "where foo.startDate = bar.date\n" ); - parse( "from eg.Cat cat where cat.mate.name is not null" ); - parse( "from eg.Cat cat, eg.Cat rival where cat.mate = rival.mate" ); - parse( "select cat, mate\n" - + "from eg.Cat cat, eg.Cat mate\n" - + "where cat.mate = mate" ); - parse( "from eg.Cat as cat where cat.id = 123" ); - parse( "from eg.Cat as cat where cat.mate.id = 69" ); - parse( "from bank.Person person\n" - + "where person.id.country = 'AU'\n" - + "and person.id.medicareNumber = 123456" ); - parse( "from bank.Account account\n" - + "where account.owner.id.country = 'AU'\n" - + "and account.owner.id.medicareNumber = 123456" ); - parse( "from eg.Cat cat where cat.class = eg.DomesticCat" ); - parse( "from eg.AuditLog log, eg.Payment payment\n" - + "where log.item.class = 'eg.Payment' and log.item.id = payment.id" ); - } - - /** - * Section 9.8 - Expressions * - */ - @Test public void testDocoExamples98() throws Exception { - parse( "from eg.DomesticCat cat where cat.name between 'A' and 'B'" ); - parse( "from eg.DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )" ); - parse( "from eg.DomesticCat cat where cat.name not between 'A' and 'B'" ); - parse( "from eg.DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz' )" ); - parse( "from eg.Cat cat where cat.kittens.size > 0" ); - parse( "from eg.Cat cat where size(cat.kittens) > 0" ); -// This is a little odd. I'm not sure whether 'current' is a keyword. -// parse("from Calendar cal where cal.holidays.maxElement > current date"); -// Using the token 'order' as both a keyword and an identifier works now, but -// the second instance causes some problems because order is valid in the second instance. -// parse("from Order order where maxindex(order.items) > 100"); -// parse("from Order order where minelement(order.items) > 10000"); - parse( "from Order ord where maxindex(ord.items) > 100" ); - parse( "from Order ord where minelement(ord.items) > 10000" ); - - parse( "select mother from eg.Cat as mother, eg.Cat as kit\n" - + "where kit in elements(foo.kittens)" ); - parse( "select p from eg.NameList list, eg.Person p\n" - + "where p.name = some elements(list.names)" ); - parse( "from eg.Cat cat where exists elements(cat.kittens)" ); - parse( "from eg.Player p where 3 > all elements(p.scores)" ); - parse( "from eg.Show show where 'fizard' in indices(show.acts)" ); - - // Yet another example of the pathological 'order' token. -// parse("from Order order where order.items[0].id = 1234"); -// parse("select person from Person person, Calendar calendar\n" -// + "where calendar.holidays['national day'] = person.birthDay\n" -// + "and person.nationality.calendar = calendar"); -// parse("select item from Item item, Order order\n" -// + "where order.items[ order.deliveredItemIndices[0] ] = item and order.id = 11"); -// parse("select item from Item item, Order order\n" -// + "where order.items[ maxindex(order.items) ] = item and order.id = 11"); - - parse( "from Order ord where ord.items[0].id = 1234" ); - parse( "select person from Person person, Calendar calendar\n" - + "where calendar.holidays['national day'] = person.birthDay\n" - + "and person.nationality.calendar = calendar" ); - parse( "select item from Item item, Order ord\n" - + "where ord.items[ ord.deliveredItemIndices[0] ] = item and ord.id = 11" ); - parse( "select item from Item item, Order ord\n" - + "where ord.items[ maxindex(ord.items) ] = item and ord.id = 11" ); - - parse( "select item from Item item, Order ord\n" - + "where ord.items[ size(ord.items) - 1 ] = item" ); - - parse( "from eg.DomesticCat cat where upper(cat.name) like 'FRI%'" ); - - parse( "select cust from Product prod, Store store\n" - + "inner join store.customers cust\n" - + "where prod.name = 'widget'\n" - + "and store.location.name in ( 'Melbourne', 'Sydney' )\n" - + "and prod = all elements(cust.currentOrder.lineItems)" ); - - } - - @Test public void testDocoExamples99() throws Exception { - parse( "from eg.DomesticCat cat\n" - + "order by cat.name asc, cat.weight desc, cat.birthdate" ); - } - - @Test public void testDocoExamples910() throws Exception { - parse( "select cat.color, sum(cat.weight), count(cat)\n" - + "from eg.Cat cat group by cat.color" ); - parse( "select foo.id, avg( elements(foo.names) ), max( indices(foo.names) )\n" - + "from eg.Foo foo group by foo.id" ); - parse( "select cat.color, sum(cat.weight), count(cat)\n" - + "from eg.Cat cat group by cat.color\n" - + "having cat.color in (eg.Color.TABBY, eg.Color.BLACK)" ); - parse( "select cat from eg.Cat cat join cat.kittens kitten\n" - + "group by cat having avg(kitten.weight) > 100\n" - + "order by count(kitten) asc, sum(kitten.weight) desc" ); - } - - @Test public void testDocoExamples911() throws Exception { - parse( "from eg.Cat as fatcat where fatcat.weight > (\n" - + "select avg(cat.weight) from eg.DomesticCat cat)" ); - parse( "from eg.DomesticCat as cat where cat.name = some (\n" - + "select name.nickName from eg.Name as name)\n" ); - parse( "from eg.Cat as cat where not exists (\n" - + "from eg.Cat as mate where mate.mate = cat)" ); - parse( "from eg.DomesticCat as cat where cat.name not in (\n" - + "select name.nickName from eg.Name as name)" ); - } - - @Test public void testDocoExamples912() throws Exception { - parse( "select ord.id, sum(price.amount), count(item)\n" - + "from Order as ord join ord.lineItems as item\n" - + "join item.product as product, Catalog as catalog\n" - + "join catalog.prices as price\n" - + "where ord.paid = false\n" - + "and ord.customer = :customer\n" - + "and price.product = product\n" - + "and catalog.effectiveDate < sysdate\n" - + "and catalog.effectiveDate >= all (\n" - + "select cat.effectiveDate from Catalog as cat where cat.effectiveDate < sysdate)\n" - + "group by ord\n" - + "having sum(price.amount) > :minAmount\n" - + "order by sum(price.amount) desc" ); - - parse( "select ord.id, sum(price.amount), count(item)\n" - + "from Order as ord join ord.lineItems as item join item.product as product,\n" - + "Catalog as catalog join catalog.prices as price\n" - + "where ord.paid = false and ord.customer = :customer\n" - + "and price.product = product and catalog = :currentCatalog\n" - + "group by ord having sum(price.amount) > :minAmount\n" - + "order by sum(price.amount) desc" ); - - parse( "select count(payment), status.name \n" - + "from Payment as payment \n" - + " join payment.currentStatus as status\n" - + " join payment.statusChanges as statusChange\n" - + "where payment.status.name <> PaymentStatus.AWAITING_APPROVAL\n" - + " or (\n" - + " statusChange.timeStamp = ( \n" - + " select max(change.timeStamp) \n" - + " from PaymentStatusChange change \n" - + " where change.payment = payment\n" - + " )\n" - + " and statusChange.user <> :currentUser\n" - + " )\n" - + "group by status.name, status.sortOrder\n" - + "order by status.sortOrder" ); - parse( "select count(payment), status.name \n" - + "from Payment as payment\n" - + " join payment.currentStatus as status\n" - + "where payment.status.name <> PaymentStatus.AWAITING_APPROVAL\n" - + " or payment.statusChanges[ maxIndex(payment.statusChanges) ].user <> :currentUser\n" - + "group by status.name, status.sortOrder\n" - + "order by status.sortOrder" ); - parse( "select account, payment\n" - + "from Account as account\n" - + " left outer join account.payments as payment\n" - + "where :currentUser in elements(account.holder.users)\n" - + " and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID)\n" - + "order by account.type.sortOrder, account.accountNumber, payment.dueDate" ); - parse( "select account, payment\n" - + "from Account as account\n" - + " join account.holder.users as user\n" - + " left outer join account.payments as payment\n" - + "where :currentUser = user\n" - + " and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID)\n" - + "order by account.type.sortOrder, account.accountNumber, payment.dueDate" ); - } - - @Test public void testExamples1() throws Exception { - parse( "select new org.hibernate.test.S(s.count, s.address)\n" - + "from s in class Simple" ); - parse( "select s.name, sysdate, trunc(s.pay), round(s.pay) from s in class Simple" ); - parse( "select round(s.pay, 2) from s" ); - parse( "select abs(round(s.pay)) from s in class Simple" ); - parse( "select trunc(round(sysdate)) from s in class Simple" ); - } - - @Test public void testArrayExpr() throws Exception { - parse( "from Order ord where ord.items[0].id = 1234" ); - } - - @Test public void testMultipleActualParameters() throws Exception { - parse( "select round(s.pay, 2) from s" ); - } - - @Test public void testMultipleFromClasses() throws Exception { - parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f" ); - parse( "FROM eg.mypackage.Cat qat, org.jabberwocky.Dipstick" ); - } - - @Test public void testFromWithJoin() throws Exception { - parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" ); - parse( "FROM eg.mypackage.Cat qat left join com.multijoin.JoinORama , com.toadstool.Foo f join net.sf.blurb.Blurb" ); - } - - @Test public void testSelect() throws Exception { - parse( "SELECT f FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" ); - parse( "SELECT DISTINCT bar FROM eg.mypackage.Cat qat left join com.multijoin.JoinORama as bar, com.toadstool.Foo f join net.sf.blurb.Blurb" ); - parse( "SELECT count(*) FROM eg.mypackage.Cat qat" ); - parse( "SELECT avg(qat.weight) FROM eg.mypackage.Cat qat" ); - } - - @Test public void testWhere() throws Exception { - parse( "FROM eg.mypackage.Cat qat where qat.name like '%fluffy%' or qat.toes > 5" ); - parse( "FROM eg.mypackage.Cat qat where not qat.name like '%fluffy%' or qat.toes > 5" ); - parse( "FROM eg.mypackage.Cat qat where not qat.name not like '%fluffy%'" ); - parse( "FROM eg.mypackage.Cat qat where qat.name in ('crater','bean','fluffy')" ); - parse( "FROM eg.mypackage.Cat qat where qat.name not in ('crater','bean','fluffy')" ); - parse( "from Animal an where sqrt(an.bodyWeight)/2 > 10" ); - parse( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" ); - } - - @Test public void testGroupBy() throws Exception { - parse( "FROM eg.mypackage.Cat qat group by qat.breed" ); - parse( "FROM eg.mypackage.Cat qat group by qat.breed, qat.eyecolor" ); - } - - @Test public void testOrderBy() throws Exception { - parse( "FROM eg.mypackage.Cat qat order by avg(qat.toes)" ); - parse( "from Animal an order by sqrt(an.bodyWeight)/2" ); - } - - @Test public void testDoubleLiteral() throws Exception { - parse( "from eg.Cat as tinycat where fatcat.weight < 3.1415" ); - parse( "from eg.Cat as enormouscat where fatcat.weight > 3.1415e3" ); - } - - @Test public void testComplexConstructor() throws Exception { - parse( "select new Foo(count(bar)) from bar" ); - parse( "select new Foo(count(bar),(select count(*) from doofus d where d.gob = 'fat' )) from bar" ); - } - - - @Test public void testInNotIn() throws Exception { - parse( "from foo where foo.bar in ('a' , 'b', 'c')" ); - parse( "from foo where foo.bar not in ('a' , 'b', 'c')" ); - } - - @Test public void testOperatorPrecedence() throws Exception { - parse( "from foo where foo.bar = 123 + foo.baz * foo.not" ); - parse( "from foo where foo.bar like 'testzzz' || foo.baz or foo.bar in ('duh', 'gob')" ); - } - - /** - * Tests HQL generated by the other unit tests. - * - * @throws Exception if the HQL could not be parsed. - */ - @Test public void testUnitTestHql() throws Exception { - parse( "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id" ); - parse( "select foo.foo, foo.dependent from foo in class org.hibernate.test.Foo order by foo.foo.string desc, foo.component.count asc, foo.dependent.id" ); - parse( "select foo from foo in class org.hibernate.test.Foo order by foo.dependent.id, foo.dependent.fi" ); - parse( "SELECT one FROM one IN CLASS org.hibernate.test.One ORDER BY one.value ASC" ); - parse( "SELECT many.one FROM many IN CLASS org.hibernate.test.Many ORDER BY many.one.value ASC, many.one.id" ); - parse( "select foo.id from org.hibernate.test.Foo foo where foo.joinedProp = 'foo'" ); - parse( "from org.hibernate.test.Foo foo inner join fetch foo.foo" ); - parse( "from org.hibernate.test.Baz baz left outer join fetch baz.fooToGlarch" ); - parse( "select foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo = 'bar'" ); - parse( "select foo.foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo = 'bar'" ); - parse( "select foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo.foo.string = 'bar'" ); - parse( "select foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo = 'bar' and foo.foo.foo.foo = 'baz'" ); - parse( "select foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo.foo.string = 'a' and foo.foo.string = 'b'" ); - parse( "from org.hibernate.test.Foo as foo where foo.component.glarch.name is not null" ); - parse( "from org.hibernate.test.Foo as foo left outer join foo.component.glarch as glarch where glarch.name = 'foo'" ); - parse( "from org.hibernate.test.Foo" ); - parse( "from org.hibernate.test.Foo foo left outer join foo.foo" ); - parse( "from org.hibernate.test.Foo, org.hibernate.test.Bar" ); - parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch, org.hibernate.test.Bar bar join bar.foo" ); - parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch join baz.fooSet" ); - parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch join fetch baz.fooSet foo left join fetch foo.foo" ); - parse( "from foo in class org.hibernate.test.Foo where foo.string='osama bin laden' and foo.boolean = true order by foo.string asc, foo.component.count desc" ); - parse( "from foo in class org.hibernate.test.Foo where foo.string='osama bin laden' order by foo.string asc, foo.component.count desc" ); - parse( "select foo.foo from foo in class org.hibernate.test.Foo" ); - parse( "from foo in class org.hibernate.test.Foo where foo.component.count is null order by foo.component.count" ); - parse( "from foo in class org.hibernate.test.Foo where foo.component.name='foo'" ); - parse( "select distinct foo.component.name, foo.component.name from foo in class org.hibernate.test.Foo where foo.component.name='foo'" ); - parse( "select distinct foo.component.name, foo.id from foo in class org.hibernate.test.Foo where foo.component.name='foo'" ); - parse( "from foo in class org.hibernate.test.Foo where foo.id=?" ); - parse( "from foo in class org.hibernate.test.Foo where foo.key=?" ); - parse( "select foo.foo from foo in class org.hibernate.test.Foo where foo.string='fizard'" ); - parse( "from foo in class org.hibernate.test.Foo where foo.component.subcomponent.name='bar'" ); - parse( "select foo.foo from foo in class org.hibernate.test.Foo where foo.foo.id=?" ); - parse( "from foo in class org.hibernate.test.Foo where foo.foo = ?" ); - parse( "from bar in class org.hibernate.test.Bar where bar.string='a string' or bar.string='a string'" ); - parse( "select foo.component.name, elements(foo.component.importantDates) from foo in class org.hibernate.test.Foo where foo.foo.id=?" ); - parse( "select max(elements(foo.component.importantDates)) from foo in class org.hibernate.test.Foo group by foo.id" ); - parse( "select foo.foo.foo.foo from foo in class org.hibernate.test.Foo, foo2 in class org.hibernate.test.Foo where foo = foo2.foo and not not ( not foo.string='fizard' ) and foo2.string between 'a' and (foo.foo.string) and ( foo2.string in ( 'fiz', 'blah') or 1=1 )" ); - parse( "from foo in class org.hibernate.test.Foo where foo.string='from BoogieDown -tinsel town =!@#$^&*())'" ); - parse( "from foo in class org.hibernate.test.Foo where not foo.string='foo''bar'" ); // Added quote quote is an escape - parse( "from foo in class org.hibernate.test.Foo where foo.component.glarch.next is null" ); - parse( " from bar in class org.hibernate.test.Bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'" ); - parse( " from i in class org.hibernate.test.Bar where i.baz.name='Bazza'" ); - parse( "select count(distinct foo.foo) from foo in class org.hibernate.test.Foo" ); - parse( "select count(foo.foo.boolean) from foo in class org.hibernate.test.Foo" ); - parse( "select count(*), foo.int from foo in class org.hibernate.test.Foo group by foo.int" ); - parse( "select sum(foo.foo.int) from foo in class org.hibernate.test.Foo" ); - parse( "select count(foo) from foo in class org.hibernate.test.Foo where foo.id=?" ); - parse( "from foo in class org.hibernate.test.Foo where foo.boolean = ?" ); - parse( "select new Foo(fo.x) from org.hibernate.test.Fo fo" ); - parse( "select new Foo(fo.integer) from org.hibernate.test.Foo fo" ); - parse( "select new Foo(fo.x) from org.hibernate.test.Foo fo" ); - parse( "select foo.long, foo.component.name, foo, foo.foo from foo in class org.hibernate.test.Foo" ); - parse( "select avg(foo.float), max(foo.component.name), count(distinct foo.id) from foo in class org.hibernate.test.Foo" ); - parse( "select foo.long, foo.component, foo, foo.foo from foo in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.MoreStuff" ); - parse( "from o in class org.hibernate.test.Many" ); - parse( "from o in class org.hibernate.test.Fee" ); - parse( "from o in class org.hibernate.test.Qux" ); - parse( "from o in class org.hibernate.test.Y" ); - parse( "from o in class org.hibernate.test.Fumm" ); - parse( "from o in class org.hibernate.test.X" ); - parse( "from o in class org.hibernate.test.Simple" ); - parse( "from o in class org.hibernate.test.Location" ); - parse( "from o in class org.hibernate.test.Holder" ); - parse( "from o in class org.hibernate.test.Part" ); - parse( "from o in class org.hibernate.test.Baz" ); - parse( "from o in class org.hibernate.test.Vetoer" ); - parse( "from o in class org.hibernate.test.Sortable" ); - parse( "from o in class org.hibernate.test.Contained" ); - parse( "from o in class org.hibernate.test.Stuff" ); - parse( "from o in class org.hibernate.test.Immutable" ); - parse( "from o in class org.hibernate.test.Container" ); - parse( "from o in class org.hibernate.test.X$XX" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from o in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.Fo" ); - parse( "from o in class org.hibernate.test.Glarch" ); - parse( "from o in class org.hibernate.test.Fum" ); - parse( "from n in class org.hibernate.test.Holder" ); - parse( "from n in class org.hibernate.test.Baz" ); - parse( "from n in class org.hibernate.test.Bar" ); - parse( "from n in class org.hibernate.test.Glarch" ); - parse( "from n in class org.hibernate.test.Holder where n.name is not null" ); - parse( "from n in class org.hibernate.test.Baz where n.name is not null" ); - parse( "from n in class org.hibernate.test.Bar where n.name is not null" ); - parse( "from n in class org.hibernate.test.Glarch where n.name is not null" ); - parse( "from n in class org.hibernate.test.Holder" ); - parse( "from n in class org.hibernate.test.Baz" ); - parse( "from n in class org.hibernate.test.Bar" ); - parse( "from n in class org.hibernate.test.Glarch" ); - parse( "from n0 in class org.hibernate.test.Holder, n1 in class org.hibernate.test.Holder where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Baz, n1 in class org.hibernate.test.Holder where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Bar, n1 in class org.hibernate.test.Holder where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Glarch, n1 in class org.hibernate.test.Holder where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Holder, n1 in class org.hibernate.test.Baz where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Baz, n1 in class org.hibernate.test.Baz where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Bar, n1 in class org.hibernate.test.Baz where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Glarch, n1 in class org.hibernate.test.Baz where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Holder, n1 in class org.hibernate.test.Bar where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Baz, n1 in class org.hibernate.test.Bar where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Bar, n1 in class org.hibernate.test.Bar where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Glarch, n1 in class org.hibernate.test.Bar where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Holder, n1 in class org.hibernate.test.Glarch where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Baz, n1 in class org.hibernate.test.Glarch where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Bar, n1 in class org.hibernate.test.Glarch where n0.name = n1.name" ); - parse( "from n0 in class org.hibernate.test.Glarch, n1 in class org.hibernate.test.Glarch where n0.name = n1.name" ); - parse( "from n in class org.hibernate.test.Holder where n.name = :name" ); - parse( "from o in class org.hibernate.test.MoreStuff" ); - parse( "from o in class org.hibernate.test.Many" ); - parse( "from o in class org.hibernate.test.Fee" ); - parse( "from o in class org.hibernate.test.Qux" ); - parse( "from o in class org.hibernate.test.Y" ); - parse( "from o in class org.hibernate.test.Fumm" ); - parse( "from o in class org.hibernate.test.X" ); - parse( "from o in class org.hibernate.test.Simple" ); - parse( "from o in class org.hibernate.test.Location" ); - parse( "from o in class org.hibernate.test.Holder" ); - parse( "from o in class org.hibernate.test.Part" ); - parse( "from o in class org.hibernate.test.Baz" ); - parse( "from o in class org.hibernate.test.Vetoer" ); - parse( "from o in class org.hibernate.test.Sortable" ); - parse( "from o in class org.hibernate.test.Contained" ); - parse( "from o in class org.hibernate.test.Stuff" ); - parse( "from o in class org.hibernate.test.Immutable" ); - parse( "from o in class org.hibernate.test.Container" ); - parse( "from o in class org.hibernate.test.X$XX" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from o in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.Fo" ); - parse( "from o in class org.hibernate.test.Glarch" ); - parse( "from o in class org.hibernate.test.Fum" ); - parse( "select baz.code, min(baz.count) from baz in class org.hibernate.test.Baz group by baz.code" ); - parse( "selecT baz from baz in class org.hibernate.test.Baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?" ); - parse( "select baz from baz in class org.hibernate.test.Baz where baz.stringDateMap['now'] is not null" ); - parse( "select baz from baz in class org.hibernate.test.Baz where baz.stringDateMap['now'] is not null and baz.stringDateMap['big bang'] < baz.stringDateMap['now']" ); - parse( "select index(date) from org.hibernate.test.Baz baz join baz.stringDateMap date" ); - parse( "from foo in class org.hibernate.test.Foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3" ); - parse( "from org.hibernate.test.Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null" ); - parse( "from org.hibernate.test.Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)" ); - parse( "from org.hibernate.test.Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)" ); - parse( "from org.hibernate.test.Foo foo join foo.foo where foo.foo in ('1','2','3')" ); - parse( "select foo.foo from org.hibernate.test.Foo foo where foo.foo in ('1','2','3')" ); - parse( "select foo.foo.string from org.hibernate.test.Foo foo where foo.foo in ('1','2','3')" ); - parse( "select foo.foo.string from org.hibernate.test.Foo foo where foo.foo.string in ('1','2','3')" ); - parse( "select foo.foo.long from org.hibernate.test.Foo foo where foo.foo.string in ('1','2','3')" ); - parse( "select count(*) from org.hibernate.test.Foo foo where foo.foo.string in ('1','2','3') or foo.foo.long in (1,2,3)" ); - parse( "select count(*) from org.hibernate.test.Foo foo where foo.foo.string in ('1','2','3') group by foo.foo.long" ); - parse( "from org.hibernate.test.Foo foo1 left join foo1.foo foo2 left join foo2.foo where foo1.string is not null" ); - parse( "from org.hibernate.test.Foo foo1 left join foo1.foo.foo where foo1.string is not null" ); - parse( "from org.hibernate.test.Foo foo1 left join foo1.foo foo2 left join foo1.foo.foo foo3 where foo1.string is not null" ); - parse( "select foo.formula from org.hibernate.test.Foo foo where foo.formula > 0" ); - parse( "from org.hibernate.test.Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'" ); - parse( "from org.hibernate.test.Holder" ); - parse( "from org.hibernate.test.Baz baz left outer join fetch baz.manyToAny" ); - parse( "from org.hibernate.test.Baz baz join baz.manyToAny" ); - parse( "select baz from org.hibernate.test.Baz baz join baz.manyToAny a where index(a) = 0" ); - parse( "select bar from org.hibernate.test.Bar bar where bar.baz.stringDateMap['now'] is not null" ); - parse( "select bar from org.hibernate.test.Bar bar join bar.baz b where b.stringDateMap['big bang'] < b.stringDateMap['now'] and b.stringDateMap['now'] is not null" ); - parse( "select bar from org.hibernate.test.Bar bar where bar.baz.stringDateMap['big bang'] < bar.baz.stringDateMap['now'] and bar.baz.stringDateMap['now'] is not null" ); - parse( "select foo.string, foo.component, foo.id from org.hibernate.test.Bar foo" ); - parse( "select elements(baz.components) from org.hibernate.test.Baz baz" ); - parse( "select bc.name from org.hibernate.test.Baz baz join baz.components bc" ); - parse( "from org.hibernate.test.Foo foo where foo.integer < 10 order by foo.string" ); - parse( "from org.hibernate.test.Fee" ); - parse( "from org.hibernate.test.Holder h join h.otherHolder oh where h.otherHolder.name = 'bar'" ); - parse( "from org.hibernate.test.Baz baz join baz.fooSet foo join foo.foo.foo foo2 where foo2.string = 'foo'" ); - parse( "from org.hibernate.test.Baz baz join baz.fooArray foo join foo.foo.foo foo2 where foo2.string = 'foo'" ); - parse( "from org.hibernate.test.Baz baz join baz.stringDateMap date where index(date) = 'foo'" ); - parse( "from org.hibernate.test.Baz baz join baz.topGlarchez g where index(g) = 'A'" ); - parse( "select index(g) from org.hibernate.test.Baz baz join baz.topGlarchez g" ); - parse( "from org.hibernate.test.Baz baz left join baz.stringSet" ); - parse( "from org.hibernate.test.Baz baz join baz.stringSet str where str='foo'" ); - parse( "from org.hibernate.test.Baz baz left join fetch baz.stringSet" ); - parse( "from org.hibernate.test.Baz baz join baz.stringSet string where string='foo'" ); - parse( "from org.hibernate.test.Baz baz inner join baz.components comp where comp.name='foo'" ); - parse( "from org.hibernate.test.Glarch g inner join g.fooComponents comp where comp.fee is not null" ); - parse( "from org.hibernate.test.Glarch g inner join g.fooComponents comp join comp.fee fee where fee.count > 0" ); - parse( "from org.hibernate.test.Glarch g inner join g.fooComponents comp where comp.fee.count is not null" ); - parse( "from org.hibernate.test.Baz baz left join fetch baz.fooBag" ); - parse( "from org.hibernate.test.Glarch" ); - parse( "from org.hibernate.test.Fee" ); - parse( "from org.hibernate.test.Baz baz left join fetch baz.sortablez order by baz.name asc" ); - parse( "from org.hibernate.test.Baz baz order by baz.name asc" ); - parse( "from org.hibernate.test.Foo foo, org.hibernate.test.Baz baz left join fetch baz.fees" ); - parse( "from org.hibernate.test.Foo foo, org.hibernate.test.Bar bar" ); - parse( "from org.hibernate.test.Foo foo" ); - parse( "from org.hibernate.test.Foo foo, org.hibernate.test.Bar bar, org.hibernate.test.Bar bar2" ); - parse( "from org.hibernate.test.X x" ); - parse( "from org.hibernate.test.Foo foo" ); - parse( "select distinct foo from org.hibernate.test.Foo foo" ); - parse( "from org.hibernate.test.Glarch g where g.multiple.glarch=g and g.multiple.count=12" ); - parse( "from org.hibernate.test.Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar %'" ); - parse( "select bar, b from org.hibernate.test.Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like 'Bar%'" ); - parse( "select bar, b from org.hibernate.test.Bar bar left join bar.baz baz left join baz.cascadingBars b where ( bar.name in (:nameList0_, :nameList1_, :nameList2_) or bar.name in (:nameList0_, :nameList1_, :nameList2_) ) and bar.string = :stringVal" ); - parse( "select bar, b from org.hibernate.test.Bar bar inner join bar.baz baz inner join baz.cascadingBars b where bar.name like 'Bar%'" ); - parse( "select bar, b from org.hibernate.test.Bar bar left join bar.baz baz left join baz.cascadingBars b where bar.name like :name and b.name like :name" ); - parse( "select bar from org.hibernate.test.Bar as bar where bar.x > ? or bar.short = 1 or bar.string = 'ff ? bb'" ); - parse( "select bar from org.hibernate.test.Bar as bar where bar.string = ' ? ' or bar.string = '?'" ); - parse( "from org.hibernate.test.Baz baz, baz.fooArray foo" ); - parse( "from s in class org.hibernate.test.Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.id.intId = ? and s.moreStuff.id.stringId = ?" ); - parse( "from s in class org.hibernate.test.Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.name = ?" ); - parse( "from s in class org.hibernate.test.Stuff where s.foo.string is not null" ); - parse( "from s in class org.hibernate.test.Stuff where s.foo > '0' order by s.foo" ); - parse( "from ms in class org.hibernate.test.MoreStuff" ); - parse( "from foo in class org.hibernate.test.Foo" ); - parse( "from fee in class org.hibernate.test.Fee" ); - parse( "select new Result(foo.string, foo.long, foo.integer) from foo in class org.hibernate.test.Foo" ); - parse( "select new Result( baz.name, foo.long, count(elements(baz.fooArray)) ) from org.hibernate.test.Baz baz join baz.fooArray foo group by baz.name, foo.long" ); - parse( "select new Result( baz.name, max(foo.long), count(foo) ) from org.hibernate.test.Baz baz join baz.fooArray foo group by baz.name" ); - parse( "select max( elements(bar.baz.fooArray) ) from org.hibernate.test.Bar as bar" ); - parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch join fetch baz.fooArray foo left join fetch foo.foo" ); - parse( "select baz.name from org.hibernate.test.Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string" ); - parse( "SELECT baz.name FROM org.hibernate.test.Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string" ); - parse( "select baz.name from org.hibernate.test.Bar bar join bar.baz baz left outer join baz.fooSet foo where baz.name = bar.string" ); - parse( "select baz.name from org.hibernate.test.Bar bar, bar.baz baz, baz.fooSet foo where baz.name = bar.string" ); - parse( "SELECT baz.name FROM org.hibernate.test.Bar AS bar, bar.baz AS baz, baz.fooSet AS foo WHERE baz.name = bar.string" ); - parse( "select baz.name from org.hibernate.test.Bar bar left join bar.baz baz left join baz.fooSet foo where baz.name = bar.string" ); - parse( "select foo.string from org.hibernate.test.Bar bar left join bar.baz.fooSet foo where bar.string = foo.string" ); - parse( "select baz.name from org.hibernate.test.Bar bar left join bar.baz baz left join baz.fooArray foo where baz.name = bar.string" ); - parse( "select foo.string from org.hibernate.test.Bar bar left join bar.baz.fooArray foo where bar.string = foo.string" ); - parse( "select foo from bar in class org.hibernate.test.Bar inner join bar.baz as baz inner join baz.fooSet as foo" ); - parse( "select foo from bar in class org.hibernate.test.Bar inner join bar.baz.fooSet as foo" ); - parse( "select foo from bar in class org.hibernate.test.Bar, bar.baz as baz, baz.fooSet as foo" ); - parse( "select foo from bar in class org.hibernate.test.Bar, bar.baz.fooSet as foo" ); - parse( "from org.hibernate.test.Bar bar join bar.baz.fooArray foo" ); - parse( "from bar in class org.hibernate.test.Bar, foo in elements( bar.baz.fooArray )" ); - parse( "select one.id, elements(one.manies) from one in class org.hibernate.test.One" ); - parse( "select max( elements(one.manies) ) from one in class org.hibernate.test.One" ); - parse( "select one, elements(one.manies) from one in class org.hibernate.test.One" ); - parse( "select one, max(elements(one.manies)) from one in class org.hibernate.test.One group by one" ); - parse( "select elements(baz.fooArray) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "select elements(baz.fooArray) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "select indices(baz.fooArray) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "select baz, max(elements(baz.timeArray)) from baz in class org.hibernate.test.Baz group by baz" ); - parse( "select baz, baz.stringSet.size, count(distinct elements(baz.stringSet)), max(elements(baz.stringSet)) from baz in class org.hibernate.test.Baz group by baz" ); - parse( "select max( elements(baz.timeArray) ) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "select max(elements(baz.stringSet)) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "select size(baz.stringSet) from baz in class org.hibernate.test.Baz where baz.id=?" ); - parse( "from org.hibernate.test.Foo foo where foo.component.glarch.id is not null" ); - parse( "from baz in class org.hibernate.test.Baz" ); - parse( "select elements(baz.stringArray) from baz in class org.hibernate.test.Baz" ); - parse( "from foo in class org.hibernate.test.Foo" ); - parse( "select elements(baz.stringList) from baz in class org.hibernate.test.Baz" ); - parse( "select count(*) from org.hibernate.test.Bar" ); - parse( "select count(*) from b in class org.hibernate.test.Bar" ); - parse( "from g in class org.hibernate.test.Glarch" ); - parse( "select baz, baz from baz in class org.hibernate.test.Baz" ); - parse( "select baz from baz in class org.hibernate.test.Baz order by baz" ); - parse( "from bar in class org.hibernate.test.Bar" ); - parse( "from g in class org.hibernate.test.Glarch" ); - parse( "from f in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from q in class org.hibernate.test.Qux" ); - parse( "select foo from foo in class org.hibernate.test.Foo where foo.string='foo bar'" ); - parse( "from foo in class org.hibernate.test.Foo order by foo.string, foo.date" ); - parse( "from foo in class org.hibernate.test.Foo where foo.class='B'" ); - parse( "from foo in class org.hibernate.test.Foo where foo.class=Bar" ); - parse( "select bar from bar in class org.hibernate.test.Bar, foo in class org.hibernate.test.Foo where bar.string = foo.string and not bar=foo" ); - parse( "from foo in class org.hibernate.test.Foo where foo.string='foo bar'" ); - parse( "select foo from foo in class org.hibernate.test.Foo" ); - parse( "from bar in class org.hibernate.test.Bar where bar.barString='bar bar'" ); - parse( "from t in class org.hibernate.test.Trivial" ); - parse( "from foo in class org.hibernate.test.Foo where foo.date = ?" ); - parse( "from o in class org.hibernate.test.MoreStuff" ); - parse( "from o in class org.hibernate.test.Many" ); - parse( "from o in class org.hibernate.test.Fee" ); - parse( "from o in class org.hibernate.test.Qux" ); - parse( "from o in class org.hibernate.test.Y" ); - parse( "from o in class org.hibernate.test.Fumm" ); - parse( "from o in class org.hibernate.test.X" ); - parse( "from o in class org.hibernate.test.Simple" ); - parse( "from o in class org.hibernate.test.Location" ); - parse( "from o in class org.hibernate.test.Holder" ); - parse( "from o in class org.hibernate.test.Part" ); - parse( "from o in class org.hibernate.test.Baz" ); - parse( "from o in class org.hibernate.test.Vetoer" ); - parse( "from o in class org.hibernate.test.Sortable" ); - parse( "from o in class org.hibernate.test.Contained" ); - parse( "from o in class org.hibernate.test.Stuff" ); - parse( "from o in class org.hibernate.test.Immutable" ); - parse( "from o in class org.hibernate.test.Container" ); - parse( "from o in class org.hibernate.test.X$XX" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from o in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.Fo" ); - parse( "from o in class org.hibernate.test.Glarch" ); - parse( "from o in class org.hibernate.test.Fum" ); - parse( "from q in class org.hibernate.test.Qux where q.stuff is null" ); - parse( "from q in class org.hibernate.test.Qux where q.stuff=?" ); - parse( "from q in class org.hibernate.test.Qux" ); - parse( "from g in class org.hibernate.test.Glarch where g.version=2" ); - parse( "from g in class org.hibernate.test.Glarch where g.next is not null" ); - parse( "from g in class org.hibernate.test.Glarch order by g.order asc" ); - parse( "from foo in class org.hibernate.test.Foo order by foo.string asc" ); - parse( "select parent, child from parent in class org.hibernate.test.Foo, child in class org.hibernate.test.Foo where parent.foo = child" ); - parse( "select count(distinct child.id), count(distinct parent.id) from parent in class org.hibernate.test.Foo, child in class org.hibernate.test.Foo where parent.foo = child" ); - parse( "select child.id, parent.id, child.long from parent in class org.hibernate.test.Foo, child in class org.hibernate.test.Foo where parent.foo = child" ); - parse( "select child.id, parent.id, child.long, child, parent.foo from parent in class org.hibernate.test.Foo, child in class org.hibernate.test.Foo where parent.foo = child" ); - parse( "select parent, child from parent in class org.hibernate.test.Foo, child in class org.hibernate.test.Foo where parent.foo = child and parent.string='a string'" ); - parse( "from fee in class org.hibernate.test.Fee" ); - parse( "from org.hibernate.test.Foo foo where foo.custom.s1 = 'one'" ); - parse( "from im in class org.hibernate.test.Immutable where im = ?" ); - parse( "from foo in class org.hibernate.test.Foo" ); - parse( "from foo in class org.hibernate.test.Foo where foo.char='X'" ); - parse( "select elements(baz.stringArray) from baz in class org.hibernate.test.Baz" ); - parse( "select distinct elements(baz.stringArray) from baz in class org.hibernate.test.Baz" ); - parse( "select elements(baz.fooArray) from baz in class org.hibernate.test.Baz" ); - parse( "from foo in class org.hibernate.test.Fo" ); - parse( "from foo in class org.hibernate.test.Foo where foo.dependent.qux.foo.string = 'foo2'" ); - parse( "from org.hibernate.test.Bar bar where bar.object.id = ? and bar.object.class = ?" ); - parse( "select one from org.hibernate.test.One one, org.hibernate.test.Bar bar where bar.object.id = one.id and bar.object.class = 'O'" ); - parse( "from l in class org.hibernate.test.Location where l.countryCode = 'AU' and l.description='foo bar'" ); - parse( "from org.hibernate.test.Bar bar" ); - parse( "From org.hibernate.test.Bar bar" ); - parse( "From org.hibernate.test.Foo foo" ); - parse( "from o in class org.hibernate.test.Baz" ); - parse( "from o in class org.hibernate.test.Foo" ); - parse( "from f in class org.hibernate.test.Foo" ); - parse( "select fum.id from fum in class org.hibernate.test.Fum where not fum.fum='FRIEND'" ); - parse( "select fum.id from fum in class org.hibernate.test.Fum where not fum.fum='FRIEND'" ); - parse( "from fum in class org.hibernate.test.Fum where not fum.fum='FRIEND'" ); - parse( "from fo in class org.hibernate.test.Fo where fo.id.string like 'an instance of fo'" ); - parse( "from org.hibernate.test.Inner" ); - parse( "from org.hibernate.test.Outer o where o.id.detailId = ?" ); - parse( "from org.hibernate.test.Outer o where o.id.main.id.sup.dudu is not null" ); - parse( "from org.hibernate.test.Outer o where o.id.main.id.sup.id.akey is not null" ); - parse( "select o.id.main.id.sup.dudu from org.hibernate.test.Outer o where o.id.main.id.sup.dudu is not null" ); - parse( "select o.id.main.id.sup.id.akey from org.hibernate.test.Outer o where o.id.main.id.sup.id.akey is not null" ); - parse( "from org.hibernate.test.Outer o where o.id.main.bla = ''" ); - parse( "from org.hibernate.test.Outer o where o.id.main.id.one = ''" ); - parse( "from org.hibernate.test.Inner inn where inn.id.bkey is not null and inn.backOut.id.main.id.sup.id.akey > 'a'" ); - parse( "from org.hibernate.test.Outer as o left join o.id.main m left join m.id.sup where o.bubu is not null" ); - parse( "from org.hibernate.test.Outer as o left join o.id.main.id.sup s where o.bubu is not null" ); - parse( "from org.hibernate.test.Outer as o left join o.id.main m left join o.id.main.id.sup s where o.bubu is not null" ); - parse( "select fum1.fo from fum1 in class org.hibernate.test.Fum where fum1.fo.fum is not null" ); - parse( "from fum1 in class org.hibernate.test.Fum where fum1.fo.fum is not null order by fum1.fo.fum" ); - parse( "select elements(fum1.friends) from fum1 in class org.hibernate.test.Fum" ); - parse( "from fum1 in class org.hibernate.test.Fum, fr in elements( fum1.friends )" ); - parse( "select new Jay(eye) from org.hibernate.test.Eye eye" ); - parse( "from org.hibernate.test.Category cat where cat.name='new foo'" ); - parse( "from org.hibernate.test.Category cat where cat.name='new sub'" ); - parse( "from org.hibernate.test.Up up order by up.id2 asc" ); - parse( "from org.hibernate.test.Down down" ); - parse( "from org.hibernate.test.Up up" ); - parse( "from m in class org.hibernate.test.Root" ); - parse( "from s in class org.hibernate.test.Several" ); - parse( "from s in class org.hibernate.test.Single" ); - parse( "\n" + - " from d in class \n" + - " org.hibernate.test.Detail\n" + - " " ); - parse( "from c in class org.hibernate.test.Category where c.name = org.hibernate.test.Category.ROOT_CATEGORY" ); - parse( "select c from c in class org.hibernate.test.Container, s in class org.hibernate.test.Simple where c.oneToMany[2] = s" ); - parse( "select c from c in class org.hibernate.test.Container, s in class org.hibernate.test.Simple where c.manyToMany[2] = s" ); - parse( "select c from c in class org.hibernate.test.Container, s in class org.hibernate.test.Simple where s = c.oneToMany[2]" ); - parse( "select c from c in class org.hibernate.test.Container, s in class org.hibernate.test.Simple where s = c.manyToMany[2]" ); - parse( "select c from c in class org.hibernate.test.Container where c.oneToMany[0].name = 's'" ); - parse( "select c from c in class org.hibernate.test.Container where c.manyToMany[0].name = 's'" ); - parse( "select c from c in class org.hibernate.test.Container where 's' = c.oneToMany[2 - 2].name" ); - parse( "select c from c in class org.hibernate.test.Container where 's' = c.manyToMany[(3+1)/4-1].name" ); - parse( "select c from c in class org.hibernate.test.Container where c.manyToMany[ maxindex(c.manyToMany) ].count = 2" ); - parse( "select c from c in class org.hibernate.test.Container where c.oneToMany[ c.manyToMany[0].count ].name = 's'" ); - parse( "select c from org.hibernate.test.Container c where c.manyToMany[ c.oneToMany[0].count ].name = 's'" ); - parse( "select count(comp.name) from org.hibernate.test.Container c join c.components comp" ); - parse( "from org.hibernate.test.Parent p left join fetch p.child" ); - parse( "from org.hibernate.test.Parent p join p.child c where c.x > 0" ); - parse( "from org.hibernate.test.Child c join c.parent p where p.x > 0" ); - parse( "from org.hibernate.test.Child" ); - parse( "from org.hibernate.test.MoreStuff" ); - parse( "from org.hibernate.test.Many" ); - parse( "from org.hibernate.test.Fee" ); - parse( "from org.hibernate.test.Qux" ); - parse( "from org.hibernate.test.Fumm" ); - parse( "from org.hibernate.test.Parent" ); - parse( "from org.hibernate.test.Simple" ); - parse( "from org.hibernate.test.Holder" ); - parse( "from org.hibernate.test.Part" ); - parse( "from org.hibernate.test.Baz" ); - parse( "from org.hibernate.test.Vetoer" ); - parse( "from org.hibernate.test.Sortable" ); - parse( "from org.hibernate.test.Contained" ); - parse( "from org.hibernate.test.Circular" ); - parse( "from org.hibernate.test.Stuff" ); - parse( "from org.hibernate.test.Immutable" ); - parse( "from org.hibernate.test.Container" ); - parse( "from org.hibernate.test.One" ); - parse( "from org.hibernate.test.Foo" ); - parse( "from org.hibernate.test.Fo" ); - parse( "from org.hibernate.test.Glarch" ); - parse( "from org.hibernate.test.Fum" ); - parse( "from org.hibernate.test.Glarch g" ); - parse( "from org.hibernate.test.Part" ); - parse( "from org.hibernate.test.Baz baz join baz.parts" ); - parse( "from c in class org.hibernate.test.Child where c.parent.count=66" ); - parse( "from org.hibernate.test.Parent p join p.child c where p.count=66" ); - parse( "select c, c.parent from c in class org.hibernate.test.Child order by c.parent.count" ); - parse( "select c, c.parent from c in class org.hibernate.test.Child where c.parent.count=66 order by c.parent.count" ); - parse( "select c, c.parent, c.parent.count from c in class org.hibernate.test.Child order by c.parent.count" ); - parse( "FROM p IN CLASS org.hibernate.test.Parent WHERE p.count = ?" ); - parse( "select count(*) from org.hibernate.test.Container as c join c.components as ce join ce.simple as s where ce.name='foo'" ); - parse( "select c, s from org.hibernate.test.Container as c join c.components as ce join ce.simple as s where ce.name='foo'" ); - parse( "from s in class org.hibernate.test.Simple" ); - parse( "from m in class org.hibernate.test.Many" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from c in class org.hibernate.test.Container" ); - parse( "from o in class org.hibernate.test.Child" ); - parse( "from o in class org.hibernate.test.MoreStuff" ); - parse( "from o in class org.hibernate.test.Many" ); - parse( "from o in class org.hibernate.test.Fee" ); - parse( "from o in class org.hibernate.test.Qux" ); - parse( "from o in class org.hibernate.test.Fumm" ); - parse( "from o in class org.hibernate.test.Parent" ); - parse( "from o in class org.hibernate.test.Simple" ); - parse( "from o in class org.hibernate.test.Holder" ); - parse( "from o in class org.hibernate.test.Part" ); - parse( "from o in class org.hibernate.test.Baz" ); - parse( "from o in class org.hibernate.test.Vetoer" ); - parse( "from o in class org.hibernate.test.Sortable" ); - parse( "from o in class org.hibernate.test.Contained" ); - parse( "from o in class org.hibernate.test.Circular" ); - parse( "from o in class org.hibernate.test.Stuff" ); - parse( "from o in class org.hibernate.test.Immutable" ); - parse( "from o in class org.hibernate.test.Container" ); - parse( "from o in class org.hibernate.test.One" ); - parse( "from o in class org.hibernate.test.Foo" ); - parse( "from o in class org.hibernate.test.Fo" ); - parse( "from o in class org.hibernate.test.Glarch" ); - parse( "from o in class org.hibernate.test.Fum" ); - parse( "from c in class org.hibernate.test.C2 where 1=1 or 1=1" ); - parse( "from b in class org.hibernate.test.B" ); - parse( "from a in class org.hibernate.test.A" ); - parse( "from b in class org.hibernate.test.B" ); - parse( "from org.hibernate.test.E e join e.reverse as b where b.count=1" ); - parse( "from org.hibernate.test.E e join e.as as b where b.count=1" ); - parse( "from org.hibernate.test.B" ); - parse( "from org.hibernate.test.C1" ); - parse( "from org.hibernate.test.C2" ); - parse( "from org.hibernate.test.E e, org.hibernate.test.A a where e.reverse = a.forward and a = ?" ); - parse( "from org.hibernate.test.E e join fetch e.reverse" ); - parse( "from org.hibernate.test.E e" ); - parse( "select max(s.count) from s in class org.hibernate.test.Simple" ); - parse( "select new org.hibernate.test.S(s.count, s.address) from s in class org.hibernate.test.Simple" ); - parse( "select max(s.count) from s in class org.hibernate.test.Simple" ); - parse( "select count(*) from s in class org.hibernate.test.Simple" ); - parse( "from s in class org.hibernate.test.Simple where s.name=:name and s.count=:count" ); - parse( "from s in class org.hibernate.test.Simple where s.name in (:several0_, :several1_)" ); - parse( "from s in class org.hibernate.test.Simple where s.name in (:stuff0_, :stuff1_)" ); - parse( "from org.hibernate.test.Simple s where s.name=?" ); - parse( "from org.hibernate.test.Simple s where s.name=:name" ); - parse( "from s in class org.hibernate.test.Simple where upper( s.name ) ='SIMPLE 1'" ); - parse( "from s in class org.hibernate.test.Simple where not( upper( s.name ) ='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar' )" ); - parse( "from s in class org.hibernate.test.Simple where lower( s.name || ' foo' ) ='simple 1 foo'" ); - parse( "from s in class org.hibernate.test.Simple where upper( s.other.name ) ='SIMPLE 2'" ); - parse( "from s in class org.hibernate.test.Simple where not ( upper( s.other.name ) ='SIMPLE 2' )" ); - parse( "select distinct s from s in class org.hibernate.test.Simple where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" ); - parse( "select s from s in class org.hibernate.test.Simple where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2 order by s.other.count" ); - parse( "select sum(s.count) from s in class org.hibernate.test.Simple group by s.count having sum(s.count) > 10" ); - parse( "select s.count from s in class org.hibernate.test.Simple group by s.count having s.count = 12" ); - parse( "select s.id, s.count, count(t), max(t.date) from s in class org.hibernate.test.Simple, t in class org.hibernate.test.Simple where s.count = t.count group by s.id, s.count order by s.count" ); - parse( "from s in class org.hibernate.test.Simple" ); - parse( "from s in class org.hibernate.test.Simple where s.name = ?" ); - parse( "from s in class org.hibernate.test.Simple where s.name = ? and upper(s.name) = ?" ); - parse( "from s in class org.hibernate.test.Simple where s.name = :foo and upper(s.name) = :bar or s.count=:count or s.count=:count + 1" ); - parse( "select s.id from s in class org.hibernate.test.Simple" ); - parse( "select all s, s.other from s in class org.hibernate.test.Simple where s = :s" ); - parse( "from s in class org.hibernate.test.Simple where s.name in (:name_list0_, :name_list1_) and s.count > :count" ); - parse( "from org.hibernate.test.Simple s" ); - parse( "from org.hibernate.test.Simple s" ); - parse( "from org.hibernate.test.Assignable" ); - parse( "from org.hibernate.test.Category" ); - parse( "from org.hibernate.test.Simple" ); - parse( "from org.hibernate.test.A" ); - parse( "from foo in class org.hibernate.test.Foo where foo.string=?" ); - parse( "from foo in class org.hibernate.test.Foo" ); - parse( "from org.hibernate.test.Po po, org.hibernate.test.Lower low where low.mypo = po" ); - parse( "from org.hibernate.test.Po po join po.set as sm where sm.amount > 0" ); - parse( "from org.hibernate.test.Po po join po.top as low where low.foo = 'po'" ); - parse( "from org.hibernate.test.SubMulti sm join sm.children smc where smc.name > 'a'" ); - parse( "select s, ya from org.hibernate.test.Lower s join s.yetanother ya" ); - parse( "from org.hibernate.test.Lower s1 join s1.bag s2" ); - parse( "from org.hibernate.test.Lower s1 left join s1.bag s2" ); - parse( "select s, a from org.hibernate.test.Lower s join s.another a" ); - parse( "select s, a from org.hibernate.test.Lower s left join s.another a" ); - parse( "from org.hibernate.test.Top s, org.hibernate.test.Lower ls" ); - parse( "from org.hibernate.test.Lower ls join ls.set s where s.name > 'a'" ); - parse( "from org.hibernate.test.Po po join po.list sm where sm.name > 'a'" ); - parse( "from org.hibernate.test.Lower ls inner join ls.another s where s.name is not null" ); - parse( "from org.hibernate.test.Lower ls where ls.other.another.name is not null" ); - parse( "from org.hibernate.test.Multi m where m.derived like 'F%'" ); - parse( "from org.hibernate.test.SubMulti m where m.derived like 'F%'" ); - parse( "select s from org.hibernate.test.SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null" ); - parse( "select elements(sm.children) from org.hibernate.test.SubMulti as sm" ); - parse( "select distinct sm from org.hibernate.test.SubMulti as sm join sm.children as s where s.amount>-1 and s.name is null" ); - parse( "select distinct s from s in class org.hibernate.test.SubMulti where s.moreChildren[1].amount < 1.0" ); - parse( "from s in class org.hibernate.test.TrivialClass where s.id = 2" ); - parse( "select s.count from s in class org.hibernate.test.Top" ); - parse( "from s in class org.hibernate.test.Lower where s.another.name='name'" ); - parse( "from s in class org.hibernate.test.Lower where s.yetanother.name='name'" ); - parse( "from s in class org.hibernate.test.Lower where s.yetanother.name='name' and s.yetanother.foo is null" ); - parse( "from s in class org.hibernate.test.Top where s.count=1" ); - parse( "select s.count from s in class org.hibernate.test.Top, ls in class org.hibernate.test.Lower where ls.another=s" ); - parse( "select elements(ls.bag), elements(ls.set) from ls in class org.hibernate.test.Lower" ); - parse( "from s in class org.hibernate.test.Lower" ); - parse( "from s in class org.hibernate.test.Top" ); - parse( "from sm in class org.hibernate.test.SubMulti" ); - parse( "select\n" + - "\n" + - "s from s in class org.hibernate.test.Top where s.count>0" ); - parse( "from m in class org.hibernate.test.Multi where m.count>0 and m.extraProp is not null" ); - parse( "from m in class org.hibernate.test.Top where m.count>0 and m.name is not null" ); - parse( "from m in class org.hibernate.test.Lower where m.other is not null" ); - parse( "from m in class org.hibernate.test.Multi where m.other.id = 1" ); - parse( "from m in class org.hibernate.test.SubMulti where m.amount > 0.0" ); - parse( "from m in class org.hibernate.test.Multi" ); - parse( "from m in class org.hibernate.test.Multi where m.class = SubMulti" ); - parse( "from m in class org.hibernate.test.Top where m.class = Multi" ); - parse( "from s in class org.hibernate.test.Top" ); - parse( "from ls in class org.hibernate.test.Lower" ); - parse( "from ls in class org.hibernate.test.Lower, s in elements(ls.bag) where s.id is not null" ); - parse( "from ls in class org.hibernate.test.Lower, s in elements(ls.set) where s.id is not null" ); - parse( "from o in class org.hibernate.test.Top" ); - parse( "from o in class org.hibernate.test.Po" ); - parse( "from ChildMap cm where cm.parent is not null" ); - parse( "from ParentMap cm where cm.child is not null" ); - parse( "from org.hibernate.test.Componentizable" ); - } - - @Test public void testUnnamedParameter() throws Exception { - parse( "select foo, bar from org.hibernate.test.Foo foo left outer join foo.foo bar where foo = ?" ); // Added '?' as a valid expression. - } - - @Test public void testInElements() throws Exception { - parse( "from bar in class org.hibernate.test.Bar, foo in elements(bar.baz.fooArray)" ); // Added collectionExpr as a valid 'in' clause. - } - - @Test public void testDotElements() throws Exception { - parse( "select distinct foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooArray)" ); - parse( "select foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooSet)" ); - parse( "select foo from baz in class org.hibernate.test.Baz, foo in elements(baz.fooArray)" ); - parse( "from org.hibernate.test.Baz baz where 'b' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)" ); - } - - @Test public void testSelectAll() throws Exception { - parse( "select all s, s.other from s in class org.hibernate.test.Simple where s = :s" ); - } - - @Test public void testNot() throws Exception { - // Cover NOT optimization in HqlParser - parse( "from eg.Cat cat where not ( cat.kittens.size < 1 )" ); - parse( "from eg.Cat cat where not ( cat.kittens.size > 1 )" ); - parse( "from eg.Cat cat where not ( cat.kittens.size >= 1 )" ); - parse( "from eg.Cat cat where not ( cat.kittens.size <= 1 )" ); - parse( "from eg.DomesticCat cat where not ( cat.name between 'A' and 'B' ) " ); - parse( "from eg.DomesticCat cat where not ( cat.name not between 'A' and 'B' ) " ); - parse( "from eg.Cat cat where not ( not cat.kittens.size <= 1 )" ); - parse( "from eg.Cat cat where not not ( not cat.kittens.size <= 1 )" ); - } - - @Test public void testOtherSyntax() throws Exception { - parse( "select bar from org.hibernate.test.Bar bar order by ((bar.x - :valueX)*(bar.x - :valueX))" ); - parse( "from bar in class org.hibernate.test.Bar, foo in elements(bar.baz.fooSet)" ); - parse( "from one in class org.hibernate.test.One, many in elements(one.manies) where one.id = 1 and many.id = 1" ); - parse( "from org.hibernate.test.Inner _inner join _inner.middles middle" ); - parse( "FROM m IN CLASS org.hibernate.test.Root WHERE NOT EXISTS ( FROM d IN elements(m.details) WHERE NOT d.i=5 )" ); - parse( "FROM m IN CLASS org.hibernate.test.Root WHERE NOT 5 IN ( SELECT d.i FROM d IN elements(m.details) )" ); - parse( "SELECT m FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" ); - parse( "SELECT m FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" ); - parse( "SELECT m.id FROM m IN CLASS org.hibernate.test.Root, d IN elements(m.details) WHERE d.i=5" ); - // I'm not sure about these... [jsd] -// parse("select bar.string, foo.string from bar in class org.hibernate.test.Bar inner join bar.baz as baz inner join elements(baz.fooSet) as foo where baz.name = 'name'"); -// parse("select bar.string, foo.string from bar in class org.hibernate.test.Bar, bar.baz as baz, elements(baz.fooSet) as foo where baz.name = 'name'"); -// parse("select count(*) where this.amount>-1 and this.name is null"); -// parse("from sm in class org.hibernate.test.SubMulti where exists sm.children.elements"); - } - - @Test public void testEjbqlExtensions() throws Exception { - parse( "select object(a) from Animal a where a.mother member of a.offspring" ); - parse( "select object(a) from Animal a where a.mother member a.offspring" ); //no member of - parse( "select object(a) from Animal a where a.offspring is empty" ); - } - - @Test public void testEmptyFilter() throws Exception { - parseFilter( "" ); // Blank is a legitimate filter. - } - - @Test public void testOrderByFilter() throws Exception { - parseFilter( "order by this.id" ); - } - - @Test public void testRestrictionFilter() throws Exception { - parseFilter( "where this.name = ?" ); - } - - @Test public void testNoFrom() throws Exception { - System.out.println( "***** This test ensures that an error is detected ERROR MESSAGES ARE OKAY! *****" ); - HqlParser parser = HqlParser.getInstance( "" ); - parser.setFilter( false ); - parser.statement(); - assertEquals( "Parser allowed no FROM clause!", 1, parser.getParseErrorHandler().getErrorCount() ); - System.out.println( "***** END OF ERROR TEST *****" ); - } - - @Test public void testHB1042() throws Exception { - parse( "select x from fmc_web.pool.Pool x left join x.containers c0 where (upper(x.name) = upper(':') and c0.id = 1)" ); - } - - @Test public void testKeywordInPath() throws Exception { - // The keyword 'order' used as a property name. - parse( "from Customer c where c.order.status = 'argh'" ); - // The keyword 'order' and 'count' used as a property name. - parse( "from Customer c where c.order.count > 3" ); - // The keywords 'where', 'order' and 'count' used as a property name. - parse( "select c.where from Customer c where c.order.count > 3" ); - parse( "from Interval i where i.end <:end" ); - parse( "from Letter l where l.case = :case" ); - } - - @Test public void testPathologicalKeywordAsIdentifier() throws Exception { - // Super evil badness... a legitimate keyword! - parse( "from Order order" ); - //parse( "from Order order join order.group" ); - parse( "from X x order by x.group.by.from" ); - parse( "from Order x order by x.order.group.by.from" ); - parse( "select order.id from Order order" ); - parse( "select order from Order order" ); - parse( "from Order order where order.group.by.from is not null" ); - parse( "from Order order order by order.group.by.from" ); - // Okay, now this is getting silly. - parse( "from Group as group group by group.by.from" ); - } - - @Test public void testHHH354() throws Exception { - parse( "from Foo f where f.full = 'yep'"); - } - - @Test public void testWhereAsIdentifier() throws Exception { - // 'where' as a package name - parse( "from where.Order" ); - } - - @Test public void testEjbqlKeywordsAsIdentifier() throws Exception { - parse( "from org.hibernate.test.Bar bar where bar.object.id = ? and bar.object.class = ?" ); - } - - @Test public void testConstructorIn() throws Exception { - parse( "from org.hibernate.test.Bar bar where (b.x, b.y, b.z) in (select foo, bar, baz from org.hibernate.test.Foo)" ); - } - - @Test public void testMultiByteCharacters() throws Exception { - parse ("from User user where user.name like '%nn\u4e2dnn%'"); - // Test for HHH-558 - parse ("from User user where user.\u432d like '%\u4e2d%'"); - parse ("from \u432d \u432d where \u432d.name like '%fred%'"); - } - - @Test public void testHHH719() throws Exception { - // Some SQLs have function names with package qualifiers. - parse("from Foo f order by com.fooco.SpecialFunction(f.id)"); - } - - @Test public void testHHH1107() throws Exception { - parse("from Animal where zoo.address.street = '123 Bogus St.'"); - } - - - @Test public void testHHH1247() throws Exception { - parse("select distinct user.party from com.itf.iceclaims.domain.party.user.UserImpl user inner join user.party.$RelatedWorkgroups relatedWorkgroups where relatedWorkgroups.workgroup.id = :workgroup and relatedWorkgroups.effectiveTime.start <= :datesnow and relatedWorkgroups.effectiveTime.end > :dateenow "); - } - - @Test public void testHHH1780() throws Exception { - // verifies the tree contains a NOT->EXISTS subtree - class Verifier { - public boolean verify(AST root) { - Stack queue = new Stack(); - queue.push( root ); - while ( !queue.isEmpty() ) { - AST parent = queue.pop(); - AST child = parent.getFirstChild(); - while ( child != null ) { - if ( parent.getType() == HqlTokenTypes.NOT && - child.getType() == HqlTokenTypes.EXISTS ) { - return true; - } - queue.push( child ); - child = child.getNextSibling(); - } - } - return false; - } - } - - // test inversion of AND - AST ast = doParse( - "from Person p where not ( p.name is null and exists(select a.id from Address a where a.id=p.id))", - false - ); - - assertTrue( new Verifier().verify( ast ) ); - - // test inversion of OR - ast = doParse( - "from Person p where not ( p.name is null or exists(select a.id from Address a where a.id=p.id))", - false - ); - - assertTrue( new Verifier().verify( ast ) ); - } - - - @Test public void testLineAndColumnNumber() throws Exception { - AST ast = doParse("from Foo f\nwhere f.name = 'fred'",false); - // Find some of the nodes and check line and column values. - ASTIterator iter = new ASTIterator(ast); - boolean foundFoo = false; - boolean foundName = false; - while (iter.hasNext()) - { - AST n = iter.nextNode(); - if ("Foo".equals(n.getText())) - { - if (foundFoo) - fail("Already found 'Foo'!"); - foundFoo = true; - Node node = (Node)n; - assertEquals(1,node.getLine()); - assertEquals(6,node.getColumn()); - } - else if ("name".equals(n.getText())) - { - if (foundName) - fail("Already found 'name'!"); - foundName = true; - Node node = (Node)n; - assertEquals(2,node.getLine()); - assertEquals(9,node.getColumn()); - } - } - assertTrue(foundFoo); - assertTrue(foundName); - } - - private void parseFilter(String input) throws TokenStreamException, RecognitionException { - doParse( input, true ); - } - - private void parse(String input) throws RecognitionException, TokenStreamException { - doParse( input, false ); - } - - private AST doParse(String input, boolean filter) throws RecognitionException, TokenStreamException { - System.out.println( "input: ->" + ASTPrinter.escapeMultibyteChars(input) + "<-" ); - HqlParser parser = HqlParser.getInstance( input ); - parser.setFilter( filter ); - parser.statement(); - AST ast = parser.getAST(); - System.out.println( "AST : " + ast.toStringTree() + "" ); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - parser.showAst( ast, new PrintStream( baos ) ); - System.out.println( baos.toString() ); - assertEquals( "At least one error occurred during parsing!", 0, parser.getParseErrorHandler().getErrorCount() ); - return ast; - } - - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/QuerySplitterTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/QuerySplitterTest.java deleted file mode 100644 index 26baefbaad..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/QuerySplitterTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - - -import org.hibernate.query.hql.internal.QuerySplitter; - -import java.lang.reflect.Field; -import java.util.Map; -import java.util.stream.IntStream; - -import org.hibernate.metamodel.internal.MetamodelImpl; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * @author Steve Ebersole - */ -public class QuerySplitterTest extends BaseNonConfigCoreFunctionalTestCase { - @Test - public void testQueryWithEntityNameAsStringLiteral() { - final String qry = "select e from Employee a where e.name = ', Employee Number 1'"; - - String[] results = QuerySplitter.concreteQueries( qry, sessionFactory() ); - assertEquals( 1, results.length ); - assertEquals( - "select e from org.hibernate.test.hql.QuerySplitterTest$Employee a where e.name = ', Employee Number 1'", - results[0] - ); - } - - @Test - @TestForIssue(jiraKey = "HHH-7973" ) - public void testQueryWithEntityNameAsStringLiteral2() { - final String qry = "from Employee where name = 'He is the, Employee Number 1'"; - - String[] results = QuerySplitter.concreteQueries( qry, sessionFactory() ); - assertEquals( 1, results.length ); - assertEquals( - "from org.hibernate.test.hql.QuerySplitterTest$Employee where name = 'He is the, Employee Number 1'", - results[0] - ); - } - - @Test - @TestForIssue(jiraKey = "HHH-14948") - public void testMemoryConsumptionOfFailedImportsCache() throws NoSuchFieldException, IllegalAccessException { - - IntStream.range( 0, 1001 ) - .forEach( i -> QuerySplitter.concreteQueries( - "from Employee e join e.company" + i, - sessionFactory() - ) ); - - MetamodelImpl metamodel = (MetamodelImpl) sessionFactory().getMetamodel(); - - Field field = MetamodelImpl.class.getDeclaredField( "imports" ); - field.setAccessible( true ); - - //noinspection unchecked - Map imports = (Map) field.get( metamodel ); - - // VERY hard-coded, but considering the possibility of a regression of a memory-related issue, - // it should be worth it - assertEquals( 1000, imports.size() ); - } - - @Test - @TestForIssue(jiraKey = "HHH-7973" ) - public void testQueryWithEntityNameAsStringLiteralAndEscapeQuoteChar() { - final String qry = "from Employee where name = '''He is '' the, Employee Number 1'''"; - - String[] results = QuerySplitter.concreteQueries( qry, sessionFactory() ); - assertEquals( 1, results.length ); - assertEquals( - "from org.hibernate.test.hql.QuerySplitterTest$Employee where name = '''He is '' the, Employee Number 1'''", - results[0] - ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Employee.class }; - } - - @Entity( name = "Employee" ) - @Table( name= "tabEmployees" ) - public class Employee { - @Id - private long id; - private String name; - - public Employee() { - - } - - public Employee(long id, String strName) { - this(); - this.name = strName; - } - - public long getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String strName) { - this.name = strName; - } - - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/hql/QueryTranslatorTestCase.java b/hibernate-core/src/test_legacy/org/hibernate/test/hql/QueryTranslatorTestCase.java deleted file mode 100644 index c769b9324e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/hql/QueryTranslatorTestCase.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.hql; - -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeMap; - -import junit.framework.ComparisonFailure; - -import org.hibernate.MappingException; -import org.hibernate.QueryException; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; -import org.hibernate.hql.internal.ast.QueryTranslatorImpl; -import org.hibernate.hql.internal.ast.util.ASTPrinter; -import org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory; -import org.hibernate.hql.spi.QueryTranslator; -import org.hibernate.hql.spi.QueryTranslatorFactory; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.type.Type; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -public abstract class QueryTranslatorTestCase extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] { - "hql/Animal.hbm.xml", - "hql/EntityWithCrazyCompositeKey.hbm.xml", - "hql/CrazyIdFieldNames.hbm.xml", - "hql/SimpleEntityWithAssociation.hbm.xml", - "hql/ComponentContainer.hbm.xml", - "/org/hibernate/orm/test/batchfetch/ProductLine.hbm.xml", - "cid/Customer.hbm.xml", - "cid/Order.hbm.xml", - "cid/LineItem.hbm.xml", - "cid/Product.hbm.xml", - "legacy/Baz.hbm.xml", - "legacy/Category.hbm.xml", - "legacy/Commento.hbm.xml", - "legacy/Container.hbm.xml", - "legacy/Custom.hbm.xml", - "legacy/Eye.hbm.xml", - "legacy/Fee.hbm.xml", - "legacy/FooBar.hbm.xml", - "legacy/Fum.hbm.xml", - "legacy/Glarch.hbm.xml", - "legacy/Holder.hbm.xml", - "legacy/Many.hbm.xml", - "legacy/Marelo.hbm.xml", - "legacy/RootDetail.hbm.xml", - "legacy/Middle.hbm.xml", - "legacy/Multi.hbm.xml", - "legacy/Nameable.hbm.xml", - "legacy/One.hbm.xml", - "legacy/Qux.hbm.xml", - "legacy/Simple.hbm.xml", - "legacy/SingleSeveral.hbm.xml", - "legacy/WZ.hbm.xml", - "legacy/UpDown.hbm.xml", - "compositeelement/Parent.hbm.xml", - "onetoone/joined/Person.hbm.xml", - "any/Properties.hbm.xml" - }; - } - - @Override - public boolean createSchema() { - return false; - } - - @Override - public boolean rebuildSessionFactoryOnError() { - return false; - } - - public void assertTranslation(String hql) throws QueryException, MappingException { - assertTranslation( hql, null ); - } - - protected void assertTranslation(String hql, Map replacements) { - ComparisonFailure cf = null; - try { - assertTranslation( hql, replacements, false, null ); - } - catch ( ComparisonFailure e ) { - e.printStackTrace(); - cf = e; - } - if ( "false".equals( System.getProperty( "org.hibernate.test.hql.SkipScalarQuery", "false" ) ) ) { - // Run the scalar translation anyway, even if there was a comparison failure. - assertTranslation( hql, replacements, true, null ); - } - if ( cf != null ) { - throw cf; - } - } - - protected void assertTranslation(String hql, Map replacements, boolean scalar, String sql) { - SessionFactoryImplementor factory = sessionFactory(); - - // Create an empty replacements map if we don't have one. - if ( replacements == null ) { - replacements = new HashMap(); - } - - // steve -> note that the empty maps here represent the currently enabled filters... - QueryTranslator oldQueryTranslator = null; - Exception oldException = null; - try { - System.out.println("Compiling with classic QueryTranslator..."); - QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory(); - oldQueryTranslator = classic.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory, null ); - oldQueryTranslator.compile( replacements, scalar ); - } - catch ( QueryException e ) { - oldException = e; - } - catch ( MappingException e ) { - oldException = e; - } - - QueryTranslator newQueryTranslator = null; - Exception newException = null; - try { - System.out.println("Compiling with AST QueryTranslator..."); - newQueryTranslator = createNewQueryTranslator( hql, replacements, scalar ); - } - catch ( QueryException e ) { - newException = e; - } - catch ( MappingException e ) { - newException = e; - } - - // If the old QT threw an exception, the new one should too. - if ( oldException != null ) { - assertNotNull( "New query translator did *NOT* throw an exception, the old one did : " + oldException, newException ); - assertEquals( oldException.getMessage(), newException.getMessage() ); - return; // Don't bother with the rest of the assertions. - } - else if ( newException != null ) { - newException.printStackTrace(); - assertNull( "Old query translator did not throw an exception, the new one did", newException ); - } - - // -- check all of the outputs -- - checkSql( oldQueryTranslator, newQueryTranslator, hql, scalar, sql ); - checkQuerySpaces( oldQueryTranslator, newQueryTranslator ); - checkReturnedTypes( oldQueryTranslator, newQueryTranslator ); - - } - - protected QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar) { - SessionFactoryImplementor factory = sessionFactory(); - return createNewQueryTranslator( hql, replacements, scalar, factory ); - } - - private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - QueryTranslatorImpl newQueryTranslator = ( QueryTranslatorImpl ) ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory, null ); - newQueryTranslator.compile( replacements, scalar ); - return newQueryTranslator; - } - - protected QueryTranslatorImpl createNewQueryTranslator(String hql) { - return createNewQueryTranslator( hql, new HashMap(), false ); - } - - protected QueryTranslatorImpl createNewQueryTranslator(String hql, SessionFactoryImplementor sfimpl) { - return createNewQueryTranslator( hql, new HashMap(), false, sfimpl ); - } - - protected HQLQueryPlan createQueryPlan(String hql, boolean scalar) { - return new HQLQueryPlan( hql, scalar, Collections.EMPTY_MAP, sessionFactory() ); - } - - protected HQLQueryPlan createQueryPlan(String hql) { - return createQueryPlan( hql, false ); - } - - @Deprecated - protected SessionFactoryImplementor getSessionFactoryImplementor() { - return sessionFactory(); - } - - private void checkReturnedTypes(QueryTranslator oldQueryTranslator, QueryTranslator newQueryTranslator) { - // Check the returned types for a regression. - Type[] oldReturnTypes = oldQueryTranslator.getReturnTypes(); - Type[] returnTypes = newQueryTranslator.getReturnTypes(); - assertEquals( "Return types array is not the right length!", oldReturnTypes.length, returnTypes.length ); - for ( int i = 0; i < returnTypes.length; i++ ) { - assertNotNull( returnTypes[i] ); - assertNotNull( oldReturnTypes[i] ); - assertEquals( "Returned types did not match!", oldReturnTypes[i].getReturnedClass(), returnTypes[i].getReturnedClass() ); - System.out.println("returnedType[" + i + "] = " + returnTypes[i] + " oldReturnTypes[" + i + "] = " + oldReturnTypes[i]); - } - } - - private void checkQuerySpaces(QueryTranslator oldQueryTranslator, QueryTranslator newQueryTranslator) { - // Check the query spaces for a regression. - Set oldQuerySpaces = oldQueryTranslator.getQuerySpaces(); - Set querySpaces = newQueryTranslator.getQuerySpaces(); - assertEquals( "Query spaces is not the right size!", oldQuerySpaces.size(), querySpaces.size() ); - for ( Object o : oldQuerySpaces ) { - assertTrue( "New query space does not contain " + o + "!", querySpaces.contains( o ) ); - } - } - - protected Exception compileBadHql(String hql, boolean scalar) { - QueryTranslator newQueryTranslator; - Map replacements = null; - Exception newException = null; - SessionFactoryImplementor factory = sessionFactory(); - try { - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - newQueryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory, null ); - newQueryTranslator.compile( replacements, scalar ); - } - catch ( QueryException e ) { - newException = e; - } - catch ( MappingException e ) { - newException = e; - } - assertNotNull( "Expected exception from compilation of '" + hql + "'!", newException ); - return newException; - } - - private void checkSql(QueryTranslator oldQueryTranslator, QueryTranslator newQueryTranslator, String hql, boolean scalar, String sql) { - - String oldsql = oldQueryTranslator.getSQLString(); - String newsql = newQueryTranslator.getSQLString(); - System.out.println( "HQL : " + ASTPrinter.escapeMultibyteChars(hql) ); - System.out.println( "OLD SQL: " + ASTPrinter.escapeMultibyteChars(oldsql) ); - System.out.println( "NEW SQL: " + ASTPrinter.escapeMultibyteChars(newsql) ); - if ( sql == null ) { - // Check the generated SQL. ASTPrinter.escapeMultibyteChars( - assertSQLEquals( "SQL is not the same as the old SQL (scalar=" + scalar + ")", oldsql, newsql ); - } - else { - assertSQLEquals( "SQL is not the same as the expected SQL (scalar=" + scalar + ")", sql, newsql ); - } - } - - private void assertSQLEquals(String message, String oldsql, String newsql) { - Map oldMap = getTokens(oldsql); - Map newMap = getTokens(newsql); - if ( !oldMap.equals(newMap) ) { - assertEquals(message, oldsql, newsql); - } - } - - - private Map getTokens(String sql) { - Map result = new TreeMap(); - if ( sql == null ) { - return result; - } - result.put( "=", Integer.valueOf( StringHelper.countUnquoted( sql, '=' ) ) ); - StringTokenizer tokenizer = new StringTokenizer( sql, "(),= " ); - while ( tokenizer.hasMoreTokens() ) { - String fragment = tokenizer.nextToken(); - /*if ( "on".equals(fragment) ) fragment = "and"; - if ( "join".equals(fragment) || "inner".equals(fragment) ) continue;*/ - Integer count = result.get(fragment); - if ( count == null ) { - count = Integer.valueOf(1); - } - else { - count = Integer.valueOf( count.intValue() + 1 ); - } - result.put(fragment, count); - } - return result; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/iterate/IterateTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/iterate/IterateTest.java deleted file mode 100644 index 5d4e1a0996..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/iterate/IterateTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.iterate; -import java.util.Iterator; - -import org.junit.Test; - -import org.hibernate.Hibernate; -import org.hibernate.ScrollableResults; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author Gavin King - */ -public class IterateTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] { "iterate/Item.hbm.xml" }; - } - - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( Environment.USE_QUERY_CACHE, "true" ); - cfg.setProperty( Environment.CACHE_REGION_PREFIX, "foo" ); - cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" ); - cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); - } - - @Test - public void testIterate() throws Exception { - sessionFactory().getStatistics().clear(); - Session s = openSession(); - Transaction t = s.beginTransaction(); - Item i1 = new Item("foo"); - Item i2 = new Item("bar"); - s.persist("Item", i1); - s.persist("Item", i2); - t.commit(); - s.close(); - - s = openSession(); - t = s.beginTransaction(); - Iterator iter = s.getNamedQuery("Item.nameDesc").iterate(); - i1 = (Item) iter.next(); - i2 = (Item) iter.next(); - assertFalse( Hibernate.isInitialized(i1) ); - assertFalse( Hibernate.isInitialized(i2) ); - i1.getName(); - i2.getName(); - assertFalse( Hibernate.isInitialized(i1) ); - assertFalse( Hibernate.isInitialized(i2) ); - assertEquals( i1.getName(), "foo" ); - assertEquals( i2.getName(), "bar" ); - Hibernate.initialize(i1); - assertFalse( iter.hasNext() ); - s.delete(i1); - s.delete(i2); - t.commit(); - s.close(); - assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 2 ); - } - - -} - diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java b/hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java deleted file mode 100644 index c0212cde47..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.jpa.compliance.tck2_2; - -import java.util.List; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.OrderBy; -import jakarta.persistence.Table; - -import org.hibernate.boot.MetadataSources; -import org.hibernate.cfg.annotations.CollectionBinder; -import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.function.SQLFunctionRegistry; -import org.hibernate.engine.spi.SessionFactoryImplementor; - -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; - -import org.hamcrest.CoreMatchers; - -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * @author Steve Ebersole - */ -public class OrderByAnnotationTests extends BaseNonConfigCoreFunctionalTestCase { - private static final String ELEMENT_TOKEN = "$element$"; - private static final String TABLE_ALIAS = "a"; - private static final String COLUMN_NAME = "name"; - - @Test - public void testOrderByEmpty() { - assertThat( translate( "" ), CoreMatchers.is( TABLE_ALIAS + '.' + COLUMN_NAME + " asc" ) ); - } - - @Test - public void testOrderByJustDesc() { - assertThat( translate( "desc" ), CoreMatchers.is( TABLE_ALIAS + '.' + COLUMN_NAME + " desc" ) ); - - assertThat( translate( "DESC"), CoreMatchers.is( TABLE_ALIAS + '.' + COLUMN_NAME + " desc" ) ); - } - - @Test - public void testOrderByJustAsc() { - assertThat( translate( "asc"), CoreMatchers.is( TABLE_ALIAS + '.' + COLUMN_NAME + " asc" ) ); - - assertThat( translate( "ASC"), CoreMatchers.is( TABLE_ALIAS + '.' + COLUMN_NAME + " asc" ) ); - } - - private String translate(String fragment) { - fragment = CollectionBinder.adjustUserSuppliedValueCollectionOrderingFragment( fragment ); - - final TranslationContext translationContext = translationContext(); - final OrderByTranslation translation = OrderByFragmentTranslator.translate( translationContext, fragment ); - - return translation.injectAliases( columnReference -> TABLE_ALIAS ); - } - - private TranslationContext translationContext() { - final ColumnMapper columnMapper = reference -> { - assert ELEMENT_TOKEN.equals( reference ); - return new SqlValueReference[] { - (ColumnReference) () -> COLUMN_NAME - }; - }; - - return new TranslationContext() { - @Override - public SessionFactoryImplementor getSessionFactory() { - return sessionFactory(); - } - - @Override - public Dialect getDialect() { - return getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect(); - } - - @Override - public SQLFunctionRegistry getSqlFunctionRegistry() { - return getSessionFactory().getSqlFunctionRegistry(); - } - - @Override - public ColumnMapper getColumnMapper() { - return columnMapper; - } - }; - } - -// @Override -// protected void applyMetadataSources(MetadataSources metadataSources) { -// super.applyMetadataSources( metadataSources ); -// metadataSources.addAnnotatedClass( A.class ); -// } -// -// @Entity( name = "A" ) -// @Table( name = "T_A" ) -// public static class A { -// @Id -// public Integer id; -// @ElementCollection -// @Column( name = "name" ) -// @OrderBy -// public List names; -// } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeAttributeResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeAttributeResultSetProcessorTest.java deleted file mode 100644 index 5fb38bd2d8..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeAttributeResultSetProcessorTest.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import java.io.Serializable; -import java.math.BigDecimal; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.hibernate.LockMode; -import org.hibernate.Session; -import org.hibernate.engine.spi.LoadQueryInfluencers; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.loader.JoinWalker; -import org.hibernate.loader.entity.EntityJoinWalker; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.persister.entity.OuterJoinLoadable; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; - -/** - * @author Gail Badner - */ -public class EncapsulatedCompositeAttributeResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Person.class, Customer.class }; - } - - @Test - public void testSimpleNestedCompositeAttributeProcessing() throws Exception { - // create some test data - Session session = openSession(); - session.beginTransaction(); - Person person = new Person(); - person.id = 1; - person.name = "Joe Blow"; - person.address = new Address(); - person.address.address1 = "1313 Mockingbird Lane"; - person.address.city = "Pleasantville"; - person.address.country = "USA"; - AddressType addressType = new AddressType(); - addressType.typeName = "snail mail"; - person.address.type = addressType; - session.save( person ); - session.getTransaction().commit(); - session.close(); - -// session = openSession(); -// session.beginTransaction(); -// Person personGotten = (Person) session.get( Person.class, person.id ); -// assertEquals( person.id, personGotten.id ); -// assertEquals( person.address.address1, personGotten.address.address1 ); -// assertEquals( person.address.city, personGotten.address.city ); -// assertEquals( person.address.country, personGotten.address.country ); -// assertEquals( person.address.type.typeName, personGotten.address.type.typeName ); -// session.getTransaction().commit(); -// session.close(); - - List results = getResults( sessionFactory().getEntityPersister( Person.class.getName() ) ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - Person personWork = ExtraAssertions.assertTyping( Person.class, result ); - assertEquals( person.id, personWork.id ); - assertEquals( person.address.address1, personWork.address.address1 ); - assertEquals( person.address.city, personWork.address.city ); - assertEquals( person.address.country, personWork.address.country ); - assertEquals( person.address.type.typeName, person.address.type.typeName ); - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete Person" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testNestedCompositeElementCollectionQueryBuilding() { - doCompare( - sessionFactory(), - (OuterJoinLoadable) sessionFactory().getClassMetadata( Customer.class ) - ); - } - - private void doCompare(SessionFactoryImplementor sf, OuterJoinLoadable persister) { - final LoadQueryInfluencers influencers = LoadQueryInfluencers.NONE; - final LockMode lockMode = LockMode.NONE; - final int batchSize = 1; - - final EntityJoinWalker walker = new EntityJoinWalker( - persister, - persister.getKeyColumnNames(), - batchSize, - lockMode, - sf, - influencers - ); - - final LoadQueryDetails details = Helper.INSTANCE.buildLoadQueryDetails( persister, sf ); - - compare( walker, details ); - } - - private void compare(JoinWalker walker, LoadQueryDetails details) { - System.out.println( "WALKER : " + walker.getSQLString() ); - System.out.println( "LOAD-PLAN : " + details.getSqlStatement() ); - System.out.println(); - } - - @Test - public void testNestedCompositeElementCollectionProcessing() throws Exception { - // create some test data - Session session = openSession(); - session.beginTransaction(); - Person person = new Person(); - person.id = 1; - person.name = "Joe Blow"; - session.save( person ); - Customer customer = new Customer(); - customer.id = 1L; - Investment investment1 = new Investment(); - investment1.description = "stock"; - investment1.date = new Date(); - investment1.monetaryAmount = new MonetaryAmount(); - investment1.monetaryAmount.currency = MonetaryAmount.CurrencyCode.USD; - investment1.monetaryAmount.amount = BigDecimal.valueOf( 1234, 2 ); - investment1.performedBy = person; - Investment investment2 = new Investment(); - investment2.description = "bond"; - investment2.date = new Date(); - investment2.monetaryAmount = new MonetaryAmount(); - investment2.monetaryAmount.currency = MonetaryAmount.CurrencyCode.EUR; - investment2.monetaryAmount.amount = BigDecimal.valueOf( 98176, 1 ); - customer.investments.add( investment1 ); - customer.investments.add( investment2 ); - session.save( customer ); - session.getTransaction().commit(); - session.close(); - -// session = openSession(); -// session.beginTransaction(); -// Customer customerGotten = (Customer) session.get( Customer.class, customer.id ); -// assertEquals( customer.id, customerGotten.id ); -// session.getTransaction().commit(); -// session.close(); - - List results = getResults( sessionFactory().getEntityPersister( Customer.class.getName() ) ); - - assertEquals( 2, results.size() ); - assertSame( results.get( 0 ), results.get( 1 ) ); - Object result = results.get( 0 ); - assertNotNull( result ); - - Customer customerWork = ExtraAssertions.assertTyping( Customer.class, result ); - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.delete( customerWork.investments.get( 0 ).performedBy ); - session.delete( customerWork ); - session.getTransaction().commit(); - session.close(); - } - - private List getResults(EntityPersister entityPersister ) { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 1 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - workSession.getTransaction().commit(); - workSession.close(); - return results; - } - - @Entity( name = "Person" ) - public static class Person implements Serializable { - @Id - Integer id; - String name; - - @Embedded - Address address; - } - - @Embeddable - public static class Address implements Serializable { - String address1; - String city; - String country; - AddressType type; - } - - @Embeddable - public static class AddressType { - String typeName; - } - - @Entity( name = "Customer" ) - public static class Customer { - private Long id; - private List investments = new ArrayList(); - - @Id - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } - - @ElementCollection(fetch = FetchType.EAGER) - @CollectionTable( name = "investments", joinColumns = @JoinColumn( name = "customer_id" ) ) - public List getInvestments() { - return investments; - } - public void setInvestments(List investments) { - this.investments = investments; - } - } - - @Embeddable - public static class Investment { - private MonetaryAmount monetaryAmount; - private String description; - private Date date; - private Person performedBy; - - @Embedded - public MonetaryAmount getMonetaryAmount() { - return monetaryAmount; - } - public void setMonetaryAmount(MonetaryAmount monetaryAmount) { - this.monetaryAmount = monetaryAmount; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - @Column(name="`date`") - public Date getDate() { - return date; - } - public void setDate(Date date) { - this.date = date; - } - @ManyToOne - public Person getPerformedBy() { - return performedBy; - } - public void setPerformedBy(Person performedBy) { - this.performedBy = performedBy; - } - } - - @Embeddable - public static class MonetaryAmount { - public static enum CurrencyCode { - USD, - EUR - } - private BigDecimal amount; - @Column(length = 3) - @Enumerated(EnumType.STRING) - private CurrencyCode currency; - - public BigDecimal getAmount() { - return amount; - } - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public CurrencyCode getCurrency() { - return currency; - } - public void setCurrency(CurrencyCode currency) { - this.currency = currency; - } - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeIdResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeIdResultSetProcessorTest.java deleted file mode 100644 index fdf25cf649..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EncapsulatedCompositeIdResultSetProcessorTest.java +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import java.io.Serializable; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import jakarta.persistence.Embeddable; -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; - -import org.hibernate.LockOptions; -import org.hibernate.Session; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.type.Type; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * @author Gail Badner - */ -public class EncapsulatedCompositeIdResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Parent.class, CardField.class, Card.class }; - } - - @Test - public void testSimpleCompositeId() throws Exception { - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Parent parent = new Parent(); - parent.id = new ParentPK(); - parent.id.firstName = "Joe"; - parent.id.lastName = "Blow"; - session.save( parent ); - session.getTransaction().commit(); - session.close(); - - session = openSession(); - session.beginTransaction(); - Parent parentGotten = (Parent) session.get( Parent.class, parent.id ); - assertEquals( parent, parentGotten ); - session.getTransaction().commit(); - session.close(); - - final List results = getResults( - sessionFactory().getEntityPersister( Parent.class.getName() ), - new Callback() { - @Override - public void bind(PreparedStatement ps) throws SQLException { - ps.setString( 1, "Joe" ); - ps.setString( 2, "Blow" ); - } - - @Override - public QueryParameters getQueryParameters() { - return new QueryParameters(); - } - - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - Parent parentWork = ExtraAssertions.assertTyping( Parent.class, result ); - assertEquals( parent, parentWork ); - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete Parent" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testCompositeIdWithKeyManyToOne() throws Exception { - final String cardId = "ace-of-spades"; - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Card card = new Card( cardId ); - final CardField cardField = new CardField( card, 1 ); - session.persist( card ); - session.persist( cardField ); - session.getTransaction().commit(); - session.close(); - - session = openSession(); - session.beginTransaction(); - Card cardProxy = (Card) session.load( Card.class, cardId ); - final CardFieldPK cardFieldPK = new CardFieldPK( cardProxy, 1 ); - CardField cardFieldGotten = (CardField) session.get( CardField.class, cardFieldPK ); - - //assertEquals( card, cardGotten ); - session.getTransaction().commit(); - session.close(); - - final EntityPersister entityPersister = sessionFactory().getEntityPersister( CardField.class.getName() ); - - final List results = getResults( - entityPersister, - new Callback() { - @Override - public void bind(PreparedStatement ps) throws SQLException { - ps.setString( 1, cardField.primaryKey.card.id ); - ps.setInt( 2, cardField.primaryKey.fieldNumber ); - } - - @Override - public QueryParameters getQueryParameters() { - QueryParameters qp = new QueryParameters(); - qp.setPositionalParameterTypes( new Type[] { entityPersister.getIdentifierType() } ); - qp.setPositionalParameterValues( new Object[] { cardFieldPK } ); - qp.setOptionalObject( null ); - qp.setOptionalEntityName( entityPersister.getEntityName() ); - qp.setOptionalId( cardFieldPK ); - qp.setLockOptions( LockOptions.NONE ); - return qp; - } - - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - CardField cardFieldWork = ExtraAssertions.assertTyping( CardField.class, result ); - assertEquals( cardFieldGotten, cardFieldWork ); - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete CardField" ).executeUpdate(); - session.createQuery( "delete Card" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - private List getResults(final EntityPersister entityPersister, final Callback callback) { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - callback.bind( ps ); - ResultSet resultSet = ps.executeQuery(); - //callback.beforeExtractResults( workSession ); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - callback.getQueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - workSession.getTransaction().commit(); - workSession.close(); - - return results; - } - - - private interface Callback { - void bind(PreparedStatement ps) throws SQLException; - QueryParameters getQueryParameters (); - } - - @Entity ( name = "Parent" ) - public static class Parent { - @EmbeddedId - public ParentPK id; - - public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof Parent ) ) return false; - - final Parent parent = (Parent) o; - - if ( !id.equals( parent.id ) ) return false; - - return true; - } - - public int hashCode() { - return id.hashCode(); - } - } - - @Embeddable - public static class ParentPK implements Serializable { - private String firstName; - private String lastName; - - public boolean equals(Object o) { - if ( this == o ) return true; - if ( !( o instanceof ParentPK ) ) return false; - - final ParentPK parentPk = (ParentPK) o; - - if ( !firstName.equals( parentPk.firstName ) ) return false; - if ( !lastName.equals( parentPk.lastName ) ) return false; - - return true; - } - - public int hashCode() { - int result; - result = firstName.hashCode(); - result = 29 * result + lastName.hashCode(); - return result; - } - } - - @Entity ( name = "CardField" ) - public static class CardField implements Serializable { - - @EmbeddedId - private CardFieldPK primaryKey; - - CardField(Card card, int fieldNumber) { - this.primaryKey = new CardFieldPK(card, fieldNumber); - } - - CardField() { - } - - public CardFieldPK getPrimaryKey() { - return primaryKey; - } - - public void setPrimaryKey(CardFieldPK primaryKey) { - this.primaryKey = primaryKey; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - - CardField cardField = (CardField) o; - - if ( primaryKey != null ? !primaryKey.equals( cardField.primaryKey ) : cardField.primaryKey != null ) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return primaryKey != null ? primaryKey.hashCode() : 0; - } - } - - @Embeddable - public static class CardFieldPK implements Serializable { - @ManyToOne(optional = false) - private Card card; - - private int fieldNumber; - - public CardFieldPK(Card card, int fieldNumber) { - this.card = card; - this.fieldNumber = fieldNumber; - } - - CardFieldPK() { - } - - public Card getCard() { - return card; - } - - public void setCard(Card card) { - this.card = card; - } - - public int getFieldNumber() { - return fieldNumber; - } - - public void setFieldNumber(int fieldNumber) { - this.fieldNumber = fieldNumber; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - - CardFieldPK that = (CardFieldPK) o; - - if ( fieldNumber != that.fieldNumber ) { - return false; - } - if ( card != null ? !card.equals( that.card ) : that.card != null ) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = card != null ? card.hashCode() : 0; - result = 31 * result + fieldNumber; - return result; - } - } - - @Entity ( name = "Card" ) - public static class Card implements Serializable { - @Id - private String id; - - public Card(String id) { - this(); - this.id = id; - } - - Card() { - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - - Card card = (Card) o; - - if ( !id.equals( card.id ) ) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityAssociationResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityAssociationResultSetProcessorTest.java deleted file mode 100644 index c74c46663e..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityAssociationResultSetProcessorTest.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * @author Gail Badner - */ -public class EntityAssociationResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Message.class, Poster.class, ReportedMessage.class }; - } - - @Test - public void testManyToOneEntityProcessing() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( Message.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Message message = new Message( 1, "the message" ); - Poster poster = new Poster( 2, "the poster" ); - session.save( message ); - session.save( poster ); - message.poster = poster; - poster.messages.add( message ); - session.getTransaction().commit(); - session.close(); - - { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 1 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - Message workMessage = ExtraAssertions.assertTyping( Message.class, result ); - assertEquals( 1, workMessage.mid.intValue() ); - assertEquals( "the message", workMessage.msgTxt ); - assertTrue( Hibernate.isInitialized( workMessage.poster ) ); - Poster workPoster = workMessage.poster; - assertEquals( 2, workPoster.pid.intValue() ); - assertEquals( "the poster", workPoster.name ); - assertFalse( Hibernate.isInitialized( workPoster.messages ) ); - - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete Message" ).executeUpdate(); - session.createQuery( "delete Poster" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testNestedManyToOneEntityProcessing() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( ReportedMessage.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Message message = new Message( 1, "the message" ); - Poster poster = new Poster( 2, "the poster" ); - session.save( message ); - session.save( poster ); - message.poster = poster; - poster.messages.add( message ); - ReportedMessage reportedMessage = new ReportedMessage( 0, "inappropriate", message ); - session.save( reportedMessage ); - session.getTransaction().commit(); - session.close(); - - { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 0 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - ReportedMessage workReportedMessage = ExtraAssertions.assertTyping( ReportedMessage.class, result ); - assertEquals( 0, workReportedMessage.id.intValue() ); - assertEquals( "inappropriate", workReportedMessage.reason ); - Message workMessage = workReportedMessage.message; - assertNotNull( workMessage ); - assertTrue( Hibernate.isInitialized( workMessage ) ); - assertEquals( 1, workMessage.mid.intValue() ); - assertEquals( "the message", workMessage.msgTxt ); - assertTrue( Hibernate.isInitialized( workMessage.poster ) ); - Poster workPoster = workMessage.poster; - assertEquals( 2, workPoster.pid.intValue() ); - assertEquals( "the poster", workPoster.name ); - assertFalse( Hibernate.isInitialized( workPoster.messages ) ); - - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete ReportedMessage" ).executeUpdate(); - session.createQuery( "delete Message" ).executeUpdate(); - session.createQuery( "delete Poster" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - @Entity( name = "ReportedMessage" ) - public static class ReportedMessage { - @Id - private Integer id; - private String reason; - @ManyToOne - @JoinColumn - private Message message; - - public ReportedMessage() {} - - public ReportedMessage(Integer id, String reason, Message message) { - this.id = id; - this.reason = reason; - this.message = message; - } - } - - @Entity( name = "Message" ) - public static class Message { - @Id - private Integer mid; - private String msgTxt; - @ManyToOne( cascade = CascadeType.MERGE ) - @JoinColumn - private Poster poster; - - public Message() {} - - public Message(Integer mid, String msgTxt) { - this.mid = mid; - this.msgTxt = msgTxt; - } - } - - @Entity( name = "Poster" ) - public static class Poster { - @Id - private Integer pid; - private String name; - @OneToMany(mappedBy = "poster") - private List messages = new ArrayList(); - - public Poster() {} - - public Poster(Integer pid, String name) { - this.pid = pid; - this.name = name; - } - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyCollectionResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyCollectionResultSetProcessorTest.java deleted file mode 100644 index 56cd70ab32..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyCollectionResultSetProcessorTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.CollectionTable; -import jakarta.persistence.Column; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -/** - * @author Gail Badner - */ -public class EntityWithNonLazyCollectionResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Person.class }; - } - - @Test - public void testEntityWithSet() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( Person.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Person person = new Person(); - person.id = 1; - person.name = "John Doe"; - person.nickNames.add( "Jack" ); - person.nickNames.add( "Johnny" ); - session.save( person ); - session.getTransaction().commit(); - session.close(); - - { - - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 1 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 2, results.size() ); - Object result1 = results.get( 0 ); - assertSame( result1, results.get( 1 ) ); - assertNotNull( result1 ); - - Person workPerson = ExtraAssertions.assertTyping( Person.class, result1 ); - assertEquals( 1, workPerson.id.intValue() ); - assertEquals( person.name, workPerson.name ); - assertTrue( Hibernate.isInitialized( workPerson.nickNames ) ); - assertEquals( 2, workPerson.nickNames.size() ); - assertEquals( person.nickNames, workPerson.nickNames ); - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.delete( person ); - session.getTransaction().commit(); - session.close(); - } - - @Entity( name = "Person" ) - public static class Person { - @Id - private Integer id; - private String name; - @ElementCollection( fetch = FetchType.EAGER ) - @CollectionTable( name = "nick_names", joinColumns = @JoinColumn( name = "pid" ) ) - @Column( name = "nick" ) - private Set nickNames = new HashSet(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManyListResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManyListResultSetProcessorTest.java deleted file mode 100644 index c409c91369..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManyListResultSetProcessorTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -/** - * @author Gail Badner - */ -public class EntityWithNonLazyOneToManyListResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Poster.class, Message.class }; - } - - @Test - public void testEntityWithList() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( Poster.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Poster poster = new Poster(); - poster.pid = 0; - poster.name = "John Doe"; - Message message1 = new Message(); - message1.mid = 1; - message1.msgTxt = "Howdy!"; - message1.poster = poster; - poster.messages.add( message1 ); - Message message2 = new Message(); - message2.mid = 2; - message2.msgTxt = "Bye!"; - message2.poster = poster; - poster.messages.add( message2 ); - session.save( poster ); - session.getTransaction().commit(); - session.close(); - -// session = openSession(); -// session.beginTransaction(); -// Poster posterGotten = (Poster) session.get( Poster.class, poster.pid ); -// assertEquals( 0, posterGotten.pid.intValue() ); -// assertEquals( poster.name, posterGotten.name ); -// assertTrue( Hibernate.isInitialized( posterGotten.messages ) ); -// assertEquals( 2, posterGotten.messages.size() ); -// assertEquals( message1.msgTxt, posterGotten.messages.get( 0 ).msgTxt ); -// assertEquals( message2.msgTxt, posterGotten.messages.get( 1 ).msgTxt ); -// assertSame( posterGotten, posterGotten.messages.get( 0 ).poster ); -// assertSame( posterGotten, posterGotten.messages.get( 1 ).poster ); -// session.getTransaction().commit(); -// session.close(); - - { - - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 0 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 2, results.size() ); - Object result1 = results.get( 0 ); - assertNotNull( result1 ); - assertSame( result1, results.get( 1 ) ); - - Poster workPoster = ExtraAssertions.assertTyping( Poster.class, result1 ); - assertEquals( 0, workPoster.pid.intValue() ); - assertEquals( poster.name, workPoster.name ); - assertTrue( Hibernate.isInitialized( workPoster.messages ) ); - assertEquals( 2, workPoster.messages.size() ); - assertTrue( Hibernate.isInitialized( workPoster.messages ) ); - assertEquals( 2, workPoster.messages.size() ); - assertEquals( message1.msgTxt, workPoster.messages.get( 0 ).msgTxt ); - assertEquals( message2.msgTxt, workPoster.messages.get( 1 ).msgTxt ); - assertSame( workPoster, workPoster.messages.get( 0 ).poster ); - assertSame( workPoster, workPoster.messages.get( 1 ).poster ); - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.delete( poster ); - session.getTransaction().commit(); - session.close(); - } - - @Entity( name = "Message" ) - public static class Message { - @Id - private Integer mid; - private String msgTxt; - @ManyToOne - @JoinColumn - private Poster poster; - } - - @Entity( name = "Poster" ) - public static class Poster { - @Id - private Integer pid; - private String name; - @OneToMany(mappedBy = "poster", fetch = FetchType.EAGER, cascade = CascadeType.ALL ) - private List messages = new ArrayList(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManySetResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManySetResultSetProcessorTest.java deleted file mode 100644 index a246d13557..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/EntityWithNonLazyOneToManySetResultSetProcessorTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.hibernate.Hibernate; -import org.hibernate.Session; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Gail Badner - */ -public class EntityWithNonLazyOneToManySetResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Poster.class, Message.class }; - } - - @Test - public void testEntityWithSet() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( Poster.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - Poster poster = new Poster(); - poster.pid = 0; - poster.name = "John Doe"; - Message message1 = new Message(); - message1.mid = 1; - message1.msgTxt = "Howdy!"; - message1.poster = poster; - poster.messages.add( message1 ); - Message message2 = new Message(); - message2.mid = 2; - message2.msgTxt = "Bye!"; - message2.poster = poster; - poster.messages.add( message2 ); - session.save( poster ); - session.getTransaction().commit(); - session.close(); - - session = openSession(); - session.beginTransaction(); - Poster posterGotten = (Poster) session.get( Poster.class, poster.pid ); - assertEquals( 0, posterGotten.pid.intValue() ); - assertEquals( poster.name, posterGotten.name ); - assertTrue( Hibernate.isInitialized( posterGotten.messages ) ); - assertEquals( 2, posterGotten.messages.size() ); - for ( Message message : posterGotten.messages ) { - if ( message.mid == 1 ) { - assertEquals( message1.msgTxt, message.msgTxt ); - } - else if ( message.mid == 2 ) { - assertEquals( message2.msgTxt, message.msgTxt ); - } - else { - fail( "unexpected message id." ); - } - assertSame( posterGotten, message.poster ); - } - session.getTransaction().commit(); - session.close(); - - { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 0 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 2, results.size() ); - Object result1 = results.get( 0 ); - assertNotNull( result1 ); - assertSame( result1, results.get( 1 ) ); - - Poster workPoster = ExtraAssertions.assertTyping( Poster.class, result1 ); - assertEquals( 0, workPoster.pid.intValue() ); - assertEquals( poster.name, workPoster.name ); - assertTrue( Hibernate.isInitialized( workPoster.messages ) ); - assertEquals( 2, workPoster.messages.size() ); - assertTrue( Hibernate.isInitialized( posterGotten.messages ) ); - assertEquals( 2, workPoster.messages.size() ); - for ( Message message : workPoster.messages ) { - if ( message.mid == 1 ) { - assertEquals( message1.msgTxt, message.msgTxt ); - } - else if ( message.mid == 2 ) { - assertEquals( message2.msgTxt, message.msgTxt ); - } - else { - fail( "unexpected message id." ); - } - assertSame( workPoster, message.poster ); - } - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.delete( poster ); - session.getTransaction().commit(); - session.close(); - } - - @Entity( name = "Message" ) - public static class Message { - @Id - private Integer mid; - private String msgTxt; - @ManyToOne - @JoinColumn - private Poster poster; - } - - @Entity( name = "Poster" ) - public static class Poster { - @Id - private Integer pid; - private String name; - @OneToMany(mappedBy = "poster", fetch = FetchType.EAGER, cascade = CascadeType.ALL ) - private Set messages = new HashSet(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/Helper.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/Helper.java deleted file mode 100644 index 8d945de745..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/Helper.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import org.hibernate.LockMode; -import org.hibernate.LockOptions; -import org.hibernate.engine.spi.LoadQueryInfluencers; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.persister.entity.EntityPersister; - -/** - * @author Steve Ebersole - */ -public class Helper implements QueryBuildingParameters { - /** - * Singleton access - */ - public static final Helper INSTANCE = new Helper(); - - private static final QueryBuildingParameters queryBuildingParameters = new QueryBuildingParametersImpl( - LoadQueryInfluencers.NONE, - 1, - LockMode.NONE, - null - ); - - private Helper() { - } - - public LoadPlan buildLoadPlan(SessionFactoryImplementor sf, EntityPersister entityPersister) { - final FetchStyleLoadPlanBuildingAssociationVisitationStrategy strategy = new FetchStyleLoadPlanBuildingAssociationVisitationStrategy( - sf, - queryBuildingParameters.getQueryInfluencers(), - queryBuildingParameters.getLockMode() - ); - return MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan( strategy, entityPersister ); - } - - public LoadQueryDetails buildLoadQueryDetails(EntityPersister entityPersister, SessionFactoryImplementor sf) { - return buildLoadQueryDetails( - buildLoadPlan( sf, entityPersister ), - sf - ); - } - - public LoadQueryDetails buildLoadQueryDetails(LoadPlan loadPlan, SessionFactoryImplementor sf) { - return BatchingLoadQueryDetailsFactory.INSTANCE.makeEntityLoadQueryDetails( - loadPlan, - null, - queryBuildingParameters, - sf - ); - } - - @Override - public LoadQueryInfluencers getQueryInfluencers() { - return queryBuildingParameters.getQueryInfluencers(); - } - - @Override - public int getBatchSize() { - return queryBuildingParameters.getBatchSize(); - } - - @Override - public LockMode getLockMode() { - return queryBuildingParameters.getLockMode(); - } - - @Override - public LockOptions getLockOptions() { - return queryBuildingParameters.getLockOptions(); - } - - public static NamedParameterContext parameterContext() { - return name -> new int[0]; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java deleted file mode 100644 index cf01b9627a..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/NonEncapsulatedCompositeIdResultSetProcessorTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.LockOptions; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.type.Type; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.orm.test.onetoone.formula.Address; -import org.hibernate.orm.test.onetoone.formula.Person; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * @author Steve Ebersole - */ -public class NonEncapsulatedCompositeIdResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected String[] getMappings() { - return new String[] { "onetoone/formula/Person.hbm.xml" }; - } - - @Test - public void testCompositeIdWithKeyManyToOne() throws Exception { - final String personId = "John Doe"; - - Person p = new Person(); - p.setName( personId ); - final Address a = new Address(); - a.setPerson( p ); - p.setAddress( a ); - a.setType( "HOME" ); - a.setStreet( "Main St" ); - a.setState( "Sweet Home Alabama" ); - a.setZip( "3181" ); - - Session s = openSession(); - Transaction t = s.beginTransaction(); - s.persist( p ); - t.commit(); - s.close(); - - final EntityPersister personPersister = sessionFactory().getEntityPersister( Person.class.getName() ); - final EntityPersister addressPersister = sessionFactory().getEntityPersister( Address.class.getName() ); - - { - final List results = getResults( - addressPersister, - new Callback() { - @Override - public void bind(PreparedStatement ps) throws SQLException { - ps.setString( 1, personId ); - ps.setString( 2, "HOME" ); - } - - @Override - public QueryParameters getQueryParameters() { - QueryParameters qp = new QueryParameters(); - qp.setPositionalParameterTypes( new Type[] { addressPersister.getIdentifierType() } ); - qp.setPositionalParameterValues( new Object[] { a } ); - qp.setOptionalObject( a ); - qp.setOptionalEntityName( addressPersister.getEntityName() ); - qp.setOptionalId( a ); - qp.setLockOptions( LockOptions.NONE ); - return qp; - } - - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - } - - // test loading the Person (the entity with normal id def, but mixed composite fk to Address) - { - final List results = getResults( - personPersister, - new Callback() { - @Override - public void bind(PreparedStatement ps) throws SQLException { - ps.setString( 1, personId ); - } - - @Override - public QueryParameters getQueryParameters() { - QueryParameters qp = new QueryParameters(); - qp.setPositionalParameterTypes( new Type[] { personPersister.getIdentifierType() } ); - qp.setPositionalParameterValues( new Object[] { personId } ); - qp.setOptionalObject( null ); - qp.setOptionalEntityName( personPersister.getEntityName() ); - qp.setOptionalId( personId ); - qp.setLockOptions( LockOptions.NONE ); - return qp; - } - - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - } - -// CardField cardFieldWork = ExtraAssertions.assertTyping( CardField.class, result ); -// assertEquals( cardFieldGotten, cardFieldWork ); - - // clean up test data - s = openSession(); - s.beginTransaction(); - s.createQuery( "delete Address" ).executeUpdate(); - s.createQuery( "delete Person" ).executeUpdate(); - s.getTransaction().commit(); - s.close(); - } - - private List getResults(final EntityPersister entityPersister, final Callback callback) { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - System.out.println( "SQL : " + sql ); - PreparedStatement ps = connection.prepareStatement( sql ); - callback.bind( ps ); - ResultSet resultSet = ps.executeQuery(); - //callback.beforeExtractResults( workSession ); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - callback.getQueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - workSession.getTransaction().commit(); - workSession.close(); - - return results; - } - - - private interface Callback { - void bind(PreparedStatement ps) throws SQLException; - QueryParameters getQueryParameters(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/SimpleResultSetProcessorTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/SimpleResultSetProcessorTest.java deleted file mode 100644 index e882e1fe93..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/SimpleResultSetProcessorTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.hibernate.Session; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.engine.spi.QueryParameters; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.jdbc.Work; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.junit4.ExtraAssertions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -/** - * @author Steve Ebersole - */ -public class SimpleResultSetProcessorTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { SimpleEntity.class }; - } - - @Test - public void testSimpleEntityProcessing() throws Exception { - final EntityPersister entityPersister = sessionFactory().getEntityPersister( SimpleEntity.class.getName() ); - - // create some test data - Session session = openSession(); - session.beginTransaction(); - session.save( new SimpleEntity( 1, "the only" ) ); - session.getTransaction().commit(); - session.close(); - - { - final LoadPlan plan = Helper.INSTANCE.buildLoadPlan( sessionFactory(), entityPersister ); - - final LoadQueryDetails queryDetails = Helper.INSTANCE.buildLoadQueryDetails( plan, sessionFactory() ); - final String sql = queryDetails.getSqlStatement(); - final ResultSetProcessor resultSetProcessor = queryDetails.getResultSetProcessor(); - - final List results = new ArrayList(); - - final Session workSession = openSession(); - workSession.beginTransaction(); - workSession.doWork( - new Work() { - @Override - public void execute(Connection connection) throws SQLException { - ( (SessionImplementor) workSession ).getFactory() - .getServiceRegistry() - .getService( JdbcServices.class ) - .getSqlStatementLogger() - .logStatement( sql ); - PreparedStatement ps = connection.prepareStatement( sql ); - ps.setInt( 1, 1 ); - ResultSet resultSet = ps.executeQuery(); - results.addAll( - resultSetProcessor.extractResults( - resultSet, - (SessionImplementor) workSession, - new QueryParameters(), - Helper.parameterContext(), - true, - false, - null, - null - ) - ); - resultSet.close(); - ps.close(); - } - } - ); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertNotNull( result ); - - SimpleEntity workEntity = ExtraAssertions.assertTyping( SimpleEntity.class, result ); - assertEquals( 1, workEntity.id.intValue() ); - assertEquals( "the only", workEntity.name ); - workSession.getTransaction().commit(); - workSession.close(); - } - - // clean up test data - session = openSession(); - session.beginTransaction(); - session.createQuery( "delete SimpleEntity" ).executeUpdate(); - session.getTransaction().commit(); - session.close(); - } - - @Entity(name = "SimpleEntity") - public static class SimpleEntity { - @Id public Integer id; - public String name; - - public SimpleEntity() { - } - - public SimpleEntity(Integer id, String name) { - this.id = id; - this.name = name; - } - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Contractor.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Contractor.java deleted file mode 100644 index 161f8c1cee..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Contractor.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process.inheritance; - -import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; - -/** - * @author Steve Ebersole - */ -@Entity -public class Contractor extends User { - - // illustrates the problematic situation described in HHH-8330 - - @ManyToOne(fetch= FetchType.EAGER) - @JoinColumn(name="reportsTo_id",nullable=false) - Department reportsTo; - - public Contractor(Integer id, Department reportsTo) { - super( id ); - this.reportsTo = reportsTo; - } - - public Contractor() { - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Department.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Department.java deleted file mode 100644 index 9db3a44e02..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Department.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process.inheritance; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; - -/** - * @author Steve Ebersole - */ -@Entity -public class Department { - @Id - Integer id; - - public Department(Integer id) { - this.id = id; - } - - public Department() { - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Employee.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Employee.java deleted file mode 100644 index fc83cec400..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Employee.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process.inheritance; - -import jakarta.persistence.Entity; -import jakarta.persistence.ManyToOne; - -/** - * @author Steve Ebersole - */ -@Entity -public class Employee extends User { - - // illustrates the problematic situation described in HHH-8980 - - @ManyToOne(optional = false) - Department belongsTo; - - public Employee(Integer id, Department belongsTo) { - super( id ); - this.belongsTo = belongsTo; - } - - public Employee() { - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Test.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Test.java deleted file mode 100644 index 79c722f23b..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/Test.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process.inheritance; - -import org.hibernate.Session; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertNotNull; - -/** - * @author Steve Ebersole - */ -public class Test extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Department.class, User.class, Employee.class, Contractor.class }; - } - - @org.junit.Test - public void basicTest() { - Session s = openSession(); - s.beginTransaction(); - User user = new User( 2 ); - s.save( user ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - assertNotNull( s.get( User.class, 2 ) ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.beginTransaction(); - s.createQuery( "delete User" ).executeUpdate(); - s.getTransaction().commit(); - s.close(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/User.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/User.java deleted file mode 100644 index aedb10c5b2..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/process/inheritance/User.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.process.inheritance; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Inheritance; -import jakarta.persistence.InheritanceType; -import jakarta.persistence.Table; - -/** - * @author Steve Ebersole - */ -@Entity -@Table( name = "`user`" ) -@Inheritance(strategy = InheritanceType.JOINED) -class User { - @Id - Integer id; - - User(Integer id) { - this.id = id; - } - - User() { - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/BasicWalkingTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/BasicWalkingTest.java deleted file mode 100644 index e7e0b9df3f..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/BasicWalkingTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.walking; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import java.util.List; - -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -/** - * @author Steve Ebersole - */ -public class BasicWalkingTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Message.class, Poster.class }; - } - - @Test - public void testIt() { - EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata(Message.class); - MetamodelGraphWalker.visitEntity( new LoggingAssociationVisitationStrategy(), ep ); - } - - @Entity( name = "Message" ) - public static class Message { - @Id - private Integer id; - private String name; - @ManyToOne - @JoinColumn - private Poster poster; - } - - @Entity( name = "Poster" ) - public static class Poster { - @Id - private Integer id; - private String name; - @OneToMany(mappedBy = "poster") - private List messages; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/CompositesWalkingTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/CompositesWalkingTest.java deleted file mode 100644 index 68c45518ff..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/CompositesWalkingTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.walking; - -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.annotations.collectionelement.TestCourse; - -/** - * @author Steve Ebersole - */ -public class CompositesWalkingTest extends BaseUnitTestCase { - /** - * Test one-level composites defined as part of an entity. - */ - @Test - public void testEntityComposite() { - final SessionFactory sf = new Configuration() - .addAnnotatedClass( TestCourse.class ) - .buildSessionFactory(); - try { - final EntityPersister ep = (EntityPersister) sf.getClassMetadata( TestCourse.class ); - MetamodelGraphWalker.visitEntity( new LoggingAssociationVisitationStrategy(), ep ); - } - finally { - sf.close(); - } - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java deleted file mode 100644 index 66bfdde9b2..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/KeyManyToOneWalkingTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.walking; - -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.orm.test.onetoone.formula.Address; - -/** - * @author Steve Ebersole - */ -public class KeyManyToOneWalkingTest extends BaseCoreFunctionalTestCase { - @Override - protected String[] getMappings() { - return new String[] { "onetoone/formula/Person.hbm.xml" }; - } - - @Test - public void testWalkingKeyManyToOneGraphs() { - // Address has a composite id with a bi-directional key-many to Person - final EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata( Address.class ); - - MetamodelGraphWalker.visitEntity( new LoggingAssociationVisitationStrategy(), ep ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java deleted file mode 100644 index 3d0b7cdd86..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.walking; - -import org.hibernate.internal.util.StringHelper; -import org.hibernate.loader.plan.spi.FetchSource; -import org.hibernate.persister.walking.spi.AnyMappingDefinition; -import org.hibernate.persister.walking.spi.AssociationAttributeDefinition; -import org.hibernate.persister.walking.spi.AssociationKey; -import org.hibernate.persister.walking.spi.AttributeDefinition; -import org.hibernate.persister.walking.spi.CollectionDefinition; -import org.hibernate.persister.walking.spi.CollectionElementDefinition; -import org.hibernate.persister.walking.spi.CollectionIndexDefinition; -import org.hibernate.persister.walking.spi.CompositionDefinition; -import org.hibernate.persister.walking.spi.EntityDefinition; -import org.hibernate.persister.walking.spi.EntityIdentifierDefinition; - -/** - * @author Steve Ebersole - */ -public class LoggingAssociationVisitationStrategy implements AssociationVisitationStrategy { - private int depth = 1; - - @Override - public void start() { - System.out.println( ">> Start" ); - } - - @Override - public void finish() { - System.out.println( "<< Finish" ); - } - - @Override - public void startingEntity(EntityDefinition entityDefinition) { - System.out.println( - String.format( - "%s Starting entity (%s)", - StringHelper.repeat( ">>", ++depth ), - entityDefinition.getEntityPersister().getEntityName() - ) - ); - } - - @Override - public void finishingEntity(EntityDefinition entityDefinition) { - System.out.println( - String.format( - "%s Finishing entity (%s)", - StringHelper.repeat( "<<", depth-- ), - entityDefinition.getEntityPersister().getEntityName() - ) - ); - } - - @Override - public void startingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) { - System.out.println( - String.format( - "%s Starting [%s] entity identifier (%s)", - StringHelper.repeat( ">>", ++depth ), - entityIdentifierDefinition.isEncapsulated() ? "encapsulated" : "non-encapsulated", - entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName() - ) - ); - } - - @Override - public void finishingEntityIdentifier(EntityIdentifierDefinition entityIdentifierDefinition) { - System.out.println( - String.format( - "%s Finishing entity identifier (%s)", - StringHelper.repeat( "<<", depth-- ), - entityIdentifierDefinition.getEntityDefinition().getEntityPersister().getEntityName() - ) - ); - } - - @Override - public boolean startingAttribute(AttributeDefinition attributeDefinition) { - System.out.println( - String.format( - "%s Handling attribute (%s)", - StringHelper.repeat( ">>", depth + 1 ), - attributeDefinition.getName() - ) - ); - return true; - } - - @Override - public void finishingAttribute(AttributeDefinition attributeDefinition) { - // nothing to do - } - - @Override - public void startingComposite(CompositionDefinition compositionDefinition) { - System.out.println( - String.format( - "%s Starting composite (%s)", - StringHelper.repeat( ">>", ++depth ), - compositionDefinition.getName() - ) - ); - } - - @Override - public void finishingComposite(CompositionDefinition compositionDefinition) { - System.out.println( - String.format( - "%s Finishing composite (%s)", - StringHelper.repeat( "<<", depth-- ), - compositionDefinition.getName() - ) - ); - } - - @Override - public void startingCollection(CollectionDefinition collectionDefinition) { - System.out.println( - String.format( - "%s Starting collection (%s)", - StringHelper.repeat( ">>", ++depth ), - collectionDefinition.getCollectionPersister().getRole() - ) - ); - } - - @Override - public void finishingCollection(CollectionDefinition collectionDefinition) { - System.out.println( - String.format( - "%s Finishing collection (%s)", - StringHelper.repeat( ">>", depth-- ), - collectionDefinition.getCollectionPersister().getRole() - ) - ); - } - - - @Override - public void startingCollectionIndex(CollectionIndexDefinition collectionIndexDefinition) { - System.out.println( - String.format( - "%s Starting collection index (%s)", - StringHelper.repeat( ">>", ++depth ), - collectionIndexDefinition.getCollectionDefinition().getCollectionPersister().getRole() - ) - ); - } - - @Override - public void finishingCollectionIndex(CollectionIndexDefinition collectionIndexDefinition) { - System.out.println( - String.format( - "%s Finishing collection index (%s)", - StringHelper.repeat( "<<", depth-- ), - collectionIndexDefinition.getCollectionDefinition().getCollectionPersister().getRole() - ) - ); - } - - @Override - public void startingCollectionElements(CollectionElementDefinition elementDefinition) { - System.out.println( - String.format( - "%s Starting collection elements (%s)", - StringHelper.repeat( ">>", ++depth ), - elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() - ) - ); - } - - @Override - public void finishingCollectionElements(CollectionElementDefinition elementDefinition) { - System.out.println( - String.format( - "%s Finishing collection elements (%s)", - StringHelper.repeat( "<<", depth-- ), - elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() - ) - ); - } - - @Override - public void foundAny(AnyMappingDefinition anyDefinition) { - // nothing to do - } - - @Override - public void associationKeyRegistered(AssociationKey associationKey) { - System.out.println( - String.format( - "%s AssociationKey registered : %s", - StringHelper.repeat( ">>", depth + 1 ), - associationKey.toString() - ) - ); - } - - @Override - public FetchSource registeredFetchSource(AssociationKey associationKey) { - return null; - } - - @Override - public void foundCircularAssociation( - AssociationAttributeDefinition attributeDefinition) { - System.out.println( - String.format( - "%s Handling circular association attribute (%s) : %s", - StringHelper.repeat( ">>", depth + 1 ), - attributeDefinition.toString(), - attributeDefinition.getAssociationKey().toString() - ) - ); - } - - @Override - public boolean isDuplicateAssociationKey(AssociationKey associationKey) { - return false; //To change body of implemented methods use File | Settings | File Templates. - } - -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/NestedCompositeElementTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/NestedCompositeElementTest.java deleted file mode 100644 index 5601753ab7..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/loadplans/walking/NestedCompositeElementTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.loadplans.walking; - -import org.hibernate.persister.entity.EntityPersister; - -import org.junit.Test; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.test.loadplans.process.EncapsulatedCompositeAttributeResultSetProcessorTest.Person; -import org.hibernate.test.loadplans.process.EncapsulatedCompositeAttributeResultSetProcessorTest.Customer; - -/** - * @author Steve Ebersole - */ -public class NestedCompositeElementTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Person.class, Customer.class }; - } - - @Test - public void testWalkingKeyManyToOneGraphs() { - final EntityPersister ep = (EntityPersister) sessionFactory().getClassMetadata( Customer.class ); - MetamodelGraphWalker.visitEntity( new LoggingAssociationVisitationStrategy(), ep ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/locale/IAmAFoo.java b/hibernate-core/src/test_legacy/org/hibernate/test/locale/IAmAFoo.java deleted file mode 100644 index 27cecf6a4d..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/locale/IAmAFoo.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.locale; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; - -/** - * @author Brett Meyer - */ -@Entity(name="IAmAFoo") -// This needs to start with an I. -public class IAmAFoo { - @Id @GeneratedValue - private long id; - - @Column - private String foo; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getFoo() { - return foo; - } - - public void setFoo(String foo) { - this.foo = foo; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/locale/LocaleTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/locale/LocaleTest.java deleted file mode 100644 index d1bbb037a7..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/locale/LocaleTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.locale; - -import java.util.Collections; -import java.util.Locale; - -import org.hibernate.HibernateException; -import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; -import org.hibernate.hql.spi.QueryTranslator; -import org.hibernate.hql.spi.QueryTranslatorFactory; -import org.hibernate.tool.hbm2ddl.SchemaValidator; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Brett Meyer - */ -public class LocaleTest extends BaseNonConfigCoreFunctionalTestCase { - - private static final String asciiRegex = "^\\p{ASCII}*$"; - - private static Locale currentLocale; - - @Test - @TestForIssue(jiraKey = "HHH-8579") - public void testAliasWithLocale() { - // Without the HHH-8579 fix, this will generate non-ascii query aliases. - String hql = "from IAmAFoo"; - - QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); - QueryTranslator queryTranslator = ast.createQueryTranslator( - hql, hql, Collections.EMPTY_MAP, sessionFactory(), null ); - queryTranslator.compile( Collections.EMPTY_MAP, false ); - String sql = queryTranslator.getSQLString(); - - assertTrue( sql.matches( asciiRegex ) ); - } - - @Test - @TestForIssue(jiraKey = "HHH-8765") - public void testMetadataWithLocale() { - try { - // Rather than building TableMetadata and checking for ascii values in table/column names, simply - // attempt to validate. - new SchemaValidator().validate( metadata() ); - } - catch (HibernateException e) { - fail("Failed with the Turkish locale, most likely due to the use of String#toLowerCase() within hbm2ddl. " - + "Search for all instaces and replace with StringHelper#toLowerCase(String)! " + e.getMessage()); - } - } - - @BeforeClass - public static void beforeClass() { - currentLocale = Locale.getDefault(); - - // Turkish will generate a "dotless i" when toLowerCase is used on "I". - Locale.setDefault(Locale.forLanguageTag("tr-TR")); - } - - @AfterClass - public static void afterClass() { - Locale.setDefault(currentLocale); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { IAmAFoo.class }; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/GetHqlQueryPlanTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/GetHqlQueryPlanTest.java deleted file mode 100644 index e53a72f76d..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/GetHqlQueryPlanTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.queryplan; - -import java.util.Arrays; -import java.util.Map; - -import org.hibernate.Session; -import org.hibernate.query.spi.QueryInterpretationCache; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.engine.spi.SessionImplementor; - -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.query.internal.QueryParameterBindingsImpl; -import org.hibernate.query.spi.QueryParameterBindings; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.*; - -/** - * Tests for HQL query plans - * - * @author Gail Badner - */ -public class GetHqlQueryPlanTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[]{ - "queryplan/filter-defs.hbm.xml", - "queryplan/Joined.hbm.xml" - }; - } - - protected Map getEnabledFilters(Session s) { - return ( ( SessionImplementor ) s ).getLoadQueryInfluencers().getEnabledFilters(); - } - - @Test - public void testHqlQueryPlan() { - Session s = openSession(); - QueryInterpretationCache cache = ( ( SessionImplementor ) s ).getFactory().getQueryInterpretationCache(); - assertTrue( getEnabledFilters( s ).isEmpty() ); - - HQLQueryPlan plan1 = cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ); - HQLQueryPlan plan2 = cache.getHQLQueryPlan( "from Person where name is null", false, getEnabledFilters( s ) ); - HQLQueryPlan plan3 = cache.getHQLQueryPlan( "from Person where name = :name", false, getEnabledFilters( s ) ); - HQLQueryPlan plan4 = cache.getHQLQueryPlan( "from Person where name = ?1", false, getEnabledFilters( s ) ); - - assertNotSame( plan1, plan2 ); - assertNotSame( plan1, plan3 ); - assertNotSame( plan1, plan4 ); - assertNotSame( plan2, plan3 ); - assertNotSame( plan2, plan4 ); - assertNotSame( plan3, plan4 ); - - assertSame( plan1, cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ) ); - assertSame( plan2, cache.getHQLQueryPlan( "from Person where name is null", false, getEnabledFilters( s ) ) ); - assertSame( plan3, cache.getHQLQueryPlan( "from Person where name = :name", false, getEnabledFilters( s ) ) ); - assertSame( plan4, cache.getHQLQueryPlan( "from Person where name = ?1", false, getEnabledFilters( s ) ) ); - - s.close(); - } - - @Test - @TestForIssue(jiraKey = "HHH-12413") - public void testExpandingQueryStringMultipleTimesWorks() { - doInHibernate( this::sessionFactory, session -> { - QueryInterpretationCache cache = ( ( SessionImplementor ) session ).getFactory().getQueryInterpretationCache(); - - String queryString = "from Person where name in :names"; - HQLQueryPlan plan = cache.getHQLQueryPlan( queryString, false, getEnabledFilters( session ) ); - - QueryParameterBindings queryParameterBindings = QueryParameterBindingsImpl.from( - plan.getParameterMetadata(), - (SessionFactoryImplementor) session.getSessionFactory(), - false - ); - - queryParameterBindings.getQueryParameterListBinding( "names" ).setBindValues( Arrays.asList( "a", "b" ) ); - String actualQueryString = queryParameterBindings.expandListValuedParameters(queryString, (SharedSessionContractImplementor) session); - String expectedQueryString = "from Person where name in (:names_0, :names_1)"; - - assertEquals( - expectedQueryString, - actualQueryString - ); - - // Expanding the same query again should work as before - actualQueryString = queryParameterBindings.expandListValuedParameters(queryString, (SharedSessionContractImplementor) session); - - assertEquals( - expectedQueryString, - actualQueryString - ); - } ); - } - - @Test - public void testHqlQueryPlanWithEnabledFilter() { - Session s = openSession(); - QueryInterpretationCache cache = ( (SessionImplementor) s ).getFactory().getQueryInterpretationCache(); - - HQLQueryPlan plan1A = cache.getHQLQueryPlan( "from Person", true, getEnabledFilters( s ) ); - HQLQueryPlan plan1B = cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ); - - s.enableFilter( "sex" ).setParameter( "sexCode", Character.valueOf( 'F' ) ); - HQLQueryPlan plan2A = cache.getHQLQueryPlan( "from Person", true, getEnabledFilters( s ) ); - HQLQueryPlan plan2B = cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ); - - s.disableFilter( "sex" ); - HQLQueryPlan plan3A = cache.getHQLQueryPlan( "from Person", true, getEnabledFilters( s ) ); - HQLQueryPlan plan3B = cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ); - - s.enableFilter( "sex" ).setParameter( "sexCode", Character.valueOf( 'M' ) ); - HQLQueryPlan plan4A = cache.getHQLQueryPlan( "from Person", true, getEnabledFilters( s ) ); - HQLQueryPlan plan4B = cache.getHQLQueryPlan( "from Person", false, getEnabledFilters( s ) ); - - assertSame( plan1A, plan3A ); - assertSame( plan1B, plan3B ); - assertSame( plan2A, plan4A ); - assertSame( plan2B, plan4B ); - - assertNotSame( plan1A, plan1B ); - assertNotSame( plan1A, plan2A ); - assertNotSame( plan1A, plan2B ); - assertNotSame( plan1B, plan2A ); - assertNotSame( plan1B, plan2B ); - - s.close(); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java deleted file mode 100644 index 4160857232..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/queryplan/NativeSQLQueryPlanEqualsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.queryplan; - -import org.junit.Test; - -import org.hibernate.engine.query.spi.NativeSQLQueryPlan; -import org.hibernate.query.spi.QueryInterpretationCache; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn; -import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; - -/** - * Tests equals() for NativeSQLQueryReturn implementations. - * - * @author Michael Stevens - */ -public class NativeSQLQueryPlanEqualsTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] {}; - } - - @Test - public void testNativeSQLQuerySpecEquals() { - QueryInterpretationCache cache = new QueryInterpretationCache( sessionFactory() ); - NativeSQLQuerySpecification firstSpec = createSpec(); - - NativeSQLQuerySpecification secondSpec = createSpec(); - - NativeSQLQueryPlan firstPlan = cache.getNativeSQLQueryPlan(firstSpec); - NativeSQLQueryPlan secondPlan = cache.getNativeSQLQueryPlan(secondSpec); - - assertEquals(firstPlan, secondPlan); - - } - - private NativeSQLQuerySpecification createSpec() { - String blah = "blah"; - String select = "select blah from blah"; - NativeSQLQueryReturn[] queryReturns = new NativeSQLQueryScalarReturn[] { - new NativeSQLQueryScalarReturn( blah, sessionFactory().getTypeResolver().basic( "int" ) ) - }; - return new NativeSQLQuerySpecification( select, queryReturns, null ); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java deleted file mode 100644 index 1b3f9ae7b6..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/sql/NativeQueryDoesNotSupportIterationTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.sql; - -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -import org.hibernate.Session; -import org.hibernate.query.NativeQuery; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -/** - * @author Andrea Boriero - */ -public class NativeQueryDoesNotSupportIterationTest - extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] {TestEntity.class}; - } - - @Test(expected = UnsupportedOperationException.class) - public void iterateShouldThrowAnUnsupportedOperationException() { - try (Session session = openSession();) { - final NativeQuery sqlQuery = session.createNativeQuery( - "select * from TEST_ENTITY" ); - sqlQuery.iterate(); - } - } - - @Entity(name = "TestEntity") - @Table(name = "TEST_ENTITY") - public static class TestEntity { - - @Id - public Long id; - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/sql/hand/query/NamedNativeQueryMementoBuilderTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/sql/hand/query/NamedNativeQueryMementoBuilderTest.java deleted file mode 100644 index a240c6eb28..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/sql/hand/query/NamedNativeQueryMementoBuilderTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.sql.hand.query; - -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; -import org.hibernate.query.NativeQuery; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * @author Andrea Boriero - */ -public class NamedNativeQueryMementoBuilderTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] { "sql/hand/query/NativeSQLQueries.hbm.xml" }; - } - - @Override - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); - } - - @Test - public void testRegisteredNamedSQLQueryWithScalar() - { - final NamedNativeQueryMementoBuilder builder = new NamedNativeQueryMementoBuilder(); - builder.setName("namedQuery"); - builder.setQuery("select count(*) AS c from ORGANIZATION"); - builder.setQueryReturns(new NativeSQLQueryReturn[1]); - - sessionFactory().registerNamedSQLQueryDefinition("namedQuery", builder.createNamedQueryDefinition()); - - final Session s = openSession(); - s.beginTransaction(); - final NativeQuery query = (NativeQuery) s.getNamedQuery( "namedQuery"); - query.addScalar("c"); - final Number result = (Number) query.uniqueResult(); - s.getTransaction().commit(); - s.close(); - - assertNotNull(result); - assertTrue(0 == result.intValue()); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/sql/storedproc/StoredProcedureParameterRegistrationTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/sql/storedproc/StoredProcedureParameterRegistrationTest.java deleted file mode 100644 index 9fd2f13a42..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/sql/storedproc/StoredProcedureParameterRegistrationTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.sql.storedproc; - -import java.util.List; -import jakarta.persistence.ParameterMode; - -import org.hibernate.JDBCException; -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.procedure.ProcedureCall; -import org.hibernate.procedure.ProcedureOutputs; -import org.hibernate.result.Output; -import org.hibernate.result.ResultSetOutput; - -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -@RequiresDialect(H2Dialect.class) -public class StoredProcedureParameterRegistrationTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { H2ProcTesting.MyEntity.class }; - } - - @Override - protected void configure(Configuration configuration) { - super.configure( configuration ); - H2ProcTesting.applyProcDefinitions( configuration ); - } - - // A warning should be logged if database metadata indicates named parameters are not supported. - @Test - public void testInParametersByName() { - Session session = openSession(); - session.beginTransaction(); - - ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); - query.registerParameter( "start", Integer.class, ParameterMode.IN ).bindValue( 1 ); - query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); - ProcedureOutputs procedureResult = query.getOutputs(); - Output currentOutput = procedureResult.getCurrent(); - assertNotNull( currentOutput ); - ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput ); - List results = resultSetReturn.getResultList(); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertTyping( Object[].class, result ); - Integer id = (Integer) ( (Object[]) result )[0]; - String name = (String) ( (Object[]) result )[1]; - assertEquals( 1, (int) id ); - assertEquals( "User 1", name ); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testInParametersByPosition() { - Session session = openSession(); - session.beginTransaction(); - - ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); - query.registerParameter( 1, Integer.class, ParameterMode.IN ) - .bindValue( 1 ); - query.registerParameter( 2, Integer.class, ParameterMode.IN ) - .bindValue( 2 ); - ProcedureOutputs procedureResult = query.getOutputs(); - Output currentOutput = procedureResult.getCurrent(); - assertNotNull( currentOutput ); - ResultSetOutput resultSetReturn = assertTyping( ResultSetOutput.class, currentOutput ); - List results = resultSetReturn.getResultList(); - assertEquals( 1, results.size() ); - Object result = results.get( 0 ); - assertTyping( Object[].class, result ); - Integer id = (Integer) ( (Object[]) result )[0]; - String name = (String) ( (Object[]) result )[1]; - assertEquals( 1, (int) id ); - assertEquals( "User 1", name ); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testInParametersNotSet() { - Session session = openSession(); - session.beginTransaction(); - - // since the procedure does not define defaults for parameters this should result in SQLExceptions on - // execution - - { - ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); - query.registerParameter( 1, Integer.class, ParameterMode.IN ); - query.registerParameter( 2, Integer.class, ParameterMode.IN ).bindValue( 2 ); - try { - query.getOutputs(); - fail( "Expecting failure due to missing parameter bind" ); - } - catch (JDBCException expected) { - } - } - -// H2 does not support named parameters -// { -// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); -// query.registerParameter( "start", Integer.class, ParameterMode.IN ); -// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); -// try { -// query.getOutputs(); -// fail( "Expecting failure due to missing parameter bind" ); -// } -// catch (JDBCException expected) { -// } -// } - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testInParametersNotSet() { - Session session = openSession(); - session.beginTransaction(); - - // since the procedure does not define defaults for parameters this should result in SQLExceptions on - // execution - - { - ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); - query.registerParameter( 1, Integer.class, ParameterMode.IN ); - query.registerParameter( 2, Integer.class, ParameterMode.IN ).bindValue( 2 ); - try { - query.getOutputs(); - fail( "Expecting failure due to missing parameter bind" ); - } - catch (JDBCException expected) { - } - } - -// H2 does not support named parameters -// { -// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); -// query.registerParameter( "start", Integer.class, ParameterMode.IN ); -// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); -// try { -// query.getOutputs(); -// fail( "Expecting failure due to missing parameter bind" ); -// } -// catch (JDBCException expected) { -// } -// } - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testInParametersNotSetPass() { - Session session = openSession(); - session.beginTransaction(); - - // unlike #testInParametersNotSet here we are asking that the NULL be passed - // so these executions should succeed - - - ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); - query.registerParameter( 1, Integer.class, ParameterMode.IN ).enablePassingNulls( true ); - query.registerParameter( 2, Integer.class, ParameterMode.IN ).bindValue( 2 ); - query.getOutputs(); - -// H2 does not support named parameters -// { -// ProcedureCall query = session.createStoredProcedureCall( "findUserRange" ); -// query.registerParameter( "start", Integer.class, ParameterMode.IN ); -// query.registerParameter( "end", Integer.class, ParameterMode.IN ).bindValue( 2 ); -// try { -// query.getOutputs(); -// fail( "Expecting failure due to missing parameter bind" ); -// } -// catch (JDBCException expected) { -// } -// } - - session.getTransaction().commit(); - session.close(); - } - - @Test - @SuppressWarnings("unchecked") - public void testInParametersNullnessPassingInNamedQueriesViaHints() { - Session session = openSession(); - session.beginTransaction(); - - // similar to #testInParametersNotSet and #testInParametersNotSetPass in terms of testing - // support for specifying whether to pass NULL argument values or not. This version tests - // named procedure support via hints. - - // first a fixture - this execution should fail - { - ProcedureCall query = session.getNamedProcedureCall( "findUserRangeNoNullPassing" ); - query.getParameterRegistration( 2 ).bindValue( 2 ); - try { - query.getOutputs(); - fail( "Expecting failure due to missing parameter bind" ); - } - catch (JDBCException ignore) { - } - } - - // here we enable NULL passing via hint through a named parameter - { - ProcedureCall query = session.getNamedProcedureCall( "findUserRangeNamedNullPassing" ); - query.getParameterRegistration( "secondArg" ).bindValue( 2 ); - query.getOutputs(); - } - - // here we enable NULL passing via hint through a named parameter - { - ProcedureCall query = session.getNamedProcedureCall( "findUserRangeOrdinalNullPassing" ); - query.getParameterRegistration( 2 ).bindValue( 2 ); - query.getOutputs(); - } - - session.getTransaction().commit(); - session.close(); - } - - -}