mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-10 22:01:00 +01:00
Add possibility to query directly via service
This commit is contained in:
parent
24b6669c7d
commit
35ca5a8560
@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.storage.database.queries.Query;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@ -73,4 +75,6 @@ public interface DataService {
|
||||
|
||||
<P, S> DataService registerSupplier(Class<S> type, Class<P> parameterType, Function<P, S> supplierWithParameter);
|
||||
|
||||
<P, S> DataService registerDBSupplier(Class<S> type, Class<P> parameterType, Function<P, Query<S>> supplierWithParameter);
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,10 @@
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.Query;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.*;
|
||||
@ -33,8 +37,13 @@ public class DataSvc implements DataService {
|
||||
private final Map<ClassPair, Function> suppliersWithParameter;
|
||||
private final MultiHashMap<Class, Consumer> consumers;
|
||||
|
||||
private final Lazy<DBSystem> dbSystem;
|
||||
|
||||
@Inject
|
||||
public DataSvc() {
|
||||
public DataSvc(
|
||||
Lazy<DBSystem> dbSystem
|
||||
) {
|
||||
this.dbSystem = dbSystem;
|
||||
mappers = new MultiHashMap<>();
|
||||
mappersReverse = new MultiHashMap<>();
|
||||
suppliers = new ConcurrentHashMap<>();
|
||||
@ -122,6 +131,11 @@ public class DataSvc implements DataService {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <P, S> DataService registerDBSupplier(Class<S> type, Class<P> parameterType, Function<P, Query<S>> queryVisitor) {
|
||||
return registerSupplier(type, parameterType, parameter -> dbSystem.get().getDatabase().query(queryVisitor.apply(parameter)));
|
||||
}
|
||||
|
||||
private static class ClassPair<A, B> {
|
||||
final Class<A> a;
|
||||
final Class<B> b;
|
||||
|
Loading…
Reference in New Issue
Block a user