mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-22 20:12:14 +00:00
Domain subproject Java 1.5 compatibility.
This commit is contained in:
parent
de6a258460
commit
5f1cb77e40
@ -220,5 +220,13 @@
|
||||
<attributes>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="var" path="MAVEN_REPO/hibernate/jars/ejb-3.0-edr2.jar">
|
||||
<attributes>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="var" path="MAVEN_REPO/hibernate/jars/hibernate-annotations-3.0-beta1.jar">
|
||||
<attributes>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/eclipseclasses"/>
|
||||
</classpath>
|
||||
|
@ -24,6 +24,9 @@
|
||||
xmlns:util="jelly:util"
|
||||
xmlns:maven="jelly:maven"
|
||||
>
|
||||
<!--
|
||||
Disabled signing the domain JAR for now because it causes Hibernate issues
|
||||
if people subclass from the net.sf.acegitech.domain.impl package.
|
||||
|
||||
<postGoal name="jar:jar">
|
||||
<j:if test="${context.getVariable('signature.alias') != null}">
|
||||
@ -35,5 +38,5 @@
|
||||
</ant:signjar>
|
||||
</j:if>
|
||||
</postGoal>
|
||||
|
||||
-->
|
||||
</project>
|
||||
|
@ -17,6 +17,21 @@
|
||||
<artifactId>hibernate</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<type>jar</type>
|
||||
<url>http://www.hibernate.org</url>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>hibernate</groupId>
|
||||
<artifactId>ejb</artifactId>
|
||||
<version>3.0-edr2</version>
|
||||
<type>jar</type>
|
||||
<url>http://www.hibernate.org</url>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>hibernate</groupId>
|
||||
<artifactId>hibernate-annotations</artifactId>
|
||||
<version>3.0-beta1</version>
|
||||
<type>jar</type>
|
||||
<url>http://www.hibernate.org</url>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
|
@ -22,10 +22,9 @@ import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Provides fundamental DAO capabilities for a single concrete {@link
|
||||
* PersistableEntity}.
|
||||
* PersistableEntity}, using JDK 1.5 generics.
|
||||
*
|
||||
* <P>
|
||||
* This interface provides a portable approach to Data Access Object (DAO)
|
||||
@ -60,7 +59,7 @@ import java.util.List;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Dao {
|
||||
public interface Dao<E extends PersistableEntity> {
|
||||
//~ Methods ================================================================
|
||||
|
||||
/**
|
||||
@ -71,7 +70,7 @@ public interface Dao {
|
||||
*
|
||||
* @return the value created (with the identity property initialised)
|
||||
*/
|
||||
public PersistableEntity create(PersistableEntity value);
|
||||
public E create(E value);
|
||||
|
||||
/**
|
||||
* Saves an existing object to the persistence layer, or creates a new
|
||||
@ -84,14 +83,14 @@ public interface Dao {
|
||||
*
|
||||
* @return the saved or updated (as appropriate) value
|
||||
*/
|
||||
public PersistableEntity createOrUpdate(PersistableEntity value);
|
||||
public E createOrUpdate(E value);
|
||||
|
||||
/**
|
||||
* Delete an object.
|
||||
*
|
||||
* @param value the value to delete
|
||||
*/
|
||||
public void delete(PersistableEntity value);
|
||||
public void delete(E value);
|
||||
|
||||
/**
|
||||
* Return all persistent instances, including subclasses.
|
||||
@ -99,7 +98,7 @@ public interface Dao {
|
||||
* @return all persistence instances (an empty <code>List</code> will be
|
||||
* returned if no matches are found)
|
||||
*/
|
||||
public List findAll();
|
||||
public List<E> findAll();
|
||||
|
||||
/**
|
||||
* Find a <code>List</code> of <code>PersistableEntity</code>s, searched by
|
||||
@ -110,7 +109,7 @@ public interface Dao {
|
||||
* @return the values with those identifiers (an empty <code>List</code>
|
||||
* will be returned if no matches are found)
|
||||
*/
|
||||
public List findId(Collection ids);
|
||||
public List<E> findId(Collection<Serializable> ids);
|
||||
|
||||
/**
|
||||
* Load a persistent instance by its identifier.
|
||||
@ -120,7 +119,7 @@ public interface Dao {
|
||||
*
|
||||
* @return the request item, or <code>null</code> if not found
|
||||
*/
|
||||
public PersistableEntity readId(Serializable id);
|
||||
public E readId(Serializable id);
|
||||
|
||||
/**
|
||||
* Find persistent instances with properties matching those of the passed
|
||||
@ -133,8 +132,8 @@ public interface Dao {
|
||||
* the query by example evaluation.
|
||||
* </p>
|
||||
*
|
||||
* @param value parameters to filter on (the class of this object will be
|
||||
* added to the filter)
|
||||
* @param value parameters to filter on (the class of this object will
|
||||
* be added to the filter)
|
||||
* @param firstElement the first result (start at zero to obtain all
|
||||
* results)
|
||||
* @param maxElements the maximum number of results desired for this page
|
||||
@ -146,17 +145,17 @@ public interface Dao {
|
||||
* @return the requested page of the result list (a properly formed
|
||||
* <code>PaginatedList</code> is returned if no results match)
|
||||
*/
|
||||
public PaginatedList scroll(PersistableEntity value, int firstElement,
|
||||
public PaginatedList<E> scroll(E value, int firstElement,
|
||||
int maxElements, String orderByAsc);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Find persistent instances with properties matching those of the passed
|
||||
* <code>PersistableEntity</code>, ignoring the class of the passed
|
||||
* <code>PersistableEntity</code> (useful if you pass a superclass, as you
|
||||
* want to find all subclass instances which match).
|
||||
*
|
||||
* @param value parameters to filter on (the class of this object will NOT
|
||||
* be added to the filter)
|
||||
*
|
||||
* @param value parameters to filter on (the class of this object will
|
||||
* NOT be added to the filter)
|
||||
* @param firstElement the first result (start at zero to obtain all
|
||||
* results)
|
||||
* @param maxElements the maximum number of results desired for this page
|
||||
@ -167,11 +166,11 @@ public interface Dao {
|
||||
*
|
||||
* @return the requested page of the result list (a properly formed
|
||||
* <code>PaginatedList</code> is returned if no results match)
|
||||
*/
|
||||
public PaginatedList scrollWithSubclasses(PersistableEntity value,
|
||||
int firstElement, int maxElements, String orderByAsc);
|
||||
*/
|
||||
public PaginatedList<E> scrollWithSubclasses(E value, int firstElement,
|
||||
int maxElements, String orderByAsc);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Indicates whether the DAO instance provides persistence services for the
|
||||
* specified class.
|
||||
*
|
||||
@ -191,5 +190,5 @@ public interface Dao {
|
||||
*
|
||||
* @return the updated value
|
||||
*/
|
||||
public PersistableEntity update(PersistableEntity value);
|
||||
public E update(E value);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class EvictionUtils {
|
||||
* @param collection whose members to evict (never <code>null</code>)
|
||||
*/
|
||||
public static void evictIfRequired(Object daoOrServices,
|
||||
Collection collection) {
|
||||
Collection<Object> collection) {
|
||||
Assert.notNull(collection, "Cannot evict a null Collection");
|
||||
|
||||
if (getEvictionCapable(daoOrServices) == null) {
|
||||
@ -70,7 +70,7 @@ public class EvictionUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator iter = collection.iterator();
|
||||
Iterator<Object> iter = collection.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Object obj = iter.next();
|
||||
|
@ -30,7 +30,7 @@ import java.util.Vector;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Represents a paginated <code>List</code>.
|
||||
* JDK1.5 compatible paginated <code>List</code>.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
@ -52,11 +52,11 @@ import java.util.Vector;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PaginatedList implements List {
|
||||
public class PaginatedList<E extends PersistableEntity> implements List<E> {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
protected final transient Log logger = LogFactory.getLog(getClass());
|
||||
private List list;
|
||||
private List<E> list;
|
||||
private int firstElement;
|
||||
private int maxElements;
|
||||
private int size;
|
||||
@ -73,23 +73,23 @@ public class PaginatedList implements List {
|
||||
* @param entity the entity to include (can be <code>null</code>, which
|
||||
* indicates an empty <code>PaginatedList</code> should be created)
|
||||
*/
|
||||
public PaginatedList(PersistableEntity entity) {
|
||||
public PaginatedList(E entity) {
|
||||
if (entity == null) {
|
||||
this.list = new Vector();
|
||||
this.list = new Vector<E>();
|
||||
this.firstElement = 0;
|
||||
this.maxElements = Integer.MAX_VALUE;
|
||||
this.size = 0;
|
||||
} else {
|
||||
List list = new Vector();
|
||||
list.add(entity);
|
||||
this.list = list;
|
||||
List<E> myList = new Vector<E>();
|
||||
myList.add(entity);
|
||||
this.list = myList;
|
||||
this.firstElement = 0;
|
||||
this.maxElements = Integer.MAX_VALUE;
|
||||
this.size = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public PaginatedList(List list, int firstElement, int maxElements, int size) {
|
||||
public PaginatedList(List<E> list, int firstElement, int maxElements, int size) {
|
||||
this.list = list;
|
||||
this.firstElement = firstElement;
|
||||
this.maxElements = maxElements;
|
||||
@ -133,7 +133,7 @@ public class PaginatedList implements List {
|
||||
return (size() - 1) / getMaxElements();
|
||||
}
|
||||
|
||||
public void setList(List list) {
|
||||
public void setList(List<E> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @return this page of the results
|
||||
*/
|
||||
public List getList() {
|
||||
public List<E> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#add(int, java.lang.Object)
|
||||
*/
|
||||
public void add(int arg0, Object arg1) {
|
||||
public void add(int arg0, E arg1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.Collection#add(java.lang.Object)
|
||||
*/
|
||||
public boolean add(Object arg0) {
|
||||
public boolean add(E arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.Collection#addAll(java.util.Collection)
|
||||
*/
|
||||
public boolean addAll(Collection arg0) {
|
||||
public boolean addAll(Collection<? extends E> arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#addAll(int, java.util.Collection)
|
||||
*/
|
||||
public boolean addAll(int arg0, Collection arg1) {
|
||||
public boolean addAll(int arg0, Collection<? extends E> arg1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.Collection#containsAll(java.util.Collection)
|
||||
*/
|
||||
public boolean containsAll(Collection arg0) {
|
||||
public boolean containsAll(Collection<?> arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -296,7 +296,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#get(int)
|
||||
*/
|
||||
public Object get(int arg0) {
|
||||
public E get(int arg0) {
|
||||
return list.get(arg0);
|
||||
}
|
||||
|
||||
@ -315,7 +315,7 @@ public class PaginatedList implements List {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator iterator() {
|
||||
public Iterator<E> iterator() {
|
||||
return new PaginatedListIterator();
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#listIterator()
|
||||
*/
|
||||
public ListIterator listIterator() {
|
||||
public ListIterator<E> listIterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -358,7 +358,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#listIterator(int)
|
||||
*/
|
||||
public ListIterator listIterator(int arg0) {
|
||||
public ListIterator<E> listIterator(int arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -373,7 +373,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#remove(int)
|
||||
*/
|
||||
public Object remove(int arg0) {
|
||||
public E remove(int arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -418,7 +418,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.Collection#retainAll(java.util.Collection)
|
||||
*/
|
||||
public boolean retainAll(Collection arg0) {
|
||||
public boolean retainAll(Collection<?> arg0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -434,7 +434,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#set(int, java.lang.Object)
|
||||
*/
|
||||
public Object set(int arg0, Object arg1) {
|
||||
public E set(int arg0, E arg1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -459,7 +459,7 @@ public class PaginatedList implements List {
|
||||
*
|
||||
* @see java.util.List#subList(int, int)
|
||||
*/
|
||||
public List subList(int arg0, int arg1) {
|
||||
public List<E> subList(int arg0, int arg1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ public class PaginatedList implements List {
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
public Object[] toArray(Object[] arg0) {
|
||||
public <T> T[] toArray(T[] arg0) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("List size when convert to array "
|
||||
+ list.toArray().length);
|
||||
@ -475,57 +475,61 @@ public class PaginatedList implements List {
|
||||
|
||||
return list.toArray(arg0);
|
||||
}
|
||||
|
||||
|
||||
private class PaginatedListIterator implements Iterator<E> {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
//~ Inner Classes ==========================================================
|
||||
private Iterator<E> iterator;
|
||||
private int i = 0;
|
||||
|
||||
private class PaginatedListIterator implements Iterator {
|
||||
private Iterator iterator;
|
||||
private int i = 0;
|
||||
/**
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return i < size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return i < size();
|
||||
}
|
||||
/**
|
||||
* This method follows the rules of Iterator.next() except that it returns
|
||||
* null when requesting an element that it's not in the current page.
|
||||
*
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public E next() {
|
||||
if (i == getFirstElement()) {
|
||||
iterator = getList().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method follows the rules of Iterator.next() except that it
|
||||
* returns null when requesting an element that it's not in the
|
||||
* current page.
|
||||
*
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public Object next() {
|
||||
if (i == getFirstElement()) {
|
||||
iterator = getList().iterator();
|
||||
}
|
||||
if ((i >= getFirstElement())
|
||||
&& (i < (getFirstElement() + getMaxElements()))) {
|
||||
i++;
|
||||
|
||||
if ((i >= getFirstElement())
|
||||
&& (i < (getFirstElement() + getMaxElements()))) {
|
||||
i++;
|
||||
return iterator.next();
|
||||
}
|
||||
|
||||
return iterator.next();
|
||||
}
|
||||
if (hasNext()) {
|
||||
i++;
|
||||
|
||||
if (hasNext()) {
|
||||
i++;
|
||||
return null;
|
||||
} else {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} else {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported operation
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
*
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Unsupported operation
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
*
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -38,15 +38,14 @@ import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* {@link Dao} implementation that uses Hibernate 3 for persistence.
|
||||
* Generics supporting {@link Dao} implementation that uses Hibernate 3 for persistence.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @author Matthew Porter
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
public class DaoHibernate<E extends PersistableEntity> extends HibernateDaoSupport implements Dao<E>,
|
||||
EvictionCapable {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
@ -63,21 +62,21 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
return supportsClass;
|
||||
}
|
||||
|
||||
public PersistableEntity create(PersistableEntity value) {
|
||||
public E create(E value) {
|
||||
Assert.notNull(value);
|
||||
getHibernateTemplate().save(value);
|
||||
|
||||
return readId(value.getInternalId());
|
||||
}
|
||||
|
||||
public PersistableEntity createOrUpdate(PersistableEntity value) {
|
||||
public E createOrUpdate(E value) {
|
||||
Assert.notNull(value);
|
||||
getHibernateTemplate().saveOrUpdate(value);
|
||||
|
||||
return readId(value.getInternalId());
|
||||
}
|
||||
|
||||
public void delete(PersistableEntity value) {
|
||||
public void delete(E value) {
|
||||
Assert.notNull(value);
|
||||
getHibernateTemplate().delete(value);
|
||||
}
|
||||
@ -87,24 +86,24 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
getHibernateTemplate().evict(entity);
|
||||
}
|
||||
|
||||
public List findAll() {
|
||||
public List<E> findAll() {
|
||||
return getHibernateTemplate().loadAll(supportsClass);
|
||||
}
|
||||
|
||||
public List findId(Collection ids) {
|
||||
public List<E> findId(Collection<Serializable> ids) {
|
||||
Assert.notNull(ids, "Collection of IDs cannot be null");
|
||||
Assert.notEmpty(ids, "There must be some values in the Collection list");
|
||||
|
||||
return (List) getHibernateTemplate().execute(getFindByIdCallback(ids));
|
||||
}
|
||||
|
||||
public PersistableEntity readId(Serializable id) {
|
||||
public E readId(Serializable id) {
|
||||
Assert.notNull(id);
|
||||
|
||||
return (PersistableEntity) getHibernateTemplate().get(supportsClass, id);
|
||||
return (E) getHibernateTemplate().get(supportsClass, id);
|
||||
}
|
||||
|
||||
public PaginatedList scroll(PersistableEntity value, int firstElement,
|
||||
public PaginatedList<E> scroll(E value, int firstElement,
|
||||
int maxElements, String orderByAsc) {
|
||||
Assert.notNull(value);
|
||||
Assert.hasText(orderByAsc,
|
||||
@ -112,10 +111,10 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
Assert.isInstanceOf(this.supportsClass, value, "Can only scroll with values this DAO supports");
|
||||
|
||||
return (PaginatedList) getHibernateTemplate().execute(getFindByValueCallback(
|
||||
value.getClass(), value, firstElement, maxElements, Order.asc(orderByAsc)));
|
||||
value.getClass(), value, firstElement, maxElements, Order.asc(orderByAsc)));
|
||||
}
|
||||
|
||||
public PaginatedList scrollWithSubclasses(PersistableEntity value, int firstElement,
|
||||
public PaginatedList<E> scrollWithSubclasses(E value, int firstElement,
|
||||
int maxElements, String orderByAsc) {
|
||||
Assert.notNull(value);
|
||||
Assert.hasText(orderByAsc,
|
||||
@ -123,7 +122,7 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
Assert.isInstanceOf(this.supportsClass, value, "Can only scroll with values this DAO supports");
|
||||
|
||||
return (PaginatedList) getHibernateTemplate().execute(getFindByValueCallback(
|
||||
this.supportsClass, value, firstElement, maxElements, Order.asc(orderByAsc)));
|
||||
this.supportsClass, value, firstElement, maxElements, Order.asc(orderByAsc)));
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
@ -132,7 +131,7 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
return this.supportsClass.equals(clazz);
|
||||
}
|
||||
|
||||
public PersistableEntity update(PersistableEntity value) {
|
||||
public E update(E value) {
|
||||
Assert.notNull(value);
|
||||
getHibernateTemplate().update(value);
|
||||
|
||||
@ -167,7 +166,7 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
*
|
||||
* @return a <code>List</code> containing the matching objects
|
||||
*/
|
||||
private HibernateCallback getFindByIdCallback(final Collection ids) {
|
||||
private HibernateCallback getFindByIdCallback(final Collection<Serializable> ids) {
|
||||
return new HibernateCallback() {
|
||||
public Object doInHibernate(Session session)
|
||||
throws HibernateException {
|
||||
@ -263,10 +262,9 @@ public class DaoHibernate extends HibernateDaoSupport implements Dao,
|
||||
*/
|
||||
int size = criteria.list().size();
|
||||
|
||||
List list = criteria.setFirstResult(firstElement)
|
||||
.setMaxResults(count).list();
|
||||
List<E> list = criteria.setFirstResult(firstElement).setMaxResults(count).list();
|
||||
|
||||
return new PaginatedList(list, firstElement, count, size);
|
||||
return new PaginatedList<E>(list, firstElement, count, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.sf.acegisecurity.domain.hibernate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.usertype.UserType;
|
||||
|
||||
/**
|
||||
* Java 1.5 <code>enum</code>eration compatible Hibernate 3 <code>UserType</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EnumUserType<E extends Enum<E>> implements UserType {
|
||||
private Class<E> clazz = null;
|
||||
protected EnumUserType(Class<E> c) {
|
||||
this.clazz = c;
|
||||
}
|
||||
|
||||
private static final int[] SQL_TYPES = {Types.VARCHAR};
|
||||
public int[] sqlTypes() {
|
||||
return SQL_TYPES;
|
||||
}
|
||||
|
||||
public Class returnedClass() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
|
||||
String name = resultSet.getString(names[0]);
|
||||
E result = null;
|
||||
if (!resultSet.wasNull()) {
|
||||
result = Enum.valueOf(clazz, name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
|
||||
if (null == value) {
|
||||
preparedStatement.setNull(index, Types.VARCHAR);
|
||||
} else {
|
||||
preparedStatement.setString(index, ((Enum)value).name());
|
||||
}
|
||||
}
|
||||
|
||||
public Object deepCopy(Object value) throws HibernateException{
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object assemble(Serializable cached, Object owner) throws HibernateException {
|
||||
return cached;
|
||||
}
|
||||
|
||||
public Serializable disassemble(Object value) throws HibernateException {
|
||||
return (Serializable)value;
|
||||
}
|
||||
|
||||
public Object replace(Object original, Object target, Object owner) throws HibernateException {
|
||||
return original;
|
||||
}
|
||||
public int hashCode(Object x) throws HibernateException {
|
||||
return x.hashCode();
|
||||
}
|
||||
public boolean equals(Object x, Object y) throws HibernateException {
|
||||
if (x == y)
|
||||
return true;
|
||||
if (null == x || null == y)
|
||||
return false;
|
||||
return x.equals(y);
|
||||
}
|
||||
}
|
@ -35,6 +35,7 @@ import org.springframework.util.Assert;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -90,17 +91,17 @@ public class IntrospectionManagerHibernate implements IntrospectionManager,
|
||||
Assert.notNull(sessionFactory, "SessionFactory is required");
|
||||
|
||||
// Eagerly pre-register Validators for all Hibernate metadata-defined classes
|
||||
Collection mappedClasses = this.sessionFactory.getAllClassMetadata()
|
||||
.keySet();
|
||||
Map<String,ClassMetadata> metadataMap = this.sessionFactory.getAllClassMetadata();
|
||||
Collection<String> mappedClasses = metadataMap.keySet();
|
||||
|
||||
for (Iterator iter = mappedClasses.iterator(); iter.hasNext();) {
|
||||
String className = (String) iter.next();
|
||||
for (Iterator<String> iter = mappedClasses.iterator(); iter.hasNext();) {
|
||||
String className = iter.next();
|
||||
this.validationRegistryManager.findValidator(Class.forName(
|
||||
className));
|
||||
}
|
||||
}
|
||||
|
||||
public void obtainImmediateChildren(Object parentObject, List allObjects) {
|
||||
public void obtainImmediateChildren(Object parentObject, List<Object> allObjects) {
|
||||
Assert.notNull(parentObject,
|
||||
"Violation of interface contract: parentObject null");
|
||||
Assert.notNull(allObjects,
|
||||
|
@ -15,8 +15,11 @@
|
||||
|
||||
package net.sf.acegisecurity.domain.impl;
|
||||
|
||||
import net.sf.acegisecurity.domain.PersistableEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import net.sf.acegisecurity.domain.PersistableEntity;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link
|
||||
@ -24,6 +27,8 @@ import net.sf.acegisecurity.domain.PersistableEntity;
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractPersistableEntity extends BusinessObject
|
||||
implements PersistableEntity {
|
||||
@ -45,6 +50,7 @@ public abstract class AbstractPersistableEntity extends BusinessObject
|
||||
* @return <code>true</code> if the instance has not been persisted,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
@Transient
|
||||
public final boolean isNew() {
|
||||
return (getInternalId() == null);
|
||||
}
|
||||
@ -60,6 +66,8 @@ public abstract class AbstractPersistableEntity extends BusinessObject
|
||||
*
|
||||
* @return the version
|
||||
*/
|
||||
@Version
|
||||
@Column(name="version", nullable=false)
|
||||
public final int getVersion() {
|
||||
return version;
|
||||
}
|
||||
@ -68,8 +76,6 @@ public abstract class AbstractPersistableEntity extends BusinessObject
|
||||
* Sets the version numbers. Should only be used by the persistence layer.
|
||||
*
|
||||
* @param version the new version number to use
|
||||
*
|
||||
* @hibernate.version type="integer"
|
||||
*/
|
||||
protected final void setVersion(int version) {
|
||||
this.version = version;
|
||||
|
@ -17,9 +17,10 @@ package net.sf.acegisecurity.domain.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* A persistable entity that uses an <code>Integer</code> based identity.
|
||||
* A persistable entity that uses a <code>Integer</code> based identity.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
@ -27,7 +28,7 @@ import java.io.Serializable;
|
||||
public abstract class PersistableEntityInteger extends AbstractPersistableEntity {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private Integer id;
|
||||
protected Integer id;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
@ -47,14 +48,12 @@ public abstract class PersistableEntityInteger extends AbstractPersistableEntity
|
||||
|
||||
/**
|
||||
* Obtains the persistence identity of this instance.
|
||||
*
|
||||
* @return the instance's identity
|
||||
*
|
||||
* @hibernate.id generator-class="native"
|
||||
*
|
||||
* <p>Marked as abstract to remind users to implement. They'll need to implement
|
||||
* so their annotations reflect the correct sequence name.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@Transient
|
||||
public abstract Integer getId();
|
||||
|
||||
/**
|
||||
* DO NOT USE DIRECTLY.
|
||||
@ -72,6 +71,7 @@ public abstract class PersistableEntityInteger extends AbstractPersistableEntity
|
||||
*
|
||||
* @return the instance's identity
|
||||
*/
|
||||
@Transient
|
||||
public Serializable getInternalId() {
|
||||
return this.getId();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ package net.sf.acegisecurity.domain.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* A persistable entity that uses a <code>Long</code> based identity.
|
||||
@ -27,7 +28,7 @@ import java.io.Serializable;
|
||||
public abstract class PersistableEntityLong extends AbstractPersistableEntity {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private Long id;
|
||||
protected Long id;
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
@ -47,14 +48,12 @@ public abstract class PersistableEntityLong extends AbstractPersistableEntity {
|
||||
|
||||
/**
|
||||
* Obtains the persistence identity of this instance.
|
||||
*
|
||||
* @return the instance's identity
|
||||
*
|
||||
* @hibernate.id generator-class="native"
|
||||
*
|
||||
* <p>Marked as abstract to remind users to implement. They'll need to implement
|
||||
* so their annotations reflect the correct sequence name.
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@Transient
|
||||
public abstract Long getId();
|
||||
|
||||
/**
|
||||
* DO NOT USE DIRECTLY.
|
||||
@ -72,6 +71,7 @@ public abstract class PersistableEntityLong extends AbstractPersistableEntity {
|
||||
*
|
||||
* @return the instance's identity
|
||||
*/
|
||||
@Transient
|
||||
public Serializable getInternalId() {
|
||||
return this.getId();
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class CollectionUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Set add(Set set, Object object) {
|
||||
public static <E> Set<E> add(Set<E> set, E object) {
|
||||
set.add(object);
|
||||
|
||||
return set;
|
||||
@ -67,7 +67,7 @@ public class CollectionUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List add(List list, Object object) {
|
||||
public static <E> List<E> add(List<E> list, E object) {
|
||||
list.add(object);
|
||||
|
||||
return list;
|
||||
@ -83,20 +83,20 @@ public class CollectionUtils {
|
||||
*
|
||||
* @throws IllegalArgumentException DOCUMENT ME!
|
||||
*/
|
||||
public static Collection clone(Collection collection) {
|
||||
public static <E> Collection<E> clone(Collection<E> collection) {
|
||||
if (collection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class clazz = collection.getClass();
|
||||
Collection clone = null;
|
||||
Collection<E> clone = null;
|
||||
|
||||
if (List.class.isAssignableFrom(clazz)) {
|
||||
clone = new ArrayList(collection);
|
||||
clone = new ArrayList<E>(collection);
|
||||
} else if (SortedSet.class.isAssignableFrom(clazz)) {
|
||||
clone = new TreeSet(collection);
|
||||
clone = new TreeSet<E>(collection);
|
||||
} else if (Set.class.isAssignableFrom(clazz)) {
|
||||
clone = new HashSet(collection);
|
||||
clone = new HashSet<E>(collection);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown collection class: "
|
||||
+ clazz);
|
||||
@ -117,18 +117,18 @@ public class CollectionUtils {
|
||||
* @throws IllegalArgumentException if the <code>Map</code> implementation
|
||||
* is not supported by this method
|
||||
*/
|
||||
public static Map clone(Map map) {
|
||||
public static <K,V> Map<K,V> clone(Map<K,V> map) {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Class clazz = map.getClass();
|
||||
Map clone = null;
|
||||
Map<K,V> clone = null;
|
||||
|
||||
if (SortedMap.class.isAssignableFrom(clazz)) {
|
||||
clone = new TreeMap(map);
|
||||
clone = new TreeMap<K,V>(map);
|
||||
} else if (Map.class.isAssignableFrom(clazz)) {
|
||||
clone = new HashMap(map);
|
||||
clone = new HashMap<K,V>(map);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown map class: " + clazz);
|
||||
}
|
||||
@ -144,8 +144,8 @@ public class CollectionUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List newList(Object object) {
|
||||
return add(new ArrayList(1), object);
|
||||
public static <E> List<E> newList(E object) {
|
||||
return add(new ArrayList<E>(1), object);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,7 +156,7 @@ public class CollectionUtils {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Set newSet(Object object) {
|
||||
return add(new HashSet(), object);
|
||||
public static <E> Set<E> newSet(E object) {
|
||||
return add(new HashSet<E>(), object);
|
||||
}
|
||||
}
|
||||
|
@ -51,5 +51,5 @@ public interface IntrospectionManager {
|
||||
* @param allObjects the list to which this method should append each
|
||||
* immediate child (guaranteed to never be <code>null</code>)
|
||||
*/
|
||||
public void obtainImmediateChildren(Object parentObject, List allObjects);
|
||||
public void obtainImmediateChildren(Object parentObject, List<Object> allObjects);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class ValidationAdvisor extends StaticMethodMatcherPointcutAdvisor
|
||||
implements InitializingBean {
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private Class supportsClass;
|
||||
private Class<? extends Object> supportsClass;
|
||||
private String[] methods = {"create", "update", "createOrUpdate"};
|
||||
|
||||
//~ Constructors ===========================================================
|
||||
@ -72,7 +72,7 @@ public class ValidationAdvisor extends StaticMethodMatcherPointcutAdvisor
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void setSupportsClass(Class clazz) {
|
||||
public void setSupportsClass(Class<? extends Object> clazz) {
|
||||
this.supportsClass = clazz;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* <p>
|
||||
* For each method invocation, any argument that is assignable from {@link
|
||||
* #argumentClasses}<b>and</b> is non-<code>null</code> will be passed to the
|
||||
* #argumentClasses} <b>and</b> is non-<code>null</code> will be passed to the
|
||||
* {@link net.sf.acegisecurity.domain.validation.ValidationManager} for
|
||||
* processing.
|
||||
* </p>
|
||||
@ -48,7 +48,7 @@ public class ValidationInterceptor implements MethodInterceptor,
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
private ValidationManager validationManager;
|
||||
private Class[] argumentClasses = {BusinessObject.class, PersistableEntity.class};
|
||||
private Class<?>[] argumentClasses = {BusinessObject.class, PersistableEntity.class};
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class ValidationManagerImpl implements InitializingBean,
|
||||
"Cannot validate a null domain object, as unable to getClass()");
|
||||
|
||||
// Construct a list of objects to be validated and adds self
|
||||
List allObjects = new Vector();
|
||||
List<Object> allObjects = new Vector<Object>();
|
||||
allObjects.add(domainObject);
|
||||
|
||||
// Add all children (and grandchildren, great-grandchildren etc)
|
||||
@ -128,7 +128,7 @@ public class ValidationManagerImpl implements InitializingBean,
|
||||
"The list of objects to be validated was empty");
|
||||
|
||||
// Process list of objects to be validated by validating each
|
||||
Iterator iter = allObjects.iterator();
|
||||
Iterator<Object> iter = allObjects.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Object currentDomainObject = iter.next();
|
||||
@ -204,7 +204,7 @@ public class ValidationManagerImpl implements InitializingBean,
|
||||
* @param parentObject the object we wish to locate all children for
|
||||
* @param allObjects the list to add the located children to
|
||||
*/
|
||||
private void obtainAllChildren(Object parentObject, List allObjects) {
|
||||
private void obtainAllChildren(Object parentObject, List<Object> allObjects) {
|
||||
Assert.notNull(parentObject, "Violation of parentObject method contract");
|
||||
Assert.notNull(allObjects, "Violation of allObjects method contract");
|
||||
Assert.isTrue(allObjects.contains(parentObject),
|
||||
@ -215,7 +215,7 @@ public class ValidationManagerImpl implements InitializingBean,
|
||||
}
|
||||
|
||||
// Add immediate children of this domain object
|
||||
List currentChildren = new Vector();
|
||||
List<Object> currentChildren = new Vector<Object>();
|
||||
introspectionManager.obtainImmediateChildren(parentObject,
|
||||
currentChildren);
|
||||
|
||||
@ -223,7 +223,7 @@ public class ValidationManagerImpl implements InitializingBean,
|
||||
allObjects.addAll(currentChildren);
|
||||
|
||||
// Now iterate the children, adding their children to the object list
|
||||
Iterator childrenIter = currentChildren.iterator();
|
||||
Iterator<Object> childrenIter = currentChildren.iterator();
|
||||
|
||||
while (childrenIter.hasNext()) {
|
||||
Object childObject = childrenIter.next();
|
||||
|
@ -46,7 +46,7 @@ public class ValidationRegistryManagerImpl implements ValidationRegistryManager,
|
||||
//~ Instance fields ========================================================
|
||||
|
||||
private ListableBeanFactory bf;
|
||||
private Map validatorMap = new HashMap();
|
||||
private Map<Class,String> validatorMap = new HashMap<Class,String>();
|
||||
|
||||
//~ Methods ================================================================
|
||||
|
||||
@ -68,11 +68,11 @@ public class ValidationRegistryManagerImpl implements ValidationRegistryManager,
|
||||
}
|
||||
|
||||
// Attempt to find Validator via introspection
|
||||
Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, Validator.class, true, true);
|
||||
Iterator iter = beans.keySet().iterator();
|
||||
Map<String,Validator> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, Validator.class, true, true);
|
||||
Iterator<String> iter = beans.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String beanName = (String) iter.next();
|
||||
Validator validator = (Validator) beans.get(beanName);
|
||||
String beanName = iter.next();
|
||||
Validator validator = beans.get(beanName);
|
||||
if (validator.supports(domainClass)) {
|
||||
this.validatorMap.put(domainClass, beanName);
|
||||
return validator;
|
||||
|
Loading…
x
Reference in New Issue
Block a user