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.
This commit is contained in:
Guillaume Smet 2018-08-03 15:27:02 +02:00
parent 8178d76ca5
commit 5d965f8e15
1 changed files with 23 additions and 1 deletions

View File

@ -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;
}