X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fusermgt%2Fhibernate%2FHibernateGroupSet.java;fp=security%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fusermgt%2Fhibernate%2FHibernateGroupSet.java;h=0000000000000000000000000000000000000000;hb=5ea8f0e2af53562c1507e8fb5a3ede2af5c5de6c;hp=237ba3aed27f6fcc9f20a5b9776f41754f7e833b;hpb=b9eccdf9751b8e2e671e0792f885d05c6ed0f43c;p=utils diff --git a/security/src/main/java/org/wamblee/usermgt/hibernate/HibernateGroupSet.java b/security/src/main/java/org/wamblee/usermgt/hibernate/HibernateGroupSet.java deleted file mode 100644 index 237ba3ae..00000000 --- a/security/src/main/java/org/wamblee/usermgt/hibernate/HibernateGroupSet.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2005-2010 the original author or authors. - * - * 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 org.wamblee.usermgt.hibernate; - -import org.wamblee.persistence.hibernate.HibernateSupport; - -import org.wamblee.usermgt.Group; -import org.wamblee.usermgt.GroupSet; - -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -/** - * Set of groups backed by the database. - * - * @author Erik Brakkee - */ -public class HibernateGroupSet extends HibernateSupport implements GroupSet { - private static final String QUERY_FIND_BY_NAME = "findGroupByName"; - - private static final String PARAM_NAME = "name"; - - private static final String QUERY_COUNT_GROUPS = "countGroups"; - - /** - * Creates a new HibernateGroupSet object. - */ - public HibernateGroupSet() { - // Empty - } - - /* - * (non-Javadoc) - * - * @see - * org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group) - */ - public void groupModified(Group aGroup) { - assert aGroup.getPrimaryKey() != null; - super.merge(aGroup); - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#find(java.lang.String) - */ - public Group find(String aName) { - List list = getHibernateTemplate().findByNamedQueryAndNamedParam( - QUERY_FIND_BY_NAME, PARAM_NAME, aName); - - if (list.size() > 1) { - throw new RuntimeException( - "More than one group with the same name '" + aName + "'"); - } - - if (list.size() == 0) { - return null; - } - - return new Group((Group) list.get(0)); - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group) - */ - public boolean contains(Group aGroup) { - return find(aGroup.getName()) != null; - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#add(org.wamblee.usermgt.Group) - */ - public boolean add(Group aGroup) { - assert aGroup.getPrimaryKey() == null; - - if (contains(aGroup)) { - return false; - } - - super.merge(aGroup); - - return true; - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#remove(org.wamblee.usermgt.Group) - */ - public boolean remove(Group aGroup) { - assert aGroup.getPrimaryKey() != null; - - if (!contains(aGroup)) { - return false; - } - - Group group = (Group) getHibernateTemplate().merge(aGroup); - getHibernateTemplate().delete(group); - aGroup.setPrimaryKey(null); - aGroup.setPersistedVersion(-1); - - return true; - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#list() - */ - public Set list() { - Set groups = new TreeSet(); - List list = getHibernateTemplate().loadAll(Group.class); - - for (Group group : list) { - groups.add(new Group(group)); - } - - return groups; - } - - /* - * (non-Javadoc) - * - * @see org.wamblee.usermgt.GroupSet#size() - */ - public int size() { - Long result = (Long) getHibernateTemplate().findByNamedQuery( - QUERY_COUNT_GROUPS).get(0); - - return result.intValue(); - } -}