From 18e0f6f9773a620fd7a4acf7df2d3de7a5967dcc Mon Sep 17 00:00:00 2001 From: Julie Sullivan Date: Tue, 10 Mar 2020 16:22:58 +0000 Subject: [PATCH] add interfaces for common manager methods #528 --- .../cellbase/lib/managers/AggregationApi.java | 34 +++++++++++++ .../cellbase/lib/managers/FeatureApi.java | 50 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/AggregationApi.java create mode 100644 cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/FeatureApi.java diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/AggregationApi.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/AggregationApi.java new file mode 100644 index 0000000000..70c63159e9 --- /dev/null +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/AggregationApi.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015-2020 OpenCB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opencb.cellbase.lib.managers; + +import org.opencb.cellbase.core.api.queries.AbstractQuery; +import org.opencb.cellbase.core.result.CellBaseDataResult; + +public interface AggregationApi extends FeatureApi { + + default CellBaseDataResult groupBy(Q query) { + query.setCount(Boolean.FALSE); + return getDBAdaptor().groupBy(query); + } + + default CellBaseDataResult aggregationStats(Q query) { + query.setCount(Boolean.TRUE); + return getDBAdaptor().groupBy(query); + } + +} diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/FeatureApi.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/FeatureApi.java new file mode 100644 index 0000000000..6af8d793b5 --- /dev/null +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/managers/FeatureApi.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015-2020 OpenCB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opencb.cellbase.lib.managers; + +import org.opencb.cellbase.core.api.core.CellBaseCoreDBAdaptor; +import org.opencb.cellbase.core.api.queries.AbstractQuery; +import org.opencb.cellbase.core.api.queries.QueryException; +import org.opencb.cellbase.core.result.CellBaseDataResult; + +import java.util.Iterator; +import java.util.List; + +public interface FeatureApi { + + CellBaseCoreDBAdaptor getDBAdaptor(); + + default CellBaseDataResult search(Q query) throws QueryException, IllegalAccessException { + query.setDefaults(); + query.validate(); + return getDBAdaptor().query(query); + } + + default List> info(List geneQueries) { + List> geneQueryResults = getDBAdaptor().query(geneQueries); + return geneQueryResults; + } + + default CellBaseDataResult distinct(Q query) { + query.setCount(Boolean.FALSE); + return getDBAdaptor().distinct(query); + } + + default Iterator iterator(Q query) { + return getDBAdaptor().iterator(query); + } +}