Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2021-10-12 13:22:33 +02:00 committed by Andrea Boriero
parent 9b48207ba0
commit 4543ab176b
3 changed files with 183 additions and 190 deletions

View File

@ -4,10 +4,25 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.joinedsubclassbatch; package org.hibernate.orm.test.joinedsubclassbatch;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -20,19 +35,8 @@ import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType; import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import org.hibernate.ScrollMode; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.ScrollableResults;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
/** /**
* Test batching of insert,update,delete on joined subclasses * Test batching of insert,update,delete on joined subclasses
@ -40,59 +44,57 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
* @author dcebotarenco * @author dcebotarenco
*/ */
@TestForIssue(jiraKey = "HHH-2558") @TestForIssue(jiraKey = "HHH-2558")
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
IdentityJoinedSubclassBatchingTest.Person.class,
IdentityJoinedSubclassBatchingTest.Employee.class,
IdentityJoinedSubclassBatchingTest.Customer.class
}
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20")
)
public class IdentityJoinedSubclassBatchingTest {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Person.class,
Employee.class,
Customer.class
};
}
@Override @Test
public void configure(Configuration cfg) { public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) {
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" ); doBatchInsertUpdateJoined( 20, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 20, 20 ); doBatchInsertUpdateJoined( 19, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 19, 20 ); doBatchInsertUpdateJoined( 21, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 21, 20 ); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeEqJdbcBatchSize() { public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize ); doBatchInsertUpdateJoined( 50, batchSize - 1, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeLtJdbcBatchSize() { public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize - 1 ); doBatchInsertUpdateJoined( 50, batchSize + 1, scope );
} }
@Test public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) {
public void testBatchInsertUpdateSizeGtJdbcBatchSize() {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize + 1 );
}
public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { scope.inTransaction( s -> {
doInHibernate( this::sessionFactory, s -> {
for ( int i = 0; i < nEntities; i++ ) { for ( int i = 0; i < nEntities; i++ ) {
Employee e = new Employee(); Employee e = new Employee();
e.getId(); e.getId();
@ -110,36 +112,34 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
e.setTitle( "Unknown" ); e.setTitle( "Unknown" );
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );
} }
@Test @Test
public void testAssertSubclassInsertedSuccessfullyAfterCommit() { public void testAssertSubclassInsertedSuccessfullyAfterCommit(SessionFactoryScope scope) {
final int nEntities = 10; final int nEntities = 10;
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
for ( int i = 0; i < nEntities; i++ ) { for ( int i = 0; i < nEntities; i++ ) {
Employee e = new Employee(); Employee e = new Employee();
e.setName( "Mark" ); e.setName( "Mark" );
@ -152,19 +152,18 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult();
Assert.assertEquals( nEntities, numberOfInsertedEmployee ); assertEquals( nEntities, numberOfInsertedEmployee );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );
@ -172,9 +171,10 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
} }
@Test @Test
public void testAssertSubclassInsertedSuccessfullyAfterFlush() { public void testAssertSubclassInsertedSuccessfullyAfterFlush(SessionFactoryScope scope) {
scope.inTransaction( s -> {
doInHibernate( this::sessionFactory, s -> {
Employee e = new Employee(); Employee e = new Employee();
e.setName( "Mark" ); e.setName( "Mark" );
e.setTitle( "internal sales" ); e.setTitle( "internal sales" );
@ -186,18 +186,17 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
s.flush(); s.flush();
long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult();
Assert.assertEquals( 1L, numberOfInsertedEmployee ); assertEquals( 1L, numberOfInsertedEmployee );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );

View File

@ -4,10 +4,24 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.joinedsubclassbatch; package org.hibernate.orm.test.joinedsubclassbatch;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -19,76 +33,61 @@ import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType; import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
/** /**
* Test batching of insert,update,delete on joined subclasses * Test batching of insert,update,delete on joined subclasses
* *
* @author dcebotarenco * @author dcebotarenco
*/ */
@TestForIssue(jiraKey = "HHH-2558") @TestForIssue(jiraKey = "HHH-2558")
public class JoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
JoinedSubclassBatchingTest.Person.class,
JoinedSubclassBatchingTest.Employee.class,
JoinedSubclassBatchingTest.Customer.class
}
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20")
)
public class JoinedSubclassBatchingTest {
@Override @Test
protected Class<?>[] getAnnotatedClasses() { public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) {
return new Class[] { doBatchInsertUpdateJoined( 20, 20, scope );
Person.class,
Employee.class,
Customer.class
};
}
@Override
public void configure(Configuration cfg) {
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 20, 20 ); doBatchInsertUpdateJoined( 19, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 19, 20 ); doBatchInsertUpdateJoined( 21, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 21, 20 ); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeEqJdbcBatchSize() { public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize ); doBatchInsertUpdateJoined( 50, batchSize - 1, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeLtJdbcBatchSize() { public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize - 1 ); doBatchInsertUpdateJoined( 50, batchSize + 1, scope );
} }
@Test public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) {
public void testBatchInsertUpdateSizeGtJdbcBatchSize() {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize + 1 );
}
public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { scope.inTransaction( s -> {
doInHibernate( this::sessionFactory, s -> {
for ( int i = 0; i < nEntities; i++ ) { for ( int i = 0; i < nEntities; i++ ) {
Employee e = new Employee(); Employee e = new Employee();
e.getId(); e.getId();
@ -106,26 +105,24 @@ public class JoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase {
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
e.setTitle( "Unknown" ); e.setTitle( "Unknown" );
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );

View File

@ -4,10 +4,25 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.test.joinedsubclassbatch; package org.hibernate.orm.test.joinedsubclassbatch;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -20,19 +35,7 @@ import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType; import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import org.hibernate.ScrollMode; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.ScrollableResults;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
/** /**
* Test batching of insert,update,delete on joined subclasses using SEQUENCE * Test batching of insert,update,delete on joined subclasses using SEQUENCE
@ -40,59 +43,56 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@TestForIssue(jiraKey = "HHH-12968\n") @TestForIssue(jiraKey = "HHH-12968\n")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class) @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = {
SequenceJoinedSubclassBatchingTest.Person.class,
SequenceJoinedSubclassBatchingTest.Employee.class,
SequenceJoinedSubclassBatchingTest.Customer.class
}
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20")
)
public class SequenceJoinedSubclassBatchingTest {
@Override @Test
protected Class<?>[] getAnnotatedClasses() { public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) {
return new Class[] { doBatchInsertUpdateJoined( 20, 20, scope );
Person.class,
Employee.class,
Customer.class
};
}
@Override
public void configure(Configuration cfg) {
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 20, 20 ); doBatchInsertUpdateJoined( 19, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 19, 20 ); doBatchInsertUpdateJoined( 21, 20, scope );
} }
@Test @Test
public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) {
doBatchInsertUpdateJoined( 21, 20 ); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeEqJdbcBatchSize() { public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize ); doBatchInsertUpdateJoined( 50, batchSize - 1, scope );
} }
@Test @Test
public void testBatchInsertUpdateSizeLtJdbcBatchSize() { public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize - 1 ); doBatchInsertUpdateJoined( 50, batchSize + 1, scope );
} }
@Test public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) {
public void testBatchInsertUpdateSizeGtJdbcBatchSize() {
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdateJoined( 50, batchSize + 1 );
}
public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { scope.inTransaction( s -> {
doInHibernate( this::sessionFactory, s -> {
for ( int i = 0; i < nEntities; i++ ) { for ( int i = 0; i < nEntities; i++ ) {
Employee e = new Employee(); Employee e = new Employee();
e.getId(); e.getId();
@ -110,35 +110,33 @@ public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
e.setTitle( "Unknown" ); e.setTitle( "Unknown" );
} }
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );
} }
@Test @Test
public void testAssertSubclassInsertedSuccessfullyAfterFlush() { public void testAssertSubclassInsertedSuccessfullyAfterFlush(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
Employee e = new Employee(); Employee e = new Employee();
e.setName( "Mark" ); e.setName( "Mark" );
e.setTitle( "internal sales" ); e.setTitle( "internal sales" );
@ -150,18 +148,17 @@ public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa
s.flush(); s.flush();
long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult();
Assert.assertEquals( 1L, numberOfInsertedEmployee ); assertEquals( 1L, numberOfInsertedEmployee );
} ); } );
doInHibernate( this::sessionFactory, s -> { scope.inTransaction( s -> {
int i = 0;
ScrollableResults sr = s.createQuery( ScrollableResults sr = s.createQuery(
"select e from Employee e" ) "select e from Employee e" )
.scroll( ScrollMode.FORWARD_ONLY ); .scroll( ScrollMode.FORWARD_ONLY );
while ( sr.next() ) { while ( sr.next() ) {
Employee e = (Employee) sr.get( ); Employee e = (Employee) sr.get();
s.delete( e ); s.delete( e );
} }
} ); } );