From e0a4779ab61f7c5ca2b7ba833668e4c4b2dce062 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 21 Nov 2021 15:49:10 +0200 Subject: [PATCH] Rewrote DataService implementation to always have identifiers. --- .../java/com/djrapitops/plan/DataService.java | 71 +++----- .../java/com/djrapitops/plan/DataSvc.java | 166 ++++++++---------- ...ataModule.java => DataPipelineModule.java} | 12 +- 3 files changed, 111 insertions(+), 138 deletions(-) rename Plan/common/src/main/java/com/djrapitops/plan/modules/{GatheringDataModule.java => DataPipelineModule.java} (70%) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/DataService.java b/Plan/common/src/main/java/com/djrapitops/plan/DataService.java index 722bb20ba..d0f94875f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/DataService.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/DataService.java @@ -17,67 +17,46 @@ package com.djrapitops.plan; import com.djrapitops.plan.storage.database.queries.Query; +import com.djrapitops.plan.storage.database.transactions.Transaction; +import com.djrapitops.plan.utilities.java.TriConsumer; import java.util.Optional; -import java.util.function.Consumer; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; -/** - * Service for sourcing, mapping and consuming data. - *
- * The service is in charge of two data flows: - * - push, given to consumers - * - pull, obtained from sources - *
- * The mappers facilitate a one way type transformation if needed. - *
- * The interface is very abstract about how data is obtained, - * but here are my general ideas of where the abstraction is coming from. - * - push cause one or multiple consumers to modify stored data - * - pull cause one or multiple suppliers to fetch stored data - * - mappers are stateless type transformers in memory - *
- * Example use-case: - * - PlayerJoinEvent is mapped to a generic event - * - that generic event is then consumed and mapped until the data is in a database. - *
- * - Some kind of data is wanted to place on a web page - * - It is requested and the suppliers and mappers give the wanted type of data. - *
- * Further research needed:
- * - Can this limited type system represent types of data that need parameters
- * (such as differentiate between two servers data)
- */
public interface DataService {
- parameterType) {
- return pull(type, () -> pull(parameterType).orElse(null));
+ default parameter) {
- return pull(type, parameter.get());
- }
+ DataService registerSupplier(Class parameterType, Function supplierWithParameter);
+ DataService registerDBSupplier(Class parameterType, Function > supplierWithParameter);
+ function = suppliersWithParameter.get(new ClassPair<>(type, parameter.getClass()));
- return function != null ? Optional.of(function.apply(parameter)) : Optional.empty();
- }
-
- @Override
- public DataService registerSupplier(Class parameterType, Function supplierWithParameter) {
- suppliersWithParameter.put(new ClassPair<>(type, parameterType), supplierWithParameter);
- return this;
- }
-
- @Override
- public DataService registerDBSupplier(Class parameterType, Function > queryVisitor) {
- return registerSupplier(type, parameterType, parameter -> dbSystem.get().getDatabase().query(queryVisitor.apply(parameter)));
+ public Optional pull(Class type);
-
- Optional pull(Class type, P parameter);
-
- B mapTo(Class toType, A from);
-
- default Optional pull(Class type, Class Optional pull(Class type, Supplier DataService registerSupplier(Class type, Supplier supplier);
+ type, Class type, Class Optional pull(Class type, P parameter) {
- if (parameter == null) return Optional.empty();
- Function type, Class type, Class