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

io.yawp.driver.postgresql.datastore.Key Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.driver.postgresql.datastore;

import io.yawp.commons.utils.JsonUtils;
import io.yawp.commons.utils.NameGenerator;

public class Key {

    private String ns;

    private Key parent;

    private String kind;

    private Long id;

    private String name;

    public Key() {

    }

    protected Key(String kind) {
        this.kind = kind;
    }

    protected Key(String ns, Key parent, String kind, String name, Long id) {
        this.ns = ns;
        this.parent = parent;
        this.kind = kind;
        this.name = name;
        this.id = id;
    }

    protected Key(Key parent, String kind, String name, Long id) {
        this(null, parent, kind, name, id);
    }

    protected String getNs() {
        return ns;
    }

    public Key getParent() {
        return parent;
    }

    public String getKind() {
        return kind;
    }

    public String getName() {
        return name;
    }

    public Long getId() {
        return id;
    }

    public String serialize() {
        return JsonUtils.to(this);
    }

    public static Key deserialize(String json) {
        return JsonUtils.from(null, json, Key.class);
    }

    public boolean isNew() {
        return name == null && id == null;
    }

    public void generate() {
        this.name = NameGenerator.generateFromUUID();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy