Commit 9906ef18 authored by Matija Obreza's avatar Matija Obreza
Browse files

Removed unused Sparse* entities, fixed column names that failed for DDL

parent 50fd636a
......@@ -101,7 +101,7 @@ public class Metadata implements java.io.Serializable {
}
@Column(nullable = false, length = 128)
@Field(name="title", store=Store.NO)
@Field(name = "title", store = Store.NO)
public String getTitle() {
return this.title;
}
......@@ -129,7 +129,7 @@ public class Metadata implements java.io.Serializable {
}
@Column(length = 128)
@Field(store=Store.NO)
@Field(store = Store.NO)
public String getLocation() {
return this.location;
}
......@@ -138,7 +138,7 @@ public class Metadata implements java.io.Serializable {
this.location = location;
}
@Column(name = "Long")
@Column(name = "\"Long\"")
public Double getLongitude() {
return this.longitude;
}
......@@ -166,7 +166,7 @@ public class Metadata implements java.io.Serializable {
}
@Lob
@Field(store=Store.NO)
@Field(store = Store.NO)
public String getCitation() {
return this.citation;
}
......@@ -176,7 +176,7 @@ public class Metadata implements java.io.Serializable {
}
@Lob
@Field(name="body", store=Store.NO)
@Field(name = "body", store = Store.NO)
public String getDescription() {
return this.description;
}
......
......@@ -193,7 +193,7 @@ public class Method implements java.io.Serializable {
// return TraitCode.parseOptionsMap(this.options);
// }
@Column(name = "Range", length = 32)
@Column(name = "\"Range\"", length = 32)
public String getRange() {
return this.range;
}
......
/**
* Copyright 2013 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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.annotations.Index;
/**
* Single Data entry representing a single dimension. Complete vector is
* obtained by looking up all {@link SparseData} relating to the same
* {@link SparseEntry}.
*/
@Entity
@Table(name = "sparsedata")
@org.hibernate.annotations.Table(appliesTo = "sparsedata", indexes = {
//@Index(columnNames = { "datasetDescriptorId", "stringId" }, name = "descriptorstring_SPARSEDATA"),
@Index(columnNames = { "sparseEntryId" }, name = "entry_SPARSEDATA"),
@Index(columnNames = { "datasetId", "datasetDescriptorId" }, name = "datasetdescriptor_SPARSEDATA"),
@Index(columnNames = { "datasetDescriptorId" }, name = "descriptor_SPARSEDATA") })
public class SparseData extends BusinessModel {
private static final long serialVersionUID = -2142036544458439223L;
@OrderColumn
private long datasetId;
@OrderColumn
private long sparseEntryId;
@OrderColumn
private long datasetDescriptorId;
@Column(nullable = false, length = 500)
private String value;
public long getDatasetId() {
return datasetId;
}
public void setDatasetId(long datasetId) {
this.datasetId = datasetId;
}
public long getSparseEntryId() {
return sparseEntryId;
}
public void setSparseEntryId(final long sparseEntryId) {
this.sparseEntryId = sparseEntryId;
}
public long getDatasetDescriptorId() {
return datasetDescriptorId;
}
public void setDatasetDescriptorId(final long datasetDescriptorId) {
this.datasetDescriptorId = datasetDescriptorId;
}
public String getValue() {
return value;
}
public void setValue(final String value) {
this.value = value;
}
}
/**
* Copyright 2013 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 javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.genesys2.server.model.BusinessModel;
/**
* Represents a sparse data vector, part of a {@link Dataset} in the system.
*
* @author mobreza
*/
@Entity
@Table(name = "sparseentry")
public class SparseEntry extends BusinessModel {
private static final long serialVersionUID = 2430418022616359050L;
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "datasetId", nullable = false)
private Dataset dataset;
public Dataset getDataset() {
return dataset;
}
public void setDataset(final Dataset dataset) {
this.dataset = dataset;
}
}
/**
* Copyright 2013 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 java.util.List;
import org.genesys2.server.model.impl.SparseData;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface SparseDataRepository extends JpaRepository<SparseData, Long> {
List<SparseData> findBySparseEntryId(long sparseEntryId);
@Query("select count(sd) from SparseData sd where sd.datasetId=?1")
@Cacheable(value="sparsedata", key="#root.methodName+#a0")
long countByDatasetId(long datasetId);
// @Query("select distinct sd.descriptorId from SparseData sd where sd.datasetId=?1")
// @Cacheable(value="sparsedata", key="#root.methodName+#a0")
// List<Long> getDescriptorIdsByDatasetId(long datasetId);
@Query("select count(sd) from SparseData sd where sd.sparseEntryId=?1")
long countBySparseEntryId(long sparseEntryId);
//List<SparseData> findByDescriptorId(long descriptorId);
//@Query("select count(sd) from SparseData sd where sd.descriptorId=?1")
//long countByDescriptorId(long descriptorId);
//List<SparseData> findByDescriptorIdAndValue(long descriptorId, SparseString value);
//@Query("select count(sd) from SparseData sd where sd.descriptorId=?1 and sd.value=?2")
//long countByDescriptorIdAndValue(long descriptorId, SparseString value);
//List<SparseData> findByDescriptorIdAndSparseString(long descriptorId,
// SparseString string);
//@Query("select count(sd) from SparseData sd where sd.descriptorId=?1 and sd.sparseString=?2")
//long countByDescriptorIdAndSparseString(long descriptorId, SparseString string);
}
/**
* Copyright 2013 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 java.util.List;
import org.genesys2.server.model.impl.Dataset;
import org.genesys2.server.model.impl.SparseEntry;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface SparseEntryRepository extends JpaRepository<SparseEntry, Long> {
List<SparseEntry> findByDataset(Dataset dataset);
@Query("select count(se) from SparseEntry se where se.dataset=?1")
@Cacheable(value="sparseentry", key="#root.methodName+#a0.id")
long countByDataset(Dataset dataset);
}
/**
* Copyright 2013 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.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.Dataset;
import org.genesys2.server.model.impl.DatasetDescriptor;
import org.genesys2.server.model.impl.Descriptor;
import org.genesys2.server.model.impl.SparseData;
import org.genesys2.server.model.impl.SparseEntry;
import org.genesys2.server.persistence.domain.DatasetDescriptorRepository;
import org.genesys2.server.persistence.domain.DatasetRepository;
import org.genesys2.server.persistence.domain.SparseDataRepository;
import org.genesys2.server.persistence.domain.SparseEntryRepository;
import org.genesys2.server.service.DataService;
import org.genesys2.server.service.DescriptorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class DataServiceImpl implements DataService {
public static final Log LOG = LogFactory.getLog(DataServiceImpl.class);
@Autowired
SparseEntryRepository entryRepository;
@Autowired
SparseDataRepository dataRepository;
@Autowired
DatasetDescriptorRepository datasetDescriptorRepository;
@Autowired
DescriptorService descriptorService;
@Autowired
private DatasetRepository datasetRepository;
@Override
public List<Dataset> list() {
return datasetRepository.findAll();
}
@Override
public Dataset getDataset(long datasetId) {
return datasetRepository.findOne(datasetId);
}
@Override
@Transactional(readOnly = false)
public void save(Dataset dataset) {
datasetRepository.save(dataset);
}
@Override
public long countEntries(Dataset dataset) {
return entryRepository.countByDataset(dataset);
}
@Override
public long countData(Dataset dataset) {
return dataRepository.countByDatasetId(dataset.getId());
}
@Override
public Iterable<Descriptor> getDescriptors(Dataset dataset) {
return datasetDescriptorRepository.findDescriptorsByDataset(dataset);
}
// FIXME This code does not handle column grouping
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void writeEntries(final Dataset dataset, final Descriptor[] descriptors, final List<String[]> datas) {
LOG.debug("Writing batch of " + datas.size());
final DatasetDescriptor[] datasetDescriptors = descriptorService.getDatasetDescriptors(dataset, descriptors);
final List<SparseEntry> sparseEntries = new ArrayList<SparseEntry>(datas.size());
final List<SparseData> sparseDatas = new ArrayList<SparseData>(descriptors.length);
for (int j = 0; j < datas.size(); j++) {
// New entry
final SparseEntry sparseEntry = new SparseEntry();
sparseEntry.setDataset(dataset);
sparseEntries.add(sparseEntry);
}
// save the lot
entryRepository.save(sparseEntries);
LOG.debug("sparseEntries.size=" + sparseEntries.size());
long datasetId = dataset.getId();
for (int j = 0; j < datas.size(); j++) {
final String[] data = datas.get(j);
final long sparseEntryId = sparseEntries.get(j).getId();
if (data.length < descriptors.length) {
LOG.warn("Funny input: " + ArrayUtils.toString(data));
}
// All traits
int valueCount = 0;
for (int i = 0; i < descriptors.length && i < data.length; i++) {
if (data[i] != null && descriptors[i] != null) {
valueCount++;
final SparseData sparseData = new SparseData();
sparseData.setSparseEntryId(sparseEntryId);
// Can throw NPE! Cool :-)
sparseData.setDatasetDescriptorId(datasetDescriptors[i].getId());
sparseData.setDatasetId(datasetId);
sparseData.setValue(data[i]);
sparseDatas.add(sparseData);
}
}
if (valueCount == 0) {
LOG.warn("No data, removing entry");
entryRepository.delete(sparseEntries.get(j));
}
}
dataRepository.save(sparseDatas);
}
}
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