Commit 952f3360 authored by Matija Obreza's avatar Matija Obreza
Browse files

UuidModel

parent ac7daef6
......@@ -24,9 +24,9 @@ import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
@MappedSuperclass
public abstract class UuidModel {
public abstract class UuidModel implements HibernateModel {
@Id
@Column(name = "uuid", unique = true, nullable = false)
@Column(name = "uuid", unique = true, nullable = false, updatable = false)
protected UUID uuid;
public UUID getUuid() {
......
......@@ -15,7 +15,7 @@ import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "ds2")
public class DS extends BusinessModel {
@Column(columnDefinition = "binary(16)")
@Column(columnDefinition = "binary(16)", unique = true, nullable=false, updatable = false)
private UUID uuid;
@OrderBy("index")
......
......@@ -17,10 +17,12 @@
package org.genesys2.server.model.impl;
import java.text.MessageFormat;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
......@@ -36,6 +38,9 @@ import org.hibernate.annotations.Type;
public class Descriptor extends BusinessModel {
private static final long serialVersionUID = 3832200593904442940L;
@Column(columnDefinition = "binary(16)", unique = true, nullable=false, updatable = false)
private UUID uuid;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String title;
......@@ -46,10 +51,29 @@ public class Descriptor extends BusinessModel {
@Lob
@Type(type = "org.hibernate.type.TextType")
private String description;
@Column(length=20)
@Column(length = 20)
private String uom;
/**
* Generate UUID if missing
*/
@PrePersist
protected void prepersist() {
if (this.uuid == null) {
this.uuid = UUID.randomUUID();
}
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public String getTitle() {
return title;
}
......@@ -77,11 +101,11 @@ public class Descriptor extends BusinessModel {
public String getUom() {
return uom;
}
public void setUom(String uom) {
this.uom = uom;
}
@Override
public String toString() {
return MessageFormat.format("Descriptor id={0,number,#} name={1}", id, code);
......
......@@ -10,7 +10,6 @@ import java.util.List;
import org.apache.http.impl.client.HttpClientBuilder;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.dataset.DSDescriptor;
import org.genesys2.server.model.dataset.DSQualifier;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepositoryCustomImpl;
import org.genesys2.server.service.DSService;
......@@ -97,11 +96,13 @@ public class WorldClimUpdaterTest {
@Test
public void deleteDataset() {
DS ds = dsService.loadDatasetByUuid(WorldClimUpdater.WORLDCLIM_DATASET);
for (DSDescriptor dsd : ds.getDescriptors()) {
dsService.deleteDescriptor(dsd);
if (ds != null) {
for (DSDescriptor dsd : ds.getDescriptors()) {
dsService.deleteDescriptor(dsd);
}
dsService.deleteRows(ds);
dsService.deleteDataset(ds);
}
dsService.deleteRows(ds);
dsService.deleteDataset(ds);
}
@Test
......
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