X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fusermgt%2Fhibernate%2FHibernateGroupSet.java;h=7154dd13dd750ba9b1ae8aef7b976bf7c4c816c2;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=957ee44da8931135cb4eb3fa3d80f2112865a4ea;hpb=532f7219273021ef3652e0abe1326b7aeed1f30a;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 index 957ee44d..7154dd13 100644 --- a/security/src/main/java/org/wamblee/usermgt/hibernate/HibernateGroupSet.java +++ b/security/src/main/java/org/wamblee/usermgt/hibernate/HibernateGroupSet.java @@ -1,120 +1,151 @@ /* * Copyright 2005 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 java.util.List; -import java.util.Set; -import java.util.TreeSet; - 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. - * + * 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) + + /* + * (non-Javadoc) + * + * @see + * org.wamblee.usermgt.GroupSet#groupModified(org.wamblee.usermgt.Group) */ public void groupModified(Group aGroup) { - assert aGroup.getPrimaryKey() != null; - super.merge(aGroup); + assert aGroup.getPrimaryKey() != null; + super.merge(aGroup); } - /* (non-Javadoc) + /* + * (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 + "'"); + 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; + + if (list.size() == 0) { + return null; } - return new Group((Group)list.get(0)); + + return new Group((Group) list.get(0)); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.wamblee.usermgt.GroupSet#contains(org.wamblee.usermgt.Group) */ public boolean contains(Group aGroup) { - return find(aGroup.getName()) != null; + return find(aGroup.getName()) != null; } - /* (non-Javadoc) + /* + * (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; + assert aGroup.getPrimaryKey() == null; + + if (contains(aGroup)) { + return false; } + super.merge(aGroup); - return true; + + return true; } - /* (non-Javadoc) + /* + * (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; + assert aGroup.getPrimaryKey() != null; + + if (!contains(aGroup)) { + return false; } - Group group = (Group) getHibernateTemplate().merge(aGroup); + + Group group = (Group) getHibernateTemplate().merge(aGroup); getHibernateTemplate().delete(group); - aGroup.setPrimaryKey(null); + aGroup.setPrimaryKey(null); aGroup.setPersistedVersion(-1); - return true; + + return true; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.wamblee.usermgt.GroupSet#list() */ public Set list() { - Set groups = new TreeSet(); + Set groups = new TreeSet(); List list = getHibernateTemplate().loadAll(Group.class); - for (Group group: list) { + + for (Group group : list) { groups.add(new Group(group)); } - return groups; + + return groups; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.wamblee.usermgt.GroupSet#size() */ public int size() { - Long result = (Long) getHibernateTemplate().findByNamedQuery(QUERY_COUNT_GROUPS).get(0); - return result.intValue(); + Long result = (Long) getHibernateTemplate().findByNamedQuery( + QUERY_COUNT_GROUPS).get(0); + + return result.intValue(); } }