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

pep1.commons.jpa.domain.AbstractRandIntPersistable Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 Leonard Osang
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package pep1.commons.jpa.domain;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.springframework.data.domain.Persistable;
import pep1.commons.jpa.util.RandomIntIdGenerator;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Variation of the {@link AbstractPersistable} Class especially numeric code id classes.
 */
@MappedSuperclass
@JsonAutoDetect(
        fieldVisibility = JsonAutoDetect.Visibility.ANY,
        getterVisibility = JsonAutoDetect.Visibility.NONE,
        isGetterVisibility = JsonAutoDetect.Visibility.NONE,
        setterVisibility = JsonAutoDetect.Visibility.NONE)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_ABSENT)
@Getter
public abstract class AbstractRandIntPersistable implements Persistable {

    @Id
    @GenericGenerator(
            name = "rand_int",
            strategy = "pep1.commons.jpa.util.RandomIntIdGenerator",
            parameters = @Parameter(name = RandomIntIdGenerator.LENGTH_CONFIG_KEY, value = "12")
    )
    @GeneratedValue(generator = "rand_int")
    private Long id;

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy