From 2a76736474f4e3f8c7151c9f97cd108be809b4ef Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 27 May 2025 11:33:45 -0500 Subject: [PATCH] Introduce QueryOrCountInputInterface --- .../helpers/QueryActionCacheHelper.java | 3 +- .../tables/QueryOrCountInputInterface.java | 117 ++++++++++++++++++ .../actions/tables/count/CountInput.java | 3 +- .../actions/tables/query/QueryInput.java | 3 +- 4 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/QueryOrCountInputInterface.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/QueryActionCacheHelper.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/QueryActionCacheHelper.java index 2d830636..6b97cbbe 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/QueryActionCacheHelper.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/tables/helpers/QueryActionCacheHelper.java @@ -41,6 +41,7 @@ import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction; import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.exceptions.QException; import com.kingsrook.qqq.backend.core.logging.QLogger; +import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrGetInputInterface; import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput; import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput; import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput; @@ -569,7 +570,7 @@ public class QueryActionCacheHelper QQueryFilter filter = new QQueryFilter().withBooleanOperator(QQueryFilter.BooleanOperator.OR); sourceQueryInput.setFilter(filter); - sourceQueryInput.setCommonParamsFrom(cacheQueryInput); + ((QueryOrGetInputInterface) sourceQueryInput).setCommonParamsFrom(cacheQueryInput); for(List uniqueKeyValue : uniqueKeyValues) { diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/QueryOrCountInputInterface.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/QueryOrCountInputInterface.java new file mode 100644 index 00000000..f659737f --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/QueryOrCountInputInterface.java @@ -0,0 +1,117 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2023. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.model.actions.tables; + + +import java.util.EnumSet; +import java.util.List; +import com.kingsrook.qqq.backend.core.actions.QBackendTransaction; +import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter; +import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin; + + +/******************************************************************************* + ** Common getters & setters, shared by both QueryInput and CountInput. + ** + ** Original impetus for this class is the setCommonParamsFrom() method - for cases + ** where we need to change a Query to a Get, or vice-versa, and we want to copy over + ** all of those input params. + *******************************************************************************/ +public interface QueryOrCountInputInterface +{ + /******************************************************************************* + ** Set in THIS, the "common params" (e.g., common to both Query & Count inputs) + ** from the parameter SOURCE object. + *******************************************************************************/ + default void setCommonParamsFrom(QueryOrCountInputInterface source) + { + this.setTransaction(source.getTransaction()); + this.setFilter(source.getFilter()); + this.setTableName(source.getTableName()); + this.setQueryJoins(source.getQueryJoins()); + this.setTimeoutSeconds(source.getTimeoutSeconds()); + this.setQueryHints(source.getQueryHints()); + } + + /******************************************************************************* + ** + *******************************************************************************/ + String getTableName(); + + /*************************************************************************** + ** + ***************************************************************************/ + void setTableName(String tableName); + + /******************************************************************************* + ** + *******************************************************************************/ + QQueryFilter getFilter(); + + /*************************************************************************** + ** + ***************************************************************************/ + void setFilter(QQueryFilter filter); + + /******************************************************************************* + ** Getter for transaction + *******************************************************************************/ + QBackendTransaction getTransaction(); + + /******************************************************************************* + ** Setter for transaction + *******************************************************************************/ + void setTransaction(QBackendTransaction transaction); + + /******************************************************************************* + ** Getter for queryJoins + *******************************************************************************/ + List getQueryJoins(); + + /******************************************************************************* + ** Setter for queryJoins + ** + *******************************************************************************/ + void setQueryJoins(List queryJoins); + + /******************************************************************************* + ** + *******************************************************************************/ + Integer getTimeoutSeconds(); + + /*************************************************************************** + ** + ***************************************************************************/ + void setTimeoutSeconds(Integer timeoutSeconds); + + + /******************************************************************************* + ** Getter for queryHints + *******************************************************************************/ + EnumSet getQueryHints(); + + + /******************************************************************************* + ** Setter for queryHints + *******************************************************************************/ + void setQueryHints(EnumSet queryHints); +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/count/CountInput.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/count/CountInput.java index 37476e61..58b30609 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/count/CountInput.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/count/CountInput.java @@ -28,6 +28,7 @@ import java.util.List; import com.kingsrook.qqq.backend.core.actions.QBackendTransaction; import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput; import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint; +import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrCountInputInterface; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter; import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin; @@ -36,7 +37,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryJoin; ** Input data for the Count action ** *******************************************************************************/ -public class CountInput extends AbstractTableActionInput +public class CountInput extends AbstractTableActionInput implements QueryOrCountInputInterface { private QBackendTransaction transaction; private QQueryFilter filter; diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QueryInput.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QueryInput.java index db4947f3..2631b785 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QueryInput.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/tables/query/QueryInput.java @@ -32,6 +32,7 @@ import com.kingsrook.qqq.backend.core.actions.QBackendTransaction; import com.kingsrook.qqq.backend.core.actions.reporting.RecordPipe; import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput; import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint; +import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrCountInputInterface; import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrGetInputInterface; @@ -42,7 +43,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrGetInputInterf ** CountInput, and AggregateInput}, with common attributes for all of these ** "read" operations (like, queryHints, *******************************************************************************/ -public class QueryInput extends AbstractTableActionInput implements QueryOrGetInputInterface, Cloneable +public class QueryInput extends AbstractTableActionInput implements QueryOrGetInputInterface, QueryOrCountInputInterface, Cloneable { private QBackendTransaction transaction; private QQueryFilter filter;