Commit a98bfa3e authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'empty-model-implements-persistable' into 'master'

EmptyModel implements Persistable

See merge request genesys-pgr/application-blocks!90
parents 4d80d88f e190fefe
...@@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonView; ...@@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonView;
* The Class BasicModel. * The Class BasicModel.
*/ */
@MappedSuperclass @MappedSuperclass
public class BasicModel extends EmptyModel implements Persistable<Long> { public class BasicModel extends EmptyModel {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = 2709998920148999956L; private static final long serialVersionUID = 2709998920148999956L;
...@@ -61,19 +61,6 @@ public class BasicModel extends EmptyModel implements Persistable<Long> { ...@@ -61,19 +61,6 @@ public class BasicModel extends EmptyModel implements Persistable<Long> {
this.id = id; this.id = id;
} }
/**
* Is the entity persisted to the database? Test is based on value of
* {@link #id} field where negative integers or null mean entity is not yet
* persisted.
*
* @return true if the {@link #id} is a positive integer, false otherwise
*/
@JsonIgnore
@Transient
public final boolean isNew() {
return (id == null) || (id.longValue() < 0);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
......
...@@ -18,16 +18,32 @@ package org.genesys.blocks.model; ...@@ -18,16 +18,32 @@ package org.genesys.blocks.model;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.genesys.blocks.util.JsonClassNameWriter; import org.genesys.blocks.util.JsonClassNameWriter;
import com.fasterxml.jackson.databind.annotation.JsonAppend; import com.fasterxml.jackson.databind.annotation.JsonAppend;
import org.springframework.data.domain.Persistable;
@MappedSuperclass @MappedSuperclass
@JsonAppend(props = { @JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class) }) @JsonAppend(props = { @JsonAppend.Prop(name = "_class", value = JsonClassNameWriter.class, type = String.class) })
public abstract class EmptyModel implements EntityId, Serializable { public abstract class EmptyModel implements EntityId, Serializable, Persistable<Long> {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = 5934941826741972456L; private static final long serialVersionUID = 5934941826741972456L;
/**
* Is the entity persisted to the database? Test is based on value of
* {@link #getId()} field where negative integers or null mean entity is not yet
* persisted.
*
* @return true if the {@link #getId()} is a positive integer, false otherwise
*/
@JsonIgnore
@Transient
public final boolean isNew() {
return getId() == null || getId() < 0;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment