Fix connection leaks by properly closing service registries
This commit is contained in:
parent
77c1370e45
commit
6314395edf
|
@ -763,7 +763,14 @@ public class Configuration {
|
|||
public SessionFactory buildSessionFactory() throws HibernateException {
|
||||
log.debug( "Building session factory using internal StandardServiceRegistryBuilder" );
|
||||
standardServiceRegistryBuilder.applySettings( properties );
|
||||
return buildSessionFactory( standardServiceRegistryBuilder.build() );
|
||||
StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
|
||||
try {
|
||||
return buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
catch (Throwable t) {
|
||||
serviceRegistry.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -223,80 +223,88 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
providedClassLoader,
|
||||
providedClassLoaderService
|
||||
);
|
||||
try {
|
||||
// merge configuration sources and build the "standard" service registry
|
||||
final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr );
|
||||
|
||||
// merge configuration sources and build the "standard" service registry
|
||||
final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr );
|
||||
final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder );
|
||||
|
||||
final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder );
|
||||
// flush before completion validation
|
||||
if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) {
|
||||
LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION );
|
||||
mergedSettings.configurationValues.put( Environment.FLUSH_BEFORE_COMPLETION, "false" );
|
||||
}
|
||||
|
||||
// flush before completion validation
|
||||
if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) {
|
||||
LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION );
|
||||
mergedSettings.configurationValues.put( Environment.FLUSH_BEFORE_COMPLETION, "false" );
|
||||
}
|
||||
// keep the merged config values for phase-2
|
||||
this.configurationValues = mergedSettings.getConfigurationValues();
|
||||
|
||||
// keep the merged config values for phase-2
|
||||
this.configurationValues = mergedSettings.getConfigurationValues();
|
||||
// Build the "standard" service registry
|
||||
ssrBuilder.applySettings( configurationValues );
|
||||
|
||||
// Build the "standard" service registry
|
||||
ssrBuilder.applySettings( configurationValues );
|
||||
this.standardServiceRegistry = ssrBuilder.build();
|
||||
|
||||
this.standardServiceRegistry = ssrBuilder.build();
|
||||
configureIdentifierGenerators( standardServiceRegistry );
|
||||
|
||||
configureIdentifierGenerators( standardServiceRegistry );
|
||||
final MetadataSources metadataSources = new MetadataSources( bsr );
|
||||
this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder(
|
||||
standardServiceRegistry );
|
||||
List<ConverterDescriptor> attributeConverterDefinitions = applyMappingResources( metadataSources );
|
||||
|
||||
final MetadataSources metadataSources = new MetadataSources( bsr );
|
||||
this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry );
|
||||
List<ConverterDescriptor> attributeConverterDefinitions = applyMappingResources( metadataSources );
|
||||
applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions );
|
||||
|
||||
applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions );
|
||||
applyMetadataBuilderContributor();
|
||||
|
||||
applyMetadataBuilderContributor();
|
||||
|
||||
// todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here
|
||||
// another option is to immediately handle them here (probably in mergeSettings?) as we encounter them...
|
||||
final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class );
|
||||
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
||||
if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
|
||||
for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig().getMappingReferences() ) {
|
||||
mappingReference.apply( metadataSources );
|
||||
// todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here
|
||||
// another option is to immediately handle them here (probably in mergeSettings?) as we encounter them...
|
||||
final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class );
|
||||
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
||||
if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
|
||||
for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig()
|
||||
.getMappingReferences() ) {
|
||||
mappingReference.apply( metadataSources );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.managedResources = MetadataBuildingProcess.prepare(
|
||||
metadataSources,
|
||||
metamodelBuilder.getBootstrapContext()
|
||||
);
|
||||
|
||||
final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY );
|
||||
if ( validatorFactory == null ) {
|
||||
withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) );
|
||||
}
|
||||
else {
|
||||
withValidatorFactory( validatorFactory );
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// push back class transformation to the environment; for the time being this only has any effect in EE
|
||||
// container situations, calling back into PersistenceUnitInfo#addClassTransformer
|
||||
|
||||
final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING );
|
||||
final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION );
|
||||
final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT );
|
||||
|
||||
if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) {
|
||||
EnhancementContext enhancementContext = getEnhancementContext(
|
||||
dirtyTrackingEnabled,
|
||||
lazyInitializationEnabled,
|
||||
associationManagementEnabled
|
||||
this.managedResources = MetadataBuildingProcess.prepare(
|
||||
metadataSources,
|
||||
metamodelBuilder.getBootstrapContext()
|
||||
);
|
||||
|
||||
persistenceUnit.pushClassTransformer( enhancementContext );
|
||||
}
|
||||
final Object validatorFactory = configurationValues.get( org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY );
|
||||
if ( validatorFactory == null ) {
|
||||
withValidatorFactory( configurationValues.get( org.hibernate.cfg.AvailableSettings.JAKARTA_JPA_VALIDATION_FACTORY ) );
|
||||
}
|
||||
else {
|
||||
withValidatorFactory( validatorFactory );
|
||||
}
|
||||
|
||||
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
||||
metamodelBuilder.applyTempClassLoader( null );
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// push back class transformation to the environment; for the time being this only has any effect in EE
|
||||
// container situations, calling back into PersistenceUnitInfo#addClassTransformer
|
||||
|
||||
final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING );
|
||||
final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION );
|
||||
final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT );
|
||||
|
||||
if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) {
|
||||
EnhancementContext enhancementContext = getEnhancementContext(
|
||||
dirtyTrackingEnabled,
|
||||
lazyInitializationEnabled,
|
||||
associationManagementEnabled
|
||||
);
|
||||
|
||||
persistenceUnit.pushClassTransformer( enhancementContext );
|
||||
}
|
||||
|
||||
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
||||
metamodelBuilder.applyTempClassLoader( null );
|
||||
}
|
||||
catch (Throwable t) {
|
||||
bsr.close();
|
||||
cleanup();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,17 +37,17 @@ public class ConfigurationTest {
|
|||
Configuration cfg = new Configuration();
|
||||
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Boat" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Plane" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Boat" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Plane" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,24 +93,24 @@ public class ConfigurationTest {
|
|||
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAnnotatedClass( Boat.class );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
s.getTransaction().begin();
|
||||
Boat boat = new Boat();
|
||||
boat.setSize( 12 );
|
||||
boat.setWeight( 34 );
|
||||
s.persist( boat );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
Transaction tx = s.beginTransaction();
|
||||
boat = (Boat) s.get( Boat.class, boat.getId() );
|
||||
assertTrue( 34 != boat.getWeight(), "Annotation has precedence" );
|
||||
s.delete( boat );
|
||||
//s.getTransaction().commit();
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
s.getTransaction().begin();
|
||||
Boat boat = new Boat();
|
||||
boat.setSize( 12 );
|
||||
boat.setWeight( 34 );
|
||||
s.persist( boat );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
Transaction tx = s.beginTransaction();
|
||||
boat = (Boat) s.get( Boat.class, boat.getId() );
|
||||
assertTrue( 34 != boat.getWeight(), "Annotation has precedence" );
|
||||
s.delete( boat );
|
||||
//s.getTransaction().commit();
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -120,23 +120,23 @@ public class ConfigurationTest {
|
|||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
|
||||
cfg.addAnnotatedClass( Boat.class );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
s.getTransaction().begin();
|
||||
Boat boat = new Boat();
|
||||
boat.setSize( 12 );
|
||||
boat.setWeight( 34 );
|
||||
s.persist( boat );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
Transaction tx = s.beginTransaction();
|
||||
boat = (Boat) s.get( Boat.class, boat.getId() );
|
||||
assertTrue( 34 == boat.getWeight(), "Annotation has precedence" );
|
||||
s.delete( boat );
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
s.getTransaction().begin();
|
||||
Boat boat = new Boat();
|
||||
boat.setSize( 12 );
|
||||
boat.setWeight( 34 );
|
||||
s.persist( boat );
|
||||
s.getTransaction().commit();
|
||||
s.clear();
|
||||
Transaction tx = s.beginTransaction();
|
||||
boat = (Boat) s.get( Boat.class, boat.getId() );
|
||||
assertTrue( 34 == boat.getWeight(), "Annotation has precedence" );
|
||||
s.delete( boat );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,17 +145,17 @@ public class ConfigurationTest {
|
|||
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
|
||||
cfg.addClass( Ferry.class );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Ferry" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Plane" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Ferry" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Plane" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -164,16 +164,16 @@ public class ConfigurationTest {
|
|||
cfg.configure( "org/hibernate/orm/test/annotations/hibernate.cfg.xml" );
|
||||
cfg.addAnnotatedClass( Port.class );
|
||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Boat" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Port" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
assertNotNull( sf );
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Query q = s.createQuery( "from Boat" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
q = s.createQuery( "from Port" );
|
||||
assertEquals( 0, q.list().size() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public class SafeMappingTest {
|
|||
if ( serviceRegistry != null ) {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
cfg.getStandardServiceRegistryBuilder().getBootstrapServiceRegistry().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ public class SecuredBindingTest {
|
|||
if ( serviceRegistry != null ) {
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
ac.getStandardServiceRegistryBuilder().getBootstrapServiceRegistry().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
@ -88,11 +90,11 @@ public class BackquoteTest {
|
|||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-4647")
|
||||
public void testInvalidReferenceToQuotedTableName() {
|
||||
try {
|
||||
Configuration config = new Configuration();
|
||||
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||
Configuration config = new Configuration( serviceRegistry );
|
||||
config.addAnnotatedClass( Printer.class );
|
||||
config.addAnnotatedClass( PrinterCable.class );
|
||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||
sessionFactory = config.buildSessionFactory( this.serviceRegistry );
|
||||
fail( "expected MappingException to be thrown" );
|
||||
}
|
||||
//we WANT MappingException to be thrown
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
//$Id$
|
||||
package org.hibernate.orm.test.annotations.configuration;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
@ -19,8 +21,8 @@ import org.junit.Test;
|
|||
public class ConfigurationTest {
|
||||
@Test
|
||||
public void testMixPackageAndResourceOrdering() throws Exception {
|
||||
try {
|
||||
Configuration config = new Configuration();
|
||||
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||
Configuration config = new Configuration( serviceRegistry );
|
||||
config.addResource( "org/hibernate/orm/test/annotations/configuration/orm.xml" );
|
||||
config.addPackage( "org.hibernate.orm/test.annotations.configuration" );
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.hibernate.orm.test.annotations.embeddables.collection;
|
|||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
|
@ -17,11 +18,8 @@ import static org.junit.Assert.fail;
|
|||
public abstract class AbstractEmbeddableWithManyToManyTest {
|
||||
@Test
|
||||
public void test() {
|
||||
try {
|
||||
BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder();
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(
|
||||
bootstrapServiceRegistryBuilder.build() );
|
||||
StandardServiceRegistry ssr = ssrb.build();
|
||||
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build();
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( serviceRegistry ).build()) {
|
||||
MetadataSources metadataSources = new MetadataSources( ssr );
|
||||
addResources( metadataSources );
|
||||
addAnnotatedClasses(metadataSources);
|
||||
|
|
|
@ -55,19 +55,19 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
config.addAnnotatedClass( Order.class );
|
||||
config.addAnnotatedClass( SupportTickets.class );
|
||||
config.addAnnotatedClass( Country.class );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
)) {
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "customer-with-orders" )
|
||||
);
|
||||
assertFalse(
|
||||
"package info should not be parsed",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "customer-with-orders" )
|
||||
);
|
||||
assertFalse(
|
||||
"package info should not be parsed",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -146,15 +146,15 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
.getContextClassLoader()
|
||||
.getResourceAsStream( "org/hibernate/orm/test/annotations/fetchprofile/mappings.hbm.xml" );
|
||||
config.addInputStream( is );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
)) {
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "orders-profile" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "orders-profile" )
|
||||
);
|
||||
}
|
||||
|
||||
// now the same with no xml
|
||||
final MetadataSources metadataSources = new MetadataSources()
|
||||
|
@ -185,18 +185,18 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
config.addAnnotatedClass( SupportTickets.class );
|
||||
config.addAnnotatedClass( Country.class );
|
||||
config.addPackage( Customer.class.getPackage().getName() );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
)) {
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-2" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "package-profile-2" )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,19 +35,19 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
|||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer6.class );
|
||||
config.addAnnotatedClass( Address.class );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
)) {
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "address-with-customer" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "address-with-customer" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -56,19 +56,19 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
|||
config.addAnnotatedClass( Customer6.class );
|
||||
config.addAnnotatedClass( Address.class );
|
||||
config.addPackage( Address.class.getPackage().getName() );
|
||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||
serviceRegistry
|
||||
);
|
||||
)) {
|
||||
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-1" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
|
||||
);
|
||||
sessionImpl.close();
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-1" )
|
||||
);
|
||||
assertTrue(
|
||||
"fetch profile not parsed properly",
|
||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import org.hibernate.annotations.JoinColumnOrFormula;
|
|||
import org.hibernate.annotations.JoinFormula;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
|
||||
|
@ -50,15 +52,17 @@ public class JoinColumnOrFormulaTest extends BaseUnitTestCase {
|
|||
@TestForIssue( jiraKey = "HHH-9897" )
|
||||
@FailureExpected( jiraKey = "HHH-9897" )
|
||||
public void testUseOfJoinColumnOrFormula() {
|
||||
Metadata metadata = new MetadataSources()
|
||||
.addAnnotatedClass( A.class )
|
||||
.addAnnotatedClass( D.class )
|
||||
.buildMetadata();
|
||||
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( A.class )
|
||||
.addAnnotatedClass( D.class )
|
||||
.buildMetadata();
|
||||
|
||||
// Binding to the mapping model works after the simple change for HHH-9897
|
||||
// But building the SessionFactory fails in the collection persister trying to
|
||||
// use the formula (it expects Columns too)
|
||||
metadata.buildSessionFactory().close();
|
||||
// Binding to the mapping model works after the simple change for HHH-9897
|
||||
// But building the SessionFactory fails in the collection persister trying to
|
||||
// use the formula (it expects Columns too)
|
||||
metadata.buildSessionFactory().close();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity( name = "A" )
|
||||
|
|
|
@ -62,7 +62,7 @@ public class EntityInheritanceAttributeOverrideTest extends EntityManagerFactory
|
|||
|
||||
@Test
|
||||
public void test() {
|
||||
produceEntityManagerFactory();
|
||||
produceEntityManagerFactory().close();
|
||||
}
|
||||
|
||||
@Entity(name = "AbstractEntity")
|
||||
|
|
|
@ -21,9 +21,7 @@ public class MappedSuperClassIdPropertyBasicAttributeOverrideTest {
|
|||
|
||||
@Test
|
||||
public void test() {
|
||||
try {
|
||||
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
StandardServiceRegistry ssr = ssrb.build();
|
||||
try (StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
|
||||
MetadataSources metadataSources = new MetadataSources( ssr );
|
||||
metadataSources.addAnnotatedClasses( MappedSuperClassWithUuidAsBasic.class );
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.hibernate.orm.test.internal.util.xml.XMLMappingHelper;
|
|||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
@ -29,19 +31,32 @@ import static org.junit.Assert.*;
|
|||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
|
||||
private BootstrapContextImpl bootstrapContext;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
bootstrapContext = new BootstrapContextImpl();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
bootstrapContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappedSuperclassAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/orm/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Organization.class, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Organization.class, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Default value in xml entity should not override @Entity.name", "JavaAdministration",
|
||||
|
@ -75,7 +90,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
assertEquals( "wrong tble name", "tablehilo", reader.getAnnotation( TableGenerator.class ).table() );
|
||||
assertEquals( "no schema overriding", "myschema", reader.getAnnotation( TableGenerator.class ).schema() );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals(
|
||||
"Java annotation not taken into account", "matchtable", reader.getAnnotation( Table.class ).name()
|
||||
|
@ -123,10 +138,10 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
assertNotNull( reader.getAnnotation( ExcludeSuperclassListeners.class ) );
|
||||
assertNotNull( reader.getAnnotation( ExcludeDefaultListeners.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, bootstrapContext );
|
||||
assertNull( "Mutualize PKJC into PKJCs", reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
assertEquals(
|
||||
|
@ -153,7 +168,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
);
|
||||
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityPhysicalAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityPhysicalAccount.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() );
|
||||
assertEquals(
|
||||
|
@ -174,7 +189,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
XMLContext context = buildContext(
|
||||
"org/hibernate/orm/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Metadata complete should ignore java annotations", "", reader.getAnnotation( Entity.class ).name()
|
||||
|
@ -183,7 +198,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Default schema not overriden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Match.class, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Overriding not taken into account", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
|
@ -194,14 +209,14 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
assertNull( reader.getAnnotation( NamedQueries.class ) );
|
||||
assertNull( reader.getAnnotation( NamedNativeQueries.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( TennisMatch.class, context, bootstrapContext );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Competition.class, context, bootstrapContext );
|
||||
assertNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityMoralAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( SocialSecurityMoralAccount.class, context, bootstrapContext );
|
||||
assertNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorValue.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||
|
@ -213,11 +228,11 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
public void testIdRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertNull( reader.getAnnotation( Id.class ) );
|
||||
assertNull( reader.getAnnotation( Column.class ) );
|
||||
Field field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Id.class ) );
|
||||
assertNotNull( reader.getAnnotation( GeneratedValue.class ) );
|
||||
assertEquals( GenerationType.SEQUENCE, reader.getAnnotation( GeneratedValue.class ).strategy() );
|
||||
|
@ -234,23 +249,23 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
"org/hibernate/orm/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
method = Administration.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertNotNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
|
||||
method = BusTrip.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
field = BusTrip.class.getDeclaredField( "id" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
|
@ -262,22 +277,22 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
"org/hibernate/orm/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
Field field = BusTrip.class.getDeclaredField( "status" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Enumerated.class ) );
|
||||
assertEquals( EnumType.STRING, reader.getAnnotation( Enumerated.class ).value() );
|
||||
assertEquals( false, reader.getAnnotation( Basic.class ).optional() );
|
||||
field = BusTrip.class.getDeclaredField( "serial" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Lob.class ) );
|
||||
assertEquals( "serialbytes", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||
field = BusTrip.class.getDeclaredField( "terminusTime" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||
assertEquals( TemporalType.TIMESTAMP, reader.getAnnotation( Temporal.class ).value() );
|
||||
assertEquals( FetchType.LAZY, reader.getAnnotation( Basic.class ).fetch() );
|
||||
|
||||
field = BusTripPk.class.getDeclaredField( "busDriver" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( Basic.class ) );
|
||||
}
|
||||
|
||||
|
@ -285,7 +300,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
public void testVersionRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
|
||||
Field field = Match.class.getDeclaredField( "version" );
|
||||
|
@ -297,12 +312,12 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "transientField" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Transient.class ) );
|
||||
assertNull( reader.getAnnotation( Basic.class ) );
|
||||
|
||||
field = Match.class.getDeclaredField( "playerASSN" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||
}
|
||||
|
||||
|
@ -311,7 +326,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "defaultBusTrip" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( OneToOne.class ) );
|
||||
assertNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
|
@ -324,7 +339,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
"org/hibernate/orm/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
field = BusTrip.class.getDeclaredField( "players" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( OneToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertEquals( 2, reader.getAnnotation( JoinColumns.class ).value().length );
|
||||
|
@ -333,7 +348,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
assertEquals( "name", reader.getAnnotation( MapKey.class ).name() );
|
||||
|
||||
field = BusTrip.class.getDeclaredField( "roads" );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( ManyToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinTable.class ) );
|
||||
assertEquals( "bus_road", reader.getAnnotation( JoinTable.class ).name() );
|
||||
|
@ -350,7 +365,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Company.class.getDeclaredField( "organizations" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||
assertNotNull( reader.getAnnotation( ElementCollection.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ).value() );
|
||||
|
@ -363,20 +378,20 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
XMLContext context = buildContext( "org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Method method = Administration.class.getDeclaredMethod( "calculate" );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
JPAXMLOverriddenAnnotationReader reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( Administration.class, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( EntityListeners.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
|
||||
assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "noLog", Object.class );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( PostLoad.class ) );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "log", Object.class );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
assertFalse( reader.isAnnotationPresent( PostPersist.class ) );
|
||||
|
||||
|
@ -387,7 +402,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
|||
private XMLContext buildContext(String ormfile) throws IOException {
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( ormfile );
|
||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
XMLContext context = new XMLContext( bootstrapContext );
|
||||
context.addDocument( mappings );
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.hibernate.orm.test.internal.util.xml.XMLMappingHelper;
|
|||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
|
@ -19,10 +21,23 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14529")
|
||||
public class XMLContextTest {
|
||||
|
||||
private BootstrapContextImpl bootstrapContext;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
bootstrapContext = new BootstrapContextImpl();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
bootstrapContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||
final XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
final XMLContext context = new XMLContext( bootstrapContext );
|
||||
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings(
|
||||
"org/hibernate/orm/test/annotations/reflection/orm.xml" );
|
||||
|
|
|
@ -18,6 +18,9 @@ import org.hibernate.orm.test.internal.util.xml.XMLMappingHelper;
|
|||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -31,9 +34,21 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
|||
|
||||
protected JPAXMLOverriddenAnnotationReader reader;
|
||||
|
||||
private BootstrapContextImpl bootstrapContext;
|
||||
|
||||
protected Ejb3XmlTestCase() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
bootstrapContext = new BootstrapContextImpl();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
bootstrapContext.close();
|
||||
}
|
||||
|
||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||
assertTrue(
|
||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||
|
@ -52,7 +67,7 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
|||
throws Exception {
|
||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||
XMLContext xmlContext = getContext( ormResourceName );
|
||||
return new JPAXMLOverriddenAnnotationReader( el, xmlContext, BootstrapContextImpl.INSTANCE );
|
||||
return new JPAXMLOverriddenAnnotationReader( el, xmlContext, bootstrapContext );
|
||||
}
|
||||
|
||||
protected AnnotatedElement getAnnotatedElement(Class<?> entityClass, String fieldName) throws Exception {
|
||||
|
@ -68,7 +83,7 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
|||
protected XMLContext getContext(InputStream is, String resourceName) throws Exception {
|
||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( is, resourceName );
|
||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
XMLContext context = new XMLContext( bootstrapContext );
|
||||
context.addDocument( mappings );
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.orm.test.annotations.xml.ejb3;
|
|||
|
||||
import org.hibernate.InvalidMappingException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||
|
||||
|
@ -21,9 +22,8 @@ import static org.junit.Assert.fail;
|
|||
public class NonExistentOrmVersionTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testNonExistentOrmVersion() {
|
||||
try {
|
||||
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
new MetadataSources( builder.build() )
|
||||
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||
new MetadataSources( serviceRegistry )
|
||||
.addResource( "org/hibernate/orm/test/annotations/xml/ejb3/orm5.xml" )
|
||||
.buildMetadata();
|
||||
fail( "Expecting failure due to unsupported xsd version" );
|
||||
|
|
|
@ -32,7 +32,8 @@ public class XmlBindingChecker {
|
|||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
jaxbMarshaller.marshal( hbmMapping, bos );
|
||||
ByteArrayInputStream is = new ByteArrayInputStream( bos.toByteArray() );
|
||||
ServiceRegistry sr = new StandardServiceRegistryBuilder().build();
|
||||
new XmlMappingBinderAccess( sr ).bind( is );
|
||||
try (ServiceRegistry sr = new StandardServiceRegistryBuilder().build()) {
|
||||
new XmlMappingBinderAccess( sr ).bind( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,21 +54,20 @@ public class NonRootEntityWithCacheAnnotationTest {
|
|||
settings.put( Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
||||
|
||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||
try (ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||
.applySettings( settings )
|
||||
.build();
|
||||
.build()) {
|
||||
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( ABase.class )
|
||||
.addAnnotatedClass( AEntity.class )
|
||||
.buildMetadata();
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( ABase.class )
|
||||
.addAnnotatedClass( AEntity.class )
|
||||
.buildMetadata();
|
||||
|
||||
assertTrue( triggerable.wasTriggered() );
|
||||
assertFalse( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||
|
||||
serviceRegistry.destroy();
|
||||
assertTrue( triggerable.wasTriggered() );
|
||||
assertFalse( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -53,23 +53,22 @@ public class NonRootEntityWithCacheableAnnotationTest {
|
|||
settings.put( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write" );
|
||||
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
||||
|
||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||
try (ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||
.applySettings( settings )
|
||||
.build();
|
||||
.build()) {
|
||||
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( ABase.class )
|
||||
.addAnnotatedClass( AEntity.class )
|
||||
.buildMetadata();
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( ABase.class )
|
||||
.addAnnotatedClass( AEntity.class )
|
||||
.buildMetadata();
|
||||
|
||||
assertFalse( metadata.getEntityBinding( ABase.class.getName() ).isCached() );
|
||||
assertTrue( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||
assertFalse( metadata.getEntityBinding( ABase.class.getName() ).isCached() );
|
||||
assertTrue( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
|
||||
serviceRegistry.destroy();
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -32,75 +32,75 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testCachingExplicitlyDisabled() {
|
||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
try (final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" )
|
||||
.build();
|
||||
|
||||
assertThat( registry.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
.build()) {
|
||||
assertThat( registry.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachingImplicitlyEnabledRegistered() {
|
||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build();
|
||||
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build()) {
|
||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||
|
||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||
assertThat( implementors.size(), equalTo( 1 ) );
|
||||
|
||||
assertThat( implementors.size(), equalTo( 1 ) );
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" )
|
||||
.build();
|
||||
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" )
|
||||
.build();
|
||||
|
||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCachingImplicitlyEnabledNoRegistered() {
|
||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build();
|
||||
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build()) {
|
||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||
|
||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||
assertThat( implementors.size(), equalTo( 1 ) );
|
||||
|
||||
assertThat( implementors.size(), equalTo( 1 ) );
|
||||
bsr.getService( StrategySelector.class ).unRegisterStrategyImplementor(
|
||||
RegionFactory.class,
|
||||
implementors.iterator().next()
|
||||
);
|
||||
|
||||
bsr.getService( StrategySelector.class ).unRegisterStrategyImplementor(
|
||||
RegionFactory.class,
|
||||
implementors.iterator().next()
|
||||
);
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" )
|
||||
.build();
|
||||
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "" )
|
||||
.build();
|
||||
|
||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionsRegistered() {
|
||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build();
|
||||
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||
.build()) {
|
||||
final Collection<Class<? extends ConnectionProvider>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( ConnectionProvider.class );
|
||||
|
||||
final Collection<Class<? extends ConnectionProvider>> implementors = bsr
|
||||
.getService( StrategySelector.class )
|
||||
.getRegisteredStrategyImplementors( ConnectionProvider.class );
|
||||
assertThat( implementors.size(), equalTo( 0 ) );
|
||||
|
||||
assertThat( implementors.size(), equalTo( 0 ) );
|
||||
bsr.getService( StrategySelector.class ).registerStrategyImplementor(
|
||||
ConnectionProvider.class,
|
||||
"testing",
|
||||
DriverManagerConnectionProviderImpl.class
|
||||
);
|
||||
|
||||
bsr.getService( StrategySelector.class ).registerStrategyImplementor(
|
||||
ConnectionProvider.class,
|
||||
"testing",
|
||||
DriverManagerConnectionProviderImpl.class
|
||||
);
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ).build();
|
||||
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr ).build();
|
||||
final ConnectionProvider configuredProvider = ssr.getService( ConnectionProvider.class );
|
||||
|
||||
final ConnectionProvider configuredProvider = ssr.getService( ConnectionProvider.class );
|
||||
|
||||
assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) );
|
||||
assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,22 +35,23 @@ public class CacheKeyImplementationHashCodeTest {
|
|||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12746")
|
||||
public void test() {
|
||||
ServiceRegistryImplementor serviceRegistry = (
|
||||
ServiceRegistryImplementor) new StandardServiceRegistryBuilder().build();
|
||||
MetadataSources ms = new MetadataSources( serviceRegistry );
|
||||
ms.addAnnotatedClass( AnEntity.class ).addAnnotatedClass( AnotherEntity.class );
|
||||
Metadata metadata = ms.buildMetadata();
|
||||
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
|
||||
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sfb.build();
|
||||
try (ServiceRegistryImplementor serviceRegistry = (
|
||||
ServiceRegistryImplementor) new StandardServiceRegistryBuilder().build()) {
|
||||
MetadataSources ms = new MetadataSources( serviceRegistry );
|
||||
ms.addAnnotatedClass( AnEntity.class ).addAnnotatedClass( AnotherEntity.class );
|
||||
Metadata metadata = ms.buildMetadata();
|
||||
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
|
||||
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sfb.build();
|
||||
|
||||
|
||||
CacheKeyImplementation anEntityCacheKey = createCacheKeyImplementation(
|
||||
1, sessionFactory.getMetamodel().entityPersister( AnEntity.class ), sessionFactory
|
||||
);
|
||||
CacheKeyImplementation anotherEntityCacheKey = createCacheKeyImplementation(
|
||||
1, sessionFactory.getMetamodel().entityPersister( AnotherEntity.class ), sessionFactory
|
||||
);
|
||||
assertFalse( anEntityCacheKey.equals( anotherEntityCacheKey ) );
|
||||
CacheKeyImplementation anEntityCacheKey = createCacheKeyImplementation(
|
||||
1, sessionFactory.getMetamodel().entityPersister( AnEntity.class ), sessionFactory
|
||||
);
|
||||
CacheKeyImplementation anotherEntityCacheKey = createCacheKeyImplementation(
|
||||
1, sessionFactory.getMetamodel().entityPersister( AnotherEntity.class ), sessionFactory
|
||||
);
|
||||
assertFalse( anEntityCacheKey.equals( anotherEntityCacheKey ) );
|
||||
}
|
||||
}
|
||||
|
||||
private CacheKeyImplementation createCacheKeyImplementation(
|
||||
|
|
|
@ -42,14 +42,13 @@ public class DelayedMixedAccessTest implements BeanContainer.LifecycleOptions {
|
|||
|
||||
@Test
|
||||
public void testDelayedMixedAccess() {
|
||||
try ( final SeContainer cdiContainer = Helper.createSeContainer() ) {
|
||||
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
||||
|
||||
try ( final SeContainer cdiContainer = Helper.createSeContainer();
|
||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() )
|
||||
.applySetting( AvailableSettings.DELAY_CDI_ACCESS, "true" )
|
||||
.build();
|
||||
.build() ) {
|
||||
|
||||
final BeanContainer beanContainer = CdiBeanContainerBuilder.fromBeanManagerReference(
|
||||
cdiContainer.getBeanManager(),
|
||||
|
|
|
@ -46,42 +46,45 @@ public class ExtendedMixedAccessTest implements BeanContainer.LifecycleOptions {
|
|||
}
|
||||
|
||||
private void doTest(TestingExtendedBeanManager extendedBeanManager) {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, extendedBeanManager )
|
||||
.build();
|
||||
.build()) {
|
||||
final BeanContainer beanContainer = ssr.getService( ManagedBeanRegistry.class ).getBeanContainer();
|
||||
|
||||
final BeanContainer beanContainer = ssr.getService( ManagedBeanRegistry.class ).getBeanContainer();
|
||||
assertThat( beanContainer, instanceOf( CdiBeanContainerExtendedAccessImpl.class ) );
|
||||
|
||||
assertThat( beanContainer, instanceOf( CdiBeanContainerExtendedAccessImpl.class ) );
|
||||
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
|
||||
final BeanManager beanManager = cdiContainer.getBeanManager();
|
||||
extendedBeanManager.notifyListenerReady( beanManager );
|
||||
|
||||
try ( final SeContainer cdiContainer = Helper.createSeContainer() ) {
|
||||
final BeanManager beanManager = cdiContainer.getBeanManager();
|
||||
extendedBeanManager.notifyListenerReady( beanManager );
|
||||
assertThat(
|
||||
beanManager,
|
||||
sameInstance( ( (CdiBeanContainerExtendedAccessImpl) beanContainer ).getUsableBeanManager() )
|
||||
);
|
||||
|
||||
assertThat( beanManager, sameInstance( ( (CdiBeanContainerExtendedAccessImpl) beanContainer ).getUsableBeanManager() ) );
|
||||
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(
|
||||
HostedBean.class,
|
||||
this,
|
||||
FallbackBeanInstanceProducer.INSTANCE
|
||||
);
|
||||
|
||||
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(
|
||||
HostedBean.class,
|
||||
this,
|
||||
FallbackBeanInstanceProducer.INSTANCE
|
||||
);
|
||||
assertThat( hostedBean, notNullValue() );
|
||||
assertThat( hostedBean.getBeanInstance(), notNullValue() );
|
||||
|
||||
assertThat( hostedBean, notNullValue() );
|
||||
assertThat( hostedBean.getBeanInstance(), notNullValue() );
|
||||
assertThat( hostedBean.getBeanInstance().getInjectedHostedBean(), notNullValue() );
|
||||
|
||||
assertThat( hostedBean.getBeanInstance().getInjectedHostedBean(), notNullValue() );
|
||||
final ContainedBean<NonHostedBean> nonHostedBean = beanContainer.getBean(
|
||||
NonHostedBean.class,
|
||||
this,
|
||||
FallbackBeanInstanceProducer.INSTANCE
|
||||
);
|
||||
|
||||
final ContainedBean<NonHostedBean> nonHostedBean = beanContainer.getBean(
|
||||
NonHostedBean.class,
|
||||
this,
|
||||
FallbackBeanInstanceProducer.INSTANCE
|
||||
);
|
||||
assertThat( nonHostedBean, notNullValue() );
|
||||
assertThat( nonHostedBean.getBeanInstance(), notNullValue() );
|
||||
|
||||
assertThat( nonHostedBean, notNullValue() );
|
||||
assertThat( nonHostedBean.getBeanInstance(), notNullValue() );
|
||||
|
||||
extendedBeanManager.notifyListenerShuttingDown( beanManager );
|
||||
extendedBeanManager.notifyListenerShuttingDown( beanManager );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ public class ImmediateMixedAccessTests implements BeanContainer.LifecycleOptions
|
|||
|
||||
@Test
|
||||
public void testImmediateMixedAccess() {
|
||||
try ( final SeContainer cdiContainer = Helper.createSeContainer() ) {
|
||||
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
||||
try ( final SeContainer cdiContainer = Helper.createSeContainer();
|
||||
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build() ) {
|
||||
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||
|
|
|
@ -13,6 +13,7 @@ import javax.persistence.Id;
|
|||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AnnotationBinder;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
@ -38,15 +39,19 @@ public class AnnotationBinderTest {
|
|||
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000137" );
|
||||
|
||||
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
|
||||
Metadata metadata = new MetadataSources( srb.build() )
|
||||
.addAnnotatedClass( InvalidPrimaryKeyJoinColumnAnnotationEntity.class )
|
||||
.buildMetadata();
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( InvalidPrimaryKeyJoinColumnAnnotationEntity.class )
|
||||
.buildMetadata();
|
||||
|
||||
assertTrue( "Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered() );
|
||||
assertTrue( "Expected invalid class name in warning HHH00137 message but it does not apper to be present; got " + triggerable.triggerMessage(),
|
||||
triggerable.triggerMessage().matches( ".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*" ) );
|
||||
assertTrue( "Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered() );
|
||||
assertTrue(
|
||||
"Expected invalid class name in warning HHH00137 message but it does not apper to be present; got " + triggerable.triggerMessage(),
|
||||
triggerable.triggerMessage()
|
||||
.matches( ".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*" )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -31,16 +31,17 @@ public class MultipleBagFetchTest {
|
|||
|
||||
@Test
|
||||
public void testEntityWithMultipleJoinFetchedBags() {
|
||||
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
|
||||
try (StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
|
||||
Metadata metadata = new MetadataSources( standardRegistry )
|
||||
.addAnnotatedClass( Post.class )
|
||||
.addAnnotatedClass( PostComment.class )
|
||||
.addAnnotatedClass( Tag.class )
|
||||
.getMetadataBuilder()
|
||||
.build();
|
||||
// make sure that this model does not cause a MultipleBagFetchException
|
||||
metadata.buildSessionFactory();
|
||||
Metadata metadata = new MetadataSources( standardRegistry )
|
||||
.addAnnotatedClass( Post.class )
|
||||
.addAnnotatedClass( PostComment.class )
|
||||
.addAnnotatedClass( Tag.class )
|
||||
.getMetadataBuilder()
|
||||
.build();
|
||||
// make sure that this model does not cause a MultipleBagFetchException
|
||||
metadata.buildSessionFactory().close();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "Post")
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
|||
import org.hibernate.orm.test.dialect.TestingDialects;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -51,6 +52,13 @@ public class DialectFactoryTest extends BaseUnitTestCase {
|
|||
dialectFactory.injectServices( (ServiceRegistryImplementor) registry );
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
if ( registry != null ) {
|
||||
registry.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitShortNameUse() {
|
||||
final Map<String, String> configValues = new HashMap<String, String>();
|
||||
|
|
|
@ -19,6 +19,7 @@ import javax.persistence.ManyToOne;
|
|||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -35,16 +36,18 @@ public class HHH14230 {
|
|||
|
||||
@Test
|
||||
public void test() {
|
||||
Metadata metadata = new MetadataSources(new StandardServiceRegistryBuilder().build())
|
||||
.addAnnotatedClass(TestEntity.class).buildMetadata();
|
||||
Table table = StreamSupport.stream(metadata.getDatabase().getNamespaces().spliterator(), false)
|
||||
.flatMap(namespace -> namespace.getTables().stream())
|
||||
.filter(t -> t.getName().equals(TABLE_NAME)).findFirst().orElse(null);
|
||||
assertNotNull(table);
|
||||
assertEquals(1, table.getForeignKeys().size());
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( TestEntity.class ).buildMetadata();
|
||||
Table table = StreamSupport.stream( metadata.getDatabase().getNamespaces().spliterator(), false )
|
||||
.flatMap( namespace -> namespace.getTables().stream() )
|
||||
.filter( t -> t.getName().equals( TABLE_NAME ) ).findFirst().orElse( null );
|
||||
assertNotNull( table );
|
||||
assertEquals( 1, table.getForeignKeys().size() );
|
||||
|
||||
// ClassCastException before HHH-14230
|
||||
assertTrue(table.getForeignKeys().keySet().iterator().next().toString().contains(JOIN_COLUMN_NAME));
|
||||
// ClassCastException before HHH-14230
|
||||
assertTrue( table.getForeignKeys().keySet().iterator().next().toString().contains( JOIN_COLUMN_NAME ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -46,10 +46,11 @@ public class DefaultConstraintModeTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
private void testForeignKeyCreation(boolean created) {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting(Environment.HBM2DDL_DEFAULT_CONSTRAINT_MODE, created ? "CONSTRAINT" : "NO_CONSTRAINT").build();
|
||||
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
|
||||
assertThat(findTable(metadata, TABLE_NAME).getForeignKeys().isEmpty(), is(!created));
|
||||
try (StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting(Environment.HBM2DDL_DEFAULT_CONSTRAINT_MODE, created ? "CONSTRAINT" : "NO_CONSTRAINT").build()) {
|
||||
Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata();
|
||||
assertThat( findTable( metadata, TABLE_NAME ).getForeignKeys().isEmpty(), is( !created ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static Table findTable(Metadata metadata, String tableName) {
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.hibernate.annotations.OnDelete;
|
|||
import org.hibernate.annotations.OnDeleteAction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -44,11 +45,13 @@ public class OneToManyBidirectionalForeignKeyTest {
|
|||
|
||||
@Test
|
||||
public void testForeignKeyShouldNotBeCreated() {
|
||||
Metadata metadata = new MetadataSources(new StandardServiceRegistryBuilder().build())
|
||||
.addAnnotatedClass(PlainTreeEntity.class).addAnnotatedClass(TreeEntityWithOnDelete.class)
|
||||
.buildMetadata();
|
||||
assertTrue(findTable(metadata, TABLE_NAME_PLAIN).getForeignKeys().isEmpty());
|
||||
assertFalse(findTable(metadata, TABLE_NAME_WITH_ON_DELETE).getForeignKeys().isEmpty());
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( PlainTreeEntity.class ).addAnnotatedClass( TreeEntityWithOnDelete.class )
|
||||
.buildMetadata();
|
||||
assertTrue( findTable( metadata, TABLE_NAME_PLAIN ).getForeignKeys().isEmpty() );
|
||||
assertFalse( findTable( metadata, TABLE_NAME_WITH_ON_DELETE ).getForeignKeys().isEmpty() );
|
||||
}
|
||||
}
|
||||
|
||||
private static Table findTable(Metadata metadata, String tableName) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.StringReader;
|
|||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.engine.jdbc.ReaderInputStream;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
@ -28,14 +29,16 @@ public class ClassCommentTest {
|
|||
public void testClassComment() {
|
||||
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder()
|
||||
.applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
|
||||
MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build());
|
||||
metadataSources.addInputStream(new ReaderInputStream(new StringReader(CLASS_COMMENT_HBM_XML)));
|
||||
Metadata metadata = metadataSources.buildMetadata();
|
||||
PersistentClass pc = metadata.getEntityBinding("org.hibernate.test.hbm.Foo");
|
||||
Assert.assertNotNull(pc);
|
||||
Table table = pc.getTable();
|
||||
Assert.assertNotNull(table);
|
||||
Assert.assertEquals("This is class 'Foo' with property 'bar'.", table.getComment());
|
||||
try (StandardServiceRegistry serviceRegistry = serviceRegistryBuilder.build()) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
metadataSources.addInputStream( new ReaderInputStream( new StringReader( CLASS_COMMENT_HBM_XML ) ) );
|
||||
Metadata metadata = metadataSources.buildMetadata();
|
||||
PersistentClass pc = metadata.getEntityBinding( "org.hibernate.test.hbm.Foo" );
|
||||
Assert.assertNotNull( pc );
|
||||
Table table = pc.getTable();
|
||||
Assert.assertNotNull( table );
|
||||
Assert.assertEquals( "This is class 'Foo' with property 'bar'.", table.getComment() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,11 +55,9 @@ public class SequenceStyleConfigUnitTest {
|
|||
*/
|
||||
@Test
|
||||
public void testDefaultedSequenceBackedConfiguration() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
||||
|
@ -77,9 +75,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
private Properties buildGeneratorPropertiesBase(StandardServiceRegistry serviceRegistry) {
|
||||
|
@ -100,11 +95,9 @@ public class SequenceStyleConfigUnitTest {
|
|||
*/
|
||||
@Test
|
||||
public void testDefaultedTableBackedConfiguration() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
||||
|
@ -122,9 +115,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,11 +125,9 @@ public class SequenceStyleConfigUnitTest {
|
|||
@Test
|
||||
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
|
||||
// for dialects which do not support pooled sequences, we default to pooled+table
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||
|
||||
|
@ -154,16 +142,11 @@ public class SequenceStyleConfigUnitTest {
|
|||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
|
||||
// for dialects which do support pooled sequences, we default to pooled+sequence
|
||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||
|
||||
|
@ -177,9 +160,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,11 +169,9 @@ public class SequenceStyleConfigUnitTest {
|
|||
*/
|
||||
@Test
|
||||
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||
|
||||
|
@ -207,9 +185,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,11 +192,9 @@ public class SequenceStyleConfigUnitTest {
|
|||
*/
|
||||
@Test
|
||||
public void testForceTableUse() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
|
||||
|
||||
|
@ -240,9 +213,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,12 +220,10 @@ public class SequenceStyleConfigUnitTest {
|
|||
*/
|
||||
@Test
|
||||
public void testExplicitOptimizerWithExplicitIncrementSize() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
// optimizer=none w/ increment > 1 => should honor optimizer
|
||||
try {
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.NONE.getExternalName() );
|
||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
||||
|
@ -300,18 +268,13 @@ public class SequenceStyleConfigUnitTest {
|
|||
assertEquals( 20, generator.getOptimizer().getIncrementSize() );
|
||||
assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferredPooledOptimizerSetting() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
.build()) {
|
||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||
|
@ -340,9 +303,6 @@ public class SequenceStyleConfigUnitTest {
|
|||
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( PooledLoThreadLocalOptimizer.class, generator.getOptimizer().getClass() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
public static class TableDialect extends Dialect {
|
||||
|
|
|
@ -55,148 +55,143 @@ import static org.junit.Assert.assertThat;
|
|||
public class AutoGenerationTypeTests {
|
||||
@Test
|
||||
public void testAutoDefaults() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
final DatabaseStructure database1Structure = entityIdGenerator.getDatabaseStructure();
|
||||
|
||||
final DatabaseStructure database1Structure = entityIdGenerator.getDatabaseStructure();
|
||||
|
||||
// implicit name : `${entity-name}_seq`
|
||||
assertThat( database1Structure.getName(), equalToIgnoringCase( "tbl_1_SEQ" ) );
|
||||
assertThat( database1Structure.getIncrementSize(), is( 50 ) );
|
||||
// implicit name : `${entity-name}_seq`
|
||||
assertThat( database1Structure.getName(), equalToIgnoringCase( "tbl_1_SEQ" ) );
|
||||
assertThat( database1Structure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAutoGeneratedValueGenerator() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
final DatabaseStructure database2Structure = idGenerator.getDatabaseStructure();
|
||||
|
||||
final DatabaseStructure database2Structure = idGenerator.getDatabaseStructure();
|
||||
|
||||
// GeneratedValue#generator value
|
||||
assertThat( database2Structure.getName(), equalToIgnoringCase( "id_seq" ) );
|
||||
assertThat( database2Structure.getIncrementSize(), is( 50 ) );
|
||||
// GeneratedValue#generator value
|
||||
assertThat( database2Structure.getName(), equalToIgnoringCase( "id_seq" ) );
|
||||
assertThat( database2Structure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionId() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
|
||||
final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Entity1#theTwos collection-id - implicit `${collection_table}_seq`
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Entity1#theTwos collection-id - implicit `${collection_table}_seq`
|
||||
final Property theTwos = entity1Binding.getProperty( "theTwos" );
|
||||
final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue();
|
||||
final KeyValue collectionIdMapping = idBagMapping.getIdentifier();
|
||||
final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
null
|
||||
);
|
||||
|
||||
final Property theTwos = entity1Binding.getProperty( "theTwos" );
|
||||
final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue();
|
||||
final KeyValue collectionIdMapping = idBagMapping.getIdentifier();
|
||||
final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
null
|
||||
);
|
||||
final DatabaseStructure idBagIdGeneratorDbStructure = collectionIdGenerator.getDatabaseStructure();
|
||||
|
||||
final DatabaseStructure idBagIdGeneratorDbStructure = collectionIdGenerator.getDatabaseStructure();
|
||||
|
||||
assertThat( idBagIdGeneratorDbStructure.getName(), equalToIgnoringCase( "tbl_2_seq" ) );
|
||||
assertThat( idBagIdGeneratorDbStructure.getIncrementSize(), is( 50 ) );
|
||||
assertThat( idBagIdGeneratorDbStructure.getName(), equalToIgnoringCase( "tbl_2_seq" ) );
|
||||
assertThat( idBagIdGeneratorDbStructure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUuid() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity4.class )
|
||||
.buildMetadata();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity4.class )
|
||||
.buildMetadata();
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
assertThat( idGenerator, instanceOf( UUIDGenerator.class ) );
|
||||
assertThat( idGenerator, instanceOf( UUIDGenerator.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity3.class )
|
||||
.buildMetadata();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity3.class )
|
||||
.buildMetadata();
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
assertThat( idGenerator, instanceOf( IncrementGenerator.class ) );
|
||||
assertThat( idGenerator, instanceOf( IncrementGenerator.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity( name = "Entity1" )
|
||||
|
|
|
@ -67,38 +67,45 @@ public class UserDefinedGeneratorsTests {
|
|||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
ssrb.applySetting( AvailableSettings.BEAN_CONTAINER, beanContainer );
|
||||
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
try (final StandardServiceRegistry ssr = ssrb.build()) {
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final IdentifierGenerator generator1 = entityBinding1.getRootClass().getIdentifier().createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding1.getRootClass()
|
||||
);
|
||||
final IdentifierGenerator generator2 = entityBinding2.getRootClass().getIdentifier().createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding2.getRootClass()
|
||||
);
|
||||
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final IdentifierGenerator generator1 = entityBinding1.getRootClass()
|
||||
.getIdentifier()
|
||||
.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding1.getRootClass()
|
||||
);
|
||||
final IdentifierGenerator generator2 = entityBinding2.getRootClass()
|
||||
.getIdentifier()
|
||||
.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding2.getRootClass()
|
||||
);
|
||||
|
||||
then( beanContainer ).should( times( 2 ) ).getBean( same( TestIdentifierGenerator.class ), any( LifecycleOptions.class ),
|
||||
same( FallbackBeanInstanceProducer.INSTANCE ) );
|
||||
then( beanContainer ).should( times( 2 ) ).getBean( same( TestIdentifierGenerator.class ),
|
||||
any( LifecycleOptions.class ),
|
||||
same( FallbackBeanInstanceProducer.INSTANCE )
|
||||
);
|
||||
|
||||
assertThat( generator1, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||
assertThat( generator2, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||
assertThat( generator1 == generator2, is( false ) ); // should not be same instance
|
||||
assertThat( generator1, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||
assertThat( generator2, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||
assertThat( generator1 == generator2, is( false ) ); // should not be same instance
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,6 @@ public class NoCdiAvailableTestDelegate {
|
|||
new HibernatePersistenceProvider().createContainerEntityManagerFactory(
|
||||
new PersistenceUnitInfoAdapter(),
|
||||
Collections.singletonMap( AvailableSettings.CDI_BEAN_MANAGER, new Object() )
|
||||
);
|
||||
).close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,229 +49,251 @@ import static org.junit.Assert.assertTrue;
|
|||
public class GeneratedValueTests extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void baseline() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator );
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||
SequenceStyleGenerator.class,
|
||||
generator
|
||||
);
|
||||
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_real_db_sequence" ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_real_db_sequence" ) );
|
||||
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitSequenceGenerator() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false" )
|
||||
.build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
.build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator );
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||
SequenceStyleGenerator.class,
|
||||
generator
|
||||
);
|
||||
|
||||
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
|
||||
// default (hibernate_sequence) should be used
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
|
||||
// default (hibernate_sequence) should be used
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
|
||||
// the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||
// the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitSequenceGeneratorGeneratorName() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator );
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||
SequenceStyleGenerator.class,
|
||||
generator
|
||||
);
|
||||
|
||||
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name
|
||||
// should be used as the default instead.
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name
|
||||
// should be used as the default instead.
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
|
||||
// the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||
// the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitSequenceGeneratorImplicitNamePreferGeneratorName() {
|
||||
// this should be the default behavior
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitSequenceGeneratorImplicitNameEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitSequenceGeneratorImplicitNameEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding(
|
||||
ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator );
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||
SequenceStyleGenerator.class,
|
||||
generator
|
||||
);
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||
|
||||
final Sequence sequence = bootModel.getDatabase()
|
||||
.getDefaultNamespace()
|
||||
.locateSequence( Identifier.toIdentifier( "my_db_sequence" ) );
|
||||
assertThat( sequence, notNullValue() );
|
||||
assertThat( sequence.getName().getSequenceName().getText(), is( "my_db_sequence" ) );
|
||||
assertThat( sequence.getInitialValue(), is( 100 ) );
|
||||
assertThat( sequence.getIncrementSize(), is( 500 ) );
|
||||
final Sequence sequence = bootModel.getDatabase()
|
||||
.getDefaultNamespace()
|
||||
.locateSequence( Identifier.toIdentifier( "my_db_sequence" ) );
|
||||
assertThat( sequence, notNullValue() );
|
||||
assertThat( sequence.getName().getSequenceName().getText(), is( "my_db_sequence" ) );
|
||||
assertThat( sequence.getInitialValue(), is( 100 ) );
|
||||
assertThat( sequence.getIncrementSize(), is( 500 ) );
|
||||
|
||||
final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings(
|
||||
sequence,
|
||||
bootModel
|
||||
);
|
||||
assertThat( sqlCreateStrings.length, is(1) );
|
||||
final String cmd = sqlCreateStrings[0].toLowerCase();
|
||||
assertTrue( cmd.startsWith( "create sequence my_db_sequence start with 100 increment by 500" ) );
|
||||
final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings(
|
||||
sequence,
|
||||
bootModel
|
||||
);
|
||||
assertThat( sqlCreateStrings.length, is( 1 ) );
|
||||
final String cmd = sqlCreateStrings[0].toLowerCase();
|
||||
assertTrue( cmd.startsWith( "create sequence my_db_sequence start with 100 increment by 500" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitTableGenerator() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitTableGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitTableGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
|
||||
assertThat( tableGenerator.getTableName(), is( "my_id_table" ) );
|
||||
assertThat( tableGenerator.getTableName(), is( "my_id_table" ) );
|
||||
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 50 ) );
|
||||
// all the JPA defaults since they were not defined
|
||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitTableGeneratorImplicitName() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitTableGeneratorImplicitNameEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitTableGeneratorImplicitNameEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
|
||||
assertThat( tableGenerator.getTableName(), is( "my_id_table" ) );
|
||||
assertThat( tableGenerator.getTableName(), is( "my_id_table" ) );
|
||||
|
||||
// - note : currently initialValue=1 in mapping is shows up here as 2
|
||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||
// - note : currently initialValue=1 in mapping is shows up here as 2
|
||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitTableGenerator() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitTableGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitTableGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
final TableGenerator tableGenerator = assertTyping( TableGenerator.class, generator );
|
||||
|
||||
assertThat( tableGenerator.getTableName(), is( "my_real_id_table" ) );
|
||||
assertThat( tableGenerator.getTableName(), is( "my_real_id_table" ) );
|
||||
|
||||
// all the JPA defaults since they were not defined
|
||||
// - note : currently initialValue=1 in mapping is shows up here
|
||||
// as 2
|
||||
// all the JPA defaults since they were not defined
|
||||
// - note : currently initialValue=1 in mapping is shows up here
|
||||
// as 2
|
||||
// assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitIncrementGenerator() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
assertTyping( IncrementGenerator.class, generator );
|
||||
assertTyping( IncrementGenerator.class, generator );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplicitIncrementGenerator() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitIncrementGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||
final Metadata bootModel = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( ImplicitIncrementGeneratorEntity.class )
|
||||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
|
||||
assertTyping( IncrementGenerator.class, generator );
|
||||
assertTyping( IncrementGenerator.class, generator );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -19,6 +19,7 @@ import javax.persistence.Version;
|
|||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -140,15 +141,20 @@ public class CachingWithSecondaryTablesTests extends BaseUnitTestCase {
|
|||
settings.put( AvailableSettings.JPA_CACHING_COMPLIANCE, "true" );
|
||||
}
|
||||
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
|
||||
.applySettings( settings );
|
||||
|
||||
return (SessionFactoryImplementor) new MetadataSources( ssrb.build() )
|
||||
.addAnnotatedClass( Person.class )
|
||||
.addAnnotatedClass( VersionedPerson.class)
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
|
||||
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings( settings )
|
||||
.build();
|
||||
try {
|
||||
return (SessionFactoryImplementor) new MetadataSources( serviceRegistry )
|
||||
.addAnnotatedClass( Person.class )
|
||||
.addAnnotatedClass( VersionedPerson.class )
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
serviceRegistry.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -33,22 +33,25 @@ public class ConfigurationObjectSettingTest {
|
|||
public void testContainerBootstrapSharedCacheMode() {
|
||||
// first, via the integration vars
|
||||
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
||||
EntityManagerFactoryBuilderImpl builder = null;
|
||||
{
|
||||
// as object
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
empty,
|
||||
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
||||
);
|
||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
{
|
||||
// as string
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
empty,
|
||||
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name() )
|
||||
);
|
||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
|
||||
// next, via the PUI
|
||||
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
||||
|
@ -58,43 +61,48 @@ public class ConfigurationObjectSettingTest {
|
|||
}
|
||||
};
|
||||
{
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
adapter,
|
||||
null
|
||||
);
|
||||
assertEquals( SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
|
||||
// via both, integration vars should take precedence
|
||||
{
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
adapter,
|
||||
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
||||
);
|
||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainerBootstrapValidationMode() {
|
||||
// first, via the integration vars
|
||||
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
||||
EntityManagerFactoryBuilderImpl builder = null;
|
||||
{
|
||||
// as object
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
empty,
|
||||
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK )
|
||||
);
|
||||
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
{
|
||||
// as string
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
empty,
|
||||
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name() )
|
||||
);
|
||||
assertEquals( ValidationMode.CALLBACK.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
|
||||
// next, via the PUI
|
||||
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
||||
|
@ -104,21 +112,23 @@ public class ConfigurationObjectSettingTest {
|
|||
}
|
||||
};
|
||||
{
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
adapter,
|
||||
null
|
||||
);
|
||||
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
|
||||
// via both, integration vars should take precedence
|
||||
{
|
||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||
adapter,
|
||||
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.NONE )
|
||||
);
|
||||
assertEquals( ValidationMode.NONE, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||
}
|
||||
builder.cancel();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,7 +139,7 @@ public class ConfigurationObjectSettingTest {
|
|||
Bootstrap.getEntityManagerFactoryBuilder(
|
||||
adapter,
|
||||
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_FACTORY, token )
|
||||
);
|
||||
).cancel();
|
||||
fail( "Was expecting error as token did not implement ValidatorFactory" );
|
||||
}
|
||||
catch ( HibernateException e ) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
|||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -63,6 +64,13 @@ public class SchemaCreateDropUtf8WithoutHbm2DdlCharsetNameTest {
|
|||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
if ( entityManagerFactoryBuilder != null ) {
|
||||
entityManagerFactoryBuilder.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10972")
|
||||
public void testEncoding() throws Exception {
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.tool.schema.spi.SchemaManagementException;
|
|||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryBasedFunctionalTest;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -60,6 +61,13 @@ public class SchemaDatabaseFileGenerationFailureTest {
|
|||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
if ( entityManagerFactoryBuilder != null ) {
|
||||
entityManagerFactoryBuilder.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12192")
|
||||
public void testErrorMessageContainsTheFailingDDLCommand() {
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.hibernate.tool.schema.spi.SchemaManagementException;
|
|||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryBasedFunctionalTest;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -52,6 +53,13 @@ public class SchemaScriptFileGenerationFailureTest {
|
|||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
if ( entityManagerFactoryBuilder != null ) {
|
||||
entityManagerFactoryBuilder.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12192")
|
||||
public void testErrorMessageContainsTheFailingDDLCommand() {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
|||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryBasedFunctionalTest;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -52,6 +53,13 @@ public class SchemaScriptFileGenerationTest {
|
|||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
if ( entityManagerFactoryBuilder != null ) {
|
||||
entityManagerFactoryBuilder.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "10601")
|
||||
public void testGenerateSchemaDoesNotProduceTheSameStatementTwice() throws Exception {
|
||||
|
|
|
@ -109,25 +109,27 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
public void testBasicOperation() {
|
||||
final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl() );
|
||||
basicValue.setJpaAttributeConverterDescriptor(
|
||||
new InstanceBasedConverterDescriptor(
|
||||
new StringClobConverter(),
|
||||
new ClassmateContext()
|
||||
)
|
||||
);
|
||||
basicValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" );
|
||||
try ( StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl( serviceRegistry ) );
|
||||
basicValue.setJpaAttributeConverterDescriptor(
|
||||
new InstanceBasedConverterDescriptor(
|
||||
new StringClobConverter(),
|
||||
new ClassmateContext()
|
||||
)
|
||||
);
|
||||
basicValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" );
|
||||
|
||||
final Type type = basicValue.getType();
|
||||
assertNotNull( type );
|
||||
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||
final Type type = basicValue.getType();
|
||||
assertNotNull( type );
|
||||
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||
|
||||
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||
|
||||
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
|
||||
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
|
||||
|
||||
final JdbcTypeDescriptor jdbcTypeDescriptor = typeAdapter.getJdbcTypeDescriptor();
|
||||
assertThat( jdbcTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
|
||||
final JdbcTypeDescriptor jdbcTypeDescriptor = typeAdapter.getJdbcTypeDescriptor();
|
||||
assertThat( jdbcTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -253,9 +255,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
session.save( new Tester4( 1L, "steve", 200 ) );
|
||||
|
@ -285,9 +285,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -328,9 +325,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
session.save( new IrrelevantInstantEntity( 1L ) );
|
||||
|
@ -351,9 +346,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -365,9 +357,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
session.save( new Tester4( 1L, "George", 150, ConvertibleEnum.DEFAULT ) );
|
||||
|
@ -397,9 +387,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -47,13 +47,18 @@ public class AttributeConverterOnSuperclassTest extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
public void testAttributeConverterOnSuperclass() {
|
||||
final BootstrapContextImpl bootstrapContext = BootstrapContextImpl.INSTANCE;
|
||||
final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor(
|
||||
StringIntegerConverterSubclass.class,
|
||||
bootstrapContext.getClassmateContext()
|
||||
);
|
||||
final BootstrapContextImpl bootstrapContext = new BootstrapContextImpl();
|
||||
try {
|
||||
final ClassBasedConverterDescriptor converterDescriptor = new ClassBasedConverterDescriptor(
|
||||
StringIntegerConverterSubclass.class,
|
||||
bootstrapContext.getClassmateContext()
|
||||
);
|
||||
|
||||
assertEquals( String.class, converterDescriptor.getDomainValueResolvedType().getErasedType() );
|
||||
assertEquals( String.class, converterDescriptor.getDomainValueResolvedType().getErasedType() );
|
||||
}
|
||||
finally {
|
||||
bootstrapContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
public interface StringLongAttributeConverter extends AttributeConverter<String, Long> {
|
||||
|
|
|
@ -75,8 +75,7 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
|||
.applySettings( cfg.getProperties() )
|
||||
.build();
|
||||
|
||||
SessionFactory sf = cfg.buildSessionFactory( ssr );
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory();) {
|
||||
Session session = sf.openSession();
|
||||
try {
|
||||
session.getTransaction().begin();
|
||||
|
@ -93,9 +92,6 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
|||
session.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
|
@ -112,8 +108,7 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
|||
cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml() )
|
||||
.applySettings( cfg.getProperties() )
|
||||
.build();
|
||||
SessionFactory sf = cfg.buildSessionFactory( ssr );
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory( ssr )) {
|
||||
Session session = sf.openSession();
|
||||
try {
|
||||
session.getTransaction().begin();
|
||||
|
@ -130,9 +125,6 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
|||
session.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
|
|
|
@ -31,13 +31,13 @@ public class InheritanceSchemaUpdateTest extends BaseUnitTestCase {
|
|||
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
|
||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Step.class )
|
||||
.addAnnotatedClass( GroupStep.class )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
try {
|
||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Step.class )
|
||||
.addAnnotatedClass( GroupStep.class )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
try {
|
||||
new SchemaUpdate().execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||
}
|
||||
|
|
|
@ -36,27 +36,27 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
|||
Configuration cfg = new Configuration()
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME )
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); // default is true
|
||||
SessionFactory factory = cfg.buildSessionFactory();
|
||||
try (SessionFactory factory = cfg.buildSessionFactory()) {
|
||||
|
||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||
// different VM
|
||||
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||
// deregister under this uuid...
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
||||
// and then register under a different uuid...
|
||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||
"some-other-uuid",
|
||||
NAME,
|
||||
false,
|
||||
(SessionFactoryImplementor) factory,
|
||||
null
|
||||
);
|
||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||
// different VM
|
||||
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||
// deregister under this uuid...
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
||||
// and then register under a different uuid...
|
||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||
"some-other-uuid",
|
||||
NAME,
|
||||
false,
|
||||
(SessionFactoryImplementor) factory,
|
||||
null
|
||||
);
|
||||
|
||||
SessionFactory factory2 = (SessionFactory) SerializationHelper.clone( factory );
|
||||
assertSame( factory, factory2 );
|
||||
SessionFactory factory2 = (SessionFactory) SerializationHelper.clone( factory );
|
||||
assertSame( factory, factory2 );
|
||||
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", NAME, false, null );
|
||||
factory.close();
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", NAME, false, null );
|
||||
}
|
||||
|
||||
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
||||
}
|
||||
|
@ -67,31 +67,31 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
|||
// here, the test should fail based just on attempted uuid resolution
|
||||
Configuration cfg = new Configuration()
|
||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); // default is true
|
||||
SessionFactory factory = cfg.buildSessionFactory();
|
||||
try (SessionFactory factory = cfg.buildSessionFactory()) {
|
||||
|
||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||
// different VM
|
||||
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||
// deregister under this uuid...
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
||||
// and then register under a different uuid...
|
||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||
"some-other-uuid",
|
||||
null,
|
||||
false,
|
||||
(SessionFactoryImplementor) factory,
|
||||
null
|
||||
);
|
||||
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||
// different VM
|
||||
String uuid = ( (SessionFactoryImplementor) factory ).getUuid();
|
||||
// deregister under this uuid...
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
||||
// and then register under a different uuid...
|
||||
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||
"some-other-uuid",
|
||||
null,
|
||||
false,
|
||||
(SessionFactoryImplementor) factory,
|
||||
null
|
||||
);
|
||||
|
||||
try {
|
||||
SerializationHelper.clone( factory );
|
||||
fail( "Expecting an error" );
|
||||
try {
|
||||
SerializationHelper.clone( factory );
|
||||
fail( "Expecting an error" );
|
||||
}
|
||||
catch (SerializationException expected) {
|
||||
}
|
||||
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", null, false, null );
|
||||
}
|
||||
catch ( SerializationException expected ) {
|
||||
}
|
||||
|
||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", null, false, null );
|
||||
factory.close();
|
||||
|
||||
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import org.hibernate.service.spi.ServiceRegistryAwareService;
|
|||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.Startable;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -28,9 +30,18 @@ import static org.junit.Assert.assertThat;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServiceRegistryTest {
|
||||
private final ServiceRegistry registry = buildRegistry();
|
||||
private ServiceRegistry registry;
|
||||
private final static int NUMBER_OF_THREADS = 100;
|
||||
private StandardServiceRegistryBuilder standardServiceRegistryBuilder;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
registry = buildRegistry();
|
||||
}
|
||||
|
||||
@After
|
||||
public void destroy() {
|
||||
registry.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10427")
|
||||
|
@ -49,9 +60,6 @@ public class ServiceRegistryTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
standardServiceRegistryBuilder.destroy( registry );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,8 +93,7 @@ public class ServiceRegistryTest {
|
|||
}
|
||||
|
||||
private ServiceRegistry buildRegistry() {
|
||||
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
|
||||
return standardServiceRegistryBuilder.addInitiator( new SlowServiceInitiator() )
|
||||
return new StandardServiceRegistryBuilder().addInitiator( new SlowServiceInitiator() )
|
||||
.addInitiator( new NullServiceInitiator() )
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ public class ServiceRegistryClosingCascadeTest extends BaseUnitTestCase {
|
|||
StandardServiceRegistry sr = new StandardServiceRegistryBuilder(bsr).build();
|
||||
assertTrue( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
||||
Configuration config = new Configuration();
|
||||
SessionFactory sf = config.buildSessionFactory( sr );
|
||||
try (SessionFactory sf = config.buildSessionFactory( sr )) {
|
||||
|
||||
sf.close();
|
||||
}
|
||||
assertFalse( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public class SubclassProxyInterfaceTest {
|
|||
final Configuration cfg = new Configuration()
|
||||
.setProperty( Environment.DIALECT, H2Dialect.class.getName() )
|
||||
.addClass( Person.class );
|
||||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
||||
cfg.buildSessionFactory( serviceRegistry ).close();
|
||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
try (ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() )) {
|
||||
cfg.buildSessionFactory( serviceRegistry ).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,11 +53,16 @@ public class DropSchemaDuringJtaTxnTest extends BaseUnitTestCase {
|
|||
settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
|
||||
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings( settings ).build();
|
||||
|
||||
return new MetadataSources( ssr )
|
||||
.addAnnotatedClass( TestEntity.class )
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
try {
|
||||
return new MetadataSources( ssr )
|
||||
.addAnnotatedClass( TestEntity.class )
|
||||
.buildMetadata()
|
||||
.buildSessionFactory();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
ssr.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,11 +37,9 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
|||
*/
|
||||
@Test
|
||||
public void testWithoutIntegrator() {
|
||||
SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||
try (SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
||||
.buildSessionFactory();
|
||||
|
||||
try {
|
||||
.buildSessionFactory()) {
|
||||
Session sess = sf.openSession();
|
||||
try {
|
||||
sess.getTransaction().begin();
|
||||
|
@ -62,20 +60,14 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
|||
}
|
||||
sess.close();
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTypeContributor() {
|
||||
SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||
try (SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||
.registerTypeContributor( new InvestorTypeContributor() )
|
||||
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
||||
.buildSessionFactory();
|
||||
|
||||
Session sess = sf.openSession();
|
||||
try {
|
||||
.buildSessionFactory(); Session sess = sf.openSession()) {
|
||||
sess.getTransaction().begin();
|
||||
Investor myInv = getInvestor();
|
||||
myInv.setId( 2L );
|
||||
|
@ -86,13 +78,6 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
|||
|
||||
Investor inv = (Investor) sess.get( Investor.class, 2L );
|
||||
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
|
||||
}catch (Exception e){
|
||||
sess.getTransaction().rollback();
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
sess.close();
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,21 +64,23 @@ public class ValueVisitorTest extends BaseUnitTestCase {
|
|||
final RootClass rootClass = new RootClass( metadataBuildingContext );
|
||||
|
||||
ValueVisitor vv = new ValueVisitorValidator();
|
||||
MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl();
|
||||
new Any( metadataBuildingContext, tbl ).accept( vv );
|
||||
new Array( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Bag( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Component( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new DependantValue( metadataBuildingContext, tbl, null ).accept( vv );
|
||||
new IdentifierBag( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new List( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new ManyToOne( metadataBuildingContext, tbl ).accept( vv );
|
||||
new Map( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new OneToMany( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new OneToOne( metadataBuildingContext, tbl, rootClass ).accept( vv );
|
||||
new PrimitiveArray( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Set( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new BasicValue( metadataBuildingContext ).accept( vv );
|
||||
try ( StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||
MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl( serviceRegistry );
|
||||
new Any( metadataBuildingContext, tbl ).accept( vv );
|
||||
new Array( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Bag( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Component( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new DependantValue( metadataBuildingContext, tbl, null ).accept( vv );
|
||||
new IdentifierBag( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new List( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new ManyToOne( metadataBuildingContext, tbl ).accept( vv );
|
||||
new Map( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new OneToMany( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new OneToOne( metadataBuildingContext, tbl, rootClass ).accept( vv );
|
||||
new PrimitiveArray( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new Set( metadataBuildingContext, rootClass ).accept( vv );
|
||||
new BasicValue( metadataBuildingContext ).accept( vv );
|
||||
}
|
||||
}
|
||||
|
||||
static public class ValueVisitorValidator implements ValueVisitor {
|
||||
|
|
|
@ -68,48 +68,54 @@ public class DiscriminatorMultiTenancyTest extends BaseUnitTestCase {
|
|||
.applySettings(settings)
|
||||
.build();
|
||||
|
||||
MetadataSources ms = new MetadataSources(serviceRegistry);
|
||||
ms.addAnnotatedClass(Customer.class);
|
||||
try {
|
||||
MetadataSources ms = new MetadataSources( serviceRegistry );
|
||||
ms.addAnnotatedClass( Customer.class );
|
||||
|
||||
Metadata metadata = ms.buildMetadata();
|
||||
final PersistentClass customerMapping = metadata.getEntityBinding( Customer.class.getName() );
|
||||
customerMapping.setCached( true );
|
||||
((RootClass) customerMapping ).setCacheConcurrencyStrategy( "read-write");
|
||||
Metadata metadata = ms.buildMetadata();
|
||||
final PersistentClass customerMapping = metadata.getEntityBinding( Customer.class.getName() );
|
||||
customerMapping.setCached( true );
|
||||
( (RootClass) customerMapping ).setCacheConcurrencyStrategy( "read-write" );
|
||||
|
||||
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
|
||||
tool.injectServices(serviceRegistry);
|
||||
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
|
||||
tool.injectServices( serviceRegistry );
|
||||
|
||||
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
||||
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
||||
|
||||
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(
|
||||
new DdlTransactionIsolatorTestingImpl(
|
||||
serviceRegistry,
|
||||
connectionProvider
|
||||
)
|
||||
);
|
||||
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(
|
||||
new DdlTransactionIsolatorTestingImpl(
|
||||
serviceRegistry,
|
||||
connectionProvider
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
new SchemaDropperImpl(serviceRegistry).doDrop(
|
||||
metadata,
|
||||
serviceRegistry,
|
||||
settings,
|
||||
true,
|
||||
target
|
||||
);
|
||||
new SchemaDropperImpl( serviceRegistry ).doDrop(
|
||||
metadata,
|
||||
serviceRegistry,
|
||||
settings,
|
||||
true,
|
||||
target
|
||||
);
|
||||
|
||||
new SchemaCreatorImpl(serviceRegistry).doCreation(
|
||||
metadata,
|
||||
serviceRegistry,
|
||||
settings,
|
||||
true,
|
||||
target
|
||||
);
|
||||
new SchemaCreatorImpl( serviceRegistry ).doCreation(
|
||||
metadata,
|
||||
serviceRegistry,
|
||||
settings,
|
||||
true,
|
||||
target
|
||||
);
|
||||
|
||||
target.release();
|
||||
target.release();
|
||||
|
||||
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
|
||||
sessionFactory = (SessionFactoryImplementor) sfb.build();
|
||||
currentTenantResolver.setHibernateBooted();
|
||||
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
|
||||
sessionFactory = (SessionFactoryImplementor) sfb.build();
|
||||
currentTenantResolver.setHibernateBooted();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
serviceRegistry.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -127,8 +127,7 @@ public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
|||
.addAnnotatedClass( Employee.class )
|
||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
cfg.addAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
||||
SessionFactory sf = cfg.buildSessionFactory();
|
||||
try {
|
||||
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||
Session session = sf.openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
|
@ -141,8 +140,5 @@ public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
finally {
|
||||
sf.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,91 +145,91 @@ public class StatsTest extends BaseUnitTestCase {
|
|||
|
||||
@Test
|
||||
public void testQueryStatGathering() {
|
||||
SessionFactory sf = buildBaseConfiguration()
|
||||
try (SessionFactory sf = buildBaseConfiguration()
|
||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
||||
.buildSessionFactory();
|
||||
.buildSessionFactory()) {
|
||||
|
||||
Session s = sf.openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
fillDb(s);
|
||||
tx.commit();
|
||||
s.close();
|
||||
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() );
|
||||
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() );
|
||||
// assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
|
||||
Iterator itr = s.createQuery( continents ).list().iterator();
|
||||
// iterate() should increment the execution count
|
||||
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
|
||||
// but should not effect the cumulative row count
|
||||
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
|
||||
Hibernate.close( itr );
|
||||
Iterator itr = s.createQuery( continents ).list().iterator();
|
||||
// iterate() should increment the execution count
|
||||
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
|
||||
// but should not effect the cumulative row count
|
||||
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
|
||||
Hibernate.close( itr );
|
||||
|
||||
ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
|
||||
// same deal with scroll()...
|
||||
assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", results, 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();
|
||||
ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
|
||||
// same deal with scroll()...
|
||||
assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() );
|
||||
assertEquals( "unexpected row count", results, 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();
|
||||
|
||||
// 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
|
||||
sf.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() );
|
||||
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() );
|
||||
// assertEquals( localities, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertFalse( s.isOpen() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
assertFalse( s.isOpen() );
|
||||
|
||||
// native sql queries
|
||||
sf.getStatistics().clear();
|
||||
// native sql queries
|
||||
sf.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() );
|
||||
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() );
|
||||
// assertEquals( sql, stats.getQueryExecutionMaxTimeQueryString() );
|
||||
tx.commit();
|
||||
s.close();
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
cleanDb( s );
|
||||
tx.commit();
|
||||
s.close();
|
||||
sf.close();
|
||||
s = sf.openSession();
|
||||
tx = s.beginTransaction();
|
||||
cleanDb( s );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Continent fillDb(Session s) {
|
||||
|
|
|
@ -56,7 +56,7 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
|
|||
|
||||
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||
try {
|
||||
config.buildSessionFactory( serviceRegistry );
|
||||
config.buildSessionFactory( serviceRegistry ).close();
|
||||
Assert.fail( "MappingException expected" );
|
||||
}
|
||||
catch ( MappingException e ) {
|
||||
|
|
|
@ -105,8 +105,13 @@ public class TestHelper {
|
|||
additionalSettings.accept( ssrb );
|
||||
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
|
||||
try {
|
||||
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
ssr.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() {
|
||||
|
|
|
@ -35,11 +35,10 @@ import org.jboss.jandex.IndexView;
|
|||
* @author Andrea Boriero
|
||||
*/
|
||||
public class BootstrapContextImpl implements BootstrapContext {
|
||||
public static final BootstrapContextImpl INSTANCE = new BootstrapContextImpl();
|
||||
|
||||
private BootstrapContext delegate;
|
||||
private final BootstrapContext delegate;
|
||||
|
||||
private BootstrapContextImpl() {
|
||||
public BootstrapContextImpl() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
|
||||
MetadataBuildingOptions buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
||||
|
||||
|
@ -150,4 +149,9 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
public void release() {
|
||||
delegate.release();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
delegate.release();
|
||||
delegate.getServiceRegistry().close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,6 @@ public class MetadataBuildingContextTestingImpl implements MetadataBuildingConte
|
|||
private final ObjectNameNormalizer objectNameNormalizer;
|
||||
private final TypeDefinitionRegistryStandardImpl typeDefinitionRegistry;
|
||||
|
||||
public MetadataBuildingContextTestingImpl() {
|
||||
this( new StandardServiceRegistryBuilder().build() );
|
||||
}
|
||||
|
||||
public MetadataBuildingContextTestingImpl(StandardServiceRegistry serviceRegistry) {
|
||||
buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
||||
bootstrapContext = new BootstrapContextImpl( serviceRegistry, buildingOptions );
|
||||
|
|
|
@ -114,16 +114,34 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
|
||||
protected void buildSessionFactory(Consumer<Configuration> configurationAdapter) {
|
||||
// for now, build the configuration to get all the property settings
|
||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||
configuration = constructAndConfigureConfiguration( bootRegistry );
|
||||
if ( configurationAdapter != null ) {
|
||||
configurationAdapter.accept(configuration);
|
||||
BootstrapServiceRegistry bootRegistry = null;
|
||||
try {
|
||||
bootRegistry = buildBootstrapServiceRegistry();
|
||||
configuration = constructAndConfigureConfiguration( bootRegistry );
|
||||
if ( configurationAdapter != null ) {
|
||||
configurationAdapter.accept( configuration );
|
||||
}
|
||||
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
afterConstructAndConfigureConfiguration( configuration );
|
||||
sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry );
|
||||
afterSessionFactoryBuilt();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if ( sessionFactory != null ) {
|
||||
sessionFactory.close();
|
||||
sessionFactory = null;
|
||||
configuration = null;
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
serviceRegistry.destroy();
|
||||
serviceRegistry = null;
|
||||
}
|
||||
else if ( bootRegistry != null ) {
|
||||
bootRegistry.close();
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
afterConstructAndConfigureConfiguration( configuration );
|
||||
sessionFactory = ( SessionFactoryImplementor ) configuration.buildSessionFactory( serviceRegistry );
|
||||
afterSessionFactoryBuilt();
|
||||
}
|
||||
|
||||
protected void rebuildSessionFactory() {
|
||||
|
@ -278,17 +296,25 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( configuration.getProperties() );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( configuration.getProperties() );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
|
||||
StandardServiceRegistryBuilder cfgRegistryBuilder = configuration.getStandardServiceRegistryBuilder();
|
||||
StandardServiceRegistryBuilder cfgRegistryBuilder = configuration.getStandardServiceRegistryBuilder();
|
||||
|
||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry, cfgRegistryBuilder.getAggregatedCfgXml() )
|
||||
.applySettings( properties );
|
||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry, cfgRegistryBuilder.getAggregatedCfgXml() )
|
||||
.applySettings( properties );
|
||||
|
||||
prepareBasicRegistryBuilder( registryBuilder );
|
||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||
prepareBasicRegistryBuilder( registryBuilder );
|
||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
if ( bootRegistry != null ) {
|
||||
bootRegistry.close();
|
||||
}
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe
|
|||
private static final MockSettings MOCK_SETTINGS = Mockito.withSettings()
|
||||
.stubOnly() //important optimisation: uses far less memory, at tradeoff of mocked methods no longer being verifiable but we often don't need that.
|
||||
.defaultAnswer( org.mockito.Answers.CALLS_REAL_METHODS );
|
||||
private static final MockSettings VERIFIEABLE_MOCK_SETTINGS = Mockito.withSettings()
|
||||
private static final MockSettings VERIFIABLE_MOCK_SETTINGS = Mockito.withSettings()
|
||||
.defaultAnswer( org.mockito.Answers.CALLS_REAL_METHODS );
|
||||
// We must keep around the mocked connections, otherwise they are garbage collected and trigger finalizers
|
||||
// Since we use CALLS_REAL_METHODS this might close underlying IO resources which makes other objects unusable
|
||||
|
@ -76,8 +76,8 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe
|
|||
|
||||
public PreparedStatementSpyConnectionProvider(boolean allowMockVerificationOnStatements, boolean allowMockVerificationOnConnections, boolean forceSupportsAggressiveRelease) {
|
||||
super(forceSupportsAggressiveRelease);
|
||||
this.settingsForStatements = allowMockVerificationOnStatements ? VERIFIEABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||
this.settingsForConnections = allowMockVerificationOnConnections ? VERIFIEABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||
this.settingsForStatements = allowMockVerificationOnStatements ? VERIFIABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||
this.settingsForConnections = allowMockVerificationOnConnections ? VERIFIABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||
}
|
||||
|
||||
protected Connection actualConnection() throws SQLException {
|
||||
|
|
|
@ -63,7 +63,6 @@ public class ServiceRegistryExtension
|
|||
ServiceRegistryScopeImpl existingScope = (ServiceRegistryScopeImpl) store.get( REGISTRY_KEY );
|
||||
|
||||
if ( existingScope == null ) {
|
||||
final ServiceRegistryScopeImpl scope = new ServiceRegistryScopeImpl( );
|
||||
log.debugf( "Creating ServiceRegistryScope - %s", context.getDisplayName() );
|
||||
|
||||
final BootstrapServiceRegistryProducer bsrProducer;
|
||||
|
@ -114,7 +113,8 @@ public class ServiceRegistryExtension
|
|||
};
|
||||
}
|
||||
|
||||
scope.createRegistry( bsrProducer, ssrProducer );
|
||||
final ServiceRegistryScopeImpl scope = new ServiceRegistryScopeImpl( bsrProducer, ssrProducer );
|
||||
scope.getRegistry();
|
||||
|
||||
locateExtensionStore( testInstance, context ).put( REGISTRY_KEY, scope );
|
||||
|
||||
|
@ -209,7 +209,6 @@ public class ServiceRegistryExtension
|
|||
@Override
|
||||
public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
|
||||
log.tracef( "#postProcessTestInstance(%s, %s)", testInstance, context.getDisplayName() );
|
||||
|
||||
findServiceRegistryScope( testInstance, context );
|
||||
}
|
||||
|
||||
|
@ -249,24 +248,26 @@ public class ServiceRegistryExtension
|
|||
private StandardServiceRegistry registry;
|
||||
private boolean active = true;
|
||||
|
||||
public ServiceRegistryScopeImpl() {
|
||||
}
|
||||
|
||||
public StandardServiceRegistry createRegistry(BootstrapServiceRegistryProducer bsrProducer, ServiceRegistryProducer ssrProducer) {
|
||||
public ServiceRegistryScopeImpl(BootstrapServiceRegistryProducer bsrProducer, ServiceRegistryProducer ssrProducer) {
|
||||
this.bsrProducer = bsrProducer;
|
||||
this.ssrProducer = ssrProducer;
|
||||
}
|
||||
|
||||
verifyActive();
|
||||
|
||||
private StandardServiceRegistry createRegistry() {
|
||||
BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder().enableAutoClose();
|
||||
|
||||
final org.hibernate.boot.registry.BootstrapServiceRegistry bsr = bsrProducer.produceServiceRegistry( bsrb );
|
||||
try {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder( bsr );
|
||||
// we will close it ourselves explicitly.
|
||||
ssrb.disableAutoClose();
|
||||
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder( bsr );
|
||||
// we will close it ourselves explicitly.
|
||||
ssrb.disableAutoClose();
|
||||
|
||||
return ssrProducer.produceServiceRegistry( ssrb );
|
||||
return registry = ssrProducer.produceServiceRegistry( ssrb );
|
||||
}
|
||||
catch (Throwable t) {
|
||||
bsr.close();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyActive() {
|
||||
|
@ -280,7 +281,7 @@ public class ServiceRegistryExtension
|
|||
verifyActive();
|
||||
|
||||
if ( registry == null ) {
|
||||
registry = createRegistry( bsrProducer, ssrProducer );
|
||||
registry = createRegistry();
|
||||
}
|
||||
|
||||
return registry;
|
||||
|
|
|
@ -132,8 +132,8 @@ public class ViburDBCPConnectionProviderTest extends BaseCoreFunctionalTestCase
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void executeAndVerifySelect(Session session) {
|
||||
List<Actor> list = session.createQuery("from Actor where firstName = ?0")
|
||||
.setParameter(0, "CHRISTIAN").list();
|
||||
List<Actor> list = session.createQuery("from Actor where firstName = ?1")
|
||||
.setParameter(1, "CHRISTIAN").list();
|
||||
|
||||
Set<String> expectedLastNames = new HashSet<>(Arrays.asList("GABLE", "AKROYD", "NEESON"));
|
||||
assertEquals(expectedLastNames.size(), list.size());
|
||||
|
|
Loading…
Reference in New Issue