From 61df8e9f7b47854710b455e310e5c5a80364b05e Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Sun, 4 Sep 2005 23:08:02 +0000 Subject: [PATCH] Support multiple SessionFactory instances (not just one). --- .../IntrospectionManagerHibernate.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/domain/src/main/java/org/acegisecurity/domain/hibernate/IntrospectionManagerHibernate.java b/domain/src/main/java/org/acegisecurity/domain/hibernate/IntrospectionManagerHibernate.java index f13aa1ceb5..718fff8ab3 100644 --- a/domain/src/main/java/org/acegisecurity/domain/hibernate/IntrospectionManagerHibernate.java +++ b/domain/src/main/java/org/acegisecurity/domain/hibernate/IntrospectionManagerHibernate.java @@ -64,17 +64,17 @@ public class IntrospectionManagerHibernate implements IntrospectionManager, InitializingBean { //~ Instance fields ======================================================== - private SessionFactory sessionFactory; + private SessionFactory[] sessionFactories; private ValidationRegistryManager validationRegistryManager; //~ Methods ================================================================ - public void setSessionFactory(SessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; + public void setSessionFactories(SessionFactory[] sessionFactorys) { + this.sessionFactories = sessionFactorys; } - public SessionFactory getSessionFactory() { - return this.sessionFactory; + public SessionFactory[] getSessionFactories() { + return this.sessionFactories; } public void setValidationRegistryManager( @@ -87,18 +87,19 @@ public class IntrospectionManagerHibernate implements IntrospectionManager, } public void afterPropertiesSet() throws Exception { - Assert.notNull(validationRegistryManager, - "ValidationRegistryManager is required"); - Assert.notNull(sessionFactory, "SessionFactory is required"); - + Assert.notNull(validationRegistryManager, "ValidationRegistryManager is required"); + Assert.notNull(sessionFactories, "SessionFactories are required"); + Assert.notEmpty(sessionFactories, "SessionFactories are required"); + // Eagerly pre-register Validators for all Hibernate metadata-defined classes - Map metadataMap = this.sessionFactory.getAllClassMetadata(); - Collection mappedClasses = metadataMap.keySet(); + for (int i = 0; i < sessionFactories.length; i++) { + Map metadataMap = this.sessionFactories[i].getAllClassMetadata(); + Collection mappedClasses = metadataMap.keySet(); - for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) { - String className = iter.next(); - this.validationRegistryManager.findValidator(Class.forName( - className)); + for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) { + String className = iter.next(); + this.validationRegistryManager.findValidator(Class.forName(className)); + } } } @@ -111,8 +112,7 @@ public class IntrospectionManagerHibernate implements IntrospectionManager, ClassMetadata classMetadata = null; try { - classMetadata = sessionFactory.getClassMetadata(parentObject - .getClass()); + classMetadata = findMetadata(parentObject.getClass()); if (classMetadata != null) { String[] propertyNames = classMetadata.getPropertyNames(); @@ -136,4 +136,14 @@ public class IntrospectionManagerHibernate implements IntrospectionManager, throw new HibernateSystemException(he); } } + + private ClassMetadata findMetadata(Class clazz) throws HibernateSystemException { + for (int i = 0; i < sessionFactories.length; i++) { + ClassMetadata result = sessionFactories[i].getClassMetadata(clazz); + if (result != null) { + return result; + } + } + return null; + } }