-
Notifications
You must be signed in to change notification settings - Fork 36
/
DefaultArangoDBTemplate.java
116 lines (94 loc) · 3.64 KB
/
DefaultArangoDBTemplate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.databases.arangodb.mapping;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Typed;
import jakarta.inject.Inject;
import org.eclipse.jnosql.communication.document.DocumentManager;
import org.eclipse.jnosql.databases.arangodb.communication.ArangoDBDocumentManager;
import org.eclipse.jnosql.mapping.Converters;
import org.eclipse.jnosql.mapping.document.AbstractDocumentTemplate;
import org.eclipse.jnosql.mapping.document.DocumentEntityConverter;
import org.eclipse.jnosql.mapping.document.DocumentEventPersistManager;
import org.eclipse.jnosql.mapping.document.DocumentWorkflow;
import org.eclipse.jnosql.mapping.reflection.EntitiesMetadata;
import java.util.Map;
import java.util.stream.Stream;
import static java.util.Objects.requireNonNull;
/**
* The Default implementation of {@link ArangoDBTemplate}
*/
@Typed(ArangoDBTemplate.class)
@ApplicationScoped
class DefaultArangoDBTemplate extends AbstractDocumentTemplate implements ArangoDBTemplate {
private final Instance<ArangoDBDocumentManager> manager;
private final DocumentEntityConverter converter;
private final DocumentWorkflow flow;
private final DocumentEventPersistManager persistManager;
private final EntitiesMetadata entities;
private final Converters converters;
@Inject
DefaultArangoDBTemplate(Instance<ArangoDBDocumentManager> manager,
DocumentEntityConverter converter, DocumentWorkflow flow,
DocumentEventPersistManager persistManager,
EntitiesMetadata entities,
Converters converters) {
this.manager = manager;
this.converter = converter;
this.flow = flow;
this.persistManager = persistManager;
this.entities = entities;
this.converters = converters;
}
@Override
protected DocumentEntityConverter getConverter() {
return converter;
}
@Override
protected DocumentManager getManager() {
return manager.get();
}
@Override
protected DocumentWorkflow getWorkflow() {
return flow;
}
@Override
protected DocumentEventPersistManager getEventManager() {
return persistManager;
}
@Override
protected EntitiesMetadata getEntities() {
return entities;
}
@Override
protected Converters getConverters() {
return converters;
}
@Override
public <T> Stream<T> aql(String query, Map<String, Object> values) {
requireNonNull(query, "query is required");
requireNonNull(values, "values is required");
return manager.get().aql(query, values).map(converter::toEntity).map(d -> (T) d);
}
@Override
public <T> Stream<T> aql(String query, Map<String, Object> values, Class<T> typeClass) {
return manager.get().aql(query, values, typeClass);
}
@Override
public <T> Stream<T> aql(String query, Class<T> typeClass) {
return manager.get().aql(query, typeClass);
}
}