fixing test failures in the merge

This commit is contained in:
Strong Liu 2013-03-20 15:44:57 +08:00
parent c48de9edc5
commit 5348367665
2 changed files with 143 additions and 191 deletions

View File

@ -138,7 +138,7 @@ public abstract class AbstractManagedType<X>
* {@inheritDoc}
*/
public Attribute<X, ?> getDeclaredAttribute(String name) {
final Attribute<X, ?> attr = declaredSingularAttributes.get( name );
final Attribute<X, ?> attr = declaredAttributes.get( name );
checkNotNull( "Attribute ", attr, name );
return attr;
}

View File

@ -33,7 +33,9 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@ -61,6 +63,7 @@ import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.ConfigLoader;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.boot.spi.JaccDefinition;
@ -74,6 +77,7 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.jpa.AvailableSettings;
@ -237,37 +241,164 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
ClassLoader classLoader = (ClassLoader) integrationSettings.get( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
if ( classLoader != null ) {
// TODO: If providedClassLoader is present (OSGi, etc.) *and*
// an APP_CLASSLOADER is provided, should throw an exception or
// warn?
ClassLoader classLoader;
ClassLoader appClassLoader = (ClassLoader) integrationSettings.get( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
if ( providedClassLoader != null ) {
classLoader = providedClassLoader;
}
else if ( appClassLoader != null ) {
classLoader = appClassLoader;
integrationSettings.remove( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
}
else {
classLoader = persistenceUnit.getClassLoader();
}
bootstrapServiceRegistryBuilder.withApplicationClassLoader( classLoader );
bootstrapServiceRegistryBuilder.with( classLoader );
return bootstrapServiceRegistryBuilder.build();
}
@SuppressWarnings("unchecked")
private Map mergePropertySources(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
final BootstrapServiceRegistry bootstrapServiceRegistry) {
final Map merged = new HashMap();
// first, apply persistence.xml-defined settings
if ( persistenceUnit.getProperties() != null ) {
merged.putAll( persistenceUnit.getProperties() );
}
JpaUnifiedSettingsBuilder.Result mergedResult = JpaUnifiedSettingsBuilder.mergePropertySources(
persistenceUnit,
integrationSettings,
bootstrapServiceRegistry
merged.put( AvailableSettings.PERSISTENCE_UNIT_NAME, persistenceUnit.getName() );
// see if the persistence.xml settings named a Hibernate config file....
final ValueHolder<ConfigLoader> configLoaderHolder = new ValueHolder<ConfigLoader>(
new ValueHolder.DeferredInitializer<ConfigLoader>() {
@Override
public ConfigLoader initialize() {
return new ConfigLoader( bootstrapServiceRegistry );
}
}
);
cfgXmlNamedMappings.addAll( mergedResult.getCfgXmlMappingArtifacts().getMappings() );
cacheRegionDefinitions.addAll( mergedResult.getCfgXmlMappingArtifacts().getCacheRegionDefinitions() );
jaccDefinitions.addAll( mergedResult.getCfgXmlMappingArtifacts().getJaccDefinitions() );
{
final String cfgXmlResourceName = (String) merged.remove( AvailableSettings.CFG_FILE );
if ( StringHelper.isNotEmpty( cfgXmlResourceName ) ) {
// it does, so load those properties
JaxbHibernateConfiguration configurationElement = configLoaderHolder.getValue()
.loadConfigXmlResource( cfgXmlResourceName );
processHibernateConfigurationElement( configurationElement, merged );
}
}
return mergedResult.getSettings();
// see if integration settings named a Hibernate config file....
{
final String cfgXmlResourceName = (String) integrationSettings.get( AvailableSettings.CFG_FILE );
if ( StringHelper.isNotEmpty( cfgXmlResourceName ) ) {
integrationSettings.remove( AvailableSettings.CFG_FILE );
// it does, so load those properties
JaxbHibernateConfiguration configurationElement = configLoaderHolder.getValue().loadConfigXmlResource(
cfgXmlResourceName
);
processHibernateConfigurationElement( configurationElement, merged );
}
}
// finally, apply integration-supplied settings (per JPA spec, integration settings should override other sources)
merged.putAll( integrationSettings );
if ( ! merged.containsKey( AvailableSettings.VALIDATION_MODE ) ) {
if ( persistenceUnit.getValidationMode() != null ) {
merged.put( AvailableSettings.VALIDATION_MODE, persistenceUnit.getValidationMode() );
}
}
if ( ! merged.containsKey( AvailableSettings.SHARED_CACHE_MODE ) ) {
if ( persistenceUnit.getSharedCacheMode() != null ) {
merged.put( AvailableSettings.SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
}
}
// was getting NPE exceptions from the underlying map when just using #putAll, so going this safer route...
Iterator itr = merged.entrySet().iterator();
while ( itr.hasNext() ) {
final Map.Entry entry = (Map.Entry) itr.next();
if ( entry.getValue() == null ) {
itr.remove();
}
}
return merged;
}
@SuppressWarnings("unchecked")
private void processHibernateConfigurationElement(
JaxbHibernateConfiguration configurationElement,
Map mergeMap) {
if ( ! mergeMap.containsKey( org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME ) ) {
String cfgName = configurationElement.getSessionFactory().getName();
if ( cfgName != null ) {
mergeMap.put( org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME, cfgName );
}
}
for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbProperty jaxbProperty : configurationElement.getSessionFactory().getProperty() ) {
mergeMap.put( jaxbProperty.getName(), jaxbProperty.getValue() );
}
for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : configurationElement.getSessionFactory().getMapping() ) {
cfgXmlNamedMappings.add( jaxbMapping );
}
for ( Object cacheDeclaration : configurationElement.getSessionFactory().getClassCacheOrCollectionCache() ) {
if ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache.class.isInstance( cacheDeclaration ) ) {
final JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache jaxbClassCache
= (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache) cacheDeclaration;
cacheRegionDefinitions.add(
new CacheRegionDefinition(
CacheRegionDefinition.CacheRegionType.ENTITY,
jaxbClassCache.getClazz(),
jaxbClassCache.getUsage().value(),
jaxbClassCache.getRegion(),
"all".equals( jaxbClassCache.getInclude() )
)
);
}
else {
final JaxbHibernateConfiguration.JaxbSessionFactory.JaxbCollectionCache jaxbCollectionCache
= (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbCollectionCache) cacheDeclaration;
cacheRegionDefinitions.add(
new CacheRegionDefinition(
CacheRegionDefinition.CacheRegionType.COLLECTION,
jaxbCollectionCache.getCollection(),
jaxbCollectionCache.getUsage().value(),
jaxbCollectionCache.getRegion(),
false
)
);
}
}
if ( configurationElement.getSecurity() != null ) {
final String contextId = configurationElement.getSecurity().getContext();
for ( JaxbHibernateConfiguration.JaxbSecurity.JaxbGrant grant : configurationElement.getSecurity().getGrant() ) {
jaccDefinitions.add(
new JaccDefinition(
contextId,
grant.getRole(),
grant.getEntityName(),
grant.getActions()
)
);
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// temporary!
@SuppressWarnings("unchecked")
@ -391,185 +522,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
}
<<<<<<< HEAD
=======
/**
* Builds the {@link BootstrapServiceRegistry} used to eventually build the {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder}; mainly
* used here during instantiation to define class-loading behavior.
*
* @param integrationSettings Any integration settings passed by the EE container or SE application
*
* @return The built BootstrapServiceRegistry
*/
private BootstrapServiceRegistry buildBootstrapServiceRegistry(Map integrationSettings) {
final BootstrapServiceRegistryBuilder bootstrapServiceRegistryBuilder = new BootstrapServiceRegistryBuilder();
bootstrapServiceRegistryBuilder.with( new JpaIntegrator() );
final IntegratorProvider integratorProvider = (IntegratorProvider) integrationSettings.get( INTEGRATOR_PROVIDER );
if ( integratorProvider != null ) {
integrationSettings.remove( INTEGRATOR_PROVIDER );
for ( Integrator integrator : integratorProvider.getIntegrators() ) {
bootstrapServiceRegistryBuilder.with( integrator );
}
}
// TODO: If providedClassLoader is present (OSGi, etc.) *and*
// an APP_CLASSLOADER is provided, should throw an exception or
// warn?
ClassLoader classLoader;
ClassLoader appClassLoader = (ClassLoader) integrationSettings.get( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
if ( providedClassLoader != null ) {
classLoader = providedClassLoader;
}
else if ( appClassLoader != null ) {
classLoader = appClassLoader;
integrationSettings.remove( org.hibernate.cfg.AvailableSettings.APP_CLASSLOADER );
}
else {
classLoader = persistenceUnit.getClassLoader();
}
bootstrapServiceRegistryBuilder.with( classLoader );
return bootstrapServiceRegistryBuilder.build();
}
@SuppressWarnings("unchecked")
private Map mergePropertySources(
PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings,
final BootstrapServiceRegistry bootstrapServiceRegistry) {
final Map merged = new HashMap();
// first, apply persistence.xml-defined settings
if ( persistenceUnit.getProperties() != null ) {
merged.putAll( persistenceUnit.getProperties() );
}
merged.put( AvailableSettings.PERSISTENCE_UNIT_NAME, persistenceUnit.getName() );
// see if the persistence.xml settings named a Hibernate config file....
final ValueHolder<ConfigLoader> configLoaderHolder = new ValueHolder<ConfigLoader>(
new ValueHolder.DeferredInitializer<ConfigLoader>() {
@Override
public ConfigLoader initialize() {
return new ConfigLoader( bootstrapServiceRegistry );
}
}
);
{
final String cfgXmlResourceName = (String) merged.remove( AvailableSettings.CFG_FILE );
if ( StringHelper.isNotEmpty( cfgXmlResourceName ) ) {
// it does, so load those properties
JaxbHibernateConfiguration configurationElement = configLoaderHolder.getValue()
.loadConfigXmlResource( cfgXmlResourceName );
processHibernateConfigurationElement( configurationElement, merged );
}
}
// see if integration settings named a Hibernate config file....
{
final String cfgXmlResourceName = (String) integrationSettings.get( AvailableSettings.CFG_FILE );
if ( StringHelper.isNotEmpty( cfgXmlResourceName ) ) {
integrationSettings.remove( AvailableSettings.CFG_FILE );
// it does, so load those properties
JaxbHibernateConfiguration configurationElement = configLoaderHolder.getValue().loadConfigXmlResource(
cfgXmlResourceName
);
processHibernateConfigurationElement( configurationElement, merged );
}
}
// finally, apply integration-supplied settings (per JPA spec, integration settings should override other sources)
merged.putAll( integrationSettings );
if ( ! merged.containsKey( AvailableSettings.VALIDATION_MODE ) ) {
if ( persistenceUnit.getValidationMode() != null ) {
merged.put( AvailableSettings.VALIDATION_MODE, persistenceUnit.getValidationMode() );
}
}
if ( ! merged.containsKey( AvailableSettings.SHARED_CACHE_MODE ) ) {
if ( persistenceUnit.getSharedCacheMode() != null ) {
merged.put( AvailableSettings.SHARED_CACHE_MODE, persistenceUnit.getSharedCacheMode() );
}
}
// was getting NPE exceptions from the underlying map when just using #putAll, so going this safer route...
Iterator itr = merged.entrySet().iterator();
while ( itr.hasNext() ) {
final Map.Entry entry = (Map.Entry) itr.next();
if ( entry.getValue() == null ) {
itr.remove();
}
}
return merged;
}
@SuppressWarnings("unchecked")
private void processHibernateConfigurationElement(
JaxbHibernateConfiguration configurationElement,
Map mergeMap) {
if ( ! mergeMap.containsKey( org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME ) ) {
String cfgName = configurationElement.getSessionFactory().getName();
if ( cfgName != null ) {
mergeMap.put( org.hibernate.cfg.AvailableSettings.SESSION_FACTORY_NAME, cfgName );
}
}
for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbProperty jaxbProperty : configurationElement.getSessionFactory().getProperty() ) {
mergeMap.put( jaxbProperty.getName(), jaxbProperty.getValue() );
}
for ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbMapping jaxbMapping : configurationElement.getSessionFactory().getMapping() ) {
cfgXmlNamedMappings.add( jaxbMapping );
}
for ( Object cacheDeclaration : configurationElement.getSessionFactory().getClassCacheOrCollectionCache() ) {
if ( JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache.class.isInstance( cacheDeclaration ) ) {
final JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache jaxbClassCache
= (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbClassCache) cacheDeclaration;
cacheRegionDefinitions.add(
new CacheRegionDefinition(
CacheRegionDefinition.CacheType.ENTITY,
jaxbClassCache.getClazz(),
jaxbClassCache.getUsage().value(),
jaxbClassCache.getRegion(),
"all".equals( jaxbClassCache.getInclude() )
)
);
}
else {
final JaxbHibernateConfiguration.JaxbSessionFactory.JaxbCollectionCache jaxbCollectionCache
= (JaxbHibernateConfiguration.JaxbSessionFactory.JaxbCollectionCache) cacheDeclaration;
cacheRegionDefinitions.add(
new CacheRegionDefinition(
CacheRegionDefinition.CacheType.COLLECTION,
jaxbCollectionCache.getCollection(),
jaxbCollectionCache.getUsage().value(),
jaxbCollectionCache.getRegion(),
false
)
);
}
}
if ( configurationElement.getSecurity() != null ) {
final String contextId = configurationElement.getSecurity().getContext();
for ( JaxbHibernateConfiguration.JaxbSecurity.JaxbGrant grant : configurationElement.getSecurity().getGrant() ) {
jaccDefinitions.add(
new JaccDefinition(
contextId,
grant.getRole(),
grant.getEntityName(),
grant.getActions()
)
);
}
}
}
>>>>>>> master
private String jaccContextId;
private void addJaccDefinition(String key, Object value) {