X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fusermgt%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthentication%2FGroup.java;fp=security%2Fusermgt%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthentication%2FGroup.java;h=1cac00f80ef3a60aba61869f75a73ce2a4c0354c;hb=9449ea0f360f6e9c14057db57f3ee0bfba947ab4;hp=0000000000000000000000000000000000000000;hpb=e8b988e92306a4aea2f047af1b48588147288831;p=utils diff --git a/security/usermgt/src/main/java/org/wamblee/security/authentication/Group.java b/security/usermgt/src/main/java/org/wamblee/security/authentication/Group.java new file mode 100644 index 00000000..1cac00f8 --- /dev/null +++ b/security/usermgt/src/main/java/org/wamblee/security/authentication/Group.java @@ -0,0 +1,162 @@ +/* + * 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 + ")"; + } +}