com.github.fauu.natrank.model.entity.BaseEntity.java Source code

Java tutorial

Introduction

Here is the source code for com.github.fauu.natrank.model.entity.BaseEntity.java

Source

/*
 * Copyright (C) 2014 natrank Developers (http://github.com/fauu/natrank)
 *
 * This software is licensed under the GNU General Public License
 * (version 3 or later). See the COPYING file in this distribution.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this software. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Piotr Grabowski <fau999@gmail.com>
 */

package com.github.fauu.natrank.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import com.github.fauu.natrank.web.json.BaseView;
import lombok.*;

import javax.persistence.*;

@MappedSuperclass
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(of = { "id" })
@ToString
public abstract class BaseEntity<T extends BaseEntity<T>> implements Comparable<T> {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonView(BaseView.class)
    protected Integer id;

    @JsonIgnore
    public boolean isNew() {
        return (this.id == null);
    }

    @Override
    public int compareTo(T other) {
        return Integer.compare(this.getId(), other.getId());
    }

}