/* * 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.security.authentication; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Version; /** * Represents a group. * * @author Erik Brakkee */ @Entity @Table(name = "SEC_GROUP") @NamedQueries( { @NamedQuery(name = Group.QUERY_FIND_BY_NAME, query = "select g from Group g where g.name = :" + Group.NAME_PARAM), @NamedQuery(name = Group.QUERY_COUNT_GROUPS, query = "select count(g) from Group g"), @NamedQuery(name = Group.QUERY_ALL_GROUPS, query = "select g from Group g") }) public class Group implements Serializable, Comparable { public static final String QUERY_FIND_BY_NAME = "Group.findByName"; public static final String QUERY_COUNT_GROUPS = "Group.count"; public static final String QUERY_ALL_GROUPS = "Group.all"; public static final String NAME_PARAM = "name"; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Version private int version; /** * Group name. */ @Column(nullable = false, unique = true) private String name; /** * Constructs the group. * * @param aName */ Group(String aName) { super(); name = aName; } /** * Creates a new Group object. * */ public Group(Group aGroup) { id = aGroup.id; version = aGroup.version; name = aGroup.name; } /** * Creates a new Group object. */ protected Group() { super(); name = null; } /** * Gets the name of the group. * * @return Group name. */ public String getName() { return name; } /** * Sets the group name. * * @param aName * Group name. */ void setName(String aName) { name = aName; } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object aGroup) { if (aGroup == null) { return false; } if (!(aGroup instanceof Group)) { return false; } return name.equals(((Group) aGroup).name); } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return name.hashCode(); } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(T) */ public int compareTo(Object aGroup) { return name.compareTo(((Group) aGroup).name); } public Long getPrimaryKey() { return id; } public void setPrimaryKey(Long aKey) { id = aKey; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return "Group(pk = " + getPrimaryKey() + ", name=" + name + ")"; } }