HHH-8260 missing api to register default entity tuplizer
This commit is contained in:
parent
c397221483
commit
390e72e2c1
|
@ -30,6 +30,7 @@ import java.util.Set;
|
||||||
import javax.naming.Referenceable;
|
import javax.naming.Referenceable;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
import org.hibernate.cfg.Settings;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
|
@ -75,6 +76,7 @@ public interface SessionFactory extends Referenceable, Serializable {
|
||||||
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
|
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
|
||||||
public SessionFactoryObserver[] getSessionFactoryObservers();
|
public SessionFactoryObserver[] getSessionFactoryObservers();
|
||||||
public EntityNameResolver[] getEntityNameResolvers();
|
public EntityNameResolver[] getEntityNameResolvers();
|
||||||
|
public Settings getSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the delegate for handling entity-not-found exception conditions.
|
* Get the delegate for handling entity-not-found exception conditions.
|
||||||
|
|
|
@ -153,6 +153,7 @@ import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||||
|
import org.hibernate.tuple.entity.EntityTuplizerFactory;
|
||||||
import org.hibernate.type.AssociationType;
|
import org.hibernate.type.AssociationType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.type.TypeResolver;
|
import org.hibernate.type.TypeResolver;
|
||||||
|
@ -224,7 +225,7 @@ public final class SessionFactoryImpl
|
||||||
final Configuration cfg,
|
final Configuration cfg,
|
||||||
Mapping mapping,
|
Mapping mapping,
|
||||||
final ServiceRegistry serviceRegistry,
|
final ServiceRegistry serviceRegistry,
|
||||||
Settings settings,
|
final Settings settings,
|
||||||
final SessionFactoryObserver userObserver) throws HibernateException {
|
final SessionFactoryObserver userObserver) throws HibernateException {
|
||||||
LOG.debug( "Building session factory" );
|
LOG.debug( "Building session factory" );
|
||||||
|
|
||||||
|
@ -273,6 +274,11 @@ public final class SessionFactoryImpl
|
||||||
return interceptor;
|
return interceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Settings getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy() {
|
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy() {
|
||||||
return customEntityDirtinessStrategy;
|
return customEntityDirtinessStrategy;
|
||||||
|
@ -301,7 +307,7 @@ public final class SessionFactoryImpl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.settings = settings;
|
this.settings = sessionFactoryOptions.getSettings();
|
||||||
|
|
||||||
this.properties = new Properties();
|
this.properties = new Properties();
|
||||||
this.properties.putAll( cfg.getProperties() );
|
this.properties.putAll( cfg.getProperties() );
|
||||||
|
@ -515,6 +521,11 @@ public final class SessionFactoryImpl
|
||||||
registerEntityNameResolvers( persister );
|
registerEntityNameResolvers( persister );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if ( sessionFactoryOptions.getEntityNameResolvers() != null ) {
|
||||||
|
for ( EntityNameResolver resolver : sessionFactoryOptions.getEntityNameResolvers() ) {
|
||||||
|
registerEntityNameResolver( resolver );
|
||||||
|
}
|
||||||
|
}
|
||||||
iter = collectionPersisters.values().iterator();
|
iter = collectionPersisters.values().iterator();
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
||||||
|
@ -693,12 +704,7 @@ public final class SessionFactoryImpl
|
||||||
this.properties = createPropertiesFromMap(
|
this.properties = createPropertiesFromMap(
|
||||||
metadata.getServiceRegistry().getService( ConfigurationService.class ).getSettings()
|
metadata.getServiceRegistry().getService( ConfigurationService.class ).getSettings()
|
||||||
);
|
);
|
||||||
|
this.settings = sessionFactoryOptions.getSettings();
|
||||||
// TODO: these should be moved into SessionFactoryOptions
|
|
||||||
this.settings = new SettingsFactory().buildSettings(
|
|
||||||
properties,
|
|
||||||
metadata.getServiceRegistry()
|
|
||||||
);
|
|
||||||
|
|
||||||
this.serviceRegistry =
|
this.serviceRegistry =
|
||||||
sessionFactoryOptions.getServiceRegistry()
|
sessionFactoryOptions.getServiceRegistry()
|
||||||
|
@ -953,6 +959,11 @@ public final class SessionFactoryImpl
|
||||||
registerEntityNameResolvers( persister );
|
registerEntityNameResolvers( persister );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if ( sessionFactoryOptions.getEntityNameResolvers() != null ) {
|
||||||
|
for ( EntityNameResolver resolver : sessionFactoryOptions.getEntityNameResolvers() ) {
|
||||||
|
registerEntityNameResolver( resolver );
|
||||||
|
}
|
||||||
|
}
|
||||||
iter = collectionPersisters.values().iterator();
|
iter = collectionPersisters.values().iterator();
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
final CollectionPersister persister = ( ( CollectionPersister ) iter.next() );
|
||||||
|
|
|
@ -24,12 +24,14 @@
|
||||||
package org.hibernate.metamodel;
|
package org.hibernate.metamodel;
|
||||||
|
|
||||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||||
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.SessionFactoryObserver;
|
import org.hibernate.SessionFactoryObserver;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
|
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contract for building a {@link SessionFactory} given a number of options.
|
* The contract for building a {@link SessionFactory} given a number of options.
|
||||||
|
@ -104,6 +106,16 @@ public interface SessionFactoryBuilder {
|
||||||
*/
|
*/
|
||||||
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate);
|
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the default {@link EntityTuplizer} to be applied to the SessionFactory.
|
||||||
|
*
|
||||||
|
* @param entityMode The entity mode that which this tuplizer will be applied.
|
||||||
|
* @param tuplizerClass The custom tuplizer class.
|
||||||
|
*
|
||||||
|
* @return {@code this}, for method chaining
|
||||||
|
*/
|
||||||
|
public SessionFactoryBuilder with(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After all options have been set, build the SessionFactory.
|
* After all options have been set, build the SessionFactory.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,9 +28,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||||
import org.hibernate.EmptyInterceptor;
|
import org.hibernate.EmptyInterceptor;
|
||||||
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.EntityNameResolver;
|
import org.hibernate.EntityNameResolver;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.ObjectNotFoundException;
|
import org.hibernate.ObjectNotFoundException;
|
||||||
|
@ -39,6 +41,8 @@ import org.hibernate.SessionFactoryObserver;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.cfg.Settings;
|
||||||
|
import org.hibernate.cfg.SettingsFactory;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.internal.DefaultCustomEntityDirtinessStrategy;
|
import org.hibernate.internal.DefaultCustomEntityDirtinessStrategy;
|
||||||
|
@ -46,6 +50,7 @@ import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
|
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -96,6 +101,12 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionFactoryBuilder with(EntityMode entityMode, Class<? extends EntityTuplizer> tuplizerClass){
|
||||||
|
this.options.settings.getEntityTuplizerFactory().registerDefaultTuplizerClass( entityMode, tuplizerClass );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionFactory build() {
|
public SessionFactory build() {
|
||||||
return new SessionFactoryImpl( metadata, options );
|
return new SessionFactoryImpl( metadata, options );
|
||||||
|
@ -110,6 +121,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
private List<SessionFactoryObserver> sessionFactoryObserverList = new ArrayList<SessionFactoryObserver>();
|
private List<SessionFactoryObserver> sessionFactoryObserverList = new ArrayList<SessionFactoryObserver>();
|
||||||
private List<EntityNameResolver> entityNameResolvers = new ArrayList<EntityNameResolver>();
|
private List<EntityNameResolver> entityNameResolvers = new ArrayList<EntityNameResolver>();
|
||||||
private EntityNotFoundDelegate entityNotFoundDelegate;
|
private EntityNotFoundDelegate entityNotFoundDelegate;
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
public SessionFactoryOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
public SessionFactoryOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
@ -141,6 +153,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
CurrentTenantIdentifierResolver.class,
|
CurrentTenantIdentifierResolver.class,
|
||||||
configurationSettings.get( AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER )
|
configurationSettings.get( AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER )
|
||||||
);
|
);
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.putAll( configurationSettings );
|
||||||
|
this.settings = new SettingsFactory().buildSettings( properties, serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,6 +178,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
return currentTenantIdentifierResolver;
|
return currentTenantIdentifierResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Settings getSettings() {
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionFactoryObserver[] getSessionFactoryObservers() {
|
public SessionFactoryObserver[] getSessionFactoryObservers() {
|
||||||
return sessionFactoryObserverList.toArray( new SessionFactoryObserver[sessionFactoryObserverList.size()] );
|
return sessionFactoryObserverList.toArray( new SessionFactoryObserver[sessionFactoryObserverList.size()] );
|
||||||
|
|
|
@ -31,12 +31,12 @@ import org.hibernate.EntityMode;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||||
import org.hibernate.test.dynamicentity.Address;
|
import org.hibernate.test.dynamicentity.Address;
|
||||||
import org.hibernate.test.dynamicentity.Company;
|
import org.hibernate.test.dynamicentity.Company;
|
||||||
import org.hibernate.test.dynamicentity.Customer;
|
import org.hibernate.test.dynamicentity.Customer;
|
||||||
import org.hibernate.test.dynamicentity.Person;
|
import org.hibernate.test.dynamicentity.Person;
|
||||||
import org.hibernate.test.dynamicentity.ProxyHelper;
|
import org.hibernate.test.dynamicentity.ProxyHelper;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -65,10 +65,13 @@ public class ImprovedTuplizerDynamicEntityTest extends BaseCoreFunctionalTestCas
|
||||||
super.configure( cfg );
|
super.configure( cfg );
|
||||||
cfg.getEntityTuplizerFactory().registerDefaultTuplizerClass( EntityMode.POJO, MyEntityTuplizer.class );
|
cfg.getEntityTuplizerFactory().registerDefaultTuplizerClass( EntityMode.POJO, MyEntityTuplizer.class );
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
protected void configSessionFactoryBuilder(SessionFactoryBuilder sessionFactoryBuilder) {
|
||||||
|
sessionFactoryBuilder.with( EntityMode.POJO, MyEntityTuplizer.class );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testIt() {
|
public void testIt() {
|
||||||
// Test saving these dyna-proxies
|
// Test saving these dyna-proxies
|
||||||
Session session = openSession();
|
Session session = openSession();
|
||||||
|
|
Loading…
Reference in New Issue