All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.landel.utils.model.AbstractDTO Maven / Gradle / Ivy

/*
 * #%L
 * utils-model
 * %%
 * Copyright (C) 2016 Gilandel
 * %%
 * Authors: Gilles Landel
 * URL: https://github.com/Gilandel
 * 
 * This file is under Apache License, version 2.0 (2004).
 * #L%
 */
package fr.landel.utils.model;

import java.io.Serializable;
import java.util.Objects;

/**
 * Abstract DTO.
 *
 * @since 14 juil. 2015
 * @author Gilles
 * 
 * @param 
 *            The DTO type.
 * @param 
 *            The primary key type.
 */
public abstract class AbstractDTO, K extends Serializable> extends AbstractModelOverObject
        implements IDO {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -7966490818333185949L;

    private Class primaryKeyClass;

    /**
     * The primary key
     */
    private K primaryKey;

    /**
     * The loaded state
     */
    private Boolean loaded;

    /**
     * 
     * Constructor
     *
     */
    public AbstractDTO() {
        super();
    }

    /**
     * Constructor
     *
     * @param clazz
     *            The DTO class.
     * @param primaryKeyClass
     *            The primary key class.
     */
    public AbstractDTO(final Class clazz, final Class primaryKeyClass) {
        super(clazz);

        this.primaryKeyClass = primaryKeyClass;
        this.loaded = Boolean.FALSE;
    }

    /**
     * @return the primaryKeyClass
     */
    public Class getPrimaryKeyClass() {
        return this.primaryKeyClass;
    }

    /**
     * @param primaryKeyClass
     *            the primaryKeyClass to set
     */
    public void setPrimaryKeyClass(Class primaryKeyClass) {
        this.primaryKeyClass = primaryKeyClass;
    }

    /**
     * @return the loaded
     */
    public Boolean getLoaded() {
        return this.loaded;
    }

    /**
     * @param loaded
     *            the loaded to set
     */
    public void setLoaded(Boolean loaded) {
        this.loaded = loaded;
    }

    /**
     * @return the primary key
     */
    public K getPrimaryKey() {
        return this.primaryKey;
    }

    /**
     * @param primaryKey
     *            the primary key to set
     */
    public void setPrimaryKey(K primaryKey) {
        this.primaryKey = primaryKey;
    }

    @Override
    protected boolean overEquals(D obj) {
        return this.getPrimaryKey().equals(obj.getPrimaryKey());
    }

    @Override
    protected int overHashCode() {
        return Objects.hashCode(this.getPrimaryKey());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy