From 3f2afe6b409e5d2bf64ca71dbddc20a741f31791 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 16 Mar 2021 17:28:51 +0100 Subject: [PATCH] Move tests from cfg, dialect, id/enhanced, jdbc to orm/test and fix SQL Server 2005 limit handler issue, as well as sqm function return type resolver issue --- .../hibernate/dialect/InformixDialect.java | 13 +- .../pagination/SQLServer2005LimitHandler.java | 66 ++++- .../function/SelfRenderingSqmFunction.java | 2 +- .../dialect/InformixDialectTestCase.java | 74 ------ .../java/org/hibernate/dialect/Mocks.java | 141 ---------- .../test}/cfg/CfgFilePropertyTest.java | 5 +- .../cfg/annotations/CollectionBinderTest.java | 57 ++-- .../test}/dialect/DerbyDialectTestCase.java | 28 +- .../test}/dialect/HANADialectTestCase.java | 4 +- .../test/dialect/InformixDialectTestCase.java | 137 ++++++++++ .../test}/dialect/OracleDialectsTest.java | 7 +- .../dialect/PostgreSQL81DialectTestCase.java | 3 +- .../dialect/PostgreSQL92DialectTestCase.java | 4 +- .../dialect/SQLServer2005DialectTestCase.java | 244 +++++++++--------- .../dialect/SQLServer2012DialectTestCase.java | 21 +- .../test}/dialect/TestingDialects.java | 3 +- .../dialect/resolver/DialectFactoryTest.java | 1 + .../dialect/resolver/DialectResolverTest.java | 2 +- .../OptimizerConcurrencyUnitTest.java | 5 +- .../test/id/enhanced/SharedSequenceTest.java} | 51 ++-- .../test}/id/enhanced/SourceMock.java | 3 +- .../{ => orm/test}/jdbc/LobCreatorTest.java | 2 +- .../test}/jdbc/util/BasicFormatterTest.java | 2 +- .../test}/jdbc/util/DdlFormatterTest.java | 4 +- 24 files changed, 448 insertions(+), 431 deletions(-) delete mode 100644 hibernate-core/src/test/java/org/hibernate/dialect/InformixDialectTestCase.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/cfg/CfgFilePropertyTest.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/cfg/annotations/CollectionBinderTest.java (60%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/DerbyDialectTestCase.java (76%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/HANADialectTestCase.java (95%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/dialect/InformixDialectTestCase.java rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/OracleDialectsTest.java (89%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/PostgreSQL81DialectTestCase.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/PostgreSQL92DialectTestCase.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/SQLServer2005DialectTestCase.java (62%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/SQLServer2012DialectTestCase.java (72%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/dialect/TestingDialects.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/id/enhanced/OptimizerConcurrencyUnitTest.java (96%) rename hibernate-core/src/test/java/org/hibernate/{id/enhanced/HHH14219.java => orm/test/id/enhanced/SharedSequenceTest.java} (52%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/id/enhanced/SourceMock.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/jdbc/LobCreatorTest.java (99%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/jdbc/util/BasicFormatterTest.java (98%) rename hibernate-core/src/test/java/org/hibernate/{ => orm/test}/jdbc/util/DdlFormatterTest.java (97%) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java index 4affa60df32c..22c031337402 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/InformixDialect.java @@ -8,6 +8,7 @@ import org.hibernate.boot.TempTableDdlTransactionHandling; import org.hibernate.dialect.function.CommonFunctionFactory; +import org.hibernate.dialect.function.CurrentFunction; import org.hibernate.dialect.function.IndividualLeastGreatestEmulation; import org.hibernate.dialect.identity.IdentityColumnSupport; import org.hibernate.dialect.identity.InformixIdentityColumnSupport; @@ -63,7 +64,7 @@ public InformixDialect(DialectResolutionInfo info) { private final LimitHandler limitHandler; public InformixDialect() { - this(7); + this( 7 ); } /** @@ -394,6 +395,16 @@ public String toBooleanValueString(boolean bool) { return bool ? "'t'" : "'f'"; } + @Override + public String currentDate() { + return "today"; + } + + @Override + public String currentTimestamp() { + return "current"; + } + @Override public String translateDatetimeFormat(String format) { //Informix' own variation of MySQL diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java index 6c3d1267bd04..76d5aae1f026 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQLServer2005LimitHandler.java @@ -238,13 +238,25 @@ private String selectAliases(String sql, int afterSelectOffset, int fromOffset, String alias; if ( asIndex == 0 ) { expression = selectElement.trim(); - //no alias found, need to generate and insert it! - alias = StringHelper.generateAlias( "col", unique++ ); - int diff = result.length() - sql.length(); - if ( result.charAt( nextOffset + diff - 1 ) == ' ' ) { - diff--; + if (expression.equals( "*" ) || expression.endsWith( ".*" )) { + alias = ""; + } + else { + int aliasIndex = getAliasIndex( expression ); + if ( aliasIndex == -1 ) { + //no alias found, need to generate and insert it! + alias = StringHelper.generateAlias( "col", unique++ ); + int diff = result.length() - sql.length(); + if ( result.charAt( nextOffset + diff - 1 ) == ' ' ) { + diff--; + } + result.insert( nextOffset + diff, " as " + alias ); + } + else { + alias = expression.substring( aliasIndex ).trim(); + expression = expression.substring( 0, aliasIndex ).trim(); + } } - result.insert( nextOffset + diff, " as " + alias); } else { expression = selectElement.substring( 0, asIndex ).trim(); @@ -263,6 +275,48 @@ private String selectAliases(String sql, int afterSelectOffset, int fromOffset, return String.join( ", ", aliases ); } + private int getAliasIndex(String sql) { + int endOffset = -1; + int depth = 0; + boolean quoted = false; + boolean doubleQuoted = false; + for ( int offset = sql.length() - 1; offset > endOffset; ) { + int nextQuote = sql.lastIndexOf('\'', offset); + if ( nextQuote < 0 || nextQuote < endOffset ) { + nextQuote = endOffset; + } + if ( !quoted ) { + for ( int index = offset; index > nextQuote; index-- ) { + final char c = sql.charAt( index ); + switch ( c ) { + case '(': + depth--; + break; + case ')': + depth++; + break; + case '"': + doubleQuoted = !doubleQuoted; + break; + case '[': + doubleQuoted = false; + break; + case ']': + doubleQuoted = true; + break; + default: + if ( Character.isWhitespace( c ) && depth == 0 && !doubleQuoted ) { + return index + 1; + } + } + } + } + quoted = !quoted; + offset = nextQuote - 1; + } + return -1; + } + enum Keyword { SELECT ("select(\\s+(distinct|all))?"), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java index 8a89b5514106..bc9fc3724dd5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SelfRenderingSqmFunction.java @@ -82,7 +82,7 @@ public SelfRenderingFunctionSqlAstExpression convertToSqlAst(SqmToSqlAstConverte public SqmExpressable getNodeType() { SqmExpressable nodeType = super.getNodeType(); if ( nodeType == null ) { - resolveResultType( nodeBuilder().getTypeConfiguration() ); + nodeType = (SqmExpressable) resolveResultType( nodeBuilder().getTypeConfiguration() ); } return nodeType; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/InformixDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/InformixDialectTestCase.java deleted file mode 100644 index 8b8f63cae9f7..000000000000 --- a/hibernate-core/src/test/java/org/hibernate/dialect/InformixDialectTestCase.java +++ /dev/null @@ -1,74 +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.hibernate.NotYetImplementedFor6Exception; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.orm.junit.FailureExpected; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Testing of patched support for Informix boolean type; see HHH-9894, HHH-10800 - * - * @author Greg Jones - */ -public class InformixDialectTestCase extends BaseUnitTestCase { - - private final InformixDialect dialect = new InformixDialect(); - - @Test - @TestForIssue(jiraKey = "HHH-9894") - public void testToBooleanValueStringTrue() { - assertEquals( "'t'", dialect.toBooleanValueString( true ) ); - } - - @Test - @TestForIssue(jiraKey = "HHH-9894") - public void testToBooleanValueStringFalse() { - assertEquals( "'f'", dialect.toBooleanValueString( false ) ); - } - - @Test - @TestForIssue(jiraKey = "HHH-10800") - @FailureExpected - public void testCurrentTimestampFunction() { - throw new NotYetImplementedFor6Exception( getClass() ); -// Map functions = dialect.getFunctions(); -// SQLFunction sqlFunction = functions.get( "current_timestamp" ); -// -// Type firstArgumentType = null; -// Mapping mapping = null; -// assertEquals( StandardBasicTypes.TIMESTAMP, sqlFunction.getReturnType( firstArgumentType, mapping ) ); -// -// firstArgumentType = null; -// List arguments = Collections.emptyList(); -// SessionFactoryImplementor factory = null; -// assertEquals( "current", sqlFunction.render( firstArgumentType, arguments, factory ) ); - } - - @Test - @TestForIssue(jiraKey = "HHH-10800") - @FailureExpected - public void testCurrentDateFunction() { - throw new NotYetImplementedFor6Exception( getClass() ); -// Map functions = dialect.getFunctions(); -// SQLFunction sqlFunction = functions.get( "current_date" ); -// -// Type firstArgumentType = null; -// Mapping mapping = null; -// assertEquals( StandardBasicTypes.DATE, sqlFunction.getReturnType( firstArgumentType, mapping ) ); -// -// firstArgumentType = null; -// List arguments = Collections.emptyList(); -// SessionFactoryImplementor factory = null; -// assertEquals( "today", sqlFunction.render( firstArgumentType, arguments, factory ) ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java b/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java deleted file mode 100644 index 47103d5fccda..000000000000 --- a/hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java +++ /dev/null @@ -1,141 +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 java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; - -/** - * @author Steve Ebersole - */ -public class Mocks { - - public static Connection createConnection(String databaseName, int majorVersion) { - return createConnection( databaseName, majorVersion, -9999 ); - } - - public static Connection createConnection(String databaseName, int majorVersion, int minorVersion) { - DatabaseMetaDataHandler metadataHandler = new DatabaseMetaDataHandler( databaseName, majorVersion, minorVersion ); - ConnectionHandler connectionHandler = new ConnectionHandler(); - - DatabaseMetaData metadataProxy = ( DatabaseMetaData ) Proxy.newProxyInstance( - ClassLoader.getSystemClassLoader(), - new Class[] { DatabaseMetaData.class }, - metadataHandler - ); - - Connection connectionProxy = ( Connection ) Proxy.newProxyInstance( - ClassLoader.getSystemClassLoader(), - new Class[] { Connection.class }, - connectionHandler - ); - - metadataHandler.setConnectionProxy( connectionProxy ); - connectionHandler.setMetadataProxy( metadataProxy ); - - return connectionProxy; - } - - private static class ConnectionHandler implements InvocationHandler { - private DatabaseMetaData metadataProxy; - - public void setMetadataProxy(DatabaseMetaData metadataProxy) { - this.metadataProxy = metadataProxy; - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final String methodName = method.getName(); - if ( "getMetaData".equals( methodName ) ) { - return metadataProxy; - } - - if ( "toString".equals( methodName ) ) { - return "Connection proxy [@" + hashCode() + "]"; - } - - if ( "hashCode".equals( methodName ) ) { - return Integer.valueOf( this.hashCode() ); - } - - if ( canThrowSQLException( method ) ) { - throw new SQLException(); - } - else { - throw new UnsupportedOperationException(); - } - } - } - - private static class DatabaseMetaDataHandler implements InvocationHandler { - private final String databaseName; - private final int majorVersion; - private final int minorVersion; - - private Connection connectionProxy; - - public void setConnectionProxy(Connection connectionProxy) { - this.connectionProxy = connectionProxy; - } - - private DatabaseMetaDataHandler(String databaseName, int majorVersion) { - this( databaseName, majorVersion, -9999 ); - } - - private DatabaseMetaDataHandler(String databaseName, int majorVersion, int minorVersion) { - this.databaseName = databaseName; - this.majorVersion = majorVersion; - this.minorVersion = minorVersion; - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final String methodName = method.getName(); - if ( "getDatabaseProductName".equals( methodName ) ) { - return databaseName; - } - - if ( "getDatabaseMajorVersion".equals( methodName ) ) { - return Integer.valueOf( majorVersion ); - } - - if ( "getDatabaseMinorVersion".equals( methodName ) ) { - return Integer.valueOf( minorVersion ); - } - - if ( "getConnection".equals( methodName ) ) { - return connectionProxy; - } - - if ( "toString".equals( methodName ) ) { - return "DatabaseMetaData proxy [db-name=" + databaseName + ", version=" + majorVersion + "]"; - } - - if ( "hashCode".equals( methodName ) ) { - return Integer.valueOf( this.hashCode() ); - } - - if ( canThrowSQLException( method ) ) { - throw new SQLException(); - } - else { - throw new UnsupportedOperationException(); - } - } - } - - private static boolean canThrowSQLException(Method method) { - final Class[] exceptions = method.getExceptionTypes(); - for ( Class exceptionType : exceptions ) { - if ( SQLException.class.isAssignableFrom( exceptionType ) ) { - return true; - } - } - return false; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/cfg/CfgFilePropertyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/CfgFilePropertyTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/cfg/CfgFilePropertyTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/cfg/CfgFilePropertyTest.java index a58fd2e10b7f..7084a0220df4 100644 --- a/hibernate-core/src/test/java/org/hibernate/cfg/CfgFilePropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/CfgFilePropertyTest.java @@ -4,17 +4,18 @@ * 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.cfg; +package org.hibernate.orm.test.cfg; import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; -import java.util.List; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; import javax.persistence.Persistence; +import org.hibernate.cfg.AvailableSettings; + import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/cfg/annotations/CollectionBinderTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/annotations/CollectionBinderTest.java similarity index 60% rename from hibernate-core/src/test/java/org/hibernate/cfg/annotations/CollectionBinderTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/cfg/annotations/CollectionBinderTest.java index edc30e455e9f..73ba132d2265 100644 --- a/hibernate-core/src/test/java/org/hibernate/cfg/annotations/CollectionBinderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cfg/annotations/CollectionBinderTest.java @@ -4,7 +4,7 @@ * 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.cfg.annotations; +package org.hibernate.orm.test.cfg.annotations; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -12,12 +12,16 @@ import java.sql.SQLException; import java.util.HashMap; +import java.util.Map; import org.hibernate.MappingException; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.cfg.Ejb3JoinColumn; +import org.hibernate.cfg.InheritanceState; import org.hibernate.cfg.PropertyHolder; +import org.hibernate.cfg.annotations.CollectionBinder; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Table; @@ -49,23 +53,44 @@ public void testAssociatedClassException() throws SQLException { when(persistentClass.getTable()).thenReturn(table); when(table.getName()).thenReturn("Hibernate"); - CollectionBinder collectionBinder = new CollectionBinder(false) { - @Override - protected Collection createCollection(PersistentClass persistentClass) { - return null; - } - - { - final PropertyHolder propertyHolder = Mockito.mock(PropertyHolder.class); - when(propertyHolder.getClassName()).thenReturn( CollectionBinderTest.class.getSimpleName() ); - this.propertyName = "abc"; - this.propertyHolder = propertyHolder; - } - }; - String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]"; try { - collectionBinder.bindOneToManySecondPass(collection, new HashMap(), null, collectionType, false, false, buildingContext, null); + new CollectionBinder( false) { + + { + final PropertyHolder propertyHolder = Mockito.mock(PropertyHolder.class); + when(propertyHolder.getClassName()).thenReturn( CollectionBinderTest.class.getSimpleName() ); + this.propertyName = "abc"; + setPropertyHolder( propertyHolder ); + } + + @Override + protected Collection createCollection(PersistentClass persistentClass) { + return null; + } + + @Override + public void bindOneToManySecondPass( + Collection collection, + Map persistentClasses, + Ejb3JoinColumn[] fkJoinColumns, + XClass collectionType, + boolean cascadeDeleteEnabled, + boolean ignoreNotFound, + MetadataBuildingContext buildingContext, + Map inheritanceStatePerClass) { + super.bindOneToManySecondPass( + collection, + persistentClasses, + fkJoinColumns, + collectionType, + cascadeDeleteEnabled, + ignoreNotFound, + buildingContext, + inheritanceStatePerClass + ); + } + }.bindOneToManySecondPass( collection, new HashMap(), null, collectionType, false, false, buildingContext, null); } catch (MappingException e) { assertEquals(expectMessage, e.getMessage()); } diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java similarity index 76% rename from hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java index 848e6e12e962..beab95f31e2b 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DerbyDialectTestCase.java @@ -4,7 +4,10 @@ * 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; +package org.hibernate.orm.test.dialect; + +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.query.Limit; import static org.junit.Assert.assertEquals; @@ -19,12 +22,6 @@ */ public class DerbyDialectTestCase extends BaseUnitTestCase { - private static class LocalDerbyDialect extends DerbyDialect { - protected boolean isTenPointFiveReleaseOrNewer() { - return true; // for test sake :) - } - } - @Test @TestForIssue( jiraKey = "HHH-3972" ) public void testInsertLimitClause() { @@ -32,7 +29,7 @@ public void testInsertLimitClause() { final String input = "select * from tablename t where t.cat = 5"; final String expected = "select * from tablename t where t.cat = 5 fetch first " + limit + " rows only"; - final String actual = new LocalDerbyDialect().getLimitString( input, 0, limit ); + final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( 0, limit ) ); assertEquals( expected, actual ); } @@ -44,7 +41,7 @@ public void testInsertLimitWithOffsetClause() { final String input = "select * from tablename t where t.cat = 5"; final String expected = "select * from tablename t where t.cat = 5 offset " + offset + " rows fetch next " + limit + " rows only"; - final String actual = new LocalDerbyDialect().getLimitString( input, offset, limit ); + final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) ); assertEquals( expected, actual ); } @@ -57,7 +54,7 @@ public void testInsertLimitWithForUpdateClause() { final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 offset " + offset + " rows fetch next " + limit + " rows only for update of c11, c13"; - final String actual = new LocalDerbyDialect().getLimitString( input, offset, limit ); + final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) ); assertEquals( expected, actual ); } @@ -70,7 +67,7 @@ public void testInsertLimitWithWithClause() { final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 where flight_id between 'AA1111' and 'AA1112' offset " + offset + " rows fetch next " + limit + " rows only with rr"; - final String actual = new LocalDerbyDialect().getLimitString( input, offset, limit ); + final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) ); assertEquals( expected, actual ); } @@ -83,7 +80,14 @@ public void testInsertLimitWithForUpdateAndWithClauses() { final String expected = "select c11 as col1, c12 as col2, c13 as col13 from t1 where flight_id between 'AA1111' and 'AA1112' offset " + offset + " rows fetch next " + limit + " rows only for update of c11,c13 with rr"; - final String actual = new LocalDerbyDialect().getLimitString( input, offset, limit ); + final String actual = new DerbyDialect( 1050 ).getLimitHandler().processSql( input, toRowSelection( offset, limit ) ); assertEquals( expected, actual ); } + + private Limit toRowSelection(int firstRow, int maxRows) { + Limit selection = new Limit(); + selection.setFirstRow( firstRow ); + selection.setMaxRows( maxRows ); + return selection; + } } diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/HANADialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/HANADialectTestCase.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/dialect/HANADialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/HANADialectTestCase.java index a08687bc0c8a..42d61bd1495f 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/HANADialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/HANADialectTestCase.java @@ -4,7 +4,7 @@ * 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; +package org.hibernate.orm.test.dialect; import static org.junit.Assert.assertEquals; @@ -13,6 +13,8 @@ import org.hibernate.LockMode; import org.hibernate.LockOptions; +import org.hibernate.dialect.HANAColumnStoreDialect; + import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/InformixDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/InformixDialectTestCase.java new file mode 100644 index 000000000000..fdf5b66c0092 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/InformixDialectTestCase.java @@ -0,0 +1,137 @@ +/* + * 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.orm.test.dialect; + +import java.util.Collections; + +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.InformixDialect; +import org.hibernate.jpa.JpaComplianceStub; +import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl; +import org.hibernate.query.criteria.ValueHandlingMode; +import org.hibernate.query.internal.NamedObjectRepositoryImpl; +import org.hibernate.query.spi.QueryEngine; +import org.hibernate.query.sqm.function.SelfRenderingSqmFunction; +import org.hibernate.query.sqm.function.SqmFunctionDescriptor; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.sql.ast.spi.SqlAppender; +import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.spi.TypeConfiguration; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Testing of patched support for Informix boolean type; see HHH-9894, HHH-10800 + * + * @author Greg Jones + */ +public class InformixDialectTestCase extends BaseUnitTestCase { + + private static final InformixDialect dialect = new InformixDialect(); + private static ServiceRegistry ssr; + private static QueryEngine queryEngine; + + @BeforeClass + public static void init() { + final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( new TypeConfiguration(), new JpaComplianceStub() ); + + ssr = new StandardServiceRegistryBuilder().build(); + queryEngine = new QueryEngine( + jpaMetamodel, + ValueHandlingMode.BIND, + dialect.getPreferredSqlTypeCodeForBoolean(), + false, + new NamedObjectRepositoryImpl( Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap() ), + null, + dialect, + ssr + ); + } + + @AfterClass + public static void tearDown() { + queryEngine.close(); + ssr.close(); + } + + @Test + @TestForIssue(jiraKey = "HHH-9894") + public void testToBooleanValueStringTrue() { + assertEquals( "'t'", dialect.toBooleanValueString( true ) ); + } + + @Test + @TestForIssue(jiraKey = "HHH-9894") + public void testToBooleanValueStringFalse() { + assertEquals( "'f'", dialect.toBooleanValueString( false ) ); + } + + @Test + @TestForIssue(jiraKey = "HHH-10800") + public void testCurrentTimestampFunction() { + SqmFunctionDescriptor functionDescriptor = queryEngine.getSqmFunctionRegistry() + .findFunctionDescriptor( "current_timestamp" ); + SelfRenderingSqmFunction sqmExpression = functionDescriptor.generateSqmExpression( + null, + queryEngine, + null + ); + assertEquals( StandardBasicTypes.TIMESTAMP, sqmExpression.getNodeType() ); + + SqlAppender appender = new StringBuilderSqlAppender(); + sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null ); + assertEquals( "current", appender.toString() ); + } + + @Test + @TestForIssue(jiraKey = "HHH-10800") + public void testCurrentDateFunction() { + SqmFunctionDescriptor functionDescriptor = queryEngine.getSqmFunctionRegistry() + .findFunctionDescriptor( "current_date" ); + SelfRenderingSqmFunction sqmExpression = functionDescriptor.generateSqmExpression( + null, + queryEngine, + null + ); + assertEquals( StandardBasicTypes.DATE, sqmExpression.getNodeType() ); + + SqlAppender appender = new StringBuilderSqlAppender(); + sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null ); + assertEquals( "today", appender.toString() ); + } + + private static class StringBuilderSqlAppender implements SqlAppender { + private final StringBuilder sb; + + public StringBuilderSqlAppender() { + this.sb = new StringBuilder(); + } + + @Override + public void appendSql(String fragment) { + sb.append( fragment ); + } + + @Override + public void appendSql(char fragment) { + sb.append( fragment ); + } + + @Override + public String toString() { + return sb.toString(); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/OracleDialectsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/OracleDialectsTest.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/dialect/OracleDialectsTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/OracleDialectsTest.java index 34099da95ad1..53d925c80fe2 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/OracleDialectsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/OracleDialectsTest.java @@ -21,9 +21,14 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.dialect; +package org.hibernate.orm.test.dialect; import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.Oracle12cDialect; +import org.hibernate.dialect.Oracle8iDialect; +import org.hibernate.dialect.Oracle9iDialect; +import org.hibernate.dialect.OracleDialect; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL81DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL81DialectTestCase.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL81DialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL81DialectTestCase.java index 37399d21bed0..dad31f6fa2ce 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL81DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL81DialectTestCase.java @@ -4,7 +4,7 @@ * 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; +package org.hibernate.orm.test.dialect; import java.sql.BatchUpdateException; import java.sql.CallableStatement; @@ -14,6 +14,7 @@ import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.PessimisticLockException; +import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.exception.LockAcquisitionException; import org.hibernate.exception.spi.SQLExceptionConversionDelegate; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL92DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL92DialectTestCase.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL92DialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL92DialectTestCase.java index dc46d2d6aedc..fee3f3076a16 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/PostgreSQL92DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQL92DialectTestCase.java @@ -4,7 +4,9 @@ * 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; +package org.hibernate.orm.test.dialect; + +import org.hibernate.dialect.PostgreSQL92Dialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2005DialectTestCase.java similarity index 62% rename from hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2005DialectTestCase.java index e84df4a5bcc6..4cd71a5f231b 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2005DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2005DialectTestCase.java @@ -4,13 +4,15 @@ * 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; +package org.hibernate.orm.test.dialect; import java.util.Locale; import org.hibernate.LockMode; import org.hibernate.LockOptions; +import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.engine.spi.RowSelection; +import org.hibernate.query.Limit; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; @@ -45,9 +47,9 @@ public void testGetLimitString() { String input = "select distinct f1 as f53245 from table849752 order by f234, f67 desc"; assertEquals( - "with query as (select inner_query.*, row_number() over (order by current_timestamp) as __hibernate_row_nr__ from ( " + - "select distinct top(?) f1 as f53245 from table849752 order by f234, f67 desc ) inner_query )" + - " select f53245 from query where __hibernate_row_nr__ >= ? and __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select distinct top(?) f1 as f53245 from table849752 order by f234, f67 desc) row_)" + + " select f53245 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( input, toRowSelection( 10, 15 ) ).toLowerCase(Locale.ROOT) ); } @@ -56,8 +58,8 @@ public void testGetLimitString() { public void testGetLimitStringWithNewlineAfterSelect() { final String query = "select" + System.lineSeparator() + "* FROM Employee E WHERE E.firstName = :firstName"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - query + " ) inner_query ) SELECT * FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + query + ") row_) select * from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 25 ) ) ); } @@ -67,8 +69,8 @@ public void testGetLimitStringWithNewlineAfterSelect() { public void testGetLimitStringWithNewlineAfterSelectWithMultipleSpaces() { final String query = "select " + System.lineSeparator() + "* FROM Employee E WHERE E.firstName = :firstName"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - query + " ) inner_query ) SELECT * FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + query + ") row_) select * from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 25 ) ) ); } @@ -78,10 +80,10 @@ public void testGetLimitStringWithNewlineAfterSelectWithMultipleSpaces() { public void testGetLimitStringWithNewlineAfterColumnList() { final String query = "select E.fieldA,E.fieldB\r\nFROM Employee E WHERE E.firstName = :firstName"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select E.fieldA as page0_,E.fieldB as page1_\r\n" + - "FROM Employee E WHERE E.firstName = :firstName ) inner_query ) SELECT page0_, page1_ FROM query " + - "WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select E.fieldA as col0_,E.fieldB\r\n as col1_" + + "FROM Employee E WHERE E.firstName = :firstName) row_) select col0_, col1_ from query_ " + + "where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 25 ) ) ); } @@ -96,9 +98,9 @@ public void testGetLimitStringWithFromColumnName() { "where persistent0_.customerid=?"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - fromColumnNameSQL + " ) inner_query ) " + - "SELECT rid1688_, deviati16_1688_, sortindex1688_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + fromColumnNameSQL + ") row_) " + + "select rid1688_, deviati16_1688_, sortindex1688_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( fromColumnNameSQL, toRowSelection( 1, 10 ) ) ); } @@ -109,9 +111,9 @@ public void testGetLimitStringAliasGeneration() { final String notAliasedSQL = "select column1, column2, column3, column4 from table1"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select column1 as page0_, column2 as page1_, column3 as page2_, column4 as page3_ from table1 ) inner_query ) " + - "SELECT page0_, page1_, page2_, page3_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select column1 as col0_, column2 as col1_, column3 as col2_, column4 as col3_ from table1) row_) " + + "select col0_, col1_, col2_, col3_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( notAliasedSQL, toRowSelection( 3, 5 ) ) ); } @@ -121,9 +123,9 @@ public void testGetLimitStringAliasGeneration() { public void testGetLimitStringAliasGenerationWithAliasesNoAs() { final String aliasedSQLNoAs = "select column1 c1, column c2, column c3, column c4 from table1"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select column1 c1, column c2, column c3, column c4 from table1 ) inner_query ) " + - "SELECT c1, c2, c3, c4 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select column1 c1, column c2, column c3, column c4 from table1) row_) " + + "select c1, c2, c3, c4 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( aliasedSQLNoAs, toRowSelection( 3, 5 ) ) ); } @@ -132,9 +134,9 @@ public void testGetLimitStringAliasGenerationWithAliasesNoAs() { @TestForIssue(jiraKey = "HHH-11352") public void testPagingWithColumnNameStartingWithFrom() { final String sql = "select column1 c1, from_column c2 from table1"; - assertEquals( "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select column1 c1, from_column c2 from table1 ) inner_query ) " + - "SELECT c1, c2 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + assertEquals( "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select column1 c1, from_column c2 from table1) row_) " + + "select c1, c2 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql(sql, toRowSelection(3, 5))); } @@ -149,9 +151,9 @@ public void testGetLimitStringWithSubselect() { "where persistent0_.type='v'"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - subselectInSelectClauseSQL + " ) inner_query ) " + - "SELECT col_0_0_, col_1_0_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + subselectInSelectClauseSQL + ") row_) " + + "select col_0_0_, col_1_0_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( subselectInSelectClauseSQL, toRowSelection( 2, 5 ) ) ); } @@ -159,14 +161,14 @@ public void testGetLimitStringWithSubselect() { @Test @TestForIssue(jiraKey = "HHH-11084") public void testGetLimitStringWithSelectDistinctSubselect() { - final String selectDistinctSubselectSQL = "select page0_.CONTENTID as CONTENT1_12_ " + - "where page0_.CONTENTTYPE='PAGE' and (page0_.CONTENTID in " + - "(select distinct page2_.PREVVER from CONTENT page2_ where (page2_.PREVVER is not null)))"; + final String selectDistinctSubselectSQL = "select col0_.CONTENTID as CONTENT1_12_ " + + "where col0_.CONTENTTYPE='PAGE' and (col0_.CONTENTID in " + + "(select distinct col2_.PREVVER from CONTENT col2_ where (col2_.PREVVER is not null)))"; assertEquals( - "select TOP(?) page0_.CONTENTID as CONTENT1_12_ " + - "where page0_.CONTENTTYPE='PAGE' and (page0_.CONTENTID in " + - "(select distinct page2_.PREVVER from CONTENT page2_ where (page2_.PREVVER is not null)))", + "select top(?) col0_.CONTENTID as CONTENT1_12_ " + + "where col0_.CONTENTTYPE='PAGE' and (col0_.CONTENTID in " + + "(select distinct col2_.PREVVER from CONTENT col2_ where (col2_.PREVVER is not null)))", dialect.getLimitHandler().processSql( selectDistinctSubselectSQL, toRowSelection( 0, 5 ) ) ); } @@ -174,14 +176,14 @@ public void testGetLimitStringWithSelectDistinctSubselect() { @Test @TestForIssue(jiraKey = "HHH-11084") public void testGetLimitStringWithSelectDistinctSubselectNotFirst() { - final String selectDistinctSubselectSQL = "select page0_.CONTENTID as CONTENT1_12_ FROM CONTEXT page0_ " + - "where page0_.CONTENTTYPE='PAGE' and (page0_.CONTENTID in " + - "(select distinct page2_.PREVVER from CONTENT page2_ where (page2_.PREVVER is not null)))"; + final String selectDistinctSubselectSQL = "select col0_.CONTENTID as CONTENT1_12_ FROM CONTEXT col0_ " + + "where col0_.CONTENTTYPE='PAGE' and (col0_.CONTENTID in " + + "(select distinct col2_.PREVVER from CONTENT col2_ where (col2_.PREVVER is not null)))"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ " + - "FROM ( " + selectDistinctSubselectSQL + " ) inner_query ) " + - "SELECT CONTENT1_12_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ " + + "from (" + selectDistinctSubselectSQL + ") row_) " + + "select CONTENT1_12_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( selectDistinctSubselectSQL, toRowSelection( 1, 5 ) ) ); } @@ -196,11 +198,11 @@ public void testGetLimitStringCaseSensitive() { "order by persistent0_.Order"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) persistent0_.id as page0_, persistent0_.uid AS tmp1, " + - "(select case when persistent0_.name = 'Smith' then 'Neo' else persistent0_.id end) as page1_ " + - "from C_Customer persistent0_ where persistent0_.type='Va' order by persistent0_.Order ) " + - "inner_query ) SELECT page0_, tmp1, page1_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) persistent0_.id as col0_, persistent0_.uid AS tmp1, " + + "(select case when persistent0_.name = 'Smith' then 'Neo' else persistent0_.id end) as col1_ " + + "from C_Customer persistent0_ where persistent0_.type='Va' order by persistent0_.Order) " + + "row_) select col0_, tmp1, col1_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( caseSensitiveSQL, toRowSelection( 1, 2 ) ) ); } @@ -211,9 +213,9 @@ public void testGetLimitStringDistinctWithinAggregation() { final String distinctInAggregateSQL = "select aggregate_function(distinct p.n) as f1 from table849752 p order by f1"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) aggregate_function(distinct p.n) as f1 from table849752 p order by f1 ) inner_query ) " + - "SELECT f1 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) aggregate_function(distinct p.n) as f1 from table849752 p order by f1) row_) " + + "select f1 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( distinctInAggregateSQL, toRowSelection( 2, 5 ) ) ); } @@ -224,9 +226,9 @@ public void testGetLimitStringDistinctWithinAggregationWithoutAlias() { final String distinctInAggregateSQL = "select aggregate_function(distinct p.n) from table849752 p order by f1"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) aggregate_function(distinct p.n) as page0_ from table849752 p order by f1 ) inner_query ) " + - "SELECT page0_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) aggregate_function(distinct p.n) as col0_ from table849752 p order by f1) row_) " + + "select col0_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( distinctInAggregateSQL, toRowSelection( 2, 5 ) ) ); } @@ -237,9 +239,9 @@ public void testGetLimitStringDistinctWithinAggregationWithAliasNoAs() { final String distinctInAggregateSQL = "select aggregate_function(distinct p.n) f1 from table849752 p order by f1"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) aggregate_function(distinct p.n) f1 from table849752 p order by f1 ) inner_query ) " + - "SELECT f1 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) aggregate_function(distinct p.n) f1 from table849752 p order by f1) row_) " + + "select f1 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( distinctInAggregateSQL, toRowSelection( 2, 5 ) ) ); } @@ -251,7 +253,7 @@ public void testGetLimitStringWithMaxOnly() { "from Product2 product2x0_ order by product2x0_.id"; assertEquals( - "select TOP(?) product2x0_.id as id0_, product2x0_.description as descript2_0_ " + + "select top(?) product2x0_.id as id0_, product2x0_.description as descript2_0_ " + "from Product2 product2x0_ order by product2x0_.id", dialect.getLimitHandler().processSql( query, toRowSelection( 0, 1 ) ) ); @@ -260,7 +262,7 @@ public void testGetLimitStringWithMaxOnly() { "from Product2 product2x0_ order by product2x0_.id"; assertEquals( - "select distinct TOP(?) product2x0_.id as id0_, product2x0_.description as descript2_0_ " + + "select distinct top(?) product2x0_.id as id0_, product2x0_.description as descript2_0_ " + "from Product2 product2x0_ order by product2x0_.id", dialect.getLimitHandler().processSql( distinctQuery, toRowSelection( 0, 5 ) ) ); @@ -273,10 +275,10 @@ public void testGetLimitStringWithCastOperator() { "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) as col_0_0_, lc302_doku6_.dokumentiID as col_1_0_ " + - "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC ) inner_query ) " + - "SELECT col_0_0_, col_1_0_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) as col_0_0_, lc302_doku6_.dokumentiID as col_1_0_ " + + "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC) row_) " + + "select col_0_0_, col_1_0_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 3 ) ) ); } @@ -288,10 +290,10 @@ public void testGetLimitStringWithCastOperatorWithAliasNoAs() { "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) f1, lc302_doku6_.dokumentiID f2 " + - "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC ) inner_query ) " + - "SELECT f1, f2 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) f1, lc302_doku6_.dokumentiID f2 " + + "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC) row_) " + + "select f1, f2 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 3 ) ) ); } @@ -303,10 +305,10 @@ public void testGetLimitStringWithCastOperatorWithoutAliases() { "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) as page0_, lc302_doku6_.dokumentiID as page1_ " + - "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC ) inner_query ) " + - "SELECT page0_, page1_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) cast(lc302_doku6_.redniBrojStavke as varchar(255)) as col0_, lc302_doku6_.dokumentiID as col1_ " + + "from LC302_Dokumenti lc302_doku6_ order by lc302_doku6_.dokumentiID DESC) row_) " + + "select col0_, col1_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 3 ) ) ); } @@ -317,9 +319,9 @@ public void testGetLimitStringSelectingMultipleColumnsFromSeveralTables() { final String query = "select t1.*, t2.* from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) t1.*, t2.* from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc ) inner_query ) " + - "SELECT * FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) t1.*, t2.* from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc) row_) " + + "select * from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 3 ) ) ); } @@ -330,9 +332,9 @@ public void testGetLimitStringSelectingAllColumns() { final String query = "select * from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) * from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc ) inner_query ) " + - "SELECT * FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) * from tab1 t1, tab2 t2 where t1.ref = t2.ref order by t1.id desc) row_) " + + "select * from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 3 ) ) ); } @@ -342,9 +344,9 @@ public void testGetLimitStringSelectingAllColumns() { public void testGetLimitStringWithFromInColumnName() { final String query = "select [Created From Nonstock Item], field2 from table1"; - assertEquals( "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select [Created From Nonstock Item] as page0_, field2 as page1_ from table1 ) inner_query ) " + - "SELECT page0_, page1_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + assertEquals( "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select [Created From Nonstock Item] as col0_, field2 as col1_ from table1) row_) " + + "select col0_, col1_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) ); } @@ -354,9 +356,9 @@ public void testGetLimitStringWithFromInColumnName() { public void testGetLimitStringWithQuotedColumnNamesAndAlias() { final String query = "select [Created From Item] c1, field2 from table1"; - assertEquals( "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select [Created From Item] c1, field2 as page0_ from table1 ) inner_query ) " + - "SELECT c1, page0_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + assertEquals( "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select [Created From Item] c1, field2 as col0_ from table1) row_) " + + "select c1, col0_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) ); } @@ -366,9 +368,9 @@ public void testGetLimitStringWithQuotedColumnNamesAndAlias() { public void testGetLimitStringWithQuotedColumnNamesAndAliasWithAs() { final String query = "select [Created From Item] as c1, field2 from table1"; - assertEquals( "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select [Created From Item] as c1, field2 as page0_ from table1 ) inner_query ) " + - "SELECT c1, page0_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + assertEquals( "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select [Created From Item] as c1, field2 as col0_ from table1) row_) " + + "select c1, col0_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) ); } @@ -379,9 +381,9 @@ public void testGetLimitStringWithSelectClauseNestedQueryUsingParenthesis() { final String query = "select t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC ) inner_query ) " + - "SELECT col_0_0, col_1_0 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC) row_) " + + "select col_0_0, col_1_0 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) ); } @@ -392,8 +394,8 @@ public void testGetLimitWithStringValueContainingParenthesis() { final String query = "select t1.c1 as col_0_0 FROM table1 t1 where t1.c1 = '(123' ORDER BY t1.c1 ASC"; assertEquals( - "WITH query AS (SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( " + - "select TOP(?) t1.c1 as col_0_0 FROM table1 t1 where t1.c1 = '(123' ORDER BY t1.c1 ASC ) inner_query ) SELECT col_0_0 FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "with query_ as (select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "select top(?) t1.c1 as col_0_0 FROM table1 t1 where t1.c1 = '(123' ORDER BY t1.c1 ASC) row_) select col_0_0 from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query, toRowSelection( 1, 5 ) ) ); } @@ -404,7 +406,7 @@ public void testGetLimitStringWithSelectClauseNestedQueryUsingParenthesisOnlyTop final String query = "select t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC"; assertEquals( - "select TOP(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC", + "select top(?) t1.c1 as col_0_0, (select case when count(t2.c1)>0 then 'ADDED' else 'UNMODIFIED' end from table2 t2 WHERE (t2.c1 in (?))) as col_1_0 from table1 t1 WHERE 1=1 ORDER BY t1.c1 ASC", dialect.getLimitHandler().processSql( query, toRowSelection( 0, 5 ) ) ); } @@ -412,37 +414,37 @@ public void testGetLimitStringWithSelectClauseNestedQueryUsingParenthesisOnlyTop @Test @TestForIssue(jiraKey = "HHH-8916") public void testGetLimitStringUsingCTEQueryNoOffset() { - RowSelection selection = toRowSelection( 0, 5 ); + Limit selection = toRowSelection( 0, 5 ); - // test top-based CTE with single CTE query definition with no odd formatting + // test top-based CTE with single CTE query_ definition with no odd formatting final String query1 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT c1, c2 FROM a"; assertEquals( - "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT TOP(?) c1, c2 FROM a", + "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT top(?) c1, c2 FROM a", dialect.getLimitHandler().processSql( query1, selection ) ); - // test top-based CTE with single CTE query definition and various tab, newline spaces + // test top-based CTE with single CTE query_ definition and various tab, newline spaces final String query2 = " \n\tWITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT c1, c2 FROM a"; assertEquals( - " \n\tWITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT TOP(?) c1, c2 FROM a", + "WITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT top(?) c1, c2 FROM a", dialect.getLimitHandler().processSql( query2, selection ) ); - // test top-based CTE with multiple CTE query definitions with no odd formatting + // test top-based CTE with multiple CTE query_ definitions with no odd formatting final String query3 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) " + "SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1"; assertEquals( "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) " + - "SELECT TOP(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", + "SELECT top(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", dialect.getLimitHandler().processSql( query3, selection ) ); - // test top-based CTE with multiple CTE query definitions and various tab, newline spaces + // test top-based CTE with multiple CTE query_ definitions and various tab, newline spaces final String query4 = " \n\r\tWITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t" + "(SELECT b1, b2 FROM t2) SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1"; assertEquals( - " \n\r\tWITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, b2 FROM t2)" + - " SELECT TOP(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", + "WITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, b2 FROM t2)" + + " SELECT top(?) c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1", dialect.getLimitHandler().processSql( query4, selection ) ); } @@ -450,47 +452,47 @@ public void testGetLimitStringUsingCTEQueryNoOffset() { @Test @TestForIssue(jiraKey = "HHH-8916") public void testGetLimitStringUsingCTEQueryWithOffset() { - RowSelection selection = toRowSelection( 1, 5 ); + Limit selection = toRowSelection( 1, 5 ); - // test non-top based CTE with single CTE query definition with no odd formatting + // test non-top based CTE with single CTE query_ definition with no odd formatting final String query1 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) SELECT c1, c2 FROM a"; assertEquals( - "WITH a (c1, c2) AS (SELECT c1, c2 FROM t), query AS (SELECT inner_query.*, ROW_NUMBER() OVER " + - "(ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( SELECT c1 as page0_, c2 as page1_ " + - "FROM a ) inner_query ) SELECT page0_, page1_ FROM query WHERE __hibernate_row_nr__ >= ? " + - "AND __hibernate_row_nr__ < ?", + "WITH a (c1, c2) AS (SELECT c1, c2 FROM t) , query_ as (select row_.*, row_number() over " + + "(order by current_timestamp) as rownumber_ from (SELECT c1 as col0_, c2 as col1_ " + + "FROM a) row_) select col0_, col1_ from query_ where rownumber_ >= ? " + + "and rownumber_ < ?", dialect.getLimitHandler().processSql( query1, selection ) ); - // test non-top based CTE with single CTE query definition and various tab, newline spaces + // test non-top based CTE with single CTE query_ definition and various tab, newline spaces final String query2 = " \n\tWITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\nSELECT c1, c2 FROM a"; assertEquals( - " \n\tWITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t), query AS (SELECT inner_query.*, ROW_NUMBER()" + - " OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( \t\nSELECT c1 as page0_, c2 " + - "as page1_ FROM a ) inner_query ) SELECT page0_, page1_ FROM query WHERE __hibernate_row_nr__ >= " + - "? AND __hibernate_row_nr__ < ?", + "WITH a (c1\n\t,c2)\t\nAS (SELECT\n\tc1,c2 FROM t)\t\n, query_ as (select row_.*, row_number()" + + " over (order by current_timestamp) as rownumber_ from (SELECT c1 as col0_, c2 " + + "as col1_ FROM a) row_) select col0_, col1_ from query_ where rownumber_ >= " + + "? and rownumber_ < ?", dialect.getLimitHandler().processSql( query2, selection ) ); - // test non-top based CTE with multiple CTE query definitions with no odd formatting + // test non-top based CTE with multiple CTE query_ definitions with no odd formatting final String query3 = "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) " + " SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1"; assertEquals( - "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2), query AS (" + - "SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM (" + - " SELECT c1 as page0_, c2 as page1_, b1 as page2_, b2 as page3_ FROM t1, t2 WHERE t1.c1 = t2.b1 ) inner_query )" + - " SELECT page0_, page1_, page2_, page3_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "WITH a (c1, c2) AS (SELECT c1, c2 FROM t1), b (b1, b2) AS (SELECT b1, b2 FROM t2) , query_ as (" + + "select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "SELECT c1 as col0_, c2 as col1_, b1 as col2_, b2 as col3_ FROM t1, t2 WHERE t1.c1 = t2.b1) row_)" + + " select col0_, col1_, col2_, col3_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query3, selection ) ); - // test top-based CTE with multiple CTE query definitions and various tab, newline spaces + // test top-based CTE with multiple CTE query_ definitions and various tab, newline spaces final String query4 = " \n\r\tWITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, " + "b2 FROM t2) SELECT c1, c2, b1, b2 FROM t1, t2 WHERE t1.c1 = t2.b1"; assertEquals( - " \n\r\tWITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, b2 FROM t2), query AS (" + - "SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM (" + - " SELECT c1 as page0_, c2 as page1_, b1 as page2_, b2 as page3_ FROM t1, t2 WHERE t1.c1 = t2.b1 ) inner_query )" + - " SELECT page0_, page1_, page2_, page3_ FROM query WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?", + "WITH a (c1, c2) AS\n\r (SELECT c1, c2 FROM t1)\n\r, b (b1, b2)\tAS\t(SELECT b1, b2 FROM t2) , query_ as (" + + "select row_.*, row_number() over (order by current_timestamp) as rownumber_ from (" + + "SELECT c1 as col0_, c2 as col1_, b1 as col2_, b2 as col3_ FROM t1, t2 WHERE t1.c1 = t2.b1) row_)" + + " select col0_, col1_, col2_, col3_ from query_ where rownumber_ >= ? and rownumber_ < ?", dialect.getLimitHandler().processSql( query4, selection ) ); } @@ -634,8 +636,8 @@ public void testAppendLockHintPessimisticWriteNoTimeOut() { assertEquals( expectedLockHint, lockHint ); } - private RowSelection toRowSelection(int firstRow, int maxRows) { - RowSelection selection = new RowSelection(); + private Limit toRowSelection(int firstRow, int maxRows) { + Limit selection = new Limit(); selection.setFirstRow( firstRow ); selection.setMaxRows( maxRows ); return selection; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2012DialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2012DialectTestCase.java similarity index 72% rename from hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2012DialectTestCase.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2012DialectTestCase.java index 468daf591f42..5da0e2355ae1 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/SQLServer2012DialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/SQLServer2012DialectTestCase.java @@ -4,11 +4,14 @@ * 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; +package org.hibernate.orm.test.dialect; import java.util.Locale; +import org.hibernate.dialect.SQLServer2012Dialect; import org.hibernate.engine.spi.RowSelection; +import org.hibernate.query.Limit; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -41,7 +44,7 @@ public void tearDown() { public void testGetLimitStringMaxRowsOnly() { final String input = "select distinct f1 as f53245 from table846752 order by f234, f67 desc"; assertEquals( - input + " offset 0 rows fetch next ? rows only", + input + " offset 0 rows fetch first ? rows only", dialect.getLimitHandler().processSql( input, toRowSelection( 0, 10 ) ).toLowerCase( Locale.ROOT ) ); } @@ -59,11 +62,9 @@ public void testGetLimitStringWithOffsetAndMaxRows() { @Test @TestForIssue(jiraKey = "HHH-8768") public void testGetLimitStringMaxRowsOnlyNoOrderBy() { - // this test defaults back to validating result matches that from SQLServer2005LimitHandler - // See SQLServer2012LimitHandler for why this falls back final String input = "select f1 from table"; assertEquals( - "select top(?) f1 from table", + "select f1 from table order by @@version offset 0 rows fetch first ? rows only", dialect.getLimitHandler().processSql( input, toRowSelection( 0, 10 ) ).toLowerCase( Locale.ROOT ) ); } @@ -71,19 +72,15 @@ public void testGetLimitStringMaxRowsOnlyNoOrderBy() { @Test @TestForIssue(jiraKey = "HHH-8768") public void testGetLimitStringWithOffsetAndMaxRowsNoOrderBy() { - // this test defaults back to validating result matches that from SQLServer2005LimitHandler - // See SQLServer2012LimitHandler for why this falls back final String input = "select f1 from table"; assertEquals( - "with query as (select inner_query.*, row_number() over (order by current_timestamp) as __hibernate_row_nr__ " + - "from ( select f1 as page0_ from table ) inner_query ) select page0_ from query where " + - "__hibernate_row_nr__ >= ? and __hibernate_row_nr__ < ?", + "select f1 from table order by @@version offset ? rows fetch next ? rows only", dialect.getLimitHandler().processSql( input, toRowSelection( 5, 10 ) ).toLowerCase( Locale.ROOT ) ); } - private RowSelection toRowSelection(int firstRow, int maxRows) { - final RowSelection selection = new RowSelection(); + private Limit toRowSelection(int firstRow, int maxRows) { + final Limit selection = new Limit(); selection.setFirstRow( firstRow ); selection.setMaxRows( maxRows ); return selection; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java index 86f0375ebe2c..b5179de08abc 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/TestingDialects.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/TestingDialects.java @@ -4,8 +4,9 @@ * 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; +package org.hibernate.orm.test.dialect; +import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.dialect.spi.BasicDialectResolver; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectFactoryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectFactoryTest.java index 86627e4ae6b5..afea9e693953 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectFactoryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectFactoryTest.java @@ -20,6 +20,7 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; +import org.hibernate.orm.test.dialect.TestingDialects; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Before; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectResolverTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectResolverTest.java index 73c9361fa2bd..0f599fa9b5bc 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectResolverTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/dialect/resolver/DialectResolverTest.java @@ -10,7 +10,7 @@ import static org.junit.Assert.assertNull; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.TestingDialects; +import org.hibernate.orm.test.dialect.TestingDialects; import org.hibernate.engine.jdbc.dialect.internal.DialectResolverSet; import org.hibernate.engine.jdbc.dialect.spi.BasicDialectResolver; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerConcurrencyUnitTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/OptimizerConcurrencyUnitTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerConcurrencyUnitTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/OptimizerConcurrencyUnitTest.java index 9757e9504893..24d25cfeefd1 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/OptimizerConcurrencyUnitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/OptimizerConcurrencyUnitTest.java @@ -4,7 +4,7 @@ * 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.enhanced; +package org.hibernate.orm.test.id.enhanced; import java.util.ArrayList; import java.util.HashSet; @@ -21,6 +21,9 @@ import java.util.stream.Collectors; import org.hibernate.AssertionFailure; +import org.hibernate.id.enhanced.Optimizer; +import org.hibernate.id.enhanced.OptimizerFactory; +import org.hibernate.id.enhanced.StandardOptimizerDescriptor; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.CustomParameterized; diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/HHH14219.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SharedSequenceTest.java similarity index 52% rename from hibernate-core/src/test/java/org/hibernate/id/enhanced/HHH14219.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SharedSequenceTest.java index 5f0c7e311854..a26c0c53ea12 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/HHH14219.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SharedSequenceTest.java @@ -4,7 +4,7 @@ * 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.enhanced; +package org.hibernate.orm.test.id.enhanced; import static org.junit.Assert.assertEquals; @@ -14,19 +14,15 @@ import javax.persistence.Id; import javax.persistence.MappedSuperclass; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.dialect.MySQLDialect; import org.hibernate.query.Query; -import org.hibernate.testing.RequiresDialect; + import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.CustomRunner; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; /** * {@inheritDoc} @@ -34,32 +30,23 @@ * @author Yanming Zhou */ @TestForIssue(jiraKey = "HHH-14219") -@RunWith(CustomRunner.class) +@DomainModel( + annotatedClasses = { + SharedSequenceTest.BaseEntity.class, + SharedSequenceTest.Foo.class, + SharedSequenceTest.Bar.class + } +) +@SessionFactory @RequiresDialect(MySQLDialect.class) -public class HHH14219 { - - private SessionFactory sf; - - @Before - public void setup() { - StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() - - .applySetting("hibernate.show_sql", "true").applySetting("hibernate.format_sql", "true") - .applySetting("hibernate.hbm2ddl.auto", "create-drop"); - - Metadata metadata = new MetadataSources(srb.build()).addAnnotatedClass(BaseEntity.class) - .addAnnotatedClass(Foo.class).addAnnotatedClass(Bar.class).buildMetadata(); - - sf = metadata.buildSessionFactory(); - } +public class SharedSequenceTest { @Test - public void testSequenceTableContainsOnlyOneRow() throws Exception { - try (Session session = sf.openSession()) { - @SuppressWarnings("unchecked") + public void testSequenceTableContainsOnlyOneRow(SessionFactoryScope scope) { + scope.inTransaction( session -> { Query q = session.createNativeQuery("select count(*) from " + BaseEntity.SHARED_SEQ_NAME); assertEquals(1, q.uniqueResult().intValue()); - } + } ); } @MappedSuperclass diff --git a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SourceMock.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SourceMock.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/id/enhanced/SourceMock.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SourceMock.java index 3015cfb6c777..94b516e0a4eb 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/enhanced/SourceMock.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/enhanced/SourceMock.java @@ -4,10 +4,11 @@ * 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.id.enhanced; +package org.hibernate.orm.test.id.enhanced; import org.hibernate.id.IdentifierGeneratorHelper; import org.hibernate.id.IntegralDataTypeHolder; +import org.hibernate.id.enhanced.AccessCallback; class SourceMock implements AccessCallback { private final String tenantId; diff --git a/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java similarity index 99% rename from hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java index 0f0e7ed1d754..b65703b411dc 100644 --- a/hibernate-core/src/test/java/org/hibernate/jdbc/LobCreatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/LobCreatorTest.java @@ -4,7 +4,7 @@ * 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.jdbc; +package org.hibernate.orm.test.jdbc; import java.io.InputStream; import java.io.OutputStream; diff --git a/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java index e5f244ae06f7..ab473c68c5d7 100644 --- a/hibernate-core/src/test/java/org/hibernate/jdbc/util/BasicFormatterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/BasicFormatterTest.java @@ -4,7 +4,7 @@ * 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.jdbc.util; +package org.hibernate.orm.test.jdbc.util; import java.util.StringTokenizer; diff --git a/hibernate-core/src/test/java/org/hibernate/jdbc/util/DdlFormatterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/DdlFormatterTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/jdbc/util/DdlFormatterTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/DdlFormatterTest.java index 7bbfe779c77d..98b234f5c240 100644 --- a/hibernate-core/src/test/java/org/hibernate/jdbc/util/DdlFormatterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jdbc/util/DdlFormatterTest.java @@ -4,7 +4,7 @@ * 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.jdbc.util; +package org.hibernate.orm.test.jdbc.util; import java.util.StringTokenizer; @@ -13,8 +13,6 @@ import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; -import org.jboss.logging.Logger; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse;