Skip to content

Commit

Permalink
HHH-8900 annotations OneToOne test fail with some sequence supporting
Browse files Browse the repository at this point in the history
dialects

Conflicts:
	hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
  • Loading branch information
tjoneslo authored and brmeyer committed Feb 10, 2014
1 parent 0fa057c commit 4656176
Showing 1 changed file with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
*/
package org.hibernate.test.annotations.onetoone;

import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import java.util.Iterator;

import org.hibernate.EmptyInterceptor;
import org.hibernate.MappingException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
Expand All @@ -42,10 +45,7 @@
import org.hibernate.test.annotations.Ticket;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
* @author Emmanuel Bernard
Expand Down Expand Up @@ -410,54 +410,58 @@ protected Class[] getAnnotatedClasses() {
protected String[] getXmlFiles() {
return new String[] { "org/hibernate/test/annotations/onetoone/orm.xml" };
}
}


/**
* Verifies that generated 'select' statement has desired number of joins
* @author Sharath Reddy
*
*/
class JoinCounter extends EmptyInterceptor {

private static final long serialVersionUID = -3689681272273261051L;

private int expectedNumberOfJoins = 0;

public JoinCounter(int val) {
super();
this.expectedNumberOfJoins = val;
}

public String onPrepareStatement(String sql) {
int numberOfJoins = 0;
if (sql.startsWith("select") & !sql.contains("nextval")) {
numberOfJoins = count(sql, "join");
assertEquals( expectedNumberOfJoins, numberOfJoins );
}

return sql;
}

/**
* Count the number of instances of substring within a string.
*
* @param string String to look for substring in.
* @param substring Sub-string to look for.
* @return Count of substrings in string.
*/
private int count(final String string, final String substring)
{
int count = 0;
int idx = 0;

while ((idx = string.indexOf(substring, idx)) != -1)
{
idx++;
count++;
/**
* Verifies that generated 'select' statement has desired number of joins
* @author Sharath Reddy
*
*/
class JoinCounter extends EmptyInterceptor {

private static final long serialVersionUID = -3689681272273261051L;

private int expectedNumberOfJoins = 0;
private String nextValString;

public JoinCounter(int val) {
super();
this.expectedNumberOfJoins = val;
try {
nextValString = getDialect().getSequenceNextValString("");
} catch (MappingException ex) {
nextValString = "nextval";
}
}

public String onPrepareStatement(String sql) {
int numberOfJoins = 0;
if (sql.startsWith("select") & !sql.contains(nextValString)) {
numberOfJoins = count(sql, "join");
assertEquals( sql, expectedNumberOfJoins, numberOfJoins );
}

return sql;
}

return count;
}


/**
* Count the number of instances of substring within a string.
*
* @param string String to look for substring in.
* @param substring Sub-string to look for.
* @return Count of substrings in string.
*/
private int count(final String string, final String substring)
{
int count = 0;
int idx = 0;

while ((idx = string.indexOf(substring, idx)) != -1)
{
idx++;
count++;
}

return count;
}
}
}

0 comments on commit 4656176

Please sign in to comment.