Skip to content

Commit

Permalink
refactor: Move methods to AbstractSqlBuilder [DHIS2-16705] (#19146)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge authored Nov 13, 2024
1 parent 9121c92 commit 72f8415
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum ValueTypeMapping {
@Getter private final UnaryOperator<String> argumentTransformer;
@Getter private final String postgresCast;

ValueTypeMapping(Function<String, Object> converter, Class... classes) {
ValueTypeMapping(Function<String, Object> converter, Class<?>... classes) {
this.converter = converter;
this.valueTypes = fromClasses(classes);
this.selectTransformer = UnaryOperator.identity();
Expand All @@ -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);
Expand All @@ -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<String, Object> converter,
UnaryOperator<String> selectTransformer,
Class... classes) {
Class<?>... classes) {
this.converter = converter;
this.valueTypes = fromClasses(classes);
this.selectTransformer = s -> Objects.isNull(s) ? null : selectTransformer.apply(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>To add support for a new analytics database engine, add the following:
*
* <ul>
* <li>Value to this {@link Database}.
* <li>Implementation class of {@link SqlBuilder}.
* <li>Register {@link SqlBuilder} implementation in {@link SqlBuilderProvider}.
* <li>Method to {@link AnalyticsDatabaseInit} (optional).
* <li>JDBC driver in <code>pom.xml</code>.
* </ul>
*
* @author Lars Helge Overland
*/
public enum Database {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> items) {
return isEmpty(items)
Expand Down Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -172,8 +171,6 @@ class EventAnalyticsServiceTest extends PostgresIntegrationTestBase {

@Autowired private CategoryService categoryService;

@Autowired private SystemSettingsService settingsService;

private OrganisationUnit ouA;

private OrganisationUnit ouB;
Expand Down

0 comments on commit 72f8415

Please sign in to comment.