HHH-8900 annotations OneToOne test fail with some sequence supporting
dialects Conflicts: hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
This commit is contained in:
parent
ae7d59529e
commit
af428a1273
|
@ -23,11 +23,14 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.onetoone;
|
package org.hibernate.test.annotations.onetoone;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.EmptyInterceptor;
|
import org.hibernate.EmptyInterceptor;
|
||||||
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
@ -42,10 +45,7 @@ import org.hibernate.test.annotations.Passport;
|
||||||
import org.hibernate.test.annotations.Ticket;
|
import org.hibernate.test.annotations.Ticket;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -410,54 +410,58 @@ public class OneToOneTest extends BaseCoreFunctionalTestCase {
|
||||||
protected String[] getXmlFiles() {
|
protected String[] getXmlFiles() {
|
||||||
return new String[] { "org/hibernate/test/annotations/onetoone/orm.xml" };
|
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;
|
||||||
|
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) {
|
||||||
* Verifies that generated 'select' statement has desired number of joins
|
int numberOfJoins = 0;
|
||||||
* @author Sharath Reddy
|
if (sql.startsWith("select") & !sql.contains(nextValString)) {
|
||||||
*
|
numberOfJoins = count(sql, "join");
|
||||||
*/
|
assertEquals( sql, expectedNumberOfJoins, numberOfJoins );
|
||||||
class JoinCounter extends EmptyInterceptor {
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = -3689681272273261051L;
|
return sql;
|
||||||
|
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
return count;
|
while ((idx = string.indexOf(substring, idx)) != -1)
|
||||||
}
|
{
|
||||||
|
idx++;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue