Re-enable additional tests
This commit is contained in:
parent
492d391e73
commit
cc43aaefb9
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Child.java 4378 2004-08-19 10:12:11Z oneovthafew $
|
||||
package org.hibernate.test.onetomany;
|
||||
package org.hibernate.orm.test.onetomany;
|
||||
|
||||
|
||||
/**
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.orm.test.onetomany;
|
||||
|
||||
|
||||
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.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/onetomany/Parent.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class OneToManyTest {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "UnusedAssignment" })
|
||||
@Test
|
||||
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsTemporaryTable.class)
|
||||
public void testOneToManyLinkTable(SessionFactoryScope scope) {
|
||||
Child c = new Child();
|
||||
Parent p = new Parent();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
c.setName( "Child One" );
|
||||
p.setName( "Parent" );
|
||||
p.getChildren().add( c );
|
||||
c.setParent( p );
|
||||
session.save( p );
|
||||
session.flush();
|
||||
|
||||
p.getChildren().remove( c );
|
||||
c.setParent( null );
|
||||
session.flush();
|
||||
|
||||
p.getChildren().add( c );
|
||||
c.setParent( p );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
c.setParent( null );
|
||||
session.update( c );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
c.setParent( p );
|
||||
session.update( c );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Child child = (Child) session.createQuery( "from Child" ).uniqueResult();
|
||||
session.createQuery( "from Child c left join fetch c.parent" ).list();
|
||||
session.createQuery( "from Child c inner join fetch c.parent" ).list();
|
||||
session.clear();
|
||||
session.createQuery( "from Parent p left join fetch p.children" )
|
||||
.uniqueResult();
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Child" ).executeUpdate();
|
||||
session.createQuery( "delete from Parent" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyToManySize(SessionFactoryScope scope) {
|
||||
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
assertEquals(
|
||||
0,
|
||||
session.createQuery( "from Parent p where size(p.children) = 0" ).list().size()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
-->
|
||||
|
||||
<hibernate-mapping
|
||||
package="org.hibernate.test.onetomany">
|
||||
package="org.hibernate.orm.test.onetomany">
|
||||
|
||||
<class name="Parent">
|
||||
<id name="id"
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Parent.java 4378 2004-08-19 10:12:11Z oneovthafew $
|
||||
package org.hibernate.test.onetomany;
|
||||
package org.hibernate.orm.test.onetomany;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.stats">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.stats">
|
||||
|
||||
<import class="Locality"/>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Continent.java 6736 2005-05-09 16:09:38Z epbernard $
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
|
@ -9,7 +9,7 @@
|
|||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.stats">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.stats">
|
||||
|
||||
<class name="Continent" table="tbl_continent">
|
||||
<id name="id">
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Country.java 6736 2005-05-09 16:09:38Z epbernard $
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
|
||||
/**
|
|
@ -4,41 +4,39 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
|
||||
import java.util.Map;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@Jpa(
|
||||
properties = { @Setting(name = AvailableSettings.QUERY_STATISTICS_MAX_SIZE, value = "100") }
|
||||
)
|
||||
public class ExplicitQueryStatsMaxSizeTest extends QueryStatsMaxSizeTest {
|
||||
|
||||
public static final int QUERY_STATISTICS_MAX_SIZE = 100;
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
super.addConfigOptions( options );
|
||||
options.put( AvailableSettings.QUERY_STATISTICS_MAX_SIZE, QUERY_STATISTICS_MAX_SIZE );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int expectedQueryStatisticsMaxSize() {
|
||||
return QUERY_STATISTICS_MAX_SIZE;
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxSize() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void testMaxSize(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
|
||||
SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class );
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
|
||||
/**
|
|
@ -4,7 +4,7 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
|
||||
/**
|
|
@ -4,46 +4,36 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import java.util.Map;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
public class QueryStatsMaxSizeTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Jpa(
|
||||
annotatedClasses = QueryStatsMaxSizeTest.Employee.class,
|
||||
generateStatistics = true
|
||||
)
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Employee.class,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
public class QueryStatsMaxSizeTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
|
||||
SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class );
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.stat.SessionStatistics;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/stats/Continent2.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class SessionStatsTest {
|
||||
|
||||
@Test
|
||||
public void testSessionStatistics(SessionFactoryScope scope) {
|
||||
boolean isStatsEnabled = scope.fromSession(
|
||||
session -> {
|
||||
try {
|
||||
Transaction tx = session.beginTransaction();
|
||||
Statistics stats = scope.getSessionFactory().getStatistics();
|
||||
stats.clear();
|
||||
boolean isStats = stats.isStatisticsEnabled();
|
||||
stats.setStatisticsEnabled( true );
|
||||
Continent europe = fillDb( session );
|
||||
tx.commit();
|
||||
session.clear();
|
||||
tx = session.beginTransaction();
|
||||
SessionStatistics sessionStats = session.getStatistics();
|
||||
assertEquals( 0, sessionStats.getEntityKeys().size() );
|
||||
assertEquals( 0, sessionStats.getEntityCount() );
|
||||
assertEquals( 0, sessionStats.getCollectionKeys().size() );
|
||||
assertEquals( 0, sessionStats.getCollectionCount() );
|
||||
europe = (Continent) session.get( Continent.class, europe.getId() );
|
||||
Hibernate.initialize( europe.getCountries() );
|
||||
Hibernate.initialize( europe.getCountries().iterator().next() );
|
||||
assertEquals( 2, sessionStats.getEntityKeys().size() );
|
||||
assertEquals( 2, sessionStats.getEntityCount() );
|
||||
assertEquals( 1, sessionStats.getCollectionKeys().size() );
|
||||
assertEquals( 1, sessionStats.getCollectionCount() );
|
||||
tx.commit();
|
||||
return isStats;
|
||||
}
|
||||
finally {
|
||||
if ( session.getTransaction().isActive() ) {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
scope.getSessionFactory().getStatistics().setStatisticsEnabled( isStatsEnabled );
|
||||
|
||||
}
|
||||
|
||||
private Continent fillDb(Session s) {
|
||||
Continent europe = new Continent();
|
||||
europe.setName( "Europe" );
|
||||
Country france = new Country();
|
||||
france.setName( "France" );
|
||||
europe.setCountries( new HashSet() );
|
||||
europe.getCountries().add( france );
|
||||
s.persist( france );
|
||||
s.persist( europe );
|
||||
return europe;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
|
||||
/**
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import org.hibernate.cache.internal.NoCachingRegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
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.SettingProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@DomainModel
|
||||
@SessionFactory
|
||||
@ServiceRegistry(
|
||||
settingProviders = @SettingProvider(provider = StatisticsWithNoCachingTest.RegionFacrotySettingProvider.class, settingName = AvailableSettings.CACHE_REGION_FACTORY)
|
||||
)
|
||||
public class StatisticsWithNoCachingTest {
|
||||
|
||||
public static class RegionFacrotySettingProvider implements SettingProvider.Provider<String> {
|
||||
|
||||
@Override
|
||||
public String getSetting() {
|
||||
return NoCachingRegionFactory.class.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12508")
|
||||
public void testUncachedRegion(SessionFactoryScope scope) {
|
||||
final Statistics statistics = scope.getSessionFactory().getStatistics();
|
||||
statistics.getSecondLevelCacheStatistics( "hibernate.test.unknown" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
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 static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@DomainModel
|
||||
@SessionFactory
|
||||
@ServiceRegistry(
|
||||
settings = {
|
||||
@Setting( name = AvailableSettings.USE_SECOND_LEVEL_CACHE, value = "true"),
|
||||
@Setting( name = AvailableSettings.USE_QUERY_CACHE, value = "false")
|
||||
}
|
||||
)
|
||||
public class StatisticsWithNoQueryCachingTest {
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13645")
|
||||
public void testUncachedRegion(SessionFactoryScope scope) {
|
||||
final Statistics statistics = scope.getSessionFactory().getStatistics();
|
||||
assertNull( statistics.getCacheRegionStatistics( "hibernate.test.unknown" ) );
|
||||
}
|
||||
}
|
|
@ -4,43 +4,37 @@
|
|||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
package org.hibernate.orm.test.stats;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.stat.QueryStatistics;
|
||||
import org.hibernate.stat.spi.StatisticsImplementor;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* Show the difference between fetch and load
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class StatsTest extends BaseUnitTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "stats/Continent.hbm.xml" };
|
||||
}
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/stats/Continent.hbm.xml"
|
||||
)
|
||||
@org.hibernate.testing.orm.junit.SessionFactory(
|
||||
generateStatistics = true
|
||||
)
|
||||
public class StatsTest {
|
||||
|
||||
private Configuration buildBaseConfiguration() {
|
||||
return new Configuration()
|
||||
.addResource( "org/hibernate/test/stats/Continent.hbm.xml" )
|
||||
.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
//
|
||||
// @Test
|
||||
// @SuppressWarnings( {"UnusedAssignment"})
|
||||
// public void testCollectionFetchVsLoad() throws Exception {
|
||||
|
@ -144,101 +138,102 @@ public class StatsTest extends BaseUnitTestCase {
|
|||
// }
|
||||
|
||||
@Test
|
||||
public void testQueryStatGathering() {
|
||||
try (SessionFactory sf = buildBaseConfiguration()
|
||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
||||
.buildSessionFactory()) {
|
||||
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
fillDb( s );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
final String continents = "from Continent";
|
||||
int results = s.createQuery( continents ).list().size();
|
||||
QueryStatistics continentStats = sf.getStatistics().getQueryStatistics( continents );
|
||||
assertNotNull( "stats were null", continentStats );
|
||||
assertEquals( "unexpected execution count", 1, continentStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
|
||||
long maxTime = continentStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() );
|
||||
public void testQueryStatGathering(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
final String continents = "from Continent";
|
||||
int results = session.createQuery( continents ).list().size();
|
||||
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
|
||||
QueryStatistics continentStats = statistics.getQueryStatistics( continents );
|
||||
assertNotNull( continentStats, "stats were null" );
|
||||
assertEquals( 1, continentStats.getExecutionCount(), "unexpected execution count" );
|
||||
assertEquals( results, continentStats.getExecutionRowCount(), "unexpected row count" );
|
||||
long maxTime = continentStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, statistics.getQueryExecutionMaxTime() );
|
||||
// assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
|
||||
s.createQuery( continents ).list().iterator();
|
||||
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", 2, continentStats.getExecutionRowCount() );
|
||||
session.createQuery( continents ).list().iterator();
|
||||
assertEquals( 2, continentStats.getExecutionCount(), "unexpected execution count" );
|
||||
assertEquals( 2, continentStats.getExecutionRowCount(), "unexpected row count" );
|
||||
|
||||
|
||||
ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
|
||||
// same deal with scroll()...
|
||||
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", 2, continentStats.getExecutionRowCount() );
|
||||
// scroll through data because SybaseASE15Dialect throws NullPointerException
|
||||
// if data is not read before closing the ResultSet
|
||||
while ( scrollableResults.next() ) {
|
||||
// do nothing
|
||||
}
|
||||
scrollableResults.close();
|
||||
tx.commit();
|
||||
s.close();
|
||||
try (ScrollableResults scrollableResults = session.createQuery( continents ).scroll()) {
|
||||
// same deal with scroll()...
|
||||
assertEquals( 2, continentStats.getExecutionCount(), "unexpected execution count" );
|
||||
assertEquals( 2, continentStats.getExecutionRowCount(), "unexpected row count" );
|
||||
// scroll through data because SybaseASE15Dialect throws NullPointerException
|
||||
// if data is not read before closing the ResultSet
|
||||
while ( scrollableResults.next() ) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// explicitly check that statistics for "split queries" get collected
|
||||
// under the original query
|
||||
sf.getStatistics().clear();
|
||||
// explicitly check that statistics for "split queries" get collected
|
||||
// under the original query
|
||||
scope.getSessionFactory().getStatistics().clear();
|
||||
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
final String localities = "from Locality";
|
||||
results = s.createQuery( localities ).list().size();
|
||||
QueryStatistics localityStats = sf.getStatistics().getQueryStatistics( localities );
|
||||
assertNotNull( "stats were null", localityStats );
|
||||
// ...one for each split query
|
||||
assertEquals( "unexpected execution count", 2, localityStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", results, localityStats.getExecutionRowCount() );
|
||||
maxTime = localityStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
final String localities = "from Locality";
|
||||
int results = session.createQuery( localities ).list().size();
|
||||
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
|
||||
QueryStatistics localityStats = statistics.getQueryStatistics( localities );
|
||||
assertNotNull( localityStats, "stats were null" );
|
||||
// ...one for each split query
|
||||
assertEquals( 2, localityStats.getExecutionCount(), "unexpected execution count" );
|
||||
assertEquals( results, localityStats.getExecutionRowCount(), "unexpected row count" );
|
||||
long maxTime = localityStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, statistics.getQueryExecutionMaxTime() );
|
||||
// assertEquals( localities, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertFalse( s.isOpen() );
|
||||
}
|
||||
);
|
||||
|
||||
// native sql queries
|
||||
sf.getStatistics().clear();
|
||||
// native sql queries
|
||||
scope.getSessionFactory().getStatistics().clear();
|
||||
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
final String sql = "select id, name from Country";
|
||||
results = s.createNativeQuery( sql ).addEntity( Country.class ).list().size();
|
||||
QueryStatistics sqlStats = sf.getStatistics().getQueryStatistics( sql );
|
||||
assertNotNull( "sql stats were null", sqlStats );
|
||||
assertEquals( "unexpected execution count", 1, sqlStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", results, sqlStats.getExecutionRowCount() );
|
||||
maxTime = sqlStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
final String sql = "select id, name from Country";
|
||||
int results = session.createNativeQuery( sql ).addEntity( Country.class ).list().size();
|
||||
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
|
||||
QueryStatistics sqlStats = statistics.getQueryStatistics( sql );
|
||||
assertNotNull( sqlStats, "sql stats were null" );
|
||||
assertEquals( 1, sqlStats.getExecutionCount(), "unexpected execution count" );
|
||||
assertEquals( results, sqlStats.getExecutionRowCount(), "unexpected row count" );
|
||||
long maxTime = sqlStats.getExecutionMaxTime();
|
||||
assertEquals( maxTime, statistics.getQueryExecutionMaxTime() );
|
||||
// assertEquals( sql, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
cleanDb( s );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
@BeforeEach
|
||||
public void setUp(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
fillDb( session )
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session ->
|
||||
cleanDb( session )
|
||||
);
|
||||
}
|
||||
|
||||
private Continent fillDb(Session s) {
|
||||
Continent europe = new Continent();
|
||||
europe.setName("Europe");
|
||||
europe.setName( "Europe" );
|
||||
Country france = new Country();
|
||||
france.setName("France");
|
||||
france.setName( "France" );
|
||||
europe.setCountries( new HashSet() );
|
||||
europe.getCountries().add(france);
|
||||
s.persist(france);
|
||||
s.persist(europe);
|
||||
europe.getCountries().add( france );
|
||||
s.persist( france );
|
||||
s.persist( europe );
|
||||
return europe;
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.onetomany;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class OneToManyTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "onetomany/Parent.hbm.xml" };
|
||||
}
|
||||
|
||||
@SuppressWarnings( {"unchecked", "UnusedAssignment"})
|
||||
@Test
|
||||
@RequiresDialectFeature(DialectChecks.SupportsTemporaryTable.class)
|
||||
public void testOneToManyLinkTable() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
Child c = new Child();
|
||||
c.setName("Child One");
|
||||
Parent p = new Parent();
|
||||
p.setName("Parent");
|
||||
p.getChildren().add(c);
|
||||
c.setParent(p);
|
||||
s.save(p);
|
||||
s.flush();
|
||||
|
||||
p.getChildren().remove(c);
|
||||
c.setParent(null);
|
||||
s.flush();
|
||||
|
||||
p.getChildren().add(c);
|
||||
c.setParent(p);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
c.setParent(null);
|
||||
s.update(c);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
c.setParent(p);
|
||||
s.update(c);
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
c = (Child) s.createQuery("from Child").uniqueResult();
|
||||
s.createQuery("from Child c left join fetch c.parent").list();
|
||||
s.createQuery("from Child c inner join fetch c.parent").list();
|
||||
s.clear();
|
||||
p = (Parent) s.createQuery("from Parent p left join fetch p.children").uniqueResult();
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
s.createQuery("delete from Child").executeUpdate();
|
||||
s.createQuery("delete from Parent").executeUpdate();
|
||||
t.commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManyToManySize() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
assertEquals( 0, s.createQuery("from Parent p where size(p.children) = 0").list().size() );
|
||||
assertEquals( 0, s.createQuery("from Parent p where p.children.size = 0").list().size() );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.stat.SessionStatistics;
|
||||
import org.hibernate.stat.Statistics;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class SessionStatsTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "stats/Continent2.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionStatistics() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Statistics stats = sessionFactory().getStatistics();
|
||||
stats.clear();
|
||||
boolean isStats = stats.isStatisticsEnabled();
|
||||
stats.setStatisticsEnabled(true);
|
||||
Continent europe = fillDb(s);
|
||||
tx.commit();
|
||||
s.clear();
|
||||
tx = s.beginTransaction();
|
||||
SessionStatistics sessionStats = s.getStatistics();
|
||||
assertEquals( 0, sessionStats.getEntityKeys().size() );
|
||||
assertEquals( 0, sessionStats.getEntityCount() );
|
||||
assertEquals( 0, sessionStats.getCollectionKeys().size() );
|
||||
assertEquals( 0, sessionStats.getCollectionCount() );
|
||||
europe = (Continent) s.get( Continent.class, europe.getId() );
|
||||
Hibernate.initialize( europe.getCountries() );
|
||||
Hibernate.initialize( europe.getCountries().iterator().next() );
|
||||
assertEquals( 2, sessionStats.getEntityKeys().size() );
|
||||
assertEquals( 2, sessionStats.getEntityCount() );
|
||||
assertEquals( 1, sessionStats.getCollectionKeys().size() );
|
||||
assertEquals( 1, sessionStats.getCollectionCount() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
stats.setStatisticsEnabled( isStats);
|
||||
|
||||
}
|
||||
|
||||
private Continent fillDb(Session s) {
|
||||
Continent europe = new Continent();
|
||||
europe.setName("Europe");
|
||||
Country france = new Country();
|
||||
france.setName("France");
|
||||
europe.setCountries( new HashSet() );
|
||||
europe.getCountries().add(france);
|
||||
s.persist(france);
|
||||
s.persist(europe);
|
||||
return europe;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
|
||||
import org.hibernate.cache.internal.NoCachingRegionFactory;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class StatisticsWithNoCachingTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.CACHE_REGION_FACTORY, NoCachingRegionFactory.class.getName() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12508")
|
||||
public void testUncachedRegion() {
|
||||
final Statistics statistics = sessionFactory().getStatistics();
|
||||
statistics.getSecondLevelCacheStatistics( "hibernate.test.unknown" );
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* 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>.
|
||||
*/
|
||||
package org.hibernate.test.stats;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.stat.Statistics;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class StatisticsWithNoQueryCachingTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" );
|
||||
configuration.setProperty( AvailableSettings.USE_QUERY_CACHE, "false" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13645")
|
||||
public void testUncachedRegion() {
|
||||
final Statistics statistics = sessionFactory().getStatistics();
|
||||
assertNull( statistics.getCacheRegionStatistics( "hibernate.test.unknown" ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue