From 5d965f8e15868bf014e724bf4d3a709df21caee3 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Fri, 3 Aug 2018 15:27:02 +0200 Subject: [PATCH] HHH-12883 Fix NaturalIdDereferenceTest with Sybase With Sybase (and maybe others), the cross join operator is ", " so only counting the " join " occurrences does not work. --- .../test/hql/NaturalIdDereferenceTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/NaturalIdDereferenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/NaturalIdDereferenceTest.java index 25a6b8e99b..5dca52d552 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/NaturalIdDereferenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/NaturalIdDereferenceTest.java @@ -246,7 +246,6 @@ public class NaturalIdDereferenceTest extends BaseCoreFunctionalTestCase { int count = 0; while ( lastIndex != -1 ) { - lastIndex = sqlQuery.indexOf( " join ", lastIndex ); if ( lastIndex != -1 ) { @@ -255,6 +254,29 @@ public class NaturalIdDereferenceTest extends BaseCoreFunctionalTestCase { } } + // we also have to deal with different cross join operators: in the case of Sybase, it's ", " + String crossJoinOperator = getDialect().getCrossJoinSeparator(); + + if ( !crossJoinOperator.contains( " join " ) ) { + int fromIndex = sqlQuery.indexOf( " from " ); + if ( fromIndex == -1 ) { + return count; + } + + int whereIndex = sqlQuery.indexOf( " where " ); + lastIndex = fromIndex + " from ".length(); + int endIndex = whereIndex > 0 ? whereIndex : sqlQuery.length(); + + while ( lastIndex != -1 && lastIndex <= endIndex ) { + lastIndex = sqlQuery.indexOf( crossJoinOperator, lastIndex ); + + if ( lastIndex != -1 ) { + count++; + lastIndex += crossJoinOperator.length(); + } + } + } + return count; }