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;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -32,6 +33,7 @@ import org.hibernate.boot.SchemaAutoTooling;
|
|||
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
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.spi.BootstrapContext;
|
||||
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.BaselineSessionEventsListenerBuilder;
|
||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.internal.ConfigurationServiceImpl;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
|
||||
|
@ -601,16 +604,42 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
return null;
|
||||
}
|
||||
|
||||
//noinspection Convert2Lambda
|
||||
return strategySelector.resolveDefaultableStrategy(
|
||||
return strategySelector.resolveStrategy(
|
||||
SqmMultiTableMutationStrategy.class,
|
||||
strategyName,
|
||||
new Callable<SqmMultiTableMutationStrategy>() {
|
||||
@Override
|
||||
public SqmMultiTableMutationStrategy call() throws Exception {
|
||||
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||
return (SqmMultiTableMutationStrategy) classLoaderService.classForName( strategyName ).newInstance();
|
||||
(SqmMultiTableMutationStrategy) null,
|
||||
strategyClass -> {
|
||||
Constructor<SqmMultiTableMutationStrategy> dialectConstructor = null;
|
||||
Constructor<SqmMultiTableMutationStrategy> emptyConstructor = null;
|
||||
// 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 javax.naming.Reference;
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
import jakarta.persistence.Cache;
|
||||
import jakarta.persistence.EntityGraph;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.PersistenceContextType;
|
||||
|
@ -95,6 +97,7 @@ import org.hibernate.mapping.PersistentClass;
|
|||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||
import org.hibernate.metamodel.internal.RuntimeMetamodelsImpl;
|
||||
import org.hibernate.metamodel.model.domain.AllowableParameterType;
|
||||
|
@ -934,6 +937,30 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
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() + "'" );
|
||||
}
|
||||
|
||||
|
|
|
@ -2663,6 +2663,9 @@ public class SessionImpl
|
|||
if ( EntityManager.class.isAssignableFrom( clazz ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
if ( PersistenceContext.class.isAssignableFrom( clazz ) ) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
throw new PersistenceException( "Hibernate cannot unwrap " + clazz );
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class DynamicMapTest extends BaseCoreFunctionalTestCase {
|
|||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] {
|
||||
"/dynamicmap/Test.hbm.xml"
|
||||
"dynamicmap/Test.hbm.xml"
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -202,6 +202,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
|
|||
protected boolean isCleanupTestDataRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
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/Product.hbm.xml",
|
||||
"/org/hibernate/orm/test/any/hbm/Properties.hbm.xml",
|
||||
"legacy/Commento.hbm.xml",
|
||||
"legacy/Marelo.hbm.xml"
|
||||
"/org/hibernate/orm/test/legacy/Commento.hbm.xml",
|
||||
"/org/hibernate/orm/test/legacy/Marelo.hbm.xml"
|
||||
};
|
||||
}
|
||||
@Override
|
||||
|
|
|
@ -46,6 +46,8 @@ import static org.junit.Assert.fail;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] {
|
||||
"hql/Animal.hbm.xml",
|
||||
|
@ -53,7 +55,7 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
|
|||
"hql/KeyManyToOneEntity.hbm.xml",
|
||||
"hql/Versions.hbm.xml",
|
||||
"hql/FooBarCopy.hbm.xml",
|
||||
"legacy/Multi.hbm.xml",
|
||||
"/org/hibernate/orm/test/legacy/Multi.hbm.xml",
|
||||
"hql/EntityWithCrazyCompositeKey.hbm.xml",
|
||||
"hql/SimpleEntityWithAssociation.hbm.xml",
|
||||
"hql/BooleanLiteralEntity.hbm.xml",
|
||||
|
|
|
@ -45,7 +45,7 @@ public class InheritanceDeleteBatchTest extends BaseCoreFunctionalTestCase {
|
|||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty(
|
||||
AvailableSettings.HQL_BULK_ID_STRATEGY,
|
||||
AvailableSettings.QUERY_MULTI_TABLE_MUTATION_STRATEGY,
|
||||
InlineStrategy.class.getName()
|
||||
);
|
||||
configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
|
|
|
@ -75,7 +75,7 @@ public class JoinedSubclassTest {
|
|||
s.save( mark );
|
||||
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 p where p.class = Customer" ).list().size(), 1 );
|
||||
|
|
Loading…
Reference in New Issue