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
This commit is contained in:
parent
222e3fb697
commit
3f2afe6b40
|
@ -8,6 +8,7 @@ package org.hibernate.dialect;
|
|||
|
||||
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 class InformixDialect extends Dialect {
|
|||
private final LimitHandler limitHandler;
|
||||
|
||||
public InformixDialect() {
|
||||
this(7);
|
||||
this( 7 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,6 +395,16 @@ public class InformixDialect extends Dialect {
|
|||
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
|
||||
|
|
|
@ -238,13 +238,25 @@ public class SQLServer2005LimitHandler extends AbstractLimitHandler {
|
|||
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 @@ public class SQLServer2005LimitHandler extends AbstractLimitHandler {
|
|||
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))?"),
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SelfRenderingSqmFunction<T> extends SqmFunction<T> {
|
|||
public SqmExpressable<T> getNodeType() {
|
||||
SqmExpressable<T> nodeType = super.getNodeType();
|
||||
if ( nodeType == null ) {
|
||||
resolveResultType( nodeBuilder().getTypeConfiguration() );
|
||||
nodeType = (SqmExpressable<T>) resolveResultType( nodeBuilder().getTypeConfiguration() );
|
||||
}
|
||||
|
||||
return nodeType;
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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<String, SQLFunction> 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<String, SQLFunction> 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 ) );
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 static org.mockito.Mockito.when;
|
|||
|
||||
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 class CollectionBinderTest extends BaseUnitTestCase {
|
|||
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<String, PersistentClass> persistentClasses,
|
||||
Ejb3JoinColumn[] fkJoinColumns,
|
||||
XClass collectionType,
|
||||
boolean cascadeDeleteEnabled,
|
||||
boolean ignoreNotFound,
|
||||
MetadataBuildingContext buildingContext,
|
||||
Map<XClass, InheritanceState> 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());
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 @@ import org.junit.Test;
|
|||
*/
|
||||
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 class DerbyDialectTestCase extends BaseUnitTestCase {
|
|||
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 class DerbyDialectTestCase extends BaseUnitTestCase {
|
|||
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 class DerbyDialectTestCase extends BaseUnitTestCase {
|
|||
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 class DerbyDialectTestCase extends BaseUnitTestCase {
|
|||
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 class DerbyDialectTestCase extends BaseUnitTestCase {
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.dialect;
|
||||
package org.hibernate.orm.test.dialect;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
@ -13,6 +13,8 @@ import java.util.Map;
|
|||
|
||||
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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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<Object> 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<Object> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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.JDBCException;
|
|||
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;
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
"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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2005DialectTestCase extends BaseUnitTestCase {
|
|||
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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 class SQLServer2012DialectTestCase extends BaseUnitTestCase {
|
|||
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 class SQLServer2012DialectTestCase extends BaseUnitTestCase {
|
|||
@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 class SQLServer2012DialectTestCase extends BaseUnitTestCase {
|
|||
@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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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;
|
|
@ -20,6 +20,7 @@ import org.hibernate.engine.jdbc.dialect.internal.StandardDialectResolver;
|
|||
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;
|
||||
|
|
|
@ -10,7 +10,7 @@ import static org.junit.Assert.assertEquals;
|
|||
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;
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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.concurrent.TimeoutException;
|
|||
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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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.GenerationType;
|
|||
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 @@ import org.junit.runner.RunWith;
|
|||
* @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<Number> q = session.createNativeQuery("select count(*) from " + BaseEntity.SHARED_SEQ_NAME);
|
||||
assertEquals(1, q.uniqueResult().intValue());
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@MappedSuperclass
|
|
@ -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;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jdbc;
|
||||
package org.hibernate.orm.test.jdbc;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jdbc.util;
|
||||
package org.hibernate.orm.test.jdbc.util;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jdbc.util;
|
||||
package org.hibernate.orm.test.jdbc.util;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
@ -13,8 +13,6 @@ import org.hibernate.engine.jdbc.internal.FormatStyle;
|
|||
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;
|
||||
|
Loading…
Reference in New Issue