package org.ccpit.base.role;

import org.ccpit.base.modol.BaseEntity;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/9/2.
 */
@Entity
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends BaseEntity implements IRole {
    private String roleName;
    private List<RoleUrl> urlPerfixs = new ArrayList<RoleUrl>();
    private String description;

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return super.getId();
    }
    
    @Override
    public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@Override
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    public List<RoleUrl> getUrlPerfixs() {
        return urlPerfixs;
    }

    public void setUrlPerfixs(List<RoleUrl> urlPerfixs) {
        this.urlPerfixs = urlPerfixs;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int hashCode() {
        return ("role"+getId()).hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(o == null){
            return false;
        }
        if(o == this){
            return true;
        }
        if(o.getClass() == Role.class){
            return o.hashCode()==this.hashCode();
        }
        return false;
    }
}
