diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricher.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricher.java index 6fd38ebfd6e8a177a4b29c30740a3444c1885051..a45dcc04bd0a6e3f854d91da1f28e9f6edb141ba 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricher.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricher.java @@ -16,15 +16,13 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.longs.LongSet; +import java.util.ArrayList; +import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AbstractEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.GenericEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Material; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType; @@ -33,6 +31,11 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ScriptType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTermEntityProperty; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; + /** * A class that can enrich a set of entities with its entity properties. * @@ -73,38 +76,6 @@ public final class EntityPropertiesEnricher implements IEntityPropertiesEnricher } }; } - - @Override - public Iterable<VocabularyTermRecord> getEntityPropertyVocabularyTermValues( - LongSet entityIDs) - { - return new AbstractBatchIterator<VocabularyTermRecord>(entityIDs, BATCH_SIZE) - { - @Override - protected Iterable<VocabularyTermRecord> createUnefficientIterator( - LongSet ids) - { - return setQuery.getEntityPropertyVocabularyTermValues(ids); - } - }; - } - - @Override - public Iterable<MaterialEntityPropertyRecord> getEntityPropertyMaterialValues( - LongSet entityIDs) - { - return new AbstractBatchIterator<MaterialEntityPropertyRecord>(entityIDs, - BATCH_SIZE) - { - @Override - protected Iterable<MaterialEntityPropertyRecord> createUnefficientIterator( - LongSet ids) - { - return setQuery.getEntityPropertyMaterialValues(ids); - } - }; - } - }; } @@ -115,87 +86,48 @@ public final class EntityPropertiesEnricher implements IEntityPropertiesEnricher @Override public void enrich(final LongSet entityIDs, final IEntityPropertiesHolderResolver entities) { - final Long2ObjectMap<PropertyType> propertyTypes = getPropertyTypes(); - // Generic properties - for (GenericEntityPropertyRecord val : propertySetQuery - .getEntityPropertyGenericValues(entityIDs)) + List<GenericEntityPropertyRecord> records = new ArrayList<>(); + LongSet vocaTermIds = new LongOpenHashSet(); + LongSet materialIds = new LongOpenHashSet(); + for (GenericEntityPropertyRecord record : propertySetQuery.getEntityPropertyGenericValues(entityIDs)) { - final IEntityPropertiesHolder entity = entities.get(val.entity_id); - final AbstractEntityProperty property = new GenericEntityProperty(); - property.setValue(val.value); - property.setPropertyType(propertyTypes.get(val.prty_id)); - property.setScriptable(val.script_id != null); - property.setDynamic(ScriptType.DYNAMIC_PROPERTY.name().equals(val.script_type)); - property.setOrdinal(val.ordinal); - entity.getProperties().add(property); - } - - // Controlled vocabulary properties - Long2ObjectMap<String> vocabularyURLMap = null; - Long2ObjectMap<VocabularyTerm> terms = new Long2ObjectOpenHashMap<VocabularyTerm>(); - for (VocabularyTermRecord val : propertySetQuery - .getEntityPropertyVocabularyTermValues(entityIDs)) - { - if (vocabularyURLMap == null) + records.add(record); + if (record.cvte_id != null) { - vocabularyURLMap = getVocabularyURLs(); + vocaTermIds.add(record.cvte_id); } - final IEntityPropertiesHolder entity = entities.get(val.entity_id); - final IEntityProperty property = new VocabularyTermEntityProperty(); - VocabularyTerm vocabularyTerm = terms.get(val.id); - if (vocabularyTerm == null) + if (record.mate_prop_id != null) { - vocabularyTerm = new VocabularyTerm(); - vocabularyTerm.setCode(val.code); - vocabularyTerm.setLabel(val.label); - vocabularyTerm.setDescription(val.description); - final String template = vocabularyURLMap.get(val.covo_id); - if (template != null) - { - String url = - template.replaceAll( - BasicConstant.DEPRECATED_VOCABULARY_URL_TEMPLATE_TERM_PATTERN, - val.code); - url = - url.replaceAll(BasicConstant.VOCABULARY_URL_TEMPLATE_TERM_PATTERN, - val.code); - vocabularyTerm.setUrl(url); - } - terms.put(val.id, vocabularyTerm); + materialIds.add(record.mate_prop_id); } - property.setVocabularyTerm(vocabularyTerm); - property.setPropertyType(propertyTypes.get(val.prty_id)); - property.setOrdinal(val.ordinal); - entity.getProperties().add(property); } - // Material-type properties - Long2ObjectMap<MaterialType> materialTypes = null; - Long2ObjectMap<Material> materials = new Long2ObjectOpenHashMap<Material>(); - for (MaterialEntityPropertyRecord val : propertySetQuery - .getEntityPropertyMaterialValues(entityIDs)) + Long2ObjectMap<VocabularyTerm> vocabularyTerms = getVocabularyTerms(vocaTermIds); + Long2ObjectMap<Material> materials = getMaterials(materialIds); + Long2ObjectMap<PropertyType> propertyTypes = getPropertyTypes(); + for (GenericEntityPropertyRecord val : records) { - if (materialTypes == null) + AbstractEntityProperty property; + if (val.cvte_id != null) { - materialTypes = getMaterialTypes(); - } - final IEntityPropertiesHolder entity = entities.get(val.entity_id); - final IEntityProperty property = new MaterialEntityProperty(); - Material material = materials.get(val.id); - if (material == null) + property = new VocabularyTermEntityProperty(); + property.setVocabularyTerm(vocabularyTerms.get(val.cvte_id)); + } else if (val.mate_prop_id != null) + { + property = new MaterialEntityProperty(); + property.setMaterial(materials.get(val.mate_prop_id)); + } else { - material = new Material(); - material.setCode(val.code); - material.setMaterialType(materialTypes.get(val.maty_id)); - material.setId(val.id); - materials.put(val.id, material); + property = new GenericEntityProperty(); + property.setValue(val.value); + property.setScriptable(val.script_id != null); + property.setDynamic(ScriptType.DYNAMIC_PROPERTY.name().equals(val.script_type)); } - property.setMaterial(material); property.setPropertyType(propertyTypes.get(val.prty_id)); property.setOrdinal(val.ordinal); + IEntityPropertiesHolder entity = entities.get(val.entity_id); entity.getProperties().add(property); } - } private Long2ObjectMap<PropertyType> getPropertyTypes() @@ -239,4 +171,56 @@ public final class EntityPropertiesEnricher implements IEntityPropertiesEnricher return materialTypeMap; } + private Long2ObjectMap<VocabularyTerm> getVocabularyTerms(LongSet vocaTermIds) + { + Long2ObjectMap<String> vocabularyURLMap = null; + Long2ObjectOpenHashMap<VocabularyTerm> map = new Long2ObjectOpenHashMap<VocabularyTerm>(); + if (vocaTermIds.isEmpty() == false) + { + for (VocabularyTermRecord record : query.getVocabularyTerms(vocaTermIds)) + { + if (vocabularyURLMap == null) + { + vocabularyURLMap = getVocabularyURLs(); + } + VocabularyTerm vocabularyTerm = new VocabularyTerm(); + vocabularyTerm.setCode(record.code); + vocabularyTerm.setLabel(record.label); + vocabularyTerm.setDescription(record.description); + final String template = vocabularyURLMap.get(record.covo_id); + if (template != null) + { + String url = template.replaceAll( + BasicConstant.DEPRECATED_VOCABULARY_URL_TEMPLATE_TERM_PATTERN, + record.code); + url = url.replaceAll(BasicConstant.VOCABULARY_URL_TEMPLATE_TERM_PATTERN, record.code); + vocabularyTerm.setUrl(url); + } + map.put(record.id, vocabularyTerm); + } + } + return map; + } + + private Long2ObjectMap<Material> getMaterials(LongSet materialIds) + { + Long2ObjectMap<MaterialType> materialTypes = null; + Long2ObjectOpenHashMap<Material> map = new Long2ObjectOpenHashMap<Material>(); + if (materialIds.isEmpty() == false) + { + for (MaterialEntityPropertyRecord record : query.getMaterials(materialIds)) + { + if (materialTypes == null) + { + materialTypes = getMaterialTypes(); + } + Material material = new Material(); + material.setCode(record.code); + material.setMaterialType(materialTypes.get(record.maty_id)); + material.setId(record.id); + map.put(record.id, material); + } + } + return map; + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/GenericEntityPropertyRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/GenericEntityPropertyRecord.java index 9a0f6973442b2f900c1ea68f714c669c479a1671..dcc58a7449b2fc20c5bfdeea7e9d02fc2c1420fa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/GenericEntityPropertyRecord.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/GenericEntityPropertyRecord.java @@ -6,4 +6,6 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common; public class GenericEntityPropertyRecord extends BaseEntityPropertyRecord { public String value; + public Long cvte_id; + public Long mate_prop_id; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IEntityPropertySetListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IEntityPropertySetListingQuery.java index 2d75629c848d5a5acbd9ae232bad4d20c18bcd0e..8633f5ad2bea9fa9e581f0dba7a0d5ccce73a802 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IEntityPropertySetListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IEntityPropertySetListingQuery.java @@ -35,18 +35,4 @@ public interface IEntityPropertySetListingQuery */ public Iterable<GenericEntityPropertyRecord> getEntityPropertyGenericValues(LongSet entityIDs); - /** - * Returns all controlled vocabulary property values of all specified entities. - * - * @param entityIDs The set of entity IDs to get the property values for. - */ - public Iterable<VocabularyTermRecord> getEntityPropertyVocabularyTermValues(LongSet entityIDs); - - /** - * Returns all material-type property values of all specified entities. - * - * @param entityIDs The set of entity IDs to get the property values for. - */ - public Iterable<MaterialEntityPropertyRecord> getEntityPropertyMaterialValues(LongSet entityIDs); - } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IPropertyListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IPropertyListingQuery.java index cfbb66435860ee0cd8cf1a98ed7bb5802e88875b..ef530fef851bd459eaec145aa9725d6b3b4f2c36 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IPropertyListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/IPropertyListingQuery.java @@ -16,10 +16,14 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common; +import net.lemnik.eodsql.DataIterator; import net.lemnik.eodsql.Select; +import ch.systemsx.cisd.common.db.mapper.LongSetMapper; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import it.unimi.dsi.fastutil.longs.LongSet; + /** * Query methods for retrieving property types, material types, and vocabulary URL templates. * @@ -27,6 +31,8 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; */ public interface IPropertyListingQuery { + public static final int FETCH_SIZE = 1000; + /** * Returns all property types. Fills only <code>id</code>, <code>code</code>, <code>label</var> and <code>DataType</code>. Note that code and * label are already HTML escaped. @@ -47,5 +53,14 @@ public interface IPropertyListingQuery */ @Select("select id, code from material_types") public CodeRecord[] getMaterialTypes(); + + @Select(sql = "SELECT id, covo_id, code, label, ordinal, description " + + "FROM controlled_vocabulary_terms WHERE id = any(?{1})", + parameterBindings = { LongSetMapper.class}, fetchSize = FETCH_SIZE) + public DataIterator<VocabularyTermRecord> getVocabularyTerms(LongSet termIds); + @Select(sql = "SELECT id, code, maty_id FROM materials WHERE id = any(?{1})", + parameterBindings = { LongSetMapper.class}, fetchSize = FETCH_SIZE) + public DataIterator<MaterialEntityPropertyRecord> getMaterials(LongSet materialIds); + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerDAO.java index 1a46bb1ab6cb33dc2ef17c0a6b32e4fa2474d862..d9206e54cdb673d123e7205156bd746ce6b8653c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerDAO.java @@ -87,19 +87,6 @@ public final class DatasetListerDAO extends AbstractDAO return query.getEntityPropertyGenericValues(entityIDs); } - @Override - public Iterable<MaterialEntityPropertyRecord> getEntityPropertyMaterialValues( - LongSet entityIDs) - { - return query.getEntityPropertyMaterialValues(entityIDs); - } - - @Override - public Iterable<VocabularyTermRecord> getEntityPropertyVocabularyTermValues( - LongSet entityIDs) - { - return query.getEntityPropertyVocabularyTermValues(entityIDs); - } }; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java index 70a7d5590e79a134f92dbd64b087fe0bbeacea19..08cdd3713b477f8a02728be1e59a79a7d782c6d6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java @@ -48,7 +48,7 @@ import net.lemnik.eodsql.TypeMapper; @Friend(toClasses = { DataStoreRecord.class }) public interface IDatasetListingQuery extends BaseQuery, IPropertyListingQuery { - public static final int FETCH_SIZE = 1000; + public static final int FETCH_SIZE = 10000; public final static String SELECT_ALL = "select data.*, external_data.*, link_data.*, content_copies.external_code, content_copies.edms_id, " @@ -311,11 +311,12 @@ public interface IDatasetListingQuery extends BaseQuery, IPropertyListingQuery * * @param entityIds The set of sample ids to get the property values for. */ - @Select(sql = "SELECT pr.ds_id as entity_id, etpt.prty_id, etpt.script_id, pr.value, sc.script_type " + @Select(sql = "SELECT pr.ds_id as entity_id, etpt.prty_id, etpt.script_id, pr.value, " + + " pr.cvte_id, pr.mate_prop_id, sc.script_type " + " FROM data_set_properties pr" + " JOIN data_set_type_property_types etpt ON pr.dstpt_id=etpt.id" + " LEFT OUTER JOIN scripts sc ON etpt.script_id = sc.id" - + " WHERE pr.value is not null AND pr.ds_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) + + " WHERE pr.ds_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) public DataIterator<GenericEntityPropertyRecord> getEntityPropertyGenericValues( LongSet entityIds); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java index 989e9e12c634da1b020b1ae2ccd73662310c8ee6..4948820978e930c4b7ffe7f20beefd42c7146bad 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java @@ -16,15 +16,8 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister; -import it.unimi.dsi.fastutil.longs.LongSet; - import java.util.List; -import net.lemnik.eodsql.BaseQuery; -import net.lemnik.eodsql.DataIterator; -import net.lemnik.eodsql.Select; -import net.lemnik.eodsql.TransactionQuery; -import net.lemnik.eodsql.TypeMapper; import ch.rinn.restrictions.Private; import ch.systemsx.cisd.common.db.mapper.LongSetMapper; import ch.systemsx.cisd.common.db.mapper.StringArrayMapper; @@ -34,6 +27,12 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.common.MaterialEntity import ch.systemsx.cisd.openbis.generic.server.business.bo.common.VocabularyTermRecord; import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.common.MetaProjectWithEntityId; +import it.unimi.dsi.fastutil.longs.LongSet; +import net.lemnik.eodsql.BaseQuery; +import net.lemnik.eodsql.DataIterator; +import net.lemnik.eodsql.Select; +import net.lemnik.eodsql.TransactionQuery; + /** * A {@link TransactionQuery} interface for obtaining large sets of material-related entities from the database. * <p> @@ -96,7 +95,8 @@ public interface IMaterialListingQuery extends BaseQuery, IPropertyListingQuery * * @param entityIds The set of material ids to get the property values for. */ - @Select(sql = "SELECT pr.mate_id as entity_id, etpt.prty_id, etpt.script_id, pr.value, sc.script_type " + @Select(sql = "SELECT pr.mate_id as entity_id, etpt.prty_id, etpt.script_id, pr.value, " + + " pr.cvte_id, pr.mate_prop_id, sc.script_type " + " FROM material_properties pr" + " JOIN material_type_property_types etpt ON pr.mtpt_id=etpt.id" + " LEFT OUTER JOIN scripts sc ON etpt.script_id = sc.id" diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerDAO.java index 93326aad0def7285c7cc74d788f2777e959ff0ac..72723023e8575eac9b231a541db4a4c1b52dcaff 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerDAO.java @@ -16,18 +16,17 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister; -import it.unimi.dsi.fastutil.longs.LongSet; -import net.lemnik.eodsql.QueryTool; import ch.rinn.restrictions.Friend; import ch.rinn.restrictions.Private; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.AbstractDAO; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.GenericEntityPropertyRecord; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.IEntityPropertySetListingQuery; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.MaterialEntityPropertyRecord; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.VocabularyTermRecord; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.PersistencyResources; +import it.unimi.dsi.fastutil.longs.LongSet; +import net.lemnik.eodsql.QueryTool; + /** * The DAO for business objects implementing {@link IMaterialLister}. Note: Even though this class is public its constructors and instance methods * have to be package protected. @@ -86,20 +85,6 @@ public final class MaterialListerDAO extends AbstractDAO { return query.getEntityPropertyGenericValues(entityIDs); } - - @Override - public Iterable<MaterialEntityPropertyRecord> getEntityPropertyMaterialValues( - LongSet entityIDs) - { - return query.getEntityPropertyMaterialValues(entityIDs); - } - - @Override - public Iterable<VocabularyTermRecord> getEntityPropertyVocabularyTermValues( - LongSet entityIDs) - { - return query.getEntityPropertyVocabularyTermValues(entityIDs); - } }; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java index a79dbea3a2a467d6cedcfb4880304ef213b47771..4f28416a95042d5bb3143e8589cbd0c9de21e639 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java @@ -412,11 +412,12 @@ public interface ISampleListingQuery extends BaseQuery, IPropertyListingQuery * * @param sampleIds The set of sample ids to get the property values for. */ - @Select(sql = "SELECT sp.samp_id as entity_id, stpt.prty_id, stpt.script_id, stpt.ordinal, sp.value, sc.script_type " + @Select(sql = "SELECT sp.samp_id as entity_id, stpt.prty_id, stpt.script_id, stpt.ordinal, " + + " sp.value, sp.cvte_id, sp.mate_prop_id, sc.script_type " + " FROM sample_properties sp" + " JOIN sample_type_property_types stpt ON sp.stpt_id=stpt.id" + " LEFT OUTER JOIN scripts sc ON stpt.script_id = sc.id" - + " WHERE sp.value is not null AND sp.samp_id = any(?{1})", parameterBindings = + + " WHERE sp.samp_id = any(?{1})", parameterBindings = { LongSetMapper.class }, fetchSize = FETCH_SIZE) public DataIterator<GenericEntityPropertyRecord> getEntityPropertyGenericValues( LongSet sampleIds); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListerDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListerDAO.java index 4d090529811892b671b12b626206202487aba828..096e0b20a9045e6b37235c89c544c2d8fc217e5c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListerDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListerDAO.java @@ -16,18 +16,17 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister; -import it.unimi.dsi.fastutil.longs.LongSet; -import net.lemnik.eodsql.QueryTool; import ch.rinn.restrictions.Friend; import ch.rinn.restrictions.Private; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.AbstractDAO; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.GenericEntityPropertyRecord; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.IEntityPropertySetListingQuery; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.MaterialEntityPropertyRecord; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.VocabularyTermRecord; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.PersistencyResources; +import it.unimi.dsi.fastutil.longs.LongSet; +import net.lemnik.eodsql.QueryTool; + /** * The DAO for business objects implementing {@link ISampleLister}. Note: Even though this class is public its constructors and instance methods have * to be package protected. @@ -85,20 +84,6 @@ public final class SampleListerDAO extends AbstractDAO { return query.getEntityPropertyGenericValues(entityIDs); } - - @Override - public Iterable<MaterialEntityPropertyRecord> getEntityPropertyMaterialValues( - LongSet entityIDs) - { - return query.getEntityPropertyMaterialValues(entityIDs); - } - - @Override - public Iterable<VocabularyTermRecord> getEntityPropertyVocabularyTermValues( - LongSet entityIDs) - { - return query.getEntityPropertyVocabularyTermValues(entityIDs); - } }; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricherTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricherTest.java index 3d051bc351e8174479aaa42bcf27e76ce7919a44..9ce30c16051b654030699f1880a8266e9b7d3afd 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricherTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/EntityPropertiesEnricherTest.java @@ -16,9 +16,6 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common; -import it.unimi.dsi.fastutil.longs.LongSet; -import it.unimi.dsi.fastutil.longs.LongSets; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -36,11 +33,17 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityPropertiesHolder import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.longs.LongSets; + /** * @author Franz-Josef Elmer */ public class EntityPropertiesEnricherTest extends AssertJUnit { + private static final long VOCABULARY_TERM_ID = 42L; + private static final long VOCABULARY_ID = 1L; private static final long ENTITY_ID = 42L; @@ -78,8 +81,7 @@ public class EntityPropertiesEnricherTest extends AssertJUnit PropertyType propertyType = new PropertyType(); propertyType.setId(PROPERTY_TYPE_ID); propertyType.setDataType(new DataType(DataTypeCode.CONTROLLEDVOCABULARY)); - will(returnValue(new PropertyType[] - { propertyType })); + will(returnValue(new PropertyType[] { propertyType })); allowing(resolver).get(ENTITY_ID); will(returnValue(holder)); @@ -104,10 +106,12 @@ public class EntityPropertiesEnricherTest extends AssertJUnit { { one(setQuery).getEntityPropertyGenericValues(entityIDs); - will(returnValue(Arrays.asList())); - - one(setQuery).getEntityPropertyMaterialValues(entityIDs); - will(returnValue(Arrays.asList())); + GenericEntityPropertyRecord record = new GenericEntityPropertyRecord(); + record.entity_id = ENTITY_ID; + record.cvte_id = VOCABULARY_TERM_ID; + record.prty_id = PROPERTY_TYPE_ID; + record.entity_id = ENTITY_ID; + will(returnValue(Arrays.asList(record))); one(query).getVocabularyURLTemplates(); CodeRecord codeRecord = new CodeRecord(); @@ -116,15 +120,15 @@ public class EntityPropertiesEnricherTest extends AssertJUnit will(returnValue(new CodeRecord[] { codeRecord })); - one(setQuery).getEntityPropertyVocabularyTermValues(entityIDs); + one(query).getVocabularyTerms(new LongOpenHashSet(Arrays.asList(record.cvte_id))); VocabularyTermRecord termRecord = new VocabularyTermRecord(); termRecord.entity_id = ENTITY_ID; termRecord.prty_id = PROPERTY_TYPE_ID; - termRecord.id = 137L; + termRecord.id = VOCABULARY_TERM_ID; termRecord.covo_id = VOCABULARY_ID; termRecord.code = "HELLO"; termRecord.label = "Hello"; - will(returnValue(Arrays.asList(termRecord))); + will(returnValue(new WrappingDataIterator<>(Arrays.asList(termRecord)))); } }); @@ -142,10 +146,12 @@ public class EntityPropertiesEnricherTest extends AssertJUnit { { one(setQuery).getEntityPropertyGenericValues(entityIDs); - will(returnValue(Arrays.asList())); - - one(setQuery).getEntityPropertyMaterialValues(entityIDs); - will(returnValue(Arrays.asList())); + GenericEntityPropertyRecord record = new GenericEntityPropertyRecord(); + record.entity_id = ENTITY_ID; + record.cvte_id = VOCABULARY_TERM_ID; + record.prty_id = PROPERTY_TYPE_ID; + record.entity_id = ENTITY_ID; + will(returnValue(Arrays.asList(record))); one(query).getVocabularyURLTemplates(); CodeRecord codeRecord = new CodeRecord(); @@ -154,15 +160,15 @@ public class EntityPropertiesEnricherTest extends AssertJUnit will(returnValue(new CodeRecord[] { codeRecord })); - one(setQuery).getEntityPropertyVocabularyTermValues(entityIDs); + one(query).getVocabularyTerms(new LongOpenHashSet(Arrays.asList(record.cvte_id))); VocabularyTermRecord termRecord = new VocabularyTermRecord(); termRecord.entity_id = ENTITY_ID; termRecord.prty_id = PROPERTY_TYPE_ID; - termRecord.id = 137L; + termRecord.id = VOCABULARY_TERM_ID; termRecord.covo_id = VOCABULARY_ID; termRecord.code = "HELLO"; termRecord.label = "Hello"; - will(returnValue(Arrays.asList(termRecord))); + will(returnValue(new WrappingDataIterator<>(Arrays.asList(termRecord)))); } }); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/WrappingDataIterator.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/WrappingDataIterator.java new file mode 100644 index 0000000000000000000000000000000000000000..1062025edda525d85b1f8809877eee2581bb845b --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/WrappingDataIterator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2017 ETH Zuerich, SIS + * + * 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 ch.systemsx.cisd.openbis.generic.server.business.bo.common; + +import java.util.Collection; +import java.util.Iterator; + +import net.lemnik.eodsql.DataIterator; + +public class WrappingDataIterator<E> implements DataIterator<E> +{ + private final Collection<E> collection; + + private final Iterator<E> iterator; + + public WrappingDataIterator(Collection<E> collection) + { + this.collection = collection; + iterator = collection.iterator(); + } + + @Override + public boolean hasNext() + { + return iterator.hasNext(); + } + + @Override + public E next() + { + return iterator.next(); + } + + @Override + public void remove() + { + iterator.remove(); + } + + @Override + public Iterator<E> iterator() + { + return collection.iterator(); + } + + @Override + public void close() + { + } + + @Override + public boolean isClosed() + { + return false; + } +} \ No newline at end of file diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerFastTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerFastTest.java index 7314731640234aa0b577557b1c879bbb8bae17be..4a865385e44d510937183bebbfc19846ddf54aca 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerFastTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListerFastTest.java @@ -19,14 +19,10 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.List; -import net.lemnik.eodsql.DataIterator; - import org.jmock.Expectations; import org.jmock.Mockery; import org.testng.AssertJUnit; @@ -36,6 +32,7 @@ import org.testng.annotations.Test; import ch.rinn.restrictions.Friend; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.IEntityPropertiesEnricher; +import ch.systemsx.cisd.openbis.generic.server.business.bo.common.WrappingDataIterator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRelationshipTypeDAO; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; @@ -199,52 +196,4 @@ public class DatasetListerFastTest extends AssertJUnit return record; } - private static final class WrappingDataIterator<E> implements DataIterator<E> - { - private final Collection<E> collection; - - private final Iterator<E> iterator; - - public WrappingDataIterator(Collection<E> collection) - { - this.collection = collection; - iterator = collection.iterator(); - } - - @Override - public boolean hasNext() - { - return iterator.hasNext(); - } - - @Override - public E next() - { - return iterator.next(); - } - - @Override - public void remove() - { - iterator.remove(); - } - - @Override - public Iterator<E> iterator() - { - return collection.iterator(); - } - - @Override - public void close() - { - } - - @Override - public boolean isClosed() - { - return false; - } - } - }