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

UuidModel

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