Small test fixes. Fix unwraps and mutation strategy configuration
This commit is contained in:
parent
9fa2671cbc
commit
a3920e5892
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.internal;
|
package org.hibernate.boot.internal;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -32,6 +33,7 @@ import org.hibernate.boot.SchemaAutoTooling;
|
||||||
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
|
import org.hibernate.boot.registry.selector.spi.StrategySelectionException;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.boot.spi.BootstrapContext;
|
import org.hibernate.boot.spi.BootstrapContext;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
|
@ -42,6 +44,7 @@ import org.hibernate.cache.spi.TimestampsCacheFactory;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.BaselineSessionEventsListenerBuilder;
|
import org.hibernate.cfg.BaselineSessionEventsListenerBuilder;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.config.internal.ConfigurationServiceImpl;
|
import org.hibernate.engine.config.internal.ConfigurationServiceImpl;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
|
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
|
||||||
|
@ -601,16 +604,42 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection Convert2Lambda
|
return strategySelector.resolveStrategy(
|
||||||
return strategySelector.resolveDefaultableStrategy(
|
|
||||||
SqmMultiTableMutationStrategy.class,
|
SqmMultiTableMutationStrategy.class,
|
||||||
strategyName,
|
strategyName,
|
||||||
new Callable<SqmMultiTableMutationStrategy>() {
|
(SqmMultiTableMutationStrategy) null,
|
||||||
@Override
|
strategyClass -> {
|
||||||
public SqmMultiTableMutationStrategy call() throws Exception {
|
Constructor<SqmMultiTableMutationStrategy> dialectConstructor = null;
|
||||||
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
Constructor<SqmMultiTableMutationStrategy> emptyConstructor = null;
|
||||||
return (SqmMultiTableMutationStrategy) classLoaderService.classForName( strategyName ).newInstance();
|
// todo (6.0) : formalize the allowed constructor parameterizations
|
||||||
|
for ( Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors() ) {
|
||||||
|
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
|
||||||
|
if ( parameterTypes.length == 1 && parameterTypes[0] == Dialect.class ) {
|
||||||
|
dialectConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ( parameterTypes.length == 0 ) {
|
||||||
|
emptyConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ( dialectConstructor != null ) {
|
||||||
|
return dialectConstructor.newInstance(
|
||||||
|
serviceRegistry.getService( JdbcServices.class ).getDialect()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if ( emptyConstructor != null ) {
|
||||||
|
return emptyConstructor.newInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new StrategySelectionException(
|
||||||
|
String.format( "Could not instantiate named strategy class [%s]", strategyClass.getName() ),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException( "Cannot instantiate the class [" + strategyClass.getName() + "] because it does not have a constructor that accepts a dialect or an empty constructor!" );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.naming.Reference;
|
import javax.naming.Reference;
|
||||||
import javax.naming.StringRefAddr;
|
import javax.naming.StringRefAddr;
|
||||||
|
|
||||||
|
import jakarta.persistence.Cache;
|
||||||
import jakarta.persistence.EntityGraph;
|
import jakarta.persistence.EntityGraph;
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
import jakarta.persistence.PersistenceContextType;
|
import jakarta.persistence.PersistenceContextType;
|
||||||
|
@ -95,6 +97,7 @@ import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.RootClass;
|
import org.hibernate.mapping.RootClass;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.metadata.CollectionMetadata;
|
import org.hibernate.metadata.CollectionMetadata;
|
||||||
|
import org.hibernate.metamodel.MappingMetamodel;
|
||||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||||
import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
|
import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
|
||||||
import org.hibernate.metamodel.model.domain.AllowableParameterType;
|
import org.hibernate.metamodel.model.domain.AllowableParameterType;
|
||||||
|
@ -934,6 +937,30 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
return type.cast( this );
|
return type.cast( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( SessionFactoryServiceRegistry.class ) ) {
|
||||||
|
return type.cast( serviceRegistry );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( JdbcServices.class ) ) {
|
||||||
|
return type.cast( jdbcServices );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( Cache.class ) || type.isAssignableFrom( org.hibernate.Cache.class ) ) {
|
||||||
|
return type.cast( cacheAccess );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( JpaMetamodel.class ) ) {
|
||||||
|
return type.cast( runtimeMetamodels.getJpaMetamodel() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( MetamodelImplementor.class ) || type.isAssignableFrom( MetadataImplementor.class ) ) {
|
||||||
|
return type.cast( runtimeMetamodels.getMappingMetamodel() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.isAssignableFrom( QueryEngine.class ) ) {
|
||||||
|
return type.cast( queryEngine );
|
||||||
|
}
|
||||||
|
|
||||||
throw new PersistenceException( "Hibernate cannot unwrap EntityManagerFactory as '" + type.getName() + "'" );
|
throw new PersistenceException( "Hibernate cannot unwrap EntityManagerFactory as '" + type.getName() + "'" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2663,6 +2663,9 @@ public class SessionImpl
|
||||||
if ( EntityManager.class.isAssignableFrom( clazz ) ) {
|
if ( EntityManager.class.isAssignableFrom( clazz ) ) {
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
if ( PersistenceContext.class.isAssignableFrom( clazz ) ) {
|
||||||
|
return (T) this;
|
||||||
|
}
|
||||||
|
|
||||||
throw new PersistenceException( "Hibernate cannot unwrap " + clazz );
|
throw new PersistenceException( "Hibernate cannot unwrap " + clazz );
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class DynamicMapTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected String[] getMappings() {
|
protected String[] getMappings() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"/dynamicmap/Test.hbm.xml"
|
"dynamicmap/Test.hbm.xml"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
protected boolean isCleanupTestDataRequired() {
|
protected boolean isCleanupTestDataRequired() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
|
@ -219,8 +220,8 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
||||||
"/org/hibernate/orm/test/cid/LineItem.hbm.xml",
|
"/org/hibernate/orm/test/cid/LineItem.hbm.xml",
|
||||||
"/org/hibernate/orm/test/cid/Product.hbm.xml",
|
"/org/hibernate/orm/test/cid/Product.hbm.xml",
|
||||||
"/org/hibernate/orm/test/any/hbm/Properties.hbm.xml",
|
"/org/hibernate/orm/test/any/hbm/Properties.hbm.xml",
|
||||||
"legacy/Commento.hbm.xml",
|
"/org/hibernate/orm/test/legacy/Commento.hbm.xml",
|
||||||
"legacy/Marelo.hbm.xml"
|
"/org/hibernate/orm/test/legacy/Marelo.hbm.xml"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -46,6 +46,8 @@ import static org.junit.Assert.fail;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getMappings() {
|
public String[] getMappings() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
"hql/Animal.hbm.xml",
|
"hql/Animal.hbm.xml",
|
||||||
|
@ -53,7 +55,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
||||||
"hql/KeyManyToOneEntity.hbm.xml",
|
"hql/KeyManyToOneEntity.hbm.xml",
|
||||||
"hql/Versions.hbm.xml",
|
"hql/Versions.hbm.xml",
|
||||||
"hql/FooBarCopy.hbm.xml",
|
"hql/FooBarCopy.hbm.xml",
|
||||||
"legacy/Multi.hbm.xml",
|
"/org/hibernate/orm/test/legacy/Multi.hbm.xml",
|
||||||
"hql/EntityWithCrazyCompositeKey.hbm.xml",
|
"hql/EntityWithCrazyCompositeKey.hbm.xml",
|
||||||
"hql/SimpleEntityWithAssociation.hbm.xml",
|
"hql/SimpleEntityWithAssociation.hbm.xml",
|
||||||
"hql/BooleanLiteralEntity.hbm.xml",
|
"hql/BooleanLiteralEntity.hbm.xml",
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class InheritanceDeleteBatchTest extends BaseCoreFunctionalTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void configure(Configuration configuration) {
|
protected void configure(Configuration configuration) {
|
||||||
configuration.setProperty(
|
configuration.setProperty(
|
||||||
AvailableSettings.HQL_BULK_ID_STRATEGY,
|
AvailableSettings.QUERY_MULTI_TABLE_MUTATION_STRATEGY,
|
||||||
InlineStrategy.class.getName()
|
InlineStrategy.class.getName()
|
||||||
);
|
);
|
||||||
configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class JoinedSubclassTest {
|
||||||
s.save( mark );
|
s.save( mark );
|
||||||
s.save( joe );
|
s.save( joe );
|
||||||
|
|
||||||
assertEquals( s.createQuery( "from java.io.Serializable" ).list().size(), 0 );
|
assertEquals( s.createQuery( "from java.lang.Object" ).list().size(), 0 );
|
||||||
|
|
||||||
assertEquals( s.createQuery( "from Person" ).list().size(), 3 );
|
assertEquals( s.createQuery( "from Person" ).list().size(), 3 );
|
||||||
assertEquals( s.createQuery( "from Person p where p.class = Customer" ).list().size(), 1 );
|
assertEquals( s.createQuery( "from Person p where p.class = Customer" ).list().size(), 1 );
|
||||||
|
|
Loading…
Reference in New Issue