Commit 3da7cb03 authored by Matija Obreza's avatar Matija Obreza

Organized DS2 entities into org.genesys2.server.model.dataset package

- Renamed DSDescriptor to DSColumn
- Renamed Descriptor to DSDescriptor
parent b0af34c4
......@@ -28,7 +28,7 @@ public class DS extends BasicModel {
@OrderBy("index")
@OneToMany(mappedBy = "dataset")
private List<DSDescriptor> descriptors;
private List<DSColumn> columns;
/**
* Generate UUID if missing
......@@ -56,11 +56,11 @@ public class DS extends BasicModel {
this.qualifiers = qualifiers;
}
public List<DSDescriptor> getDescriptors() {
return descriptors;
public List<DSColumn> getColumns() {
return columns;
}
public void setDescriptors(List<DSDescriptor> descriptors) {
this.descriptors = descriptors;
public void setColumns(List<DSColumn> columns) {
this.columns = columns;
}
}
package org.genesys2.server.model.dataset;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
/**
* Dataset column.
*/
@Entity
@Table(name = "ds2column")
public class DSColumn extends BasicModel {
/**
*
*/
private static final long serialVersionUID = -7693331325536594367L;
@Column(name="idx")
private float index = 1.0f;
@ManyToOne(optional = false)
@JoinColumn(name="ds")
private DS dataset;
@ManyToOne(optional = false)
@JoinColumn(name="d")
private DSDescriptor descriptor;
public float getIndex() {
return index;
}
public void setIndex(float index) {
this.index = index;
}
public DS getDataset() {
return dataset;
}
public void setDataset(DS dataset) {
this.dataset = dataset;
}
public DSDescriptor getDescriptor() {
return descriptor;
}
public void setDescriptor(DSDescriptor descriptor) {
this.descriptor = descriptor;
}
@Override
public String toString() {
return "DSD " + this.getId();
}
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model.dataset;
import java.text.MessageFormat;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Lob;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
import org.genesys2.server.model.impl.Descriptor;
import org.hibernate.annotations.Type;
/**
* Dataset descriptor
* A DSDescriptor represents a dimension of a sparse vector.
*
* @author mobreza
*/
@Entity
@Table(name = "ds2descriptor")
public class DSDescriptor extends BasicModel {
private static final long serialVersionUID = 3832200593904442940L;
@Column(unique = true, nullable=false, updatable = false)
@Type(type = "uuid-binary")
private UUID uuid;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String title;
@Column(nullable = false, length = 200)
private String code;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String description;
@Column(length = 20)
private String uom;
/**
*
* Generate UUID if missing
*/
private static final long serialVersionUID = -7693331325536594367L;
@PrePersist
protected void prepersist() {
if (this.uuid == null) {
this.uuid = UUID.randomUUID();
}
}
@Column(name="idx")
private float index = 1.0f;
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@ManyToOne(optional = false)
@JoinColumn(name="ds")
private DS dataset;
public String getTitle() {
return title;
}
@ManyToOne(optional = false)
@JoinColumn(name="d")
private Descriptor descriptor;
public void setTitle(String title) {
this.title = title;
}
public float getIndex() {
return index;
public String getCode() {
return code;
}
public void setIndex(float index) {
this.index = index;
public void setCode(String code) {
this.code = code;
}
public DS getDataset() {
return dataset;
public String getDescription() {
return description;
}
public void setDataset(DS dataset) {
this.dataset = dataset;
public void setDescription(final String description) {
this.description = description;
}
public Descriptor getDescriptor() {
return descriptor;
public String getUom() {
return uom;
}
public void setDescriptor(Descriptor descriptor) {
this.descriptor = descriptor;
public void setUom(String uom) {
this.uom = uom;
}
@Override
public String toString() {
return "DSD " + this.getId();
return MessageFormat.format("DSDescriptor id={0,number,#} name={1}", getId(), code);
}
}
......@@ -7,10 +7,9 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys.blocks.model.BasicModel;
import org.genesys2.server.model.impl.Descriptor;
/**
* Dataset qualifier specification
* The dataset qualifier is a key lookup component for dataset rows.
*/
@Entity
@Table(name = "ds2qualifier")
......@@ -30,7 +29,7 @@ public class DSQualifier extends BasicModel {
@ManyToOne(optional = false)
@JoinColumn(name="d")
private Descriptor descriptor;
private DSDescriptor descriptor;
public float getIndex() {
return index;
......@@ -48,11 +47,11 @@ public class DSQualifier extends BasicModel {
this.dataset = dataset;
}
public Descriptor getDescriptor() {
public DSDescriptor getDescriptor() {
return descriptor;
}
public void setDescriptor(Descriptor descriptor) {
public void setDescriptor(DSDescriptor descriptor) {
this.descriptor = descriptor;
}
......
......@@ -17,6 +17,16 @@ import javax.persistence.UniqueConstraint;
import org.genesys.blocks.model.EntityId;
/**
* Represents a row in a DS2 dataset. The row has a unique {@link #id} and
* groups together different {@link DSValue} values (column values).
*
* The row is qualified by a list of row qualifiers ({@link DSRowQualifier})
* that represent the "keys" of the row. Their SHA-1 and MD5 sums are calculated
* and stored in {@link #sha1} and {@link #md5} respectively.
*
* @author Matija Obreza
*/
@Entity
@Table(name = "ds2row", uniqueConstraints = { @UniqueConstraint(columnNames = { "md5", "sha1" }) })
public class DSRow implements EntityId {
......
......@@ -14,6 +14,16 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* Abstract class {@link DSRowQualifier} represents the "columns" of a
* {@link DSRow} that serve as "keys" or qualifying columns to a row. A row may
* have more than one qualifier and are not necessarily unique, but provide a
* fast mechanism to look up values in a row ({@link DSValue}).
*
* @author Matija Obreza
*
* @param <T> type of qualifier value
*/
@Entity
@Table(name = "ds2rowqualifier", indexes = { @Index(columnList = "dsq, vall") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
......
......@@ -15,7 +15,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "ds2value", indexes = { @Index(columnList = "r,dsd"), @Index(columnList = "dsd,vall"), @Index(columnList = "dsd,vald") })
@Table(name = "ds2value", indexes = { @Index(columnList = "r,dsc"), @Index(columnList = "dsc,vall"), @Index(columnList = "dsc,vald") })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.INTEGER, name = "typ")
public abstract class DSValue<T> {
......@@ -28,8 +28,8 @@ public abstract class DSValue<T> {
private DSRow row;
@ManyToOne(fetch=FetchType.LAZY, optional = false)
@JoinColumn(name = "dsd")
private DSDescriptor datasetDescriptor;
@JoinColumn(name = "dsc")
private DSColumn datasetColumn;
public abstract T getValue();
......@@ -51,12 +51,12 @@ public abstract class DSValue<T> {
this.row = row;
}
public DSDescriptor getDatasetDescriptor() {
return datasetDescriptor;
public DSColumn getDatasetColumn() {
return datasetColumn;
}
public void setDatasetDescriptor(DSDescriptor datasetDescriptor) {
this.datasetDescriptor = datasetDescriptor;
public void setDatasetColumn(DSColumn datasetColumn) {
this.datasetColumn = datasetColumn;
}
public static DSValue<?> make(Object v) {
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
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.genesys.blocks.model.BasicModel;
import org.hibernate.annotations.Type;
/**
* A Descriptor represents a dimension of a sparse vector.
*
* @author mobreza
*/
@Entity
@Table(name = "descriptor")
public class Descriptor extends BasicModel {
private static final long serialVersionUID = 3832200593904442940L;
@Column(unique = true, nullable=false, updatable = false)
@Type(type = "uuid-binary")
private UUID uuid;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String title;
@Column(nullable = false, length = 200)
private String code;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String description;
@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;
}
public void setTitle(String title) {
this.title = title;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
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}", getId(), code);
}
}
......@@ -3,7 +3,7 @@ package org.genesys2.server.model.json;
import java.util.HashMap;
import java.util.Map;
import org.genesys2.server.model.impl.Descriptor;
import org.genesys2.server.model.dataset.DSDescriptor;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -18,7 +18,7 @@ public class WorldclimJson {
private Double[] tempMax = new Double[12];
@JsonIgnore
private Map<Descriptor, Object> other = new HashMap<Descriptor, Object>();
private Map<DSDescriptor, Object> other = new HashMap<DSDescriptor, Object>();
public Long[] getPrecipitation() {
return precipitation;
......@@ -36,11 +36,11 @@ public class WorldclimJson {
return tempMin;
}
public void addOther(Descriptor descriptor, Object val) {
other.put(descriptor, val);
public void addOther(DSDescriptor dSDescriptor, Object val) {
other.put(dSDescriptor, val);
}
public Map<Descriptor, Object> getOther() {
public Map<DSDescriptor, Object> getOther() {
return this.other;
}
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.impl.Descriptor;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DescriptorRepository extends JpaRepository<Descriptor, Long> {
Descriptor findByCode(String code);
}
package org.genesys2.server.persistence.domain.dataset;
import org.genesys2.server.model.dataset.DSColumn;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DSColumnRepository extends JpaRepository<DSColumn, Long> {
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.persistence.domain.dataset;
import org.genesys2.server.model.dataset.DSDescriptor;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DSDescriptorRepository extends JpaRepository<DSDescriptor, Long> {
DSDescriptor findByCode(String code);
}
......@@ -5,7 +5,7 @@ import java.util.List;
import java.util.Map;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.dataset.DSDescriptor;
import org.genesys2.server.model.dataset.DSColumn;
import org.genesys2.server.model.dataset.DSRow;
import org.genesys2.server.model.dataset.DSValue;
......@@ -13,12 +13,12 @@ public interface DSRowCustomRepository {
DSRow findRow(DS ds, Object[] qualifiers);
Map<Long, DSValue<?>> rowValueMap(Collection<DSRow> dsrs, DSDescriptor dsd);
Map<Long, DSValue<?>> rowValueMap(Collection<DSRow> dsrs, DSColumn dsd);
List<Object[]> getQualifiers(DS ds);
/**
* Array of dsv.values as per DSDescriptor order
* Array of dsv.values as per DSColumn order
*
* @param rowId
* @param columnDescriptors
......@@ -27,7 +27,7 @@ public interface DSRowCustomRepository {
Object[] getRowValues(long rowId, Long[] columnDescriptors);
/**
* List of arrays of dsv.values as per rowId order and DSDescriptor order
* List of arrays of dsv.values as per rowId order and DSColumn order
*
* @param rowId
* @param columnDescriptors
......
......@@ -13,7 +13,7 @@ import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.dataset.DSDescriptor;
import org.genesys2.server.model.dataset.DSColumn;
import org.genesys2.server.model.dataset.DSQualifier;
import org.genesys2.server.model.dataset.DSRow;
import org.genesys2.server.model.dataset.DSValue;
......@@ -74,7 +74,7 @@ public class DSRowRepositoryCustomImpl implements DSRowCustomRepository {
}
@Override
public Map<Long, DSValue<?>> rowValueMap(Collection<DSRow> dsrs, DSDescriptor dsd) {
public Map<Long, DSValue<?>> rowValueMap(Collection<DSRow> dsrs, DSColumn dsc) {
List<DSRow> validRows = new ArrayList<DSRow>(dsrs.size());
for (DSRow dsr : dsrs) {
if (dsr.getId() != null) {
......@@ -86,9 +86,9 @@ public class DSRowRepositoryCustomImpl implements DSRowCustomRepository {
if (!validRows.isEmpty()) {
// LOG.info("getting row value map");
Query q = entityManager.createQuery("select dsv.row.id, dsv from DSValue dsv where dsv.row in (?1) and dsv.datasetDescriptor=?2");
Query q = entityManager.createQuery("select dsv.row.id, dsv from DSValue dsv where dsv.row in (?1) and dsv.datasetColumn=?2");
q.setParameter(1, validRows);
q.setParameter(2, dsd);
q.setParameter(2, dsc);
@SuppressWarnings("unchecked")
List<Object[]> res = q.getResultList();
......@@ -102,7 +102,7 @@ public class DSRowRepositoryCustomImpl implements DSRowCustomRepository {
}
/**