From 7cb83cac9514c6e034b1ca20b3ac9f634186d86b Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sun, 7 Feb 2010 19:27:19 +0000 Subject: [PATCH] HHH-4664 - Implement EntityManagerFactory#getProperties() git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18712 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../engine/SessionFactoryImplementor.java | 8 +++++++ .../hibernate/impl/SessionFactoryImpl.java | 4 ++++ .../ejb/EntityManagerFactoryImpl.java | 24 +++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java b/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java index 5b779226f0..69d3003474 100644 --- a/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java +++ b/core/src/main/java/org/hibernate/engine/SessionFactoryImplementor.java @@ -25,6 +25,7 @@ package org.hibernate.engine; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.sql.Connection; @@ -62,6 +63,13 @@ */ public interface SessionFactoryImplementor extends Mapping, SessionFactory { + /** + * Get a copy of the Properties used to configure this session factory. + * + * @return The properties. + */ + public Properties getProperties(); + /** * Get the persister for the named entity * diff --git a/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java b/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java index 81cf213d77..dc2dfcb973 100644 --- a/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java +++ b/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java @@ -467,6 +467,10 @@ public void handleEntityNotFound(String entityName, Serializable id) { this.observer.sessionFactoryCreated( this ); } + public Properties getProperties() { + return properties; + } + public IdentifierGeneratorFactory getIdentifierGeneratorFactory() { return null; } diff --git a/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java b/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java index 6bc40acc3d..fe468931d7 100755 --- a/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java @@ -21,7 +21,10 @@ */ package org.hibernate.ejb; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.Iterator; import java.io.Serializable; @@ -61,7 +64,9 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory { private final CriteriaBuilderImpl criteriaBuilder; private final Metamodel metamodel; private final HibernatePersistenceUnitUtil util; + private final Map properties; + @SuppressWarnings( "unchecked" ) public EntityManagerFactoryImpl( SessionFactory sessionFactory, PersistenceUnitTransactionType transactionType, @@ -72,7 +77,6 @@ public EntityManagerFactoryImpl( this.transactionType = transactionType; this.discardOnClose = discardOnClose; this.sessionInterceptorClass = sessionInterceptorClass; - @SuppressWarnings( "unchecked" ) final Iterator classes = cfg.getClassMappings(); //a safe guard till we are confident that metamodel is wll tested if ( !"disabled".equalsIgnoreCase( cfg.getProperty( "hibernate.ejb.metamodel.generation" ) ) ) { @@ -83,6 +87,19 @@ public EntityManagerFactoryImpl( } this.criteriaBuilder = new CriteriaBuilderImpl( this ); this.util = new HibernatePersistenceUnitUtil( this ); + + HashMap props = new HashMap(); + addAll( props, ( (SessionFactoryImplementor) sessionFactory ).getProperties() ); + addAll( props, cfg.getProperties() ); + this.properties = Collections.unmodifiableMap( props ); + } + + private static void addAll(HashMap propertyMap, Properties properties) { + for ( Map.Entry entry : properties.entrySet() ) { + if ( String.class.isInstance( entry.getKey() ) ) { + propertyMap.put( (String)entry.getKey(), entry.getValue() ); + } + } } public EntityManager createEntityManager() { @@ -102,7 +119,7 @@ public CriteriaBuilder getCriteriaBuilder() { } public Metamodel getMetamodel() { - return metamodel; //To change body of implemented methods use File | Settings | File Templates. + return metamodel; } public void close() { @@ -110,8 +127,7 @@ public void close() { } public Map getProperties() { - //FIXME - return null; //To change body of implemented methods use File | Settings | File Templates. + return properties; } public Cache getCache() {