diff --git a/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java b/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java index 17056be970..21fb9481b3 100644 --- a/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java +++ b/domain/src/main/java/org/acegisecurity/domain/hibernate/DaoHibernate.java @@ -25,6 +25,7 @@ import net.sf.acegisecurity.domain.dao.Dao; import net.sf.acegisecurity.domain.dao.EvictionCapable; import net.sf.acegisecurity.domain.dao.InitializationCapable; import net.sf.acegisecurity.domain.dao.PaginatedList; +import net.sf.acegisecurity.domain.util.GenericsUtils; import net.sf.acegisecurity.domain.validation.ValidationManager; import org.hibernate.Criteria; @@ -62,6 +63,15 @@ public class DaoHibernate extends HibernateDaoSuppo /** Enables mutator methods to validate an object prior to persistence */ private ValidationManager validationManager; + public DaoHibernate() { + this.supportsClass = GenericsUtils.getGeneric(getClass()); + if (this.supportsClass == null) { + if (logger.isWarnEnabled()) { + logger.warn("Could not determine the generics type - you will need to set manually"); + } + } + } + //~ Methods ================================================================ public void setSupportsClass(Class supportClass) { @@ -220,8 +230,7 @@ public class DaoHibernate extends HibernateDaoSuppo protected final void initDao() throws Exception { Assert.notNull(supportsClass, "supportClass is required"); Assert.notNull(validationManager, "validationManager is required"); - Assert.isTrue(PersistableEntity.class.isAssignableFrom(supportsClass), - "supportClass is not an implementation of PersistableEntity"); + Assert.isTrue(PersistableEntity.class.isAssignableFrom(supportsClass), "supportClass is not an implementation of PersistableEntity"); initHibernateDao(); } @@ -338,6 +347,10 @@ public class DaoHibernate extends HibernateDaoSuppo if (name.equals("version")) { continue; } + + if (name.equals("lastUpdatedUsername") || name.equals("lastUpdatedDate")) { + continue; + } if (type.equals(Hibernate.STRING)) { // if the property is mapped as String, find partial match diff --git a/domain/src/main/java/org/acegisecurity/domain/service/ManagerImpl.java b/domain/src/main/java/org/acegisecurity/domain/service/ManagerImpl.java index a0d6a1df9b..3f68683c48 100644 --- a/domain/src/main/java/org/acegisecurity/domain/service/ManagerImpl.java +++ b/domain/src/main/java/org/acegisecurity/domain/service/ManagerImpl.java @@ -16,13 +16,17 @@ package net.sf.acegisecurity.domain.service; import java.io.Serializable; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.Collection; import java.util.List; import net.sf.acegisecurity.domain.PersistableEntity; import net.sf.acegisecurity.domain.dao.Dao; import net.sf.acegisecurity.domain.dao.PaginatedList; +import net.sf.acegisecurity.domain.util.GenericsUtils; +import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.support.ApplicationObjectSupport; import org.springframework.transaction.annotation.Transactional; @@ -40,10 +44,20 @@ public class ManagerImpl extends ApplicationObjectS /** The class that this instance provides services for */ private Class supportsClass; + private String beanName; protected Dao dao; //~ Methods ================================================================ + + public ManagerImpl() { + this.supportsClass = GenericsUtils.getGeneric(getClass()); + if (supportsClass == null) { + if (logger.isWarnEnabled()) { + logger.warn("Could not determine the generics type - you will need to set manually"); + } + } + } public void setSupportsClass(Class supportClass) { this.supportsClass = supportClass; @@ -171,4 +185,8 @@ public class ManagerImpl extends ApplicationObjectS } return dao.update(value); } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } } diff --git a/domain/src/main/java/org/acegisecurity/domain/util/GenericsUtils.java b/domain/src/main/java/org/acegisecurity/domain/util/GenericsUtils.java new file mode 100644 index 0000000000..8e97bcc3ed --- /dev/null +++ b/domain/src/main/java/org/acegisecurity/domain/util/GenericsUtils.java @@ -0,0 +1,33 @@ +package net.sf.acegisecurity.domain.util; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + + +/** + * Provides a helper that locates the declarated generics type of a class. + * + * @author Ben Alex + * @version $Id$ + */ +public class GenericsUtils { + /** + * Locates the first generic declaration on a class. + * + * @param clazz The class to introspect + * @return the first generic declaration, or null if cannot be determined + */ + public static Class getGeneric(Class clazz) { + Type genType = clazz.getGenericSuperclass(); + + if (genType instanceof ParameterizedType) { + Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); + + if ((params != null) && (params.length == 1)) { + return (Class) params[0]; + } + } + + return null; + } +}