Backport of changes from 6314395edf
on
wip/6.0 (Fix connection leaks by properly closing service registries)
This commit is contained in:
parent
e0d262cc3f
commit
0af8755949
|
@ -741,7 +741,14 @@ public class Configuration {
|
||||||
public SessionFactory buildSessionFactory() throws HibernateException {
|
public SessionFactory buildSessionFactory() throws HibernateException {
|
||||||
log.debug( "Building session factory using internal StandardServiceRegistryBuilder" );
|
log.debug( "Building session factory using internal StandardServiceRegistryBuilder" );
|
||||||
standardServiceRegistryBuilder.applySettings( properties );
|
standardServiceRegistryBuilder.applySettings( properties );
|
||||||
return buildSessionFactory( standardServiceRegistryBuilder.build() );
|
StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
|
||||||
|
try {
|
||||||
|
return buildSessionFactory( serviceRegistry );
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
serviceRegistry.close();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.boot.archive.scan.internal.StandardScanOptions;
|
||||||
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
||||||
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
||||||
import org.hibernate.boot.cfgxml.spi.MappingReference;
|
import org.hibernate.boot.cfgxml.spi.MappingReference;
|
||||||
|
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
|
||||||
import org.hibernate.boot.model.process.spi.ManagedResources;
|
import org.hibernate.boot.model.process.spi.ManagedResources;
|
||||||
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
|
import org.hibernate.boot.model.process.spi.MetadataBuildingProcess;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
@ -222,7 +223,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
providedClassLoader,
|
providedClassLoader,
|
||||||
providedClassLoaderService
|
providedClassLoaderService
|
||||||
);
|
);
|
||||||
|
try {
|
||||||
// merge configuration sources and build the "standard" service registry
|
// merge configuration sources and build the "standard" service registry
|
||||||
final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr );
|
final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr );
|
||||||
|
|
||||||
|
@ -245,9 +246,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
configureIdentifierGenerators( standardServiceRegistry );
|
configureIdentifierGenerators( standardServiceRegistry );
|
||||||
|
|
||||||
final MetadataSources metadataSources = new MetadataSources( bsr );
|
final MetadataSources metadataSources = new MetadataSources( bsr );
|
||||||
|
this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry );
|
||||||
List<AttributeConverterDefinition> attributeConverterDefinitions = applyMappingResources( metadataSources );
|
List<AttributeConverterDefinition> attributeConverterDefinitions = applyMappingResources( metadataSources );
|
||||||
|
|
||||||
this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry );
|
|
||||||
applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions );
|
applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions );
|
||||||
|
|
||||||
applyMetadataBuilderContributor();
|
applyMetadataBuilderContributor();
|
||||||
|
@ -257,7 +258,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class );
|
final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.getService( CfgXmlAccessService.class );
|
||||||
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
||||||
if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
|
if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
|
||||||
for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig().getMappingReferences() ) {
|
for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig()
|
||||||
|
.getMappingReferences() ) {
|
||||||
mappingReference.apply( metadataSources );
|
mappingReference.apply( metadataSources );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,6 +299,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
// for the time being we want to revoke access to the temp ClassLoader if one was passed
|
||||||
metamodelBuilder.applyTempClassLoader( null );
|
metamodelBuilder.applyTempClassLoader( null );
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
bsr.close();
|
||||||
|
cleanup();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension point for subclasses. Used by Hibernate Reactive
|
* Extension point for subclasses. Used by Hibernate Reactive
|
||||||
|
@ -532,8 +540,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
if ( keyString.startsWith( JACC_PREFIX ) ) {
|
if ( keyString.startsWith( JACC_PREFIX ) ) {
|
||||||
if( !JACC_CONTEXT_ID.equals( keyString ) && !JACC_ENABLED.equals( keyString )) {
|
if( !JACC_CONTEXT_ID.equals( keyString ) && !JACC_ENABLED.equals( keyString )) {
|
||||||
if ( jaccContextId == null ) {
|
if ( jaccContextId == null ) {
|
||||||
LOG.debug(
|
LOG.debugf(
|
||||||
"Found JACC permission grant [%s] in properties, but no JACC context id was specified; ignoring"
|
"Found JACC permission grant [%s] in properties, but no JACC context id was specified; ignoring",
|
||||||
|
keyString
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -716,7 +725,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
|
|
||||||
if ( txnType == null ) {
|
if ( txnType == null ) {
|
||||||
// is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
|
// is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
|
||||||
LOG.debugf( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" );
|
LOG.debug( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" );
|
||||||
txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class CacheKeyImplementationHashCodeTest {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-12746")
|
@TestForIssue( jiraKey = "HHH-12746")
|
||||||
public void test() {
|
public void test() {
|
||||||
ServiceRegistryImplementor serviceRegistry = (
|
try (ServiceRegistryImplementor serviceRegistry = (
|
||||||
ServiceRegistryImplementor) new StandardServiceRegistryBuilder().build();
|
ServiceRegistryImplementor) new StandardServiceRegistryBuilder().build()) {
|
||||||
MetadataSources ms = new MetadataSources( serviceRegistry );
|
MetadataSources ms = new MetadataSources( serviceRegistry );
|
||||||
ms.addAnnotatedClass( AnEntity.class ).addAnnotatedClass( AnotherEntity.class );
|
ms.addAnnotatedClass( AnEntity.class ).addAnnotatedClass( AnotherEntity.class );
|
||||||
Metadata metadata = ms.buildMetadata();
|
Metadata metadata = ms.buildMetadata();
|
||||||
|
@ -51,6 +51,7 @@ public class CacheKeyImplementationHashCodeTest {
|
||||||
);
|
);
|
||||||
assertFalse( anEntityCacheKey.equals( anotherEntityCacheKey ) );
|
assertFalse( anEntityCacheKey.equals( anotherEntityCacheKey ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private CacheKeyImplementation createCacheKeyImplementation(
|
private CacheKeyImplementation createCacheKeyImplementation(
|
||||||
int id,
|
int id,
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -50,6 +51,13 @@ public class DialectFactoryTest extends BaseUnitTestCase {
|
||||||
dialectFactory.injectServices( (ServiceRegistryImplementor) registry );
|
dialectFactory.injectServices( (ServiceRegistryImplementor) registry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
if ( registry != null ) {
|
||||||
|
registry.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitShortNameUse() {
|
public void testExplicitShortNameUse() {
|
||||||
final Map<String, String> configValues = new HashMap<String, String>();
|
final Map<String, String> configValues = new HashMap<String, String>();
|
||||||
|
|
|
@ -34,15 +34,13 @@ import static org.junit.Assert.assertEquals;
|
||||||
public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test all params defaulted with a dialect supporting sequences
|
* Test all params defaulted with a dialect supporting pooled sequences
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultedSequenceBackedConfiguration() {
|
public void testDefaultedSequenceBackedConfiguration() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||||
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
||||||
|
@ -55,9 +53,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties buildGeneratorPropertiesBase(StandardServiceRegistry serviceRegistry) {
|
private Properties buildGeneratorPropertiesBase(StandardServiceRegistry serviceRegistry) {
|
||||||
|
@ -74,11 +69,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultedTableBackedConfiguration() {
|
public void testDefaultedTableBackedConfiguration() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||||
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
generator.configure( StandardBasicTypes.LONG, props, serviceRegistry );
|
||||||
|
@ -91,9 +84,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,11 +94,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
|
public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
|
||||||
// for dialects which do not support pooled sequences, we default to pooled+table
|
// 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() )
|
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||||
|
|
||||||
|
@ -123,16 +111,11 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
|
|
||||||
// for dialects which do support pooled sequences, we default to pooled+sequence
|
// 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() )
|
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||||
|
|
||||||
|
@ -146,9 +129,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,11 +138,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
|
public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
.applySetting( AvailableSettings.DIALECT, TableDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "10" );
|
||||||
|
|
||||||
|
@ -176,9 +154,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,11 +161,9 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testForceTableUse() {
|
public void testForceTableUse() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
|
props.setProperty( SequenceStyleGenerator.FORCE_TBL_PARAM, "true" );
|
||||||
|
|
||||||
|
@ -204,9 +177,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,12 +184,10 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitOptimizerWithExplicitIncrementSize() {
|
public void testExplicitOptimizerWithExplicitIncrementSize() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
|
||||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// optimizer=none w/ increment > 1 => should honor optimizer
|
// 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 );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.NONE.getExternalName() );
|
props.setProperty( SequenceStyleGenerator.OPT_PARAM, StandardOptimizerDescriptor.NONE.getExternalName() );
|
||||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
||||||
|
@ -264,18 +232,13 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertEquals( 20, generator.getOptimizer().getIncrementSize() );
|
assertEquals( 20, generator.getOptimizer().getIncrementSize() );
|
||||||
assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
|
assertEquals( 20, generator.getDatabaseStructure().getIncrementSize() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreferredPooledOptimizerSetting() {
|
public void testPreferredPooledOptimizerSetting() {
|
||||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
Properties props = buildGeneratorPropertiesBase( serviceRegistry );
|
||||||
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
props.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "20" );
|
||||||
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
SequenceStyleGenerator generator = new SequenceStyleGenerator();
|
||||||
|
@ -304,9 +267,6 @@ public class SequenceStyleConfigUnitTest extends BaseUnitTestCase {
|
||||||
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
|
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
|
||||||
assertClassAssignability( PooledLoThreadLocalOptimizer.class, generator.getOptimizer().getClass() );
|
assertClassAssignability( PooledLoThreadLocalOptimizer.class, generator.getOptimizer().getClass() );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TableDialect extends Dialect {
|
public static class TableDialect extends Dialect {
|
||||||
|
|
|
@ -29,6 +29,6 @@ public class NoCdiAvailableTestDelegate {
|
||||||
new HibernatePersistenceProvider().createContainerEntityManagerFactory(
|
new HibernatePersistenceProvider().createContainerEntityManagerFactory(
|
||||||
new PersistenceUnitInfoAdapter(),
|
new PersistenceUnitInfoAdapter(),
|
||||||
Collections.singletonMap( AvailableSettings.CDI_BEAN_MANAGER, new Object() )
|
Collections.singletonMap( AvailableSettings.CDI_BEAN_MANAGER, new Object() )
|
||||||
);
|
).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import javax.persistence.SharedCacheMode;
|
||||||
import javax.persistence.ValidationMode;
|
import javax.persistence.ValidationMode;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
|
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
|
||||||
import org.hibernate.jpa.boot.spi.Bootstrap;
|
import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||||
import org.hibernate.jpa.test.PersistenceUnitInfoAdapter;
|
import org.hibernate.jpa.test.PersistenceUnitInfoAdapter;
|
||||||
|
@ -32,22 +32,25 @@ public class ConfigurationObjectSettingTest extends BaseUnitTestCase {
|
||||||
public void testContainerBootstrapSharedCacheMode() {
|
public void testContainerBootstrapSharedCacheMode() {
|
||||||
// first, via the integration vars
|
// first, via the integration vars
|
||||||
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
||||||
|
EntityManagerFactoryBuilderImpl builder = null;
|
||||||
{
|
{
|
||||||
// as object
|
// as object
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
empty,
|
empty,
|
||||||
Collections.singletonMap( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
||||||
);
|
);
|
||||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.SHARED_CACHE_MODE ) );
|
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
{
|
{
|
||||||
// as string
|
// as string
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
empty,
|
empty,
|
||||||
Collections.singletonMap( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name() )
|
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE.name() )
|
||||||
);
|
);
|
||||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), builder.getConfigurationValues().get( AvailableSettings.SHARED_CACHE_MODE ) );
|
assertEquals( SharedCacheMode.DISABLE_SELECTIVE.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
|
|
||||||
// next, via the PUI
|
// next, via the PUI
|
||||||
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
||||||
|
@ -57,43 +60,48 @@ public class ConfigurationObjectSettingTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
adapter,
|
adapter,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
assertEquals( SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.SHARED_CACHE_MODE ) );
|
assertEquals( SharedCacheMode.ENABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
|
|
||||||
// via both, integration vars should take precedence
|
// via both, integration vars should take precedence
|
||||||
{
|
{
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
adapter,
|
adapter,
|
||||||
Collections.singletonMap( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
Collections.singletonMap( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.DISABLE_SELECTIVE )
|
||||||
);
|
);
|
||||||
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.SHARED_CACHE_MODE ) );
|
assertEquals( SharedCacheMode.DISABLE_SELECTIVE, builder.getConfigurationValues().get( AvailableSettings.JPA_SHARED_CACHE_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainerBootstrapValidationMode() {
|
public void testContainerBootstrapValidationMode() {
|
||||||
// first, via the integration vars
|
// first, via the integration vars
|
||||||
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
PersistenceUnitInfoAdapter empty = new PersistenceUnitInfoAdapter();
|
||||||
|
EntityManagerFactoryBuilderImpl builder = null;
|
||||||
{
|
{
|
||||||
// as object
|
// as object
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
empty,
|
empty,
|
||||||
Collections.singletonMap( AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK )
|
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK )
|
||||||
);
|
);
|
||||||
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.VALIDATION_MODE ) );
|
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
{
|
{
|
||||||
// as string
|
// as string
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
empty,
|
empty,
|
||||||
Collections.singletonMap( AvailableSettings.VALIDATION_MODE, ValidationMode.CALLBACK.name() )
|
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.CALLBACK.name() )
|
||||||
);
|
);
|
||||||
assertEquals( ValidationMode.CALLBACK.name(), builder.getConfigurationValues().get( AvailableSettings.VALIDATION_MODE ) );
|
assertEquals( ValidationMode.CALLBACK.name(), builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
|
|
||||||
// next, via the PUI
|
// next, via the PUI
|
||||||
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
PersistenceUnitInfoAdapter adapter = new PersistenceUnitInfoAdapter() {
|
||||||
|
@ -103,21 +111,23 @@ public class ConfigurationObjectSettingTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
adapter,
|
adapter,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.VALIDATION_MODE ) );
|
assertEquals( ValidationMode.CALLBACK, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
|
|
||||||
// via both, integration vars should take precedence
|
// via both, integration vars should take precedence
|
||||||
{
|
{
|
||||||
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
adapter,
|
adapter,
|
||||||
Collections.singletonMap( AvailableSettings.VALIDATION_MODE, ValidationMode.NONE )
|
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_MODE, ValidationMode.NONE )
|
||||||
);
|
);
|
||||||
assertEquals( ValidationMode.NONE, builder.getConfigurationValues().get( AvailableSettings.VALIDATION_MODE ) );
|
assertEquals( ValidationMode.NONE, builder.getConfigurationValues().get( AvailableSettings.JPA_VALIDATION_MODE ) );
|
||||||
}
|
}
|
||||||
|
builder.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -127,8 +137,8 @@ public class ConfigurationObjectSettingTest extends BaseUnitTestCase {
|
||||||
try {
|
try {
|
||||||
Bootstrap.getEntityManagerFactoryBuilder(
|
Bootstrap.getEntityManagerFactoryBuilder(
|
||||||
adapter,
|
adapter,
|
||||||
Collections.singletonMap( AvailableSettings.VALIDATION_FACTORY, token )
|
Collections.singletonMap( AvailableSettings.JPA_VALIDATION_FACTORY, token )
|
||||||
);
|
).cancel();
|
||||||
fail( "Was expecting error as token did not implement ValidatorFactory" );
|
fail( "Was expecting error as token did not implement ValidatorFactory" );
|
||||||
}
|
}
|
||||||
catch ( HibernateException e ) {
|
catch ( HibernateException e ) {
|
||||||
|
|
|
@ -21,8 +21,9 @@ import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.jpa.boot.spi.Bootstrap;
|
import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||||
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -63,6 +64,13 @@ public class SchemaCreateDropUtf8WithoutHbm2DdlCharsetNameTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
if ( entityManagerFactoryBuilder != null ) {
|
||||||
|
entityManagerFactoryBuilder.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-10972")
|
@TestForIssue(jiraKey = "HHH-10972")
|
||||||
public void testEncoding() throws Exception {
|
public void testEncoding() throws Exception {
|
||||||
|
|
|
@ -27,8 +27,9 @@ import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementException;
|
import org.hibernate.tool.schema.spi.SchemaManagementException;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -60,6 +61,13 @@ public class SchemaDatabaseFileGenerationFailureTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
if ( entityManagerFactoryBuilder != null ) {
|
||||||
|
entityManagerFactoryBuilder.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-12192")
|
@TestForIssue(jiraKey = "HHH-12192")
|
||||||
public void testErrorMessageContainsTheFailingDDLCommand() {
|
public void testErrorMessageContainsTheFailingDDLCommand() {
|
||||||
|
@ -83,7 +91,6 @@ public class SchemaDatabaseFileGenerationFailureTest {
|
||||||
|
|
||||||
SQLException root = (SQLException) e.getCause().getCause().getCause();
|
SQLException root = (SQLException) e.getCause().getCause().getCause();
|
||||||
assertEquals( "Expected", root.getMessage() );
|
assertEquals( "Expected", root.getMessage() );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,5 +126,4 @@ public class SchemaDatabaseFileGenerationFailureTest {
|
||||||
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
|
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,9 @@ import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
import org.hibernate.tool.schema.spi.CommandAcceptanceException;
|
||||||
import org.hibernate.tool.schema.spi.SchemaManagementException;
|
import org.hibernate.tool.schema.spi.SchemaManagementException;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -52,12 +53,19 @@ public class SchemaScriptFileGenerationFailureTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
if ( entityManagerFactoryBuilder != null ) {
|
||||||
|
entityManagerFactoryBuilder.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-12192")
|
@TestForIssue(jiraKey = "HHH-12192")
|
||||||
public void testErrorMessageContainsTheFailingDDLCommand() {
|
public void testErrorMessageContainsTheFailingDDLCommand() {
|
||||||
try {
|
try {
|
||||||
entityManagerFactoryBuilder.generateSchema();
|
entityManagerFactoryBuilder.generateSchema();
|
||||||
fail( "Should haave thrown IOException" );
|
fail( "Should have thrown IOException" );
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
assertTrue( e instanceof PersistenceException );
|
assertTrue( e instanceof PersistenceException );
|
||||||
|
@ -126,7 +134,6 @@ public class SchemaScriptFileGenerationFailureTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
||||||
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -53,6 +54,13 @@ public class SchemaScriptFileGenerationTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
if ( entityManagerFactoryBuilder != null ) {
|
||||||
|
entityManagerFactoryBuilder.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "10601")
|
@TestForIssue(jiraKey = "10601")
|
||||||
public void testGenerateSchemaDoesNotProduceTheSameStatementTwice() throws Exception {
|
public void testGenerateSchemaDoesNotProduceTheSameStatementTwice() throws Exception {
|
||||||
|
@ -109,5 +117,4 @@ public class SchemaScriptFileGenerationTest {
|
||||||
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
|
config.put( org.hibernate.jpa.AvailableSettings.LOADED_CLASSES, classes );
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
Configuration cfg = new Configuration()
|
Configuration cfg = new Configuration()
|
||||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME )
|
.setProperty( AvailableSettings.SESSION_FACTORY_NAME, NAME )
|
||||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); // default is true
|
.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
|
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||||
// different VM
|
// different VM
|
||||||
|
@ -44,13 +44,19 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
// deregister under this uuid...
|
// deregister under this uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, NAME, false, null );
|
||||||
// and then register under a different uuid...
|
// and then register under a different uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.addSessionFactory( "some-other-uuid", NAME, false, factory, null );
|
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||||
|
"some-other-uuid",
|
||||||
|
NAME,
|
||||||
|
false,
|
||||||
|
factory,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
SessionFactory factory2 = (SessionFactory) SerializationHelper.clone( factory );
|
SessionFactory factory2 = (SessionFactory) SerializationHelper.clone( factory );
|
||||||
assertSame( factory, factory2 );
|
assertSame( factory, factory2 );
|
||||||
|
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", NAME, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", NAME, false, null );
|
||||||
factory.close();
|
}
|
||||||
|
|
||||||
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
||||||
}
|
}
|
||||||
|
@ -61,7 +67,7 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
// here, the test should fail based just on attempted uuid resolution
|
// here, the test should fail based just on attempted uuid resolution
|
||||||
Configuration cfg = new Configuration()
|
Configuration cfg = new Configuration()
|
||||||
.setProperty( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); // default is true
|
.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
|
// we need to do some tricking here so that Hibernate thinks the deserialization happens in a
|
||||||
// different VM
|
// different VM
|
||||||
|
@ -69,17 +75,23 @@ public class SessionFactorySerializationTest extends BaseUnitTestCase {
|
||||||
// deregister under this uuid...
|
// deregister under this uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( uuid, null, false, null );
|
||||||
// and then register under a different uuid...
|
// and then register under a different uuid...
|
||||||
SessionFactoryRegistry.INSTANCE.addSessionFactory( "some-other-uuid", null, false, factory, null );
|
SessionFactoryRegistry.INSTANCE.addSessionFactory(
|
||||||
|
"some-other-uuid",
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
factory,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SerializationHelper.clone( factory );
|
SerializationHelper.clone( factory );
|
||||||
fail( "Expecting an error" );
|
fail( "Expecting an error" );
|
||||||
}
|
}
|
||||||
catch ( SerializationException expected ) {
|
catch (SerializationException expected) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", null, false, null );
|
SessionFactoryRegistry.INSTANCE.removeSessionFactory( "some-other-uuid", null, false, null );
|
||||||
factory.close();
|
}
|
||||||
|
|
||||||
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
assertFalse( SessionFactoryRegistry.INSTANCE.hasRegistrations() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.Startable;
|
import org.hibernate.service.spi.Startable;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -25,9 +27,18 @@ import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ServiceRegistryTest {
|
public class ServiceRegistryTest {
|
||||||
private final ServiceRegistry registry = buildRegistry();
|
private ServiceRegistry registry;
|
||||||
private final static int NUMBER_OF_THREADS = 100;
|
private final static int NUMBER_OF_THREADS = 100;
|
||||||
private StandardServiceRegistryBuilder standardServiceRegistryBuilder;
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
registry = buildRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
registry.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-10427")
|
@TestForIssue(jiraKey = "HHH-10427")
|
||||||
|
@ -46,9 +57,6 @@ public class ServiceRegistryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
standardServiceRegistryBuilder.destroy( registry );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,8 +90,7 @@ public class ServiceRegistryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceRegistry buildRegistry() {
|
private ServiceRegistry buildRegistry() {
|
||||||
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
|
return new StandardServiceRegistryBuilder().addInitiator( new SlowServiceInitiator() )
|
||||||
return standardServiceRegistryBuilder.addInitiator( new SlowServiceInitiator() )
|
|
||||||
.addInitiator( new NullServiceInitiator() )
|
.addInitiator( new NullServiceInitiator() )
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ public class ServiceRegistryClosingCascadeTest extends BaseUnitTestCase {
|
||||||
StandardServiceRegistry sr = new StandardServiceRegistryBuilder(bsr).build();
|
StandardServiceRegistry sr = new StandardServiceRegistryBuilder(bsr).build();
|
||||||
assertTrue( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
assertTrue( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
SessionFactory sf = config.buildSessionFactory( sr );
|
try (SessionFactory sf = config.buildSessionFactory( sr )) {
|
||||||
|
|
||||||
sf.close();
|
}
|
||||||
assertFalse( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
assertFalse( ( (BootstrapServiceRegistryImpl) bsr ).isActive() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ public class SubclassProxyInterfaceTest extends BaseUnitTestCase {
|
||||||
final Configuration cfg = new Configuration()
|
final Configuration cfg = new Configuration()
|
||||||
.setProperty( Environment.DIALECT, H2Dialect.class.getName() )
|
.setProperty( Environment.DIALECT, H2Dialect.class.getName() )
|
||||||
.addClass( Person.class );
|
.addClass( Person.class );
|
||||||
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() );
|
try (ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( cfg.getProperties() )) {
|
||||||
cfg.buildSessionFactory( serviceRegistry ).close();
|
cfg.buildSessionFactory( serviceRegistry ).close();
|
||||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,11 @@ import static org.junit.Assert.fail;
|
||||||
*/
|
*/
|
||||||
public class ConfigurationTest {
|
public class ConfigurationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDeclarativeMix() throws Exception {
|
public void testDeclarativeMix() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
assertNotNull( sf );
|
assertNotNull( sf );
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
@ -45,10 +45,11 @@ public class ConfigurationTest {
|
||||||
assertEquals( 0, q.list().size() );
|
assertEquals( 0, q.list().size() );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIgnoringHbm() throws Exception {
|
public void testIgnoringHbm() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
|
@ -85,12 +86,12 @@ public class ConfigurationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrecedenceHbm() throws Exception {
|
public void testPrecedenceHbm() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.addAnnotatedClass( Boat.class );
|
cfg.addAnnotatedClass( Boat.class );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
assertNotNull( sf );
|
assertNotNull( sf );
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
|
@ -107,16 +108,17 @@ public class ConfigurationTest {
|
||||||
//s.getTransaction().commit();
|
//s.getTransaction().commit();
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrecedenceAnnotation() throws Exception {
|
public void testPrecedenceAnnotation() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
|
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
|
||||||
cfg.addAnnotatedClass( Boat.class );
|
cfg.addAnnotatedClass( Boat.class );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
assertNotNull( sf );
|
assertNotNull( sf );
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
|
@ -132,15 +134,16 @@ public class ConfigurationTest {
|
||||||
s.delete( boat );
|
s.delete( boat );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHbmWithSubclassExtends() throws Exception {
|
public void testHbmWithSubclassExtends() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.addClass( Ferry.class );
|
cfg.addClass( Ferry.class );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
assertNotNull( sf );
|
assertNotNull( sf );
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
@ -150,15 +153,16 @@ public class ConfigurationTest {
|
||||||
assertEquals( 0, q.list().size() );
|
assertEquals( 0, q.list().size() );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnnReferencesHbm() throws Exception {
|
public void testAnnReferencesHbm() {
|
||||||
Configuration cfg = new Configuration();
|
Configuration cfg = new Configuration();
|
||||||
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
|
||||||
cfg.addAnnotatedClass( Port.class );
|
cfg.addAnnotatedClass( Port.class );
|
||||||
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
assertNotNull( sf );
|
assertNotNull( sf );
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
@ -168,6 +172,6 @@ public class ConfigurationTest {
|
||||||
assertEquals( 0, q.list().size() );
|
assertEquals( 0, q.list().size() );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class SafeMappingTest {
|
||||||
if ( serviceRegistry != null ) {
|
if ( serviceRegistry != null ) {
|
||||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
cfg.getStandardServiceRegistryBuilder().getBootstrapServiceRegistry().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class SecuredBindingTest {
|
||||||
if ( serviceRegistry != null ) {
|
if ( serviceRegistry != null ) {
|
||||||
ServiceRegistryBuilder.destroy( serviceRegistry );
|
ServiceRegistryBuilder.destroy( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
ac.getStandardServiceRegistryBuilder().getBootstrapServiceRegistry().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,14 @@ package org.hibernate.test.annotations.backquotes;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.SessionFactory;
|
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.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
@ -46,8 +47,12 @@ public class BackquoteTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
if(sessionFactory !=null) sessionFactory.close();
|
if(sessionFactory !=null) {
|
||||||
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
if (serviceRegistry != null) {
|
||||||
|
ServiceRegistryBuilder.destroy(serviceRegistry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,15 +60,15 @@ public class BackquoteTest extends BaseUnitTestCase {
|
||||||
public void testBackquotes() {
|
public void testBackquotes() {
|
||||||
try {
|
try {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
config.addAnnotatedClass(Bug.class);
|
config.addAnnotatedClass( Bug.class );
|
||||||
config.addAnnotatedClass(Category.class);
|
config.addAnnotatedClass( Category.class );
|
||||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
catch( Exception e ) {
|
catch( Exception e ) {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(writer));
|
e.printStackTrace( new PrintWriter(writer) );
|
||||||
log.debug(writer.toString());
|
log.debug( writer.toString() );
|
||||||
fail(e.getMessage());
|
fail( e.getMessage() );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if ( sessionFactory != null ) {
|
if ( sessionFactory != null ) {
|
||||||
|
@ -83,12 +88,12 @@ public class BackquoteTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-4647" )
|
@TestForIssue( jiraKey = "HHH-4647" )
|
||||||
public void testInvalidReferenceToQuotedTableName() {
|
public void testInvalidReferenceToQuotedTableName() {
|
||||||
try {
|
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration( serviceRegistry );
|
||||||
config.addAnnotatedClass(Printer.class);
|
config.addAnnotatedClass( Printer.class );
|
||||||
config.addAnnotatedClass(PrinterCable.class);
|
config.addAnnotatedClass( PrinterCable.class );
|
||||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
sessionFactory = config.buildSessionFactory( this.serviceRegistry );
|
||||||
fail("expected MappingException to be thrown");
|
fail( "expected MappingException to be thrown" );
|
||||||
}
|
}
|
||||||
//we WANT MappingException to be thrown
|
//we WANT MappingException to be thrown
|
||||||
catch( MappingException e ) {
|
catch( MappingException e ) {
|
||||||
|
@ -96,9 +101,9 @@ public class BackquoteTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
e.printStackTrace(new PrintWriter(writer));
|
e.printStackTrace( new PrintWriter(writer) );
|
||||||
log.debug(writer.toString());
|
log.debug( writer.toString() );
|
||||||
fail(e.getMessage());
|
fail( e.getMessage() );
|
||||||
} finally {
|
} finally {
|
||||||
if(sessionFactory!=null){
|
if(sessionFactory!=null){
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.annotations.configuration;
|
package org.hibernate.test.annotations.configuration;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -19,8 +21,8 @@ import org.junit.Test;
|
||||||
public class ConfigurationTest {
|
public class ConfigurationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMixPackageAndResourceOrdering() throws Exception {
|
public void testMixPackageAndResourceOrdering() throws Exception {
|
||||||
try {
|
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration( serviceRegistry );
|
||||||
config.addResource( "org/hibernate/test/annotations/configuration/orm.xml" );
|
config.addResource( "org/hibernate/test/annotations/configuration/orm.xml" );
|
||||||
config.addPackage( "org.hibernate.test.annotations.configuration" );
|
config.addPackage( "org.hibernate.test.annotations.configuration" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,9 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWithoutIntegrator() {
|
public void testWithoutIntegrator() {
|
||||||
SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
try (SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||||
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
||||||
.buildSessionFactory();
|
.buildSessionFactory()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Session sess = sf.openSession();
|
Session sess = sf.openSession();
|
||||||
try {
|
try {
|
||||||
sess.getTransaction().begin();
|
sess.getTransaction().begin();
|
||||||
|
@ -62,20 +60,14 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
sess.close();
|
sess.close();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithTypeContributor() {
|
public void testWithTypeContributor() {
|
||||||
SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
try (SessionFactory sf = new Configuration().addAnnotatedClass( Investor.class )
|
||||||
.registerTypeContributor( new InvestorTypeContributor() )
|
.registerTypeContributor( new InvestorTypeContributor() )
|
||||||
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
.setProperty( "hibernate.hbm2ddl.auto", "create-drop" )
|
||||||
.buildSessionFactory();
|
.buildSessionFactory(); Session sess = sf.openSession()) {
|
||||||
|
|
||||||
Session sess = sf.openSession();
|
|
||||||
try {
|
|
||||||
sess.getTransaction().begin();
|
sess.getTransaction().begin();
|
||||||
Investor myInv = getInvestor();
|
Investor myInv = getInvestor();
|
||||||
myInv.setId( 2L );
|
myInv.setId( 2L );
|
||||||
|
@ -86,13 +78,6 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
Investor inv = (Investor) sess.get( Investor.class, 2L );
|
Investor inv = (Investor) sess.get( Investor.class, 2L );
|
||||||
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
|
assertEquals( new BigDecimal( "100" ), inv.getInvestments().get( 0 ).getAmount().getAmount() );
|
||||||
}catch (Exception e){
|
|
||||||
sess.getTransaction().rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
sess.close();
|
|
||||||
sf.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,6 @@ public class EmbeddableWithManyToMany_HHH_11302_Test
|
||||||
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
serviceRegistry().destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -61,9 +61,6 @@ public class EmbeddableWithOneToMany_HHH_11302_Test
|
||||||
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
serviceRegistry().destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -55,9 +55,6 @@ public class EmbeddableWithOneToMany_HHH_8564_Test
|
||||||
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
serviceRegistry().destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -53,9 +53,6 @@ public class EmbeddableWithOneToMany_HHH_8860_Test
|
||||||
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
"@OneToMany, @ManyToMany or @ElementCollection cannot be used inside an @Embeddable that is also contained within an @ElementCollection"
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
serviceRegistry().destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
||||||
config.addAnnotatedClass( Order.class );
|
config.addAnnotatedClass( Order.class );
|
||||||
config.addAnnotatedClass( SupportTickets.class );
|
config.addAnnotatedClass( SupportTickets.class );
|
||||||
config.addAnnotatedClass( Country.class );
|
config.addAnnotatedClass( Country.class );
|
||||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
)) {
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
|
@ -69,7 +69,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
||||||
"package info should not be parsed",
|
"package info should not be parsed",
|
||||||
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
|
||||||
);
|
);
|
||||||
sessionImpl.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,15 +148,15 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
||||||
.getContextClassLoader()
|
.getContextClassLoader()
|
||||||
.getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" );
|
.getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" );
|
||||||
config.addInputStream( is );
|
config.addInputStream( is );
|
||||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
)) {
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
sessionImpl.containsFetchProfileDefinition( "orders-profile" )
|
sessionImpl.containsFetchProfileDefinition( "orders-profile" )
|
||||||
);
|
);
|
||||||
sessionImpl.close();
|
}
|
||||||
|
|
||||||
// now the same with no xml
|
// now the same with no xml
|
||||||
final MetadataSources metadataSources = new MetadataSources()
|
final MetadataSources metadataSources = new MetadataSources()
|
||||||
|
@ -187,9 +187,9 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
||||||
config.addAnnotatedClass( SupportTickets.class );
|
config.addAnnotatedClass( SupportTickets.class );
|
||||||
config.addAnnotatedClass( Country.class );
|
config.addAnnotatedClass( Country.class );
|
||||||
config.addPackage( Customer.class.getPackage().getName() );
|
config.addPackage( Customer.class.getPackage().getName() );
|
||||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
)) {
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
|
@ -199,6 +199,6 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
sessionImpl.containsFetchProfileDefinition( "package-profile-2" )
|
sessionImpl.containsFetchProfileDefinition( "package-profile-2" )
|
||||||
);
|
);
|
||||||
sessionImpl.close();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
config.addAnnotatedClass( Customer6.class );
|
config.addAnnotatedClass( Customer6.class );
|
||||||
config.addAnnotatedClass( Address.class );
|
config.addAnnotatedClass( Address.class );
|
||||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
)) {
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
|
@ -46,7 +46,7 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
|
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
|
||||||
);
|
);
|
||||||
sessionImpl.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,9 +55,9 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
||||||
config.addAnnotatedClass( Customer6.class );
|
config.addAnnotatedClass( Customer6.class );
|
||||||
config.addAnnotatedClass( Address.class );
|
config.addAnnotatedClass( Address.class );
|
||||||
config.addPackage( Address.class.getPackage().getName() );
|
config.addPackage( Address.class.getPackage().getName() );
|
||||||
SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
|
||||||
serviceRegistry
|
serviceRegistry
|
||||||
);
|
)) {
|
||||||
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
|
@ -67,7 +67,7 @@ public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
|
||||||
"fetch profile not parsed properly",
|
"fetch profile not parsed properly",
|
||||||
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
|
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
|
||||||
);
|
);
|
||||||
sessionImpl.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import org.hibernate.annotations.JoinColumnOrFormula;
|
||||||
import org.hibernate.annotations.JoinFormula;
|
import org.hibernate.annotations.JoinFormula;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
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.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
|
||||||
|
@ -50,7 +52,8 @@ public class JoinColumnOrFormulaTest extends BaseUnitTestCase {
|
||||||
@TestForIssue( jiraKey = "HHH-9897" )
|
@TestForIssue( jiraKey = "HHH-9897" )
|
||||||
@FailureExpected( jiraKey = "HHH-9897" )
|
@FailureExpected( jiraKey = "HHH-9897" )
|
||||||
public void testUseOfJoinColumnOrFormula() {
|
public void testUseOfJoinColumnOrFormula() {
|
||||||
Metadata metadata = new MetadataSources()
|
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||||
|
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||||
.addAnnotatedClass( A.class )
|
.addAnnotatedClass( A.class )
|
||||||
.addAnnotatedClass( D.class )
|
.addAnnotatedClass( D.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -60,6 +63,7 @@ public class JoinColumnOrFormulaTest extends BaseUnitTestCase {
|
||||||
// use the formula (it expects Columns too)
|
// use the formula (it expects Columns too)
|
||||||
metadata.buildSessionFactory().close();
|
metadata.buildSessionFactory().close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Entity( name = "A" )
|
@Entity( name = "A" )
|
||||||
@Table( name = "A" )
|
@Table( name = "A" )
|
||||||
|
|
|
@ -11,6 +11,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import javax.persistence.AttributeOverride;
|
import javax.persistence.AttributeOverride;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Inheritance;
|
import javax.persistence.Inheritance;
|
||||||
import javax.persistence.InheritanceType;
|
import javax.persistence.InheritanceType;
|
||||||
|
@ -39,24 +40,26 @@ public class EntityInheritanceAttributeOverrideTest extends BaseEntityManagerFun
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?>[] getAnnotatedClasses() {
|
public Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[]{
|
return new Class[] {
|
||||||
CategoryEntity.class,
|
CategoryEntity.class,
|
||||||
TaxonEntity.class,
|
TaxonEntity.class,
|
||||||
AbstractEntity.class
|
AbstractEntity.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public EntityManagerFactory produceEntityManagerFactory() {
|
||||||
public void buildEntityManagerFactory() {
|
|
||||||
Triggerable warningLogged = logInspection.watchForLogMessages( "HHH000499:" );
|
Triggerable warningLogged = logInspection.watchForLogMessages( "HHH000499:" );
|
||||||
|
|
||||||
super.buildEntityManagerFactory();
|
super.buildEntityManagerFactory();
|
||||||
|
EntityManagerFactory entityManagerFactory = entityManagerFactory();
|
||||||
|
|
||||||
assertTrue("A warning should have been logged for this unsupported configuration", warningLogged.wasTriggered());
|
assertTrue("A warning should have been logged for this unsupported configuration", warningLogged.wasTriggered());
|
||||||
|
return entityManagerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
produceEntityManagerFactory().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "AbstractEntity")
|
@Entity(name = "AbstractEntity")
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -29,19 +31,32 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14529")
|
@TestForIssue(jiraKey = "HHH-14529")
|
||||||
public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
|
private BootstrapContextImpl bootstrapContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
bootstrapContext = new BootstrapContextImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
bootstrapContext.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMappedSuperclassAnnotations() throws Exception {
|
public void testMappedSuperclassAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext(
|
XMLContext context = buildContext(
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/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 ) );
|
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityRelatedAnnotations() throws Exception {
|
public void testEntityRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/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 ) );
|
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Default value in xml entity should not override @Entity.name", "JavaAdministration",
|
"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( "wrong tble name", "tablehilo", reader.getAnnotation( TableGenerator.class ).table() );
|
||||||
assertEquals( "no schema overriding", "myschema", reader.getAnnotation( TableGenerator.class ).schema() );
|
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 ) );
|
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Java annotation not taken into account", "matchtable", reader.getAnnotation( Table.class ).name()
|
"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( ExcludeSuperclassListeners.class ) );
|
||||||
assertNotNull( reader.getAnnotation( ExcludeDefaultListeners.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 ) );
|
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 ) );
|
assertNull( "Mutualize PKJC into PKJCs", reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||||
assertEquals(
|
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 ) );
|
assertNotNull( reader.getAnnotation( IdClass.class ) );
|
||||||
assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() );
|
assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -174,7 +189,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
XMLContext context = buildContext(
|
XMLContext context = buildContext(
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/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 ) );
|
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Metadata complete should ignore java annotations", "", reader.getAnnotation( Entity.class ).name()
|
"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( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||||
assertEquals( "Default schema not overriden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
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 ) );
|
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||||
assertEquals( "Overriding not taken into account", "myschema", reader.getAnnotation( Table.class ).schema() );
|
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( NamedQueries.class ) );
|
||||||
assertNull( reader.getAnnotation( NamedNativeQueries.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( PrimaryKeyJoinColumn.class ) );
|
||||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumns.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 ) );
|
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( IdClass.class ) );
|
||||||
assertNull( reader.getAnnotation( DiscriminatorValue.class ) );
|
assertNull( reader.getAnnotation( DiscriminatorValue.class ) );
|
||||||
assertNull( reader.getAnnotation( DiscriminatorColumn.class ) );
|
assertNull( reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||||
|
@ -213,11 +228,11 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
public void testIdRelatedAnnotations() throws Exception {
|
public void testIdRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
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( Id.class ) );
|
||||||
assertNull( reader.getAnnotation( Column.class ) );
|
assertNull( reader.getAnnotation( Column.class ) );
|
||||||
Field field = Administration.class.getDeclaredField( "id" );
|
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( Id.class ) );
|
||||||
assertNotNull( reader.getAnnotation( GeneratedValue.class ) );
|
assertNotNull( reader.getAnnotation( GeneratedValue.class ) );
|
||||||
assertEquals( GenerationType.SEQUENCE, reader.getAnnotation( GeneratedValue.class ).strategy() );
|
assertEquals( GenerationType.SEQUENCE, reader.getAnnotation( GeneratedValue.class ).strategy() );
|
||||||
|
@ -234,23 +249,23 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
);
|
);
|
||||||
method = Administration.class.getDeclaredMethod( "getId" );
|
method = Administration.class.getDeclaredMethod( "getId" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
"Default access type when not defined in metadata complete should be property",
|
"Default access type when not defined in metadata complete should be property",
|
||||||
reader.getAnnotation( Id.class )
|
reader.getAnnotation( Id.class )
|
||||||
);
|
);
|
||||||
field = Administration.class.getDeclaredField( "id" );
|
field = Administration.class.getDeclaredField( "id" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||||
assertNull(
|
assertNull(
|
||||||
"Default access type when not defined in metadata complete should be property",
|
"Default access type when not defined in metadata complete should be property",
|
||||||
reader.getAnnotation( Id.class )
|
reader.getAnnotation( Id.class )
|
||||||
);
|
);
|
||||||
|
|
||||||
method = BusTrip.class.getDeclaredMethod( "getId" );
|
method = BusTrip.class.getDeclaredMethod( "getId" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( method, context, bootstrapContext );
|
||||||
assertNull( reader.getAnnotation( EmbeddedId.class ) );
|
assertNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||||
field = BusTrip.class.getDeclaredField( "id" );
|
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( EmbeddedId.class ) );
|
||||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||||
|
@ -262,22 +277,22 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
);
|
);
|
||||||
Field field = BusTrip.class.getDeclaredField( "status" );
|
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 ) );
|
assertNotNull( reader.getAnnotation( Enumerated.class ) );
|
||||||
assertEquals( EnumType.STRING, reader.getAnnotation( Enumerated.class ).value() );
|
assertEquals( EnumType.STRING, reader.getAnnotation( Enumerated.class ).value() );
|
||||||
assertEquals( false, reader.getAnnotation( Basic.class ).optional() );
|
assertEquals( false, reader.getAnnotation( Basic.class ).optional() );
|
||||||
field = BusTrip.class.getDeclaredField( "serial" );
|
field = BusTrip.class.getDeclaredField( "serial" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||||
assertNotNull( reader.getAnnotation( Lob.class ) );
|
assertNotNull( reader.getAnnotation( Lob.class ) );
|
||||||
assertEquals( "serialbytes", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
assertEquals( "serialbytes", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||||
field = BusTrip.class.getDeclaredField( "terminusTime" );
|
field = BusTrip.class.getDeclaredField( "terminusTime" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||||
assertEquals( TemporalType.TIMESTAMP, reader.getAnnotation( Temporal.class ).value() );
|
assertEquals( TemporalType.TIMESTAMP, reader.getAnnotation( Temporal.class ).value() );
|
||||||
assertEquals( FetchType.LAZY, reader.getAnnotation( Basic.class ).fetch() );
|
assertEquals( FetchType.LAZY, reader.getAnnotation( Basic.class ).fetch() );
|
||||||
|
|
||||||
field = BusTripPk.class.getDeclaredField( "busDriver" );
|
field = BusTripPk.class.getDeclaredField( "busDriver" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||||
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +300,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
public void testVersionRelatedAnnotations() throws Exception {
|
public void testVersionRelatedAnnotations() throws Exception {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
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 ) );
|
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||||
|
|
||||||
Field field = Match.class.getDeclaredField( "version" );
|
Field field = Match.class.getDeclaredField( "version" );
|
||||||
|
@ -297,12 +312,12 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
Field field = Administration.class.getDeclaredField( "transientField" );
|
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 ) );
|
assertNotNull( reader.getAnnotation( Transient.class ) );
|
||||||
assertNull( reader.getAnnotation( Basic.class ) );
|
assertNull( reader.getAnnotation( Basic.class ) );
|
||||||
|
|
||||||
field = Match.class.getDeclaredField( "playerASSN" );
|
field = Match.class.getDeclaredField( "playerASSN" );
|
||||||
reader = new JPAXMLOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
reader = new JPAXMLOverriddenAnnotationReader( field, context, bootstrapContext );
|
||||||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +326,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
Field field = Administration.class.getDeclaredField( "defaultBusTrip" );
|
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 ) );
|
assertNotNull( reader.getAnnotation( OneToOne.class ) );
|
||||||
assertNull( reader.getAnnotation( JoinColumns.class ) );
|
assertNull( reader.getAnnotation( JoinColumns.class ) );
|
||||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||||
|
@ -324,7 +339,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||||
);
|
);
|
||||||
field = BusTrip.class.getDeclaredField( "players" );
|
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( OneToMany.class ) );
|
||||||
assertNotNull( reader.getAnnotation( JoinColumns.class ) );
|
assertNotNull( reader.getAnnotation( JoinColumns.class ) );
|
||||||
assertEquals( 2, reader.getAnnotation( JoinColumns.class ).value().length );
|
assertEquals( 2, reader.getAnnotation( JoinColumns.class ).value().length );
|
||||||
|
@ -333,7 +348,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
assertEquals( "name", reader.getAnnotation( MapKey.class ).name() );
|
assertEquals( "name", reader.getAnnotation( MapKey.class ).name() );
|
||||||
|
|
||||||
field = BusTrip.class.getDeclaredField( "roads" );
|
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( ManyToMany.class ) );
|
||||||
assertNotNull( reader.getAnnotation( JoinTable.class ) );
|
assertNotNull( reader.getAnnotation( JoinTable.class ) );
|
||||||
assertEquals( "bus_road", reader.getAnnotation( JoinTable.class ).name() );
|
assertEquals( "bus_road", reader.getAnnotation( JoinTable.class ).name() );
|
||||||
|
@ -350,7 +365,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
Field field = Company.class.getDeclaredField( "organizations" );
|
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( ElementCollection.class ) );
|
||||||
assertNotNull( reader.getAnnotation( Converts.class ) );
|
assertNotNull( reader.getAnnotation( Converts.class ) );
|
||||||
assertNotNull( reader.getAnnotation( Converts.class ).value() );
|
assertNotNull( reader.getAnnotation( Converts.class ).value() );
|
||||||
|
@ -363,20 +378,20 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
|
|
||||||
Method method = Administration.class.getDeclaredMethod( "calculate" );
|
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 ) );
|
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 ) );
|
assertTrue( reader.isAnnotationPresent( EntityListeners.class ) );
|
||||||
assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
|
assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
|
||||||
assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );
|
assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );
|
||||||
|
|
||||||
method = LogListener.class.getDeclaredMethod( "noLog", Object.class );
|
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 ) );
|
assertTrue( reader.isAnnotationPresent( PostLoad.class ) );
|
||||||
|
|
||||||
method = LogListener.class.getDeclaredMethod( "log", Object.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 ) );
|
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||||
assertFalse( reader.isAnnotationPresent( PostPersist.class ) );
|
assertFalse( reader.isAnnotationPresent( PostPersist.class ) );
|
||||||
|
|
||||||
|
@ -387,7 +402,7 @@ public class JPAXMLOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||||
private XMLContext buildContext(String ormfile) throws IOException {
|
private XMLContext buildContext(String ormfile) throws IOException {
|
||||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( ormfile );
|
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( ormfile );
|
||||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
XMLContext context = new XMLContext( bootstrapContext );
|
||||||
context.addDocument( mappings );
|
context.addDocument( mappings );
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,10 +21,23 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14529")
|
@TestForIssue(jiraKey = "HHH-14529")
|
||||||
public class XMLContextTest {
|
public class XMLContextTest {
|
||||||
|
|
||||||
|
private BootstrapContextImpl bootstrapContext;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
bootstrapContext = new BootstrapContextImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
bootstrapContext.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAll() throws Exception {
|
public void testAll() throws Exception {
|
||||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||||
final XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
final XMLContext context = new XMLContext( bootstrapContext );
|
||||||
|
|
||||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( "org/hibernate/test/annotations/reflection/orm.xml" );
|
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||||
context.addDocument( mappings );
|
context.addDocument( mappings );
|
||||||
|
|
|
@ -18,6 +18,9 @@ import org.hibernate.internal.util.xml.XMLMappingHelper;
|
||||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
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.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -31,9 +34,21 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
protected JPAXMLOverriddenAnnotationReader reader;
|
protected JPAXMLOverriddenAnnotationReader reader;
|
||||||
|
|
||||||
|
private BootstrapContextImpl bootstrapContext;
|
||||||
|
|
||||||
protected Ejb3XmlTestCase() {
|
protected Ejb3XmlTestCase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
bootstrapContext = new BootstrapContextImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void destroy() {
|
||||||
|
bootstrapContext.close();
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||||
|
@ -52,7 +67,7 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
|
||||||
throws Exception {
|
throws Exception {
|
||||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||||
XMLContext xmlContext = getContext( ormResourceName );
|
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 {
|
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 {
|
protected XMLContext getContext(InputStream is, String resourceName) throws Exception {
|
||||||
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
XMLMappingHelper xmlHelper = new XMLMappingHelper();
|
||||||
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( is, resourceName );
|
JaxbEntityMappings mappings = xmlHelper.readOrmXmlMappings( is, resourceName );
|
||||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
XMLContext context = new XMLContext( bootstrapContext );
|
||||||
context.addDocument( mappings );
|
context.addDocument( mappings );
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.test.annotations.xml.ejb3;
|
||||||
|
|
||||||
import org.hibernate.InvalidMappingException;
|
import org.hibernate.InvalidMappingException;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||||
|
|
||||||
|
@ -21,9 +22,8 @@ import static org.junit.Assert.fail;
|
||||||
public class NonExistentOrmVersionTest extends BaseUnitTestCase {
|
public class NonExistentOrmVersionTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testNonExistentOrmVersion() {
|
public void testNonExistentOrmVersion() {
|
||||||
try {
|
try (BootstrapServiceRegistry serviceRegistry = new BootstrapServiceRegistryBuilder().build()) {
|
||||||
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
new MetadataSources( serviceRegistry )
|
||||||
new MetadataSources( builder.build() )
|
|
||||||
.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" )
|
.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
fail( "Expecting failure due to unsupported xsd version" );
|
fail( "Expecting failure due to unsupported xsd version" );
|
||||||
|
|
|
@ -32,7 +32,8 @@ public class XmlBindingChecker {
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
jaxbMarshaller.marshal( hbmMapping, bos );
|
jaxbMarshaller.marshal( hbmMapping, bos );
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream( bos.toByteArray() );
|
ByteArrayInputStream is = new ByteArrayInputStream( bos.toByteArray() );
|
||||||
ServiceRegistry sr = new StandardServiceRegistryBuilder().build();
|
try (ServiceRegistry sr = new StandardServiceRegistryBuilder().build()) {
|
||||||
new XmlMappingBinderAccess( sr ).bind( is );
|
new XmlMappingBinderAccess( sr ).bind( is );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@ public class NonRootEntityWithCacheAnnotationTest {
|
||||||
settings.put( Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
settings.put( Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||||
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
||||||
|
|
||||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
try (ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( settings )
|
.applySettings( settings )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@ public class NonRootEntityWithCacheAnnotationTest {
|
||||||
|
|
||||||
assertTrue( triggerable.wasTriggered() );
|
assertTrue( triggerable.wasTriggered() );
|
||||||
assertFalse( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
assertFalse( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||||
|
}
|
||||||
serviceRegistry.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class NonRootEntityWithCacheableAnnotationTest {
|
||||||
settings.put( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write" );
|
settings.put( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write" );
|
||||||
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
||||||
|
|
||||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
try (ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( settings )
|
.applySettings( settings )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000482" );
|
||||||
|
|
||||||
|
@ -68,8 +68,7 @@ public class NonRootEntityWithCacheableAnnotationTest {
|
||||||
assertTrue( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
assertTrue( metadata.getEntityBinding( AEntity.class.getName() ).isCached() );
|
||||||
|
|
||||||
assertFalse( triggerable.wasTriggered() );
|
assertFalse( triggerable.wasTriggered() );
|
||||||
|
}
|
||||||
serviceRegistry.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -32,18 +32,17 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testCachingExplicitlyDisabled() {
|
public void testCachingExplicitlyDisabled() {
|
||||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
try (final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" )
|
.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" )
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
assertThat( registry.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
assertThat( registry.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachingImplicitlyEnabledRegistered() {
|
public void testCachingImplicitlyEnabledRegistered() {
|
||||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||||
.getService( StrategySelector.class )
|
.getService( StrategySelector.class )
|
||||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||||
|
@ -56,12 +55,12 @@ public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCachingImplicitlyEnabledNoRegistered() {
|
public void testCachingImplicitlyEnabledNoRegistered() {
|
||||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
final Collection<Class<? extends RegionFactory>> implementors = bsr
|
||||||
.getService( StrategySelector.class )
|
.getService( StrategySelector.class )
|
||||||
.getRegisteredStrategyImplementors( RegionFactory.class );
|
.getRegisteredStrategyImplementors( RegionFactory.class );
|
||||||
|
@ -79,12 +78,12 @@ public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
assertThat( ssr.getService( RegionFactory.class ), instanceOf( NoCachingRegionFactory.class ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionsRegistered() {
|
public void testConnectionsRegistered() {
|
||||||
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
try (final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
|
||||||
.build();
|
.build()) {
|
||||||
|
|
||||||
final Collection<Class<? extends ConnectionProvider>> implementors = bsr
|
final Collection<Class<? extends ConnectionProvider>> implementors = bsr
|
||||||
.getService( StrategySelector.class )
|
.getService( StrategySelector.class )
|
||||||
.getRegisteredStrategyImplementors( ConnectionProvider.class );
|
.getRegisteredStrategyImplementors( ConnectionProvider.class );
|
||||||
|
@ -103,4 +102,5 @@ public class SingleRegisteredProviderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) );
|
assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,14 +42,13 @@ public class DelayedMixedAccessTest implements BeanContainer.LifecycleOptions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelayedMixedAccess() {
|
public void testDelayedMixedAccess() {
|
||||||
try ( final SeContainer cdiContainer = Helper.createSeContainer() ) {
|
try ( final SeContainer cdiContainer = Helper.createSeContainer();
|
||||||
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
||||||
|
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||||
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() )
|
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() )
|
||||||
.applySetting( AvailableSettings.DELAY_CDI_ACCESS, "true" )
|
.applySetting( AvailableSettings.DELAY_CDI_ACCESS, "true" )
|
||||||
.build();
|
.build() ) {
|
||||||
|
|
||||||
final BeanContainer beanContainer = CdiBeanContainerBuilder.fromBeanManagerReference(
|
final BeanContainer beanContainer = CdiBeanContainerBuilder.fromBeanManagerReference(
|
||||||
cdiContainer.getBeanManager(),
|
cdiContainer.getBeanManager(),
|
||||||
|
|
|
@ -46,20 +46,22 @@ public class ExtendedMixedAccessTest implements BeanContainer.LifecycleOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(TestingExtendedBeanManager extendedBeanManager) {
|
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.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||||
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, extendedBeanManager )
|
.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() ) {
|
try (final SeContainer cdiContainer = Helper.createSeContainer()) {
|
||||||
final BeanManager beanManager = cdiContainer.getBeanManager();
|
final BeanManager beanManager = cdiContainer.getBeanManager();
|
||||||
extendedBeanManager.notifyListenerReady( beanManager );
|
extendedBeanManager.notifyListenerReady( beanManager );
|
||||||
|
|
||||||
assertThat( beanManager, sameInstance( ( (CdiBeanContainerExtendedAccessImpl) beanContainer ).getUsableBeanManager() ) );
|
assertThat(
|
||||||
|
beanManager,
|
||||||
|
sameInstance( ( (CdiBeanContainerExtendedAccessImpl) beanContainer ).getUsableBeanManager() )
|
||||||
|
);
|
||||||
|
|
||||||
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(
|
final ContainedBean<HostedBean> hostedBean = beanContainer.getBean(
|
||||||
HostedBean.class,
|
HostedBean.class,
|
||||||
|
@ -84,6 +86,7 @@ public class ExtendedMixedAccessTest implements BeanContainer.LifecycleOptions {
|
||||||
extendedBeanManager.notifyListenerShuttingDown( beanManager );
|
extendedBeanManager.notifyListenerShuttingDown( beanManager );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUseCachedReferences() {
|
public boolean canUseCachedReferences() {
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class ImmediateMixedAccessTests implements BeanContainer.LifecycleOptions
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImmediateMixedAccess() {
|
public void testImmediateMixedAccess() {
|
||||||
try ( final SeContainer cdiContainer = Helper.createSeContainer() ) {
|
try ( final SeContainer cdiContainer = Helper.createSeContainer();
|
||||||
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
|
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build() ) {
|
||||||
|
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
|
||||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.persistence.Id;
|
||||||
import javax.persistence.PrimaryKeyJoinColumn;
|
import javax.persistence.PrimaryKeyJoinColumn;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AnnotationBinder;
|
import org.hibernate.cfg.AnnotationBinder;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
@ -38,15 +39,19 @@ public class AnnotationBinderTest {
|
||||||
|
|
||||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000137" );
|
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000137" );
|
||||||
|
|
||||||
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
|
|
||||||
Metadata metadata = new MetadataSources( srb.build() )
|
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||||
.addAnnotatedClass( InvalidPrimaryKeyJoinColumnAnnotationEntity.class )
|
.addAnnotatedClass( InvalidPrimaryKeyJoinColumnAnnotationEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
|
||||||
assertTrue( "Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered() );
|
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(),
|
assertTrue(
|
||||||
triggerable.triggerMessage().matches( ".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*" ) );
|
"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
|
@Entity
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
|
||||||
import org.hibernate.loader.MultipleBagFetchException;
|
import org.hibernate.loader.MultipleBagFetchException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -32,7 +31,7 @@ public class MultipleBagFetchTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityWithMultipleJoinFetchedBags() {
|
public void testEntityWithMultipleJoinFetchedBags() {
|
||||||
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
|
try (StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
|
|
||||||
Metadata metadata = new MetadataSources( standardRegistry )
|
Metadata metadata = new MetadataSources( standardRegistry )
|
||||||
.addAnnotatedClass( Post.class )
|
.addAnnotatedClass( Post.class )
|
||||||
|
@ -47,6 +46,7 @@ public class MultipleBagFetchTest {
|
||||||
catch (MultipleBagFetchException expected) {
|
catch (MultipleBagFetchException expected) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Entity(name = "Post")
|
@Entity(name = "Post")
|
||||||
@Table(name = "post")
|
@Table(name = "post")
|
||||||
|
|
|
@ -99,8 +99,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicOperation() {
|
public void testBasicOperation() {
|
||||||
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
SimpleValue simpleValue = new SimpleValue( new MetadataBuildingContextTestingImpl() );
|
SimpleValue simpleValue = new SimpleValue( new MetadataBuildingContextTestingImpl( serviceRegistry ) );
|
||||||
simpleValue.setJpaAttributeConverterDescriptor(
|
simpleValue.setJpaAttributeConverterDescriptor(
|
||||||
new InstanceBasedConverterDescriptor(
|
new InstanceBasedConverterDescriptor(
|
||||||
new StringClobConverter(),
|
new StringClobConverter(),
|
||||||
|
@ -117,7 +117,11 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
assertEquals(
|
||||||
|
Dialect.getDialect().remapSqlTypeDescriptor( ClobTypeDescriptor.CLOB_BINDING ).getSqlType(),
|
||||||
|
sqlTypeDescriptor.getSqlType()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -151,24 +155,24 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( Tester.class )
|
.addAnnotatedClass( Tester.class )
|
||||||
.getMetadataBuilder()
|
.getMetadataBuilder()
|
||||||
.applyAttributeConverter( StringClobConverter.class, true )
|
.applyAttributeConverter( StringClobConverter.class, true )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
||||||
Property nameProp = tester.getProperty( "name" );
|
final Property nameProp = tester.getProperty( "name" );
|
||||||
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
final SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
||||||
Type type = nameValue.getType();
|
final Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
assertTyping( BasicType.class, type );
|
assertTyping( BasicType.class, type );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
||||||
fail( "AttributeConverter not applied" );
|
fail( "AttributeConverter not applied" );
|
||||||
}
|
}
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
final AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
final SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -196,9 +200,9 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
||||||
fail( "AttributeConverter not applied" );
|
fail( "AttributeConverter not applied" );
|
||||||
}
|
}
|
||||||
AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
|
final AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
final SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -242,9 +246,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||||
|
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save( new Tester4( 1L, "steve", 200 ) );
|
session.save( new Tester4( 1L, "steve", 200 ) );
|
||||||
|
@ -274,9 +276,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -285,23 +284,23 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( Tester5.class )
|
.addAnnotatedClass( Tester5.class )
|
||||||
.getMetadataBuilder()
|
.getMetadataBuilder()
|
||||||
.applyAttributeConverter( IntegerToVarcharConverter.class, true )
|
.applyAttributeConverter( IntegerToVarcharConverter.class, true )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PersistentClass tester = metadata.getEntityBinding( Tester5.class.getName() );
|
final PersistentClass tester = metadata.getEntityBinding( Tester5.class.getName() );
|
||||||
Property codeProp = tester.getProperty( "code" );
|
final Property codeProp = tester.getProperty( "code" );
|
||||||
SimpleValue nameValue = (SimpleValue) codeProp.getValue();
|
final SimpleValue nameValue = (SimpleValue) codeProp.getValue();
|
||||||
Type type = nameValue.getType();
|
Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
||||||
fail( "AttributeConverter not applied to primitive type field: code(int)" );
|
fail( "AttributeConverter not applied to primitive type field: code(int)" );
|
||||||
}
|
}
|
||||||
AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
|
final AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
|
||||||
assertSame( IntegerTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertSame( IntegerTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
final SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
||||||
assertEquals( VarcharTypeDescriptor.INSTANCE.getSqlType(), sqlTypeDescriptor.getSqlType() );
|
assertEquals( VarcharTypeDescriptor.INSTANCE.getSqlType(), sqlTypeDescriptor.getSqlType() );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -317,9 +316,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||||
|
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save( new IrrelevantInstantEntity( 1L ) );
|
session.save( new IrrelevantInstantEntity( 1L ) );
|
||||||
|
@ -340,9 +337,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -354,9 +348,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
cfg.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
cfg.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||||
|
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
|
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save( new Tester4( 1L, "George", 150, ConvertibleEnum.DEFAULT ) );
|
session.save( new Tester4( 1L, "George", 150, ConvertibleEnum.DEFAULT ) );
|
||||||
|
@ -386,9 +378,6 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -406,16 +395,16 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// first lets validate that the converter was applied...
|
// first lets validate that the converter was applied...
|
||||||
PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
|
final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
|
||||||
Property nameProp = tester.getProperty( "convertibleEnum" );
|
final Property nameProp = tester.getProperty( "convertibleEnum" );
|
||||||
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
final SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
||||||
Type type = nameValue.getType();
|
final Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
assertTyping( BasicType.class, type );
|
assertTyping( BasicType.class, type );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
||||||
fail( "AttributeConverter not applied" );
|
fail( "AttributeConverter not applied" );
|
||||||
}
|
}
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
final AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
||||||
assertTyping( EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor() );
|
assertTyping( EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor() );
|
||||||
if (metadata.getDatabase().getDialect() instanceof HANACloudColumnStoreDialect) {
|
if (metadata.getDatabase().getDialect() instanceof HANACloudColumnStoreDialect) {
|
||||||
assertEquals( Types.NVARCHAR, basicType.getSqlTypeDescriptor().getSqlType() );
|
assertEquals( Types.NVARCHAR, basicType.getSqlTypeDescriptor().getSqlType() );
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*/
|
||||||
package org.hibernate.test.converter.inheritence;
|
package org.hibernate.test.converter.inheritence;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
|
||||||
import org.hibernate.cfg.AttributeConverterDefinition;
|
import org.hibernate.cfg.AttributeConverterDefinition;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.persistence.ManyToOne;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -35,16 +36,18 @@ public class HHH14230 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
Metadata metadata = new MetadataSources(new StandardServiceRegistryBuilder().build())
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
.addAnnotatedClass(TestEntity.class).buildMetadata();
|
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||||
Table table = StreamSupport.stream(metadata.getDatabase().getNamespaces().spliterator(), false)
|
.addAnnotatedClass( TestEntity.class ).buildMetadata();
|
||||||
.flatMap(namespace -> namespace.getTables().stream())
|
Table table = StreamSupport.stream( metadata.getDatabase().getNamespaces().spliterator(), false )
|
||||||
.filter(t -> t.getName().equals(TABLE_NAME)).findFirst().orElse(null);
|
.flatMap( namespace -> namespace.getTables().stream() )
|
||||||
assertNotNull(table);
|
.filter( t -> t.getName().equals( TABLE_NAME ) ).findFirst().orElse( null );
|
||||||
assertEquals(1, table.getForeignKeys().size());
|
assertNotNull( table );
|
||||||
|
assertEquals( 1, table.getForeignKeys().size() );
|
||||||
|
|
||||||
// ClassCastException before HHH-14230
|
// ClassCastException before HHH-14230
|
||||||
assertTrue(table.getForeignKeys().keySet().iterator().next().toString().contains(JOIN_COLUMN_NAME));
|
assertTrue( table.getForeignKeys().keySet().iterator().next().toString().contains( JOIN_COLUMN_NAME ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -46,10 +46,11 @@ public class DefaultConstraintModeTest extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testForeignKeyCreation(boolean created) {
|
private void testForeignKeyCreation(boolean created) {
|
||||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
try (StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||||
.applySetting(Environment.HBM2DDL_DEFAULT_CONSTRAINT_MODE, created ? "CONSTRAINT" : "NO_CONSTRAINT").build();
|
.applySetting(Environment.HBM2DDL_DEFAULT_CONSTRAINT_MODE, created ? "CONSTRAINT" : "NO_CONSTRAINT").build()) {
|
||||||
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
|
Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata();
|
||||||
assertThat(findTable(metadata, TABLE_NAME).getForeignKeys().isEmpty(), is(!created));
|
assertThat( findTable( metadata, TABLE_NAME ).getForeignKeys().isEmpty(), is( !created ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Table findTable(Metadata metadata, String tableName) {
|
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.annotations.OnDeleteAction;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -44,11 +45,13 @@ public class OneToManyBidirectionalForeignKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForeignKeyShouldNotBeCreated() {
|
public void testForeignKeyShouldNotBeCreated() {
|
||||||
Metadata metadata = new MetadataSources(new StandardServiceRegistryBuilder().build())
|
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
.addAnnotatedClass(PlainTreeEntity.class).addAnnotatedClass(TreeEntityWithOnDelete.class)
|
Metadata metadata = new MetadataSources( serviceRegistry )
|
||||||
|
.addAnnotatedClass( PlainTreeEntity.class ).addAnnotatedClass( TreeEntityWithOnDelete.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
assertTrue(findTable(metadata, TABLE_NAME_PLAIN).getForeignKeys().isEmpty());
|
assertTrue( findTable( metadata, TABLE_NAME_PLAIN ).getForeignKeys().isEmpty() );
|
||||||
assertFalse(findTable(metadata, TABLE_NAME_WITH_ON_DELETE).getForeignKeys().isEmpty());
|
assertFalse( findTable( metadata, TABLE_NAME_WITH_ON_DELETE ).getForeignKeys().isEmpty() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Table findTable(Metadata metadata, String tableName) {
|
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.Metadata;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.engine.jdbc.ReaderInputStream;
|
import org.hibernate.engine.jdbc.ReaderInputStream;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
|
@ -28,14 +29,16 @@ public class ClassCommentTest {
|
||||||
public void testClassComment() {
|
public void testClassComment() {
|
||||||
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder()
|
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder()
|
||||||
.applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
|
.applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
|
||||||
MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build());
|
try (StandardServiceRegistry serviceRegistry = serviceRegistryBuilder.build()) {
|
||||||
metadataSources.addInputStream(new ReaderInputStream(new StringReader(CLASS_COMMENT_HBM_XML)));
|
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||||
|
metadataSources.addInputStream( new ReaderInputStream( new StringReader( CLASS_COMMENT_HBM_XML ) ) );
|
||||||
Metadata metadata = metadataSources.buildMetadata();
|
Metadata metadata = metadataSources.buildMetadata();
|
||||||
PersistentClass pc = metadata.getEntityBinding("org.hibernate.test.hbm.Foo");
|
PersistentClass pc = metadata.getEntityBinding( "org.hibernate.test.hbm.Foo" );
|
||||||
Assert.assertNotNull(pc);
|
Assert.assertNotNull( pc );
|
||||||
Table table = pc.getTable();
|
Table table = pc.getTable();
|
||||||
Assert.assertNotNull(table);
|
Assert.assertNotNull( table );
|
||||||
Assert.assertEquals("This is class 'Foo' with property 'bar'.", table.getComment());
|
Assert.assertEquals( "This is class 'Foo' with property 'bar'.", table.getComment() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
||||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||||
ssrb.applySetting( AvailableSettings.BEAN_CONTAINER, beanContainer );
|
ssrb.applySetting( AvailableSettings.BEAN_CONTAINER, beanContainer );
|
||||||
|
|
||||||
final StandardServiceRegistry ssr = ssrb.build();
|
try (final StandardServiceRegistry ssr = ssrb.build()) {
|
||||||
final Metadata metadata = new MetadataSources( ssr )
|
final Metadata metadata = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( Entity1.class )
|
.addAnnotatedClass( Entity1.class )
|
||||||
.addAnnotatedClass( Entity2.class )
|
.addAnnotatedClass( Entity2.class )
|
||||||
|
@ -75,14 +75,18 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
|
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
|
||||||
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
|
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
|
||||||
final IdentifierGenerator generator1 = entityBinding1.getRootClass().getIdentifier().createIdentifierGenerator(
|
final IdentifierGenerator generator1 = entityBinding1.getRootClass()
|
||||||
|
.getIdentifier()
|
||||||
|
.createIdentifierGenerator(
|
||||||
generatorFactory,
|
generatorFactory,
|
||||||
new H2Dialect(),
|
new H2Dialect(),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
entityBinding1.getRootClass()
|
entityBinding1.getRootClass()
|
||||||
);
|
);
|
||||||
final IdentifierGenerator generator2 = entityBinding2.getRootClass().getIdentifier().createIdentifierGenerator(
|
final IdentifierGenerator generator2 = entityBinding2.getRootClass()
|
||||||
|
.getIdentifier()
|
||||||
|
.createIdentifierGenerator(
|
||||||
generatorFactory,
|
generatorFactory,
|
||||||
new H2Dialect(),
|
new H2Dialect(),
|
||||||
"",
|
"",
|
||||||
|
@ -90,12 +94,15 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase {
|
||||||
entityBinding2.getRootClass()
|
entityBinding2.getRootClass()
|
||||||
);
|
);
|
||||||
|
|
||||||
then( beanContainer ).should( times( 2 ) ).getBean( same( TestIdentifierGenerator.class ), any( LifecycleOptions.class ),
|
then( beanContainer ).should( times( 2 ) ).getBean( same( TestIdentifierGenerator.class ),
|
||||||
same( FallbackBeanInstanceProducer.INSTANCE ) );
|
any( LifecycleOptions.class ),
|
||||||
|
same( FallbackBeanInstanceProducer.INSTANCE )
|
||||||
|
);
|
||||||
|
|
||||||
assertThat( generator1, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
assertThat( generator1, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||||
assertThat( generator2, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
assertThat( generator2, is( instanceOf( TestIdentifierGenerator.class ) ) );
|
||||||
assertThat( generator1 == generator2, is( false ) ); // should not be same instance
|
assertThat( generator1 == generator2, is( false ) ); // should not be same instance
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
public class GeneratedValueTests extends BaseUnitTestCase {
|
public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void baseline() {
|
public void baseline() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ExplicitGeneratorEntity.class )
|
.addAnnotatedClass( ExplicitGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -62,7 +62,10 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
(RootClass) entityMapping
|
(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" ) );
|
||||||
|
|
||||||
|
@ -70,12 +73,13 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 500 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitSequenceGenerator() {
|
public void testImplicitSequenceGenerator() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||||
.applySetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false" )
|
.applySetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false" )
|
||||||
.build();
|
.build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -88,7 +92,10 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
(RootClass) entityMapping
|
(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
|
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
|
||||||
// default (hibernate_sequence) should be used
|
// default (hibernate_sequence) should be used
|
||||||
|
@ -98,10 +105,11 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitSequenceGeneratorGeneratorName() {
|
public void testImplicitSequenceGeneratorGeneratorName() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
.addAnnotatedClass( ImplicitSequenceGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -114,7 +122,10 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
(RootClass) entityMapping
|
(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
|
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name
|
||||||
// should be used as the default instead.
|
// should be used as the default instead.
|
||||||
|
@ -124,6 +135,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitSequenceGeneratorImplicitName() {
|
public void testExplicitSequenceGeneratorImplicitName() {
|
||||||
|
@ -152,11 +164,12 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitSequenceGeneratorImplicitNamePreferGeneratorName() {
|
public void testExplicitSequenceGeneratorImplicitNamePreferGeneratorName() {
|
||||||
// this should be the default behavior
|
// this should be the default behavior
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ExplicitSequenceGeneratorImplicitNameEntity.class )
|
.addAnnotatedClass( ExplicitSequenceGeneratorImplicitNameEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
|
final PersistentClass entityMapping = bootModel.getEntityBinding(
|
||||||
|
ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
|
||||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||||
bootModel.getIdentifierGeneratorFactory(),
|
bootModel.getIdentifierGeneratorFactory(),
|
||||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||||
|
@ -165,7 +178,10 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
(RootClass) entityMapping
|
(RootClass) entityMapping
|
||||||
);
|
);
|
||||||
|
|
||||||
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping( SequenceStyleGenerator.class, generator );
|
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(
|
||||||
|
SequenceStyleGenerator.class,
|
||||||
|
generator
|
||||||
|
);
|
||||||
// all the JPA defaults since they were not defined
|
// all the JPA defaults since they were not defined
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 100 ) );
|
||||||
|
@ -179,14 +195,15 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
sequence,
|
sequence,
|
||||||
bootModel
|
bootModel
|
||||||
);
|
);
|
||||||
assertThat( sqlCreateStrings.length, is(1) );
|
assertThat( sqlCreateStrings.length, is( 1 ) );
|
||||||
final String cmd = sqlCreateStrings[0].toLowerCase();
|
final String cmd = sqlCreateStrings[0].toLowerCase();
|
||||||
assertTrue( cmd.startsWith( "create sequence my_db_sequence start with 100 increment by 500" ) );
|
assertTrue( cmd.startsWith( "create sequence my_db_sequence start with 100 increment by 500" ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitTableGenerator() {
|
public void testImplicitTableGenerator() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ImplicitTableGeneratorEntity.class )
|
.addAnnotatedClass( ImplicitTableGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -207,10 +224,11 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||||
assertThat( tableGenerator.getIncrementSize(), is( 50 ) );
|
assertThat( tableGenerator.getIncrementSize(), is( 50 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitTableGeneratorImplicitName() {
|
public void testExplicitTableGeneratorImplicitName() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ExplicitTableGeneratorImplicitNameEntity.class )
|
.addAnnotatedClass( ExplicitTableGeneratorImplicitNameEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -231,10 +249,11 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitTableGenerator() {
|
public void testExplicitTableGenerator() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ExplicitTableGeneratorEntity.class )
|
.addAnnotatedClass( ExplicitTableGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -257,10 +276,11 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
// assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
// assertThat( tableGenerator.getInitialValue(), is( 1 ) );
|
||||||
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
assertThat( tableGenerator.getIncrementSize(), is( 25 ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitIncrementGenerator() {
|
public void testExplicitIncrementGenerator() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
|
.addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -275,10 +295,11 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertTyping( IncrementGenerator.class, generator );
|
assertTyping( IncrementGenerator.class, generator );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitIncrementGenerator() {
|
public void testImplicitIncrementGenerator() {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build()) {
|
||||||
final Metadata bootModel = new MetadataSources( ssr )
|
final Metadata bootModel = new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( ImplicitIncrementGeneratorEntity.class )
|
.addAnnotatedClass( ImplicitIncrementGeneratorEntity.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
|
@ -293,6 +314,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
assertTyping( IncrementGenerator.class, generator );
|
assertTyping( IncrementGenerator.class, generator );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public static class ExplicitGeneratorEntity {
|
public static class ExplicitGeneratorEntity {
|
||||||
|
@ -320,7 +342,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
||||||
@Entity
|
@Entity
|
||||||
public static class ExplicitSequenceGeneratorImplicitNameEntity {
|
public static class ExplicitSequenceGeneratorImplicitNameEntity {
|
||||||
/**
|
/**
|
||||||
* This entity does not have explicit {@link SequenceGenerator} defined
|
* This entity does have explicit {@link SequenceGenerator} defined
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "my_db_sequence" )
|
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "my_db_sequence" )
|
||||||
|
|
|
@ -19,6 +19,7 @@ import javax.persistence.Version;
|
||||||
|
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
@ -140,15 +141,20 @@ public class CachingWithSecondaryTablesTests extends BaseUnitTestCase {
|
||||||
settings.put( AvailableSettings.JPA_CACHING_COMPLIANCE, "true" );
|
settings.put( AvailableSettings.JPA_CACHING_COMPLIANCE, "true" );
|
||||||
}
|
}
|
||||||
|
|
||||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
|
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( settings );
|
.applySettings( settings )
|
||||||
|
.build();
|
||||||
return (SessionFactoryImplementor) new MetadataSources( ssrb.build() )
|
try {
|
||||||
|
return (SessionFactoryImplementor) new MetadataSources( serviceRegistry )
|
||||||
.addAnnotatedClass( Person.class )
|
.addAnnotatedClass( Person.class )
|
||||||
.addAnnotatedClass( VersionedPerson.class)
|
.addAnnotatedClass( VersionedPerson.class )
|
||||||
.buildMetadata()
|
.buildMetadata()
|
||||||
.buildSessionFactory();
|
.buildSessionFactory();
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
serviceRegistry.close();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -63,7 +63,8 @@ public class ValueVisitorTest extends BaseUnitTestCase {
|
||||||
final RootClass rootClass = new RootClass( metadataBuildingContext );
|
final RootClass rootClass = new RootClass( metadataBuildingContext );
|
||||||
|
|
||||||
ValueVisitor vv = new ValueVisitorValidator();
|
ValueVisitor vv = new ValueVisitorValidator();
|
||||||
MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl();
|
try ( StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
|
||||||
|
MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl( serviceRegistry );
|
||||||
new Any( metadataBuildingContext, tbl ).accept( vv );
|
new Any( metadataBuildingContext, tbl ).accept( vv );
|
||||||
new Array( metadataBuildingContext, rootClass ).accept( vv );
|
new Array( metadataBuildingContext, rootClass ).accept( vv );
|
||||||
new Bag( metadataBuildingContext, rootClass ).accept( vv );
|
new Bag( metadataBuildingContext, rootClass ).accept( vv );
|
||||||
|
@ -79,6 +80,7 @@ public class ValueVisitorTest extends BaseUnitTestCase {
|
||||||
new Set( metadataBuildingContext, rootClass ).accept( vv );
|
new Set( metadataBuildingContext, rootClass ).accept( vv );
|
||||||
new SimpleValue( metadataBuildingContext ).accept( vv );
|
new SimpleValue( metadataBuildingContext ).accept( vv );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static public class ValueVisitorValidator implements ValueVisitor {
|
static public class ValueVisitorValidator implements ValueVisitor {
|
||||||
|
|
||||||
|
|
|
@ -68,16 +68,17 @@ public class DiscriminatorMultiTenancyTest extends BaseUnitTestCase {
|
||||||
.applySettings(settings)
|
.applySettings(settings)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MetadataSources ms = new MetadataSources(serviceRegistry);
|
try {
|
||||||
ms.addAnnotatedClass(Customer.class);
|
MetadataSources ms = new MetadataSources( serviceRegistry );
|
||||||
|
ms.addAnnotatedClass( Customer.class );
|
||||||
|
|
||||||
Metadata metadata = ms.buildMetadata();
|
Metadata metadata = ms.buildMetadata();
|
||||||
final PersistentClass customerMapping = metadata.getEntityBinding( Customer.class.getName() );
|
final PersistentClass customerMapping = metadata.getEntityBinding( Customer.class.getName() );
|
||||||
customerMapping.setCached( true );
|
customerMapping.setCached( true );
|
||||||
((RootClass) customerMapping ).setCacheConcurrencyStrategy( "read-write");
|
( (RootClass) customerMapping ).setCacheConcurrencyStrategy( "read-write" );
|
||||||
|
|
||||||
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
|
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
|
||||||
tool.injectServices(serviceRegistry);
|
tool.injectServices( serviceRegistry );
|
||||||
|
|
||||||
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ public class DiscriminatorMultiTenancyTest extends BaseUnitTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
new SchemaDropperImpl(serviceRegistry).doDrop(
|
new SchemaDropperImpl( serviceRegistry ).doDrop(
|
||||||
metadata,
|
metadata,
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
settings,
|
settings,
|
||||||
|
@ -97,7 +98,7 @@ public class DiscriminatorMultiTenancyTest extends BaseUnitTestCase {
|
||||||
target
|
target
|
||||||
);
|
);
|
||||||
|
|
||||||
new SchemaCreatorImpl(serviceRegistry).doCreation(
|
new SchemaCreatorImpl( serviceRegistry ).doCreation(
|
||||||
metadata,
|
metadata,
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
settings,
|
settings,
|
||||||
|
@ -111,6 +112,11 @@ public class DiscriminatorMultiTenancyTest extends BaseUnitTestCase {
|
||||||
sessionFactory = (SessionFactoryImplementor) sfb.build();
|
sessionFactory = (SessionFactoryImplementor) sfb.build();
|
||||||
currentTenantResolver.setHibernateBooted();
|
currentTenantResolver.setHibernateBooted();
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
serviceRegistry.close();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
|
|
@ -75,8 +75,7 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
SessionFactory sf = cfg.buildSessionFactory( ssr );
|
try (SessionFactory sf = cfg.buildSessionFactory();) {
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
try {
|
try {
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
@ -93,9 +92,6 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
@ -112,8 +108,7 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
||||||
cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml() )
|
cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml() )
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.build();
|
.build();
|
||||||
SessionFactory sf = cfg.buildSessionFactory( ssr );
|
try (SessionFactory sf = cfg.buildSessionFactory( ssr )) {
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
try {
|
try {
|
||||||
session.getTransaction().begin();
|
session.getTransaction().begin();
|
||||||
|
@ -130,9 +125,6 @@ public class SchemaUpdateSchemaNameTest extends BaseUnitTestCase {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
|
|
@ -31,13 +31,13 @@ public class InheritanceSchemaUpdateTest extends BaseUnitTestCase {
|
||||||
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
|
public void testBidirectionalOneToManyReferencingRootEntity() throws Exception {
|
||||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
|
|
||||||
|
try {
|
||||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( Step.class )
|
.addAnnotatedClass( Step.class )
|
||||||
.addAnnotatedClass( GroupStep.class )
|
.addAnnotatedClass( GroupStep.class )
|
||||||
.buildMetadata();
|
.buildMetadata();
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
|
|
||||||
try {
|
|
||||||
try {
|
try {
|
||||||
new SchemaUpdate().execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
new SchemaUpdate().execute( EnumSet.of( TargetType.DATABASE ), metadata );
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,8 +123,7 @@ public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
||||||
.addAnnotatedClass( Employee.class )
|
.addAnnotatedClass( Employee.class )
|
||||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||||
cfg.addAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
cfg.addAuxiliaryDatabaseObject( new ProcedureDefinition() );
|
||||||
SessionFactory sf = cfg.buildSessionFactory();
|
try (SessionFactory sf = cfg.buildSessionFactory()) {
|
||||||
try {
|
|
||||||
Session session = sf.openSession();
|
Session session = sf.openSession();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
|
|
||||||
|
@ -137,8 +136,5 @@ public class StoredProcedureResultSetMappingTest extends BaseUnitTestCase {
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
sf.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,13 +145,13 @@ public class StatsTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryStatGathering() {
|
public void testQueryStatGathering() {
|
||||||
SessionFactory sf = buildBaseConfiguration()
|
try (SessionFactory sf = buildBaseConfiguration()
|
||||||
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
||||||
.buildSessionFactory();
|
.buildSessionFactory()) {
|
||||||
|
|
||||||
Session s = sf.openSession();
|
Session s = sf.openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
fillDb(s);
|
fillDb( s );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ public class StatsTest extends BaseUnitTestCase {
|
||||||
cleanDb( s );
|
cleanDb( s );
|
||||||
tx.commit();
|
tx.commit();
|
||||||
s.close();
|
s.close();
|
||||||
sf.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Continent fillDb(Session s) {
|
private Continent fillDb(Session s) {
|
||||||
|
|
|
@ -53,12 +53,17 @@ public class DropSchemaDuringJtaTxnTest extends BaseUnitTestCase {
|
||||||
settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
|
settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
|
||||||
|
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings( settings ).build();
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings( settings ).build();
|
||||||
|
try {
|
||||||
return new MetadataSources( ssr )
|
return new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( TestEntity.class )
|
.addAnnotatedClass( TestEntity.class )
|
||||||
.buildMetadata()
|
.buildMetadata()
|
||||||
.buildSessionFactory();
|
.buildSessionFactory();
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
ssr.close();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Entity( name = "TestEntity" )
|
@Entity( name = "TestEntity" )
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe
|
||||||
private static final MockSettings MOCK_SETTINGS = Mockito.withSettings()
|
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.
|
.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 );
|
.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 );
|
.defaultAnswer( org.mockito.Answers.CALLS_REAL_METHODS );
|
||||||
// We must keep around the mocked connections, otherwise they are garbage collected and trigger finalizers
|
// 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
|
// Since we use CALLS_REAL_METHODS this might close underlying IO resources which makes other objects unusable
|
||||||
|
@ -69,8 +69,8 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe
|
||||||
* When you really need to verify invocations, set the relevant constructor parameter to true.
|
* When you really need to verify invocations, set the relevant constructor parameter to true.
|
||||||
*/
|
*/
|
||||||
public PreparedStatementSpyConnectionProvider(boolean allowMockVerificationOnStatements, boolean allowMockVerificationOnConnections) {
|
public PreparedStatementSpyConnectionProvider(boolean allowMockVerificationOnStatements, boolean allowMockVerificationOnConnections) {
|
||||||
this.settingsForStatements = allowMockVerificationOnStatements ? VERIFIEABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
this.settingsForStatements = allowMockVerificationOnStatements ? VERIFIABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||||
this.settingsForConnections = allowMockVerificationOnConnections ? VERIFIEABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
this.settingsForConnections = allowMockVerificationOnConnections ? VERIFIABLE_MOCK_SETTINGS : MOCK_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection actualConnection() throws SQLException {
|
protected Connection actualConnection() throws SQLException {
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
|
||||||
|
|
||||||
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||||
try {
|
try {
|
||||||
config.buildSessionFactory( serviceRegistry );
|
config.buildSessionFactory( serviceRegistry ).close();
|
||||||
Assert.fail( "MappingException expected" );
|
Assert.fail( "MappingException expected" );
|
||||||
}
|
}
|
||||||
catch ( MappingException e ) {
|
catch ( MappingException e ) {
|
||||||
|
|
|
@ -105,9 +105,14 @@ public class TestHelper {
|
||||||
additionalSettings.accept( ssrb );
|
additionalSettings.accept( ssrb );
|
||||||
|
|
||||||
final StandardServiceRegistry ssr = ssrb.build();
|
final StandardServiceRegistry ssr = ssrb.build();
|
||||||
|
try {
|
||||||
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
|
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
ssr.close();
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() {
|
public static StandardServiceRegistryBuilder getStandardServiceRegistryBuilder() {
|
||||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
|
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
|
||||||
|
|
|
@ -33,11 +33,10 @@ import org.jboss.jandex.IndexView;
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
public class BootstrapContextImpl implements BootstrapContext {
|
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();
|
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
|
||||||
MetadataBuildingOptions buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
MetadataBuildingOptions buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
||||||
|
|
||||||
|
@ -143,4 +142,9 @@ public class BootstrapContextImpl implements BootstrapContext {
|
||||||
public void release() {
|
public void release() {
|
||||||
delegate.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 ObjectNameNormalizer objectNameNormalizer;
|
||||||
|
|
||||||
public MetadataBuildingContextTestingImpl() {
|
|
||||||
this( new StandardServiceRegistryBuilder().build() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetadataBuildingContextTestingImpl(StandardServiceRegistry serviceRegistry) {
|
public MetadataBuildingContextTestingImpl(StandardServiceRegistry serviceRegistry) {
|
||||||
buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry );
|
||||||
bootstrapContext = new BootstrapContextImpl( serviceRegistry, buildingOptions );
|
bootstrapContext = new BootstrapContextImpl( serviceRegistry, buildingOptions );
|
||||||
|
|
|
@ -112,17 +112,35 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
protected void buildSessionFactory(Consumer<Configuration> configurationAdapter) {
|
protected void buildSessionFactory(Consumer<Configuration> configurationAdapter) {
|
||||||
// for now, build the configuration to get all the property settings
|
// for now, build the configuration to get all the property settings
|
||||||
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
BootstrapServiceRegistry bootRegistry = null;
|
||||||
|
try {
|
||||||
|
bootRegistry = buildBootstrapServiceRegistry();
|
||||||
configuration = constructAndConfigureConfiguration( bootRegistry );
|
configuration = constructAndConfigureConfiguration( bootRegistry );
|
||||||
if ( configurationAdapter != null ) {
|
if ( configurationAdapter != null ) {
|
||||||
configurationAdapter.accept(configuration);
|
configurationAdapter.accept( configuration );
|
||||||
}
|
}
|
||||||
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||||
// this is done here because Configuration does not currently support 4.0 xsd
|
// this is done here because Configuration does not currently support 4.0 xsd
|
||||||
afterConstructAndConfigureConfiguration( configuration );
|
afterConstructAndConfigureConfiguration( configuration );
|
||||||
sessionFactory = ( SessionFactoryImplementor ) configuration.buildSessionFactory( serviceRegistry );
|
sessionFactory = (SessionFactoryImplementor) configuration.buildSessionFactory( serviceRegistry );
|
||||||
afterSessionFactoryBuilt();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void rebuildSessionFactory() {
|
protected void rebuildSessionFactory() {
|
||||||
rebuildSessionFactory( null );
|
rebuildSessionFactory( null );
|
||||||
|
@ -277,6 +295,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
|
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
|
||||||
|
try {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.putAll( configuration.getProperties() );
|
properties.putAll( configuration.getProperties() );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
|
@ -289,6 +308,13 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
prepareBasicRegistryBuilder( registryBuilder );
|
prepareBasicRegistryBuilder( registryBuilder );
|
||||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||||
}
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
if ( bootRegistry != null ) {
|
||||||
|
bootRegistry.close();
|
||||||
|
}
|
||||||
|
throw t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,8 +132,8 @@ public class ViburDBCPConnectionProviderTest extends BaseCoreFunctionalTestCase
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static void executeAndVerifySelect(Session session) {
|
private static void executeAndVerifySelect(Session session) {
|
||||||
List<Actor> list = session.createQuery("from Actor where firstName = ?0")
|
List<Actor> list = session.createQuery("from Actor where firstName = ?1")
|
||||||
.setParameter(0, "CHRISTIAN").list();
|
.setParameter(1, "CHRISTIAN").list();
|
||||||
|
|
||||||
Set<String> expectedLastNames = new HashSet<>(Arrays.asList("GABLE", "AKROYD", "NEESON"));
|
Set<String> expectedLastNames = new HashSet<>(Arrays.asList("GABLE", "AKROYD", "NEESON"));
|
||||||
assertEquals(expectedLastNames.size(), list.size());
|
assertEquals(expectedLastNames.size(), list.size());
|
||||||
|
|
Loading…
Reference in New Issue