From 14280b3d0d96b4a3faea6fbe4fc93570ee390b43 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Mon, 12 Nov 2012 22:40:45 +0000 Subject: [PATCH] Use a managed database connection where we used to get the connection from the Hibernate session. SVN: 27581 --- .../AuthorizationDataProvider.java | 7 ---- .../IAuthorizationDataProvider.java | 6 ---- .../predicate/ExperimentListPredicate.java | 35 ++++++++++--------- .../predicate/SampleListPredicate.java | 31 ++++++++-------- .../business/bo/AbstractBusinessObject.java | 7 ---- .../business/bo/EntityCodeGenerator.java | 3 +- .../bo/common/DatabaseContextUtils.java | 10 ------ .../entity/ISecondaryEntityListingQuery.java | 4 +-- .../bo/common/entity/SecondaryEntityDAO.java | 7 +--- .../bo/datasetlister/DatasetListerDAO.java | 7 +--- .../datasetlister/IDatasetListingQuery.java | 3 +- .../datasetlister/DataSetLister.java | 4 +-- .../experimentlister/ExperimentLister.java | 4 +-- .../samplelister/SampleLister.java | 4 +-- .../materiallister/IMaterialListingQuery.java | 3 +- .../bo/materiallister/MaterialListerDAO.java | 7 +--- .../bo/samplelister/ISampleListingQuery.java | 3 +- .../bo/samplelister/SampleListerDAO.java | 7 +--- .../dataaccess/IAuthorizationDAOFactory.java | 7 ---- .../db/AuthorizationDAOFactory.java | 10 ------ .../DatasetListingQueryTest.java | 11 ------ .../samplelister/SampleListingQueryTest.java | 10 ------ .../screening/server/ScreeningServer.java | 9 ++--- .../ScreeningPlateListReadOnlyPredicate.java | 27 +++++++------- .../server/logic/AbstractContentLoader.java | 5 +-- .../server/logic/ScreeningApiImpl.java | 5 +-- 26 files changed, 68 insertions(+), 168 deletions(-) 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 03d81825012..257451524c4 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 a8947eb59cb..9eee1176660 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 080a7aa5d9c..791df168cb1 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 181e93efef2..6e797a91cb1 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 5b6b62a4ee8..b82887f6119 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 8b2ebe4d21b..694cb93a1a5 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 81a5242873d..96941b1a19e 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 defe86fa58d..64ffe1bea36 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 ced273d33b7..c07a7a020f7 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 0da2f9e89a1..a8c7f6dca79 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 5c114ce3e10..5f51859fbde 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 650365334d2..4cd44087b68 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 8c71af2587b..6f8db96ecdc 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 a27da73de8d..87443cf3243 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 3bcee0a51e9..5811b838d08 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 ff63d404a09..6d9d8480578 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 6b7b3346ab8..1ddb6419239 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 412c171c699..69854945b2b 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 85d8eed5277..8577615b99d 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 c625d1486c8..b3659cb455b 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 a6cb850221e..d81132c8994 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 f593bf42084..802d94716e5 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 98639ad83f3..df12948a571 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 6b2099af7a7..ccb10d1cc71 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 62333474dc0..6d8b53533b3 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 d3f81de748f..d12829923b5 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) -- GitLab