HHH-11996 : Fix test to work with 5.1 branch
This commit is contained in:
parent
c9541834d5
commit
21253df74d
|
@ -21,14 +21,17 @@ import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.SequenceGenerator;
|
import javax.persistence.SequenceGenerator;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider;
|
import org.hibernate.test.util.jdbc.BasicPreparedStatementObserver;
|
||||||
|
import org.hibernate.test.util.jdbc.PreparedStatementObserver;
|
||||||
|
import org.hibernate.test.util.jdbc.PreparedStatementProxyConnectionProvider;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -40,7 +43,11 @@ import static org.mockito.Mockito.verify;
|
||||||
public class InsertOrderingWithMultipleManyToOne
|
public class InsertOrderingWithMultipleManyToOne
|
||||||
extends BaseNonConfigCoreFunctionalTestCase {
|
extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
|
|
||||||
private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
|
private static final PreparedStatementObserver preparedStatementObserver = new BasicPreparedStatementObserver();
|
||||||
|
private static final PreparedStatementProxyConnectionProvider connectionProvider = new PreparedStatementProxyConnectionProvider(
|
||||||
|
preparedStatementObserver
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
|
@ -69,7 +76,9 @@ public class InsertOrderingWithMultipleManyToOne
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatching() throws SQLException {
|
public void testBatching() throws SQLException {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
Session session = openSession();
|
||||||
|
session.getTransaction().begin();
|
||||||
|
{
|
||||||
Parent parent = new Parent();
|
Parent parent = new Parent();
|
||||||
session.persist(parent);
|
session.persist(parent);
|
||||||
|
|
||||||
|
@ -81,10 +90,12 @@ public class InsertOrderingWithMultipleManyToOne
|
||||||
childB.setParent(parent);
|
childB.setParent(parent);
|
||||||
session.persist(childB);
|
session.persist(childB);
|
||||||
|
|
||||||
connectionProvider.clear();
|
preparedStatementObserver.clear();
|
||||||
} );
|
}
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
assertEquals( 3, connectionProvider.getPreparedStatements().size() );
|
assertEquals( 3, preparedStatementObserver.getPreparedStatements().size() );
|
||||||
/*PreparedStatement addressPreparedStatement = connectionProvider.getPreparedStatement(
|
/*PreparedStatement addressPreparedStatement = connectionProvider.getPreparedStatement(
|
||||||
"insert into Address (ID) values (?)" );
|
"insert into Address (ID) values (?)" );
|
||||||
verify( addressPreparedStatement, times( 2 ) ).addBatch();
|
verify( addressPreparedStatement, times( 2 ) ).addBatch();
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class PreparedStatementProxyConnectionProvider extends ConnectionProvider
|
||||||
private final Map<Connection, Connection> acquiredConnectionProxyByConnection = new LinkedHashMap<Connection,Connection>();
|
private final Map<Connection, Connection> acquiredConnectionProxyByConnection = new LinkedHashMap<Connection,Connection>();
|
||||||
private final PreparedStatementObserver preparedStatementObserver;
|
private final PreparedStatementObserver preparedStatementObserver;
|
||||||
|
|
||||||
public PreparedStatementProxyConnectionProvider(BasicPreparedStatementObserver preparedStatementObserver) {
|
public PreparedStatementProxyConnectionProvider(PreparedStatementObserver preparedStatementObserver) {
|
||||||
this.preparedStatementObserver = preparedStatementObserver;
|
this.preparedStatementObserver = preparedStatementObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue