mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-06 10:42:33 +00:00
Hibernate 3 refactorings.
This commit is contained in:
parent
2ee7cc1c18
commit
a2d68e4fc5
@ -15,7 +15,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>hibernate</groupId>
|
<groupId>hibernate</groupId>
|
||||||
<artifactId>hibernate</artifactId>
|
<artifactId>hibernate</artifactId>
|
||||||
<version>2.1.8</version>
|
<version>3.0rc1</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -15,35 +15,32 @@
|
|||||||
|
|
||||||
package net.sf.acegisecurity.domain.hibernate;
|
package net.sf.acegisecurity.domain.hibernate;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.acegisecurity.domain.PersistableEntity;
|
import net.sf.acegisecurity.domain.PersistableEntity;
|
||||||
import net.sf.acegisecurity.domain.dao.Dao;
|
import net.sf.acegisecurity.domain.dao.Dao;
|
||||||
import net.sf.acegisecurity.domain.dao.EvictionCapable;
|
import net.sf.acegisecurity.domain.dao.EvictionCapable;
|
||||||
import net.sf.acegisecurity.domain.dao.PaginatedList;
|
import net.sf.acegisecurity.domain.dao.PaginatedList;
|
||||||
|
|
||||||
import net.sf.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import net.sf.hibernate.Hibernate;
|
import org.hibernate.EntityMode;
|
||||||
import net.sf.hibernate.HibernateException;
|
import org.hibernate.Hibernate;
|
||||||
import net.sf.hibernate.Session;
|
import org.hibernate.HibernateException;
|
||||||
import net.sf.hibernate.expression.Expression;
|
import org.hibernate.Session;
|
||||||
import net.sf.hibernate.expression.MatchMode;
|
import org.hibernate.criterion.Expression;
|
||||||
import net.sf.hibernate.expression.Order;
|
import org.hibernate.criterion.MatchMode;
|
||||||
import net.sf.hibernate.metadata.ClassMetadata;
|
import org.hibernate.criterion.Order;
|
||||||
import net.sf.hibernate.type.Type;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
|
import org.hibernate.type.Type;
|
||||||
import org.springframework.orm.hibernate.HibernateCallback;
|
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||||
import org.springframework.orm.hibernate.HibernateObjectRetrievalFailureException;
|
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||||
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Dao} implementation that uses Hibernate for persistence.
|
* {@link Dao} implementation that uses Hibernate 3 for persistence.
|
||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @author Matthew Porter
|
* @author Matthew Porter
|
||||||
@ -104,12 +101,7 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
|||||||
public PersistableEntity readId(Serializable id) {
|
public PersistableEntity readId(Serializable id) {
|
||||||
Assert.notNull(id);
|
Assert.notNull(id);
|
||||||
|
|
||||||
try {
|
return (PersistableEntity) getHibernateTemplate().get(supportsClass, id);
|
||||||
return (PersistableEntity) getHibernateTemplate().load(supportsClass,
|
|
||||||
id);
|
|
||||||
} catch (HibernateObjectRetrievalFailureException notFound) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaginatedList scroll(PersistableEntity value, int firstElement,
|
public PaginatedList scroll(PersistableEntity value, int firstElement,
|
||||||
@ -215,7 +207,9 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
|||||||
/* for each persistent property of the bean */
|
/* for each persistent property of the bean */
|
||||||
for (int i = 0; i < propertyNames.length; i++) {
|
for (int i = 0; i < propertyNames.length; i++) {
|
||||||
String name = propertyNames[i];
|
String name = propertyNames[i];
|
||||||
Object value = classMetadata.getPropertyValue(bean, name);
|
|
||||||
|
// TODO: Check if EntityMode.POJO appropriate
|
||||||
|
Object value = classMetadata.getPropertyValue(bean, name, EntityMode.POJO);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
continue;
|
continue;
|
||||||
@ -231,7 +225,7 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ignore any collections
|
// ignore any collections
|
||||||
if (propertyTypes[i].isPersistentCollectionType()) {
|
if (propertyTypes[i].isCollectionType()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,18 +16,24 @@
|
|||||||
package net.sf.acegisecurity.domain.hibernate;
|
package net.sf.acegisecurity.domain.hibernate;
|
||||||
|
|
||||||
import net.sf.acegisecurity.domain.validation.IntrospectionManager;
|
import net.sf.acegisecurity.domain.validation.IntrospectionManager;
|
||||||
|
import net.sf.acegisecurity.domain.validation.ValidationRegistryManager;
|
||||||
|
|
||||||
import net.sf.hibernate.HibernateException;
|
import org.hibernate.EntityMode;
|
||||||
import net.sf.hibernate.SessionFactory;
|
import org.hibernate.HibernateException;
|
||||||
import net.sf.hibernate.metadata.ClassMetadata;
|
import org.hibernate.SessionFactory;
|
||||||
import net.sf.hibernate.type.Type;
|
|
||||||
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
|
|
||||||
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.springframework.orm.hibernate.HibernateSystemException;
|
import org.springframework.orm.hibernate3.HibernateSystemException;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@ -57,6 +63,7 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
|||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
private ValidationRegistryManager validationRegistryManager;
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
@ -68,8 +75,27 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
|||||||
return this.sessionFactory;
|
return this.sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setValidationRegistryManager(
|
||||||
|
ValidationRegistryManager validationRegistryManager) {
|
||||||
|
this.validationRegistryManager = validationRegistryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationRegistryManager getValidationRegistryManager() {
|
||||||
|
return validationRegistryManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
Assert.notNull(validationRegistryManager,
|
||||||
|
"ValidationRegistryManager is required");
|
||||||
Assert.notNull(sessionFactory, "SessionFactory is required");
|
Assert.notNull(sessionFactory, "SessionFactory is required");
|
||||||
|
|
||||||
|
// Eagerly pre-register Validators for all Hibernate metadata-defined classes
|
||||||
|
Collection mappedClasses = this.sessionFactory.getAllClassMetadata()
|
||||||
|
.keySet();
|
||||||
|
|
||||||
|
for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) {
|
||||||
|
this.validationRegistryManager.findValidator((Class) iter.next());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void obtainImmediateChildren(Object parentObject, List allObjects) {
|
public void obtainImmediateChildren(Object parentObject, List allObjects) {
|
||||||
@ -90,9 +116,12 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
|||||||
for (int i = 0; i < propertyNames.length; i++) {
|
for (int i = 0; i < propertyNames.length; i++) {
|
||||||
Type propertyType = classMetadata.getPropertyType(propertyNames[i]);
|
Type propertyType = classMetadata.getPropertyType(propertyNames[i]);
|
||||||
|
|
||||||
if (propertyType.isObjectType()) {
|
// Add this property to the List of Objects to validate
|
||||||
|
// only if a Validator is registered for that Object
|
||||||
|
if (this.validationRegistryManager.findValidator(
|
||||||
|
propertyType.getReturnedClass()) != null) {
|
||||||
allObjects.add(classMetadata.getPropertyValue(
|
allObjects.add(classMetadata.getPropertyValue(
|
||||||
parentObject, propertyNames[i]));
|
parentObject, propertyNames[i], EntityMode.POJO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user