net.kamhon.ieagle.function.log.vo.SessionLog.java Source code

Java tutorial

Introduction

Here is the source code for net.kamhon.ieagle.function.log.vo.SessionLog.java

Source

/*
 * Copyright 2012 Eng Kam Hon (kamhon@gmail.com)
 * 
 * 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 net.kamhon.ieagle.function.log.vo;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.kamhon.ieagle.function.user.vo.User;
import net.kamhon.ieagle.vo.annotation.ToTrim;
import net.kamhon.ieagle.vo.annotation.ToUpperCase;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "lg_session_log")
@Access(AccessType.FIELD)
public class SessionLog extends net.kamhon.ieagle.vo.VoBase {
    private static final long serialVersionUID = 1L;

    public static final String LOGIN_STATUS_SUCCESS = "SUCCESS";
    public static final String LOGIN_STATUS_FAILED = "FAILED";

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name = "session_id", unique = true, nullable = false, length = 32)
    private String sessionId;

    @Column(name = "user_id")
    private String userId;

    @ManyToOne
    @JoinColumn(name = "user_id", insertable = false, updatable = false, nullable = true)
    private User user;

    @ToTrim
    @ToUpperCase
    @Column(name = "username", length = 20, nullable = false)
    private String username;

    @ToTrim
    @ToUpperCase
    @Column(name = "ip_address", length = 30, nullable = false)
    private String ipAddress;

    @ToTrim
    @ToUpperCase
    @Column(name = "login_status", length = 10, nullable = false)
    private String loginStatus;

    public SessionLog() {
    }

    public SessionLog(String sessionId) {
        this.sessionId = sessionId;
    }

    public SessionLog(boolean defaultValue) {
        if (defaultValue) {
            loginStatus = LOGIN_STATUS_SUCCESS;
        }
    }

    public String getSessionId() {
        return sessionId;
    }

    public String getUserId() {
        return userId;
    }

    public String getUsername() {
        return username;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public String getLoginStatus() {
        return loginStatus;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public void setLoginStatus(String loginStatus) {
        this.loginStatus = loginStatus;
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final SessionLog other = (SessionLog) obj;
        if (this.sessionId == null) {
            if (other.sessionId != null)
                return false;
        } else if (!this.sessionId.equals(other.sessionId))
            return false;
        return true;
    }

    public int hashCode() {
        HashCodeBuilder hashCode = new HashCodeBuilder();
        if (sessionId != null)
            hashCode.append(sessionId);
        return hashCode.toHashCode();
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}