Support multiple SessionFactory instances (not just one).
This commit is contained in:
parent
3f24824f66
commit
61df8e9f7b
|
@ -64,17 +64,17 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||||
InitializingBean {
|
InitializingBean {
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory[] sessionFactories;
|
||||||
private ValidationRegistryManager validationRegistryManager;
|
private ValidationRegistryManager validationRegistryManager;
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
public void setSessionFactories(SessionFactory[] sessionFactorys) {
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactories = sessionFactorys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionFactory getSessionFactory() {
|
public SessionFactory[] getSessionFactories() {
|
||||||
return this.sessionFactory;
|
return this.sessionFactories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValidationRegistryManager(
|
public void setValidationRegistryManager(
|
||||||
|
@ -87,18 +87,19 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Assert.notNull(validationRegistryManager,
|
Assert.notNull(validationRegistryManager, "ValidationRegistryManager is required");
|
||||||
"ValidationRegistryManager is required");
|
Assert.notNull(sessionFactories, "SessionFactories are required");
|
||||||
Assert.notNull(sessionFactory, "SessionFactory is required");
|
Assert.notEmpty(sessionFactories, "SessionFactories are required");
|
||||||
|
|
||||||
// Eagerly pre-register Validators for all Hibernate metadata-defined classes
|
// Eagerly pre-register Validators for all Hibernate metadata-defined classes
|
||||||
Map<String,ClassMetadata> metadataMap = this.sessionFactory.getAllClassMetadata();
|
for (int i = 0; i < sessionFactories.length; i++) {
|
||||||
Collection<String> mappedClasses = metadataMap.keySet();
|
Map<String,ClassMetadata> metadataMap = this.sessionFactories[i].getAllClassMetadata();
|
||||||
|
Collection<String> mappedClasses = metadataMap.keySet();
|
||||||
|
|
||||||
for (Iterator<String> iter = mappedClasses.iterator(); iter.hasNext();) {
|
for (Iterator<String> iter = mappedClasses.iterator(); iter.hasNext();) {
|
||||||
String className = iter.next();
|
String className = iter.next();
|
||||||
this.validationRegistryManager.findValidator(Class.forName(
|
this.validationRegistryManager.findValidator(Class.forName(className));
|
||||||
className));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +112,7 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||||
ClassMetadata classMetadata = null;
|
ClassMetadata classMetadata = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
classMetadata = sessionFactory.getClassMetadata(parentObject
|
classMetadata = findMetadata(parentObject.getClass());
|
||||||
.getClass());
|
|
||||||
|
|
||||||
if (classMetadata != null) {
|
if (classMetadata != null) {
|
||||||
String[] propertyNames = classMetadata.getPropertyNames();
|
String[] propertyNames = classMetadata.getPropertyNames();
|
||||||
|
@ -136,4 +136,14 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||||
throw new HibernateSystemException(he);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue