From 72f8415a6fe5f61bd8236a595e9aafc715aab175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 13 Nov 2024 22:24:54 +0100 Subject: [PATCH] refactor: Move methods to AbstractSqlBuilder [DHIS2-16705] (#19146) --- .../analytics/common/ValueTypeMapping.java | 8 ++--- .../data/DefaultEventDataQueryService.java | 3 -- .../table/setting/AnalyticsTableSettings.java | 2 +- .../java/org/hisp/dhis/db/model/Database.java | 14 ++++++++ .../hisp/dhis/db/sql/AbstractSqlBuilder.java | 32 +++++++++++++++++++ .../org/hisp/dhis/db/sql/DorisSqlBuilder.java | 30 ----------------- .../hisp/dhis/db/sql/PostgreSqlBuilder.java | 10 ------ .../dhis/external/conf/ConfigurationKey.java | 4 +-- .../event/data/EventAnalyticsServiceTest.java | 3 -- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/ValueTypeMapping.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/ValueTypeMapping.java index bac5c446b1f2..3710ae0736cf 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/ValueTypeMapping.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/common/ValueTypeMapping.java @@ -71,7 +71,7 @@ public enum ValueTypeMapping { @Getter private final UnaryOperator argumentTransformer; @Getter private final String postgresCast; - ValueTypeMapping(Function converter, Class... classes) { + ValueTypeMapping(Function converter, Class... classes) { this.converter = converter; this.valueTypes = fromClasses(classes); this.selectTransformer = UnaryOperator.identity(); @@ -86,7 +86,7 @@ public enum ValueTypeMapping { * @param classes the classes to be converted * @return the respective {@link ValueType} array */ - private ValueType[] fromClasses(Class... classes) { + private ValueType[] fromClasses(Class... classes) { return stream(ValueType.values()) .filter(valueType -> isAssignableFrom(classes, valueType)) .toArray(ValueType[]::new); @@ -99,14 +99,14 @@ private ValueType[] fromClasses(Class... classes) { * @param valueType the {@link ValueType} to be checked * @return true if the {@link ValueType} is assignable from the given classes, false otherwise */ - private static boolean isAssignableFrom(Class[] classes, ValueType valueType) { + private static boolean isAssignableFrom(Class[] classes, ValueType valueType) { return stream(classes).anyMatch(valueType.getJavaClass()::isAssignableFrom); } ValueTypeMapping( Function converter, UnaryOperator selectTransformer, - Class... classes) { + Class... classes) { this.converter = converter; this.valueTypes = fromClasses(classes); this.selectTransformer = s -> Objects.isNull(s) ? null : selectTransformer.apply(s); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java index 42f345e3b7b9..b08af886985a 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventDataQueryService.java @@ -94,7 +94,6 @@ import org.hisp.dhis.setting.UserSettings; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; -import org.hisp.dhis.user.UserSettingsService; import org.springframework.stereotype.Service; import org.springframework.util.Assert; @@ -119,8 +118,6 @@ public class DefaultEventDataQueryService implements EventDataQueryService { private final DataQueryService dataQueryService; - private final UserSettingsService userSettingsService; - @Override public EventQueryParams getFromRequest(EventDataQueryRequest request) { return getFromRequest(request, false); diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/setting/AnalyticsTableSettings.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/setting/AnalyticsTableSettings.java index 8fdedbcd8937..749e1173e694 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/setting/AnalyticsTableSettings.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/setting/AnalyticsTableSettings.java @@ -102,7 +102,7 @@ public boolean isAnalyticsDatabaseConfigured() { } /** - * Returns the configured analytics {@link Database}. Default is {@link Database#POSTGRESQL}. + * Returns the configured analytics {@link Database}. The default is {@link Database#POSTGRESQL}. * * @return the analytics {@link Database}. */ diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/model/Database.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/model/Database.java index c20f9ac54767..2696f2e9370d 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/model/Database.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/model/Database.java @@ -27,9 +27,23 @@ */ package org.hisp.dhis.db.model; +import org.hisp.dhis.analytics.table.init.AnalyticsDatabaseInit; +import org.hisp.dhis.db.sql.SqlBuilder; +import org.hisp.dhis.db.sql.SqlBuilderProvider; + /** * Enumeration of database platforms. * + *

To add support for a new analytics database engine, add the following: + * + *

    + *
  • Value to this {@link Database}. + *
  • Implementation class of {@link SqlBuilder}. + *
  • Register {@link SqlBuilder} implementation in {@link SqlBuilderProvider}. + *
  • Method to {@link AnalyticsDatabaseInit} (optional). + *
  • JDBC driver in pom.xml. + *
+ * * @author Lars Helge Overland */ public enum Database { diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/AbstractSqlBuilder.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/AbstractSqlBuilder.java index d40f83c2214a..b62719af559c 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/AbstractSqlBuilder.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/AbstractSqlBuilder.java @@ -58,11 +58,21 @@ public abstract class AbstractSqlBuilder implements SqlBuilder { // Utilities + @Override + public String quote(String alias, String relation) { + return alias + DOT + quote(relation); + } + @Override public String quoteAx(String relation) { return ALIAS_AX + DOT + quote(relation); } + @Override + public String singleQuote(String value) { + return SINGLE_QUOTE + escape(value) + SINGLE_QUOTE; + } + @Override public String singleQuotedCommaDelimited(Collection items) { return isEmpty(items) @@ -103,6 +113,28 @@ public String countRows(Table table) { return String.format("select count(*) as row_count from %s;", quote(table.getName())); } + // Table + + @Override + public String analyzeTable(String name) { + return notSupported(); + } + + @Override + public String vacuumTable(Table table) { + return notSupported(); + } + + @Override + public String setParentTable(Table table, String parentName) { + return notSupported(); + } + + @Override + public String removeParentTable(Table table, String parentName) { + return notSupported(); + } + // Mapping /** diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java index cf13ca1a9949..736e0db02f11 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/DorisSqlBuilder.java @@ -195,16 +195,6 @@ public String quote(String relation) { return QUOTE + escapedRelation + QUOTE; } - @Override - public String quote(String alias, String relation) { - return alias + DOT + quote(relation); - } - - @Override - public String singleQuote(String value) { - return SINGLE_QUOTE + escape(value) + SINGLE_QUOTE; - } - @Override public String escape(String value) { return value @@ -314,16 +304,6 @@ private String getDistKey(Table table) { return null; } - @Override - public String analyzeTable(String name) { - return notSupported(); - } - - @Override - public String vacuumTable(Table table) { - return notSupported(); - } - @Override public String renameTable(Table table, String newName) { return String.format("alter table %s rename %s;", quote(table.getName()), quote(newName)); @@ -344,16 +324,6 @@ public String dropTableIfExistsCascade(String name) { return dropTableIfExists(name); } - @Override - public String setParentTable(Table table, String parentName) { - return notSupported(); - } - - @Override - public String removeParentTable(Table table, String parentName) { - return notSupported(); - } - @Override public String tableExists(String name) { return String.format( diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java index 4dcfe13a4001..0eb39aaaa64f 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/db/sql/PostgreSqlBuilder.java @@ -198,16 +198,6 @@ public String quote(String relation) { return QUOTE + escapedRelation + QUOTE; } - @Override - public String quote(String alias, String relation) { - return alias + DOT + quote(relation); - } - - @Override - public String singleQuote(String value) { - return SINGLE_QUOTE + escape(value) + SINGLE_QUOTE; - } - @Override public String escape(String value) { return value diff --git a/dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java b/dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java index d14567fa8431..a67e6f9151d8 100644 --- a/dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java +++ b/dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java @@ -684,8 +684,8 @@ public enum ConfigurationKey { /** * Confidential means that the system setting will be encrypted and not visible through the API. - * The system setting will be used internally in the backend, but cannot be used by web apps - * and clients. + * The system setting will be used internally in the backend, but cannot be used by web apps and + * clients. */ private final boolean confidential; diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java index 60a4b5bbd74e..3ca3e385d074 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java @@ -115,7 +115,6 @@ import org.hisp.dhis.program.ProgramTrackedEntityAttribute; import org.hisp.dhis.scheduling.JobProgress; import org.hisp.dhis.security.acl.AccessStringHelper; -import org.hisp.dhis.setting.SystemSettingsService; import org.hisp.dhis.test.integration.PostgresIntegrationTestBase; import org.hisp.dhis.trackedentity.TrackedEntity; import org.hisp.dhis.trackedentity.TrackedEntityAttribute; @@ -172,8 +171,6 @@ class EventAnalyticsServiceTest extends PostgresIntegrationTestBase { @Autowired private CategoryService categoryService; - @Autowired private SystemSettingsService settingsService; - private OrganisationUnit ouA; private OrganisationUnit ouB;