diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java index 03d81825012c996549c39ecac36e6eb40f2674d3..257451524c4662d0d3b5a684674c60789170c110 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java @@ -1,6 +1,5 @@ package ch.systemsx.cisd.openbis.generic.server.authorization; -import java.sql.Connection; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -484,10 +483,4 @@ final public class AuthorizationDataProvider implements IAuthorizationDataProvid { return list; } - - @Override - public Connection getConnection() - { - return daoFactory.getConnection(); - } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/IAuthorizationDataProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/IAuthorizationDataProvider.java index a8947eb59cb59a582a814ede538a6fc9195abbde..9eee11766601b6071921772666462bee0ce1d547 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/IAuthorizationDataProvider.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/IAuthorizationDataProvider.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.generic.server.authorization; -import java.sql.Connection; import java.util.List; import java.util.Set; @@ -155,9 +154,4 @@ public interface IAuthorizationDataProvider extends IDatabaseInstanceFinder * Fetches metaproject with given tech id. */ public MetaprojectPE getMetaproject(TechId id); - - /** - * Returns the JDBC connection. - */ - public Connection getConnection(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/ExperimentListPredicate.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/ExperimentListPredicate.java index 080a7aa5d9cf0d1215f66f43404ddcf6e0e785a6..791df168cb106f031c92c21390981afc0a42d048 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/ExperimentListPredicate.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/ExperimentListPredicate.java @@ -50,6 +50,21 @@ import ch.systemsx.cisd.openbis.generic.shared.util.SpaceCodeHelper; @ShouldFlattenCollections(value = false) public class ExperimentListPredicate extends AbstractSpacePredicate<List<Experiment>> { + public static interface IExperimentToSpaceQuery extends BaseQuery + { + @Select(sql = "select distinct space_id from projects p left join experiments e on e.proj_id = p.id " + + "where e.id = any(?{1}) union " + + "select distinct space_id from projects p left join experiments e on e.proj_id = p.id " + + "where e.perm_id = any(?{2})", parameterBindings = + { LongArrayMapper.class, StringArrayMapper.class }) + public List<Long> getExperimentSpaceIds(long[] experimentIds, String[] experimentPermIds); + } + + private final static int ARRAY_SIZE_LIMIT = 999; + + private final IExperimentToSpaceQuery experimentToSpaceQuery = + QueryTool.getManagedQuery(IExperimentToSpaceQuery.class); + // // AbstractPredicate // @@ -105,18 +120,6 @@ public class ExperimentListPredicate extends AbstractSpacePredicate<List<Experim return Status.OK; } - private final static int ARRAY_SIZE_LIMIT = 999; - - public static interface IExperimentToSpaceQuery extends BaseQuery - { - @Select(sql = "select distinct space_id from projects p left join experiments e on e.proj_id = p.id " - + "where e.id = any(?{1}) union " - + "select distinct space_id from projects p left join experiments e on e.proj_id = p.id " - + "where e.perm_id = any(?{2})", parameterBindings = - { LongArrayMapper.class, StringArrayMapper.class }) - public List<Long> getExperimentSpaceIds(long[] experimentIds, String[] experimentPermIds); - } - private Collection<Long> getExperimentSpaceIds(final List<Long> ids, final List<String> permIds) { if (ids.size() != permIds.size()) @@ -128,9 +131,6 @@ public class ExperimentListPredicate extends AbstractSpacePredicate<List<Experim { return Collections.emptyList(); } - final IExperimentToSpaceQuery query = - QueryTool.getQuery(authorizationDataProvider.getConnection(), - IExperimentToSpaceQuery.class); if (size > ARRAY_SIZE_LIMIT) { final Set<Long> spaceIds = new HashSet<Long>(size); @@ -140,13 +140,14 @@ public class ExperimentListPredicate extends AbstractSpacePredicate<List<Experim Math.min(size, startIdx + ARRAY_SIZE_LIMIT)); final List<String> permIdSubList = permIds.subList(startIdx, Math.min(size, startIdx + ARRAY_SIZE_LIMIT)); - spaceIds.addAll(query.getExperimentSpaceIds(toArray(idSubList), + spaceIds.addAll(experimentToSpaceQuery.getExperimentSpaceIds(toArray(idSubList), permIdSubList.toArray(new String[permIdSubList.size()]))); } return spaceIds; } else { - return query.getExperimentSpaceIds(toArray(ids), permIds.toArray(new String[size])); + return experimentToSpaceQuery.getExperimentSpaceIds(toArray(ids), + permIds.toArray(new String[size])); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/SampleListPredicate.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/SampleListPredicate.java index 181e93efef20483a8c3ba8e634bd9ad790b8c1e6..6e797a91cb1e529003974a9ad74c4538e5f125f6 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/SampleListPredicate.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/predicate/SampleListPredicate.java @@ -50,11 +50,24 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleOwnerIdentif @ShouldFlattenCollections(value = false) public class SampleListPredicate extends AbstractSpacePredicate<List<Sample>> { + private final static int ARRAY_SIZE_LIMIT = 999; + + public static interface ISampleToSpaceQuery extends BaseQuery + { + @Select(sql = "select distinct space_id from samples where id = any(?{1}) " + + "union select distinct space_id from samples where perm_id = any(?{2})", parameterBindings = + { LongArrayMapper.class, StringArrayMapper.class }) + public List<Long> getSampleSpaceIds(long[] sampleIds, String[] samplePermIds); + } + private final SampleOwnerIdentifierPredicate idOwnerPredicate; + private final ISampleToSpaceQuery sampleToSpaceQuery; + public SampleListPredicate() { idOwnerPredicate = new SampleOwnerIdentifierPredicate(); + sampleToSpaceQuery = QueryTool.getManagedQuery(ISampleToSpaceQuery.class); } // @@ -133,16 +146,6 @@ public class SampleListPredicate extends AbstractSpacePredicate<List<Sample>> return Status.OK; } - private final static int ARRAY_SIZE_LIMIT = 999; - - public static interface ISampleToSpaceQuery extends BaseQuery - { - @Select(sql = "select distinct space_id from samples where id = any(?{1}) " - + "union select distinct space_id from samples where perm_id = any(?{2})", parameterBindings = - { LongArrayMapper.class, StringArrayMapper.class }) - public List<Long> getSampleSpaceIds(long[] sampleIds, String[] samplePermIds); - } - private Collection<Long> getSampleSpaceIds(final List<Long> ids, final List<String> permIds) { if (ids.size() != permIds.size()) @@ -154,9 +157,6 @@ public class SampleListPredicate extends AbstractSpacePredicate<List<Sample>> { return Collections.emptyList(); } - final ISampleToSpaceQuery query = - QueryTool.getQuery(authorizationDataProvider.getConnection(), - ISampleToSpaceQuery.class); if (size > ARRAY_SIZE_LIMIT) { final Set<Long> spaceIds = new HashSet<Long>(size); @@ -166,13 +166,14 @@ public class SampleListPredicate extends AbstractSpacePredicate<List<Sample>> Math.min(size, startIdx + ARRAY_SIZE_LIMIT)); final List<String> permIdSubList = permIds.subList(startIdx, Math.min(size, startIdx + ARRAY_SIZE_LIMIT)); - spaceIds.addAll(query.getSampleSpaceIds(toArray(idSubList), + spaceIds.addAll(sampleToSpaceQuery.getSampleSpaceIds(toArray(idSubList), permIdSubList.toArray(new String[permIdSubList.size()]))); } return spaceIds; } else { - return query.getSampleSpaceIds(toArray(ids), permIds.toArray(new String[size])); + return sampleToSpaceQuery.getSampleSpaceIds(toArray(ids), + permIds.toArray(new String[size])); } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java index 5b6b62a4ee8f84eda36814d8a7b6a2dd2e35cc99..b82887f6119a75af309da02fee3bf39a8e65a7ed 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/AbstractBusinessObject.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo; -import java.sql.Connection; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -512,12 +511,6 @@ abstract class AbstractBusinessObject implements IDAOFactory return daoFactory.getExternalDataManagementSystemDAO(); } - @Override - public Connection getConnection() - { - return daoFactory.getConnection(); - } - @Override public IMetaprojectDAO getMetaprojectDAO() { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityCodeGenerator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityCodeGenerator.java index 8b2ebe4d21b27d18437dbe02651add28ede7e2a3..694cb93a1a570155c81c6bc51c766f7570804c9d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityCodeGenerator.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/EntityCodeGenerator.java @@ -23,7 +23,6 @@ import net.lemnik.eodsql.BaseQuery; import net.lemnik.eodsql.QueryTool; import net.lemnik.eodsql.Select; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.dto.TableNames; @@ -67,7 +66,7 @@ public class EntityCodeGenerator { String[] codes = new String[numberOfCodes]; - query = QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), Query.class); + query = QueryTool.getManagedQuery(Query.class); for (int i = 0; i < numberOfCodes; i++) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/DatabaseContextUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/DatabaseContextUtils.java index 81a5242873dabe22507103af6904656a29691c79..96941b1a19ea37dd8a40e8ffa86ed074cfd9bd1b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/DatabaseContextUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/DatabaseContextUtils.java @@ -16,11 +16,8 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common; -import java.sql.Connection; - import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.dbmigration.DatabaseConfigurationContext; -import ch.systemsx.cisd.openbis.generic.server.dataaccess.IAuthorizationDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.PersistencyResources; @@ -31,13 +28,6 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.PersistencyResources; */ public class DatabaseContextUtils { - - @SuppressWarnings("deprecation") - public static Connection getConnection(IAuthorizationDAOFactory daoFactory) - { - return daoFactory.getSessionFactory().getCurrentSession().connection(); - } - /** * @return associated database configuration context * @throws ConfigurationFailureException if it was impossible to get the context diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/ISecondaryEntityListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/ISecondaryEntityListingQuery.java index defe86fa58d4a6ea1a6e80b7fc88af2e1ad526cb..64ffe1bea3601cf2e2218c6f10c57cd7ace8db5d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/ISecondaryEntityListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/ISecondaryEntityListingQuery.java @@ -17,9 +17,9 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.common.entity; 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; import ch.rinn.restrictions.Friend; import ch.rinn.restrictions.Private; @@ -36,7 +36,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; @Private @Friend(toClasses = { SampleReferenceRecord.class }) -public interface ISecondaryEntityListingQuery extends TransactionQuery +public interface ISecondaryEntityListingQuery extends BaseQuery { public static final int FETCH_SIZE = 1000; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/SecondaryEntityDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/SecondaryEntityDAO.java index ced273d33b757b568909b5e0b03e3931e855ec65..c07a7a020f781f634e9c1b2eb2c47c55cc3cbe8e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/SecondaryEntityDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/common/entity/SecondaryEntityDAO.java @@ -20,9 +20,6 @@ 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; - -import java.sql.Connection; - import net.lemnik.eodsql.QueryTool; import org.springframework.dao.EmptyResultDataAccessException; @@ -30,7 +27,6 @@ import org.springframework.dao.EmptyResultDataAccessException; import ch.rinn.restrictions.Friend; import ch.rinn.restrictions.Private; import ch.systemsx.cisd.common.exceptions.UserFailureException; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.PersistencyResources; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; @@ -62,9 +58,8 @@ public class SecondaryEntityDAO */ public static SecondaryEntityDAO create(IDAOFactory daoFactory) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); ISecondaryEntityListingQuery query = - QueryTool.getQuery(connection, ISecondaryEntityListingQuery.class); + QueryTool.getManagedQuery(ISecondaryEntityListingQuery.class); return create(daoFactory, query); } 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 0da2f9e89a15fefb9f735c8553ad858898ce1173..a8c7f6dca79c67222f3e78ad2fbc9a67d14d24bb 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 @@ -17,15 +17,11 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister; import it.unimi.dsi.fastutil.longs.LongSet; - -import java.sql.Connection; - 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.DatabaseContextUtils; 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; @@ -50,8 +46,7 @@ public final class DatasetListerDAO extends AbstractDAO */ public static DatasetListerDAO create(IDAOFactory daoFactory) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); - IDatasetListingQuery query = QueryTool.getQuery(connection, IDatasetListingQuery.class); + IDatasetListingQuery query = QueryTool.getManagedQuery(IDatasetListingQuery.class); return create(daoFactory, query); } 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 5c114ce3e10a97979378f050b1645800b1706290..5f51859fbde354a934430c479288f3c9f6c773d9 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 @@ -21,6 +21,7 @@ import it.unimi.dsi.fastutil.longs.LongSet; import java.util.Date; import java.util.List; +import net.lemnik.eodsql.BaseQuery; import net.lemnik.eodsql.DataIterator; import net.lemnik.eodsql.Select; import net.lemnik.eodsql.TransactionQuery; @@ -49,7 +50,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.StringArrayMapper; @Private @Friend(toClasses = { DataStoreRecord.class }) -public interface IDatasetListingQuery extends TransactionQuery, IPropertyListingQuery +public interface IDatasetListingQuery extends BaseQuery, IPropertyListingQuery { public static final int FETCH_SIZE = 1000; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java index 650365334d2e8c3375a07afce628763eb73706e2..4cd44087b6855f569341d8560d6b62e4eb3b7e46 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java @@ -28,7 +28,6 @@ import net.lemnik.eodsql.QueryTool; import org.apache.commons.lang.StringUtils; import ch.systemsx.cisd.common.exceptions.UserFailureException; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IAuthorizationDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.DataSetInitializer; @@ -58,8 +57,7 @@ public class DataSetLister implements IDataSetLister public DataSetLister(IAuthorizationDAOFactory daoFactory, PersonPE person) { - this(QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), - IDataSetListingQuery.class), person); + this(QueryTool.getManagedQuery(IDataSetListingQuery.class), person); } public DataSetLister(IDataSetListingQuery query, PersonPE person) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java index 8c71af2587be57a395f31f9d5e7b717026b1c51a..6f8db96ecdc49ef0b29f1395f86d53ea7b1269d3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java @@ -29,7 +29,6 @@ import net.lemnik.eodsql.QueryTool; import org.apache.commons.lang.StringUtils; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.PermlinkUtilities; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; @@ -60,8 +59,7 @@ public class ExperimentLister implements IExperimentLister public ExperimentLister(IDAOFactory daoFactory, String baseIndexURL) { - this(daoFactory, baseIndexURL, QueryTool.getQuery( - DatabaseContextUtils.getConnection(daoFactory), IExperimentListingQuery.class)); + this(daoFactory, baseIndexURL, QueryTool.getManagedQuery(IExperimentListingQuery.class)); } public ExperimentLister(IDAOFactory daoFactory, String baseIndexURL, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/samplelister/SampleLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/samplelister/SampleLister.java index a27da73de8dbfac74a780aab5133833479db6a49..87443cf3243baddea5cbaf0502710b2ecafd0963 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/samplelister/SampleLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/samplelister/SampleLister.java @@ -34,7 +34,6 @@ import net.lemnik.eodsql.QueryTool; import ch.systemsx.cisd.common.collection.IKeyExtractor; import ch.systemsx.cisd.common.collection.TableMap; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.common.EntityMetaprojectRelationRecord; import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.common.MetaprojectCreator; import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.common.MetaprojectRecord; @@ -98,8 +97,7 @@ public class SampleLister implements ISampleLister public SampleLister(IDAOFactory daoFactory, PersonPE person) { - this(QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), - ISampleListingQuery.class), person); + this(QueryTool.getManagedQuery(ISampleListingQuery.class), person); } SampleLister(ISampleListingQuery query, PersonPE person) 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 3bcee0a51e9975cb61d8a2f57b1aa3e46528dab4..5811b838d08da0040f9db933adbde040ff217230 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 @@ -20,6 +20,7 @@ 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; @@ -44,7 +45,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.StringArrayMapper; * @author Tomasz Pylak */ @Private -public interface IMaterialListingQuery extends TransactionQuery, IPropertyListingQuery +public interface IMaterialListingQuery extends BaseQuery, IPropertyListingQuery { public static final int FETCH_SIZE = 1000; 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 ff63d404a090d42b0dcf12e33c8c95228a954cbd..6d9d848057806236076c8f0506d02a64f5238ef2 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 @@ -17,15 +17,11 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister; import it.unimi.dsi.fastutil.longs.LongSet; - -import java.sql.Connection; - 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.DatabaseContextUtils; 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; @@ -50,8 +46,7 @@ public final class MaterialListerDAO extends AbstractDAO */ public static MaterialListerDAO create(IDAOFactory daoFactory) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); - IMaterialListingQuery query = QueryTool.getQuery(connection, IMaterialListingQuery.class); + IMaterialListingQuery query = QueryTool.getManagedQuery(IMaterialListingQuery.class); return create(daoFactory, query); } 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 6b7b3346ab812fc09c038a62f54dc7f6176de10e..1ddb6419239817a1a9391c3c7e6de8f324b3cde0 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 @@ -22,6 +22,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import net.lemnik.eodsql.BaseQuery; import net.lemnik.eodsql.DataIterator; import net.lemnik.eodsql.EoDException; import net.lemnik.eodsql.Select; @@ -53,7 +54,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; @Friend(toClasses = { ExperimentProjectSpaceCodeRecord.class }) @Private -public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQuery +public interface ISampleListingQuery extends BaseQuery, IPropertyListingQuery { public static final int FETCH_SIZE = 1000; 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 412c171c699bdb633a5715a61ba2a75f857bdf68..69854945b2b51098c76bf9f5e48d969628509ca8 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 @@ -17,15 +17,11 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister; import it.unimi.dsi.fastutil.longs.LongSet; - -import java.sql.Connection; - 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.DatabaseContextUtils; 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; @@ -50,8 +46,7 @@ public final class SampleListerDAO extends AbstractDAO */ public static SampleListerDAO create(IDAOFactory daoFactory) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); - ISampleListingQuery query = QueryTool.getQuery(connection, ISampleListingQuery.class); + ISampleListingQuery query = QueryTool.getManagedQuery(ISampleListingQuery.class); return create(daoFactory, query); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IAuthorizationDAOFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IAuthorizationDAOFactory.java index 85d8eed527731970e4e2b4044aacfd38e4d5e72c..8577615b99d6e855762bf80bdcb4d24da2531aaa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IAuthorizationDAOFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IAuthorizationDAOFactory.java @@ -16,8 +16,6 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess; -import java.sql.Connection; - import org.hibernate.SessionFactory; import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE; @@ -78,9 +76,4 @@ public interface IAuthorizationDAOFactory public IDeletionDAO getDeletionDAO(); public IMetaprojectDAO getMetaprojectDAO(); - - /** - * Returns the JDBC connection. - */ - public Connection getConnection(); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AuthorizationDAOFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AuthorizationDAOFactory.java index c625d1486c84250c4deb761024612916a25531a0..b3659cb455bb32f667ed5e91e95dfaf242d7137c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AuthorizationDAOFactory.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/AuthorizationDAOFactory.java @@ -16,8 +16,6 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess.db; -import java.sql.Connection; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.hibernate.SessionFactory; @@ -291,12 +289,4 @@ public class AuthorizationDAOFactory implements IAuthorizationDAOFactory Session currentSession = sessionFactory.getCurrentSession(); HibernateUtils.setBatchUpdateMode(currentSession, batchMode); } - - @SuppressWarnings("deprecation") - @Override - public Connection getConnection() - { - final SessionFactory sessionFactory = persistencyResources.getSessionFactory(); - return sessionFactory.getCurrentSession().connection(); - } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListingQueryTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListingQueryTest.java index a6cb850221ee9512abdda4528ddb9ed5b0a8a71a..d81132c89946edf8876166937d598cebc61a5a6a 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListingQueryTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetListingQueryTest.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang.builder.EqualsBuilder; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -79,16 +78,6 @@ public class DatasetListingQueryTest extends AbstractDAOTest query = dao.getQuery(); } - @AfterClass(alwaysRun = true) - public void cleanUp() throws SQLException - { - if (query != null) - { - query.commit(); - } - - } - public static DatasetListerDAO createDatasetListerDAO(IDAOFactory daoFactory) { IDatasetListingQuery query = diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingQueryTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingQueryTest.java index f593bf42084a0d4b6ebe1887ad796df90bdda0a2..802d94716e5149ab72921ac592c115916d312f56 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingQueryTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingQueryTest.java @@ -32,7 +32,6 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.lang.builder.EqualsBuilder; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -124,15 +123,6 @@ public class SampleListingQueryTest extends AbstractDAOTest parentChildRelationshipTypeId = query.getRelationshipTypeId("PARENT_CHILD", true); } - @AfterClass(alwaysRun = true) - public void cleanUp() throws SQLException - { - if (query != null) - { - query.commit(); - } - } - public static SampleListerDAO createSampleListerDAO(IDAOFactory daoFactory) { ISampleListingQuery query = diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java index 98639ad83f33b9cad4edd3f6bce2db671d6865be..df12948a5714569bbc2dfd9c4ae8d351fda67a3b 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/ScreeningServer.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.plugin.screening.server; -import java.sql.Connection; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -38,14 +37,13 @@ import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.Authoriz import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.Capability; import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.ReturnValueFilter; import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.RolesAllowed; +import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.AbstractTechIdPredicate.DataSetTechIdPredicate; +import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.AbstractTechIdPredicate.ExperimentTechIdPredicate; import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.DataSetCodeCollectionPredicate; import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.DataSetCodePredicate; import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.SampleTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.AbstractTechIdPredicate.DataSetTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.AbstractTechIdPredicate.ExperimentTechIdPredicate; import ch.systemsx.cisd.openbis.generic.server.business.IPropertiesBatchManager; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IVocabularyDAO; import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin; @@ -654,8 +652,7 @@ public final class ScreeningServer extends AbstractServer<IScreeningServer> impl private static IScreeningQuery createDAO(IDAOFactory daoFactory) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); - return QueryTool.getQuery(connection, IScreeningQuery.class); + return QueryTool.getManagedQuery(IScreeningQuery.class); } private ScreeningApiImpl createScreeningApiImpl(String sessionToken) diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/authorization/ScreeningPlateListReadOnlyPredicate.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/authorization/ScreeningPlateListReadOnlyPredicate.java index 6b2099af7a7bfd16f121dbd346b4524cb8639847..ccb10d1cc71b56231bc15ce4ee8e381a9697979f 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/authorization/ScreeningPlateListReadOnlyPredicate.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/authorization/ScreeningPlateListReadOnlyPredicate.java @@ -49,6 +49,17 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.PlateIdentifi public class ScreeningPlateListReadOnlyPredicate extends AbstractSpacePredicate<List<? extends PlateIdentifier>> { + private final static int ARRAY_SIZE_LIMIT = 999; + + private final ISampleToSpaceQuery sampleToSpaceQuery = QueryTool + .getManagedQuery(ISampleToSpaceQuery.class); + + interface ISampleToSpaceQuery extends BaseQuery + { + @Select(sql = "select distinct space_id from samples where perm_id = any(?{1})", parameterBindings = + { StringArrayMapper.class }) + public List<Long> getSampleSpaceIds(String[] samplePermIds); + } @Override public String getCandidateDescription() @@ -106,20 +117,8 @@ public class ScreeningPlateListReadOnlyPredicate extends return Status.OK; } - private final static int ARRAY_SIZE_LIMIT = 999; - - interface ISampleToSpaceQuery extends BaseQuery - { - @Select(sql = "select distinct space_id from samples where perm_id = any(?{1})", parameterBindings = - { StringArrayMapper.class }) - public List<Long> getSampleSpaceIds(String[] samplePermIds); - } - private Collection<Long> getSampleSpaceIds(final List<String> permIds) { - final ISampleToSpaceQuery query = - QueryTool.getQuery(authorizationDataProvider.getConnection(), - ISampleToSpaceQuery.class); if (permIds.size() > ARRAY_SIZE_LIMIT) { final Set<Long> spaceIds = new HashSet<Long>(permIds.size()); @@ -127,13 +126,13 @@ public class ScreeningPlateListReadOnlyPredicate extends { final List<String> permIdSubList = permIds.subList(startIdx, Math.min(permIds.size(), startIdx + ARRAY_SIZE_LIMIT)); - spaceIds.addAll(query.getSampleSpaceIds(permIdSubList.toArray( + spaceIds.addAll(sampleToSpaceQuery.getSampleSpaceIds(permIdSubList.toArray( new String[permIdSubList.size()]))); } return spaceIds; } else { - return query + return sampleToSpaceQuery .getSampleSpaceIds(permIds.toArray(new String[permIds.size()])); } } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java index 62333474dc055ec614df2cbf059150f39eb541a9..6d8b53533b3cfd0907257dff819aa3c882287c32 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/AbstractContentLoader.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.plugin.screening.server.logic; -import java.sql.Connection; import java.util.Set; import net.lemnik.eodsql.QueryTool; @@ -27,7 +26,6 @@ import org.apache.log4j.Logger; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE; @@ -71,8 +69,7 @@ abstract class AbstractContentLoader { if (screeningDao == null) { - Connection connection = DatabaseContextUtils.getConnection(daoFactory); - screeningDao = QueryTool.getQuery(connection, IScreeningQuery.class); + screeningDao = QueryTool.getManagedQuery(IScreeningQuery.class); } return screeningDao; } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java index d3f81de748f1053a8c21a3e254602a9b2f84a084..d12829923b5a3d83957eb62a378a5d3c9f58c0f0 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/ScreeningApiImpl.java @@ -16,7 +16,6 @@ package ch.systemsx.cisd.openbis.plugin.screening.server.logic; -import java.sql.Connection; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -36,7 +35,6 @@ import ch.rinn.restrictions.Friend; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.server.business.bo.IDataBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; -import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleTypeDAO; @@ -662,8 +660,7 @@ public class ScreeningApiImpl private IScreeningQuery createScreeningQuery() { - final Connection connection = DatabaseContextUtils.getConnection(daoFactory); - return QueryTool.getQuery(connection, IScreeningQuery.class); + return QueryTool.getManagedQuery(IScreeningQuery.class); } private ExperimentPE getExperimentFromDB(ExperimentIdentifier experimentIdentifierFromUser)