/
ColumnTemplateProducer.java
112 lines (88 loc) · 3.3 KB
/
ColumnTemplateProducer.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
/*
* 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.mapping.column;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Vetoed;
import jakarta.inject.Inject;
import org.eclipse.jnosql.communication.semistructured.DatabaseManager;
import org.eclipse.jnosql.mapping.core.Converters;
import org.eclipse.jnosql.mapping.metadata.EntitiesMetadata;
import org.eclipse.jnosql.mapping.semistructured.AbstractSemistructuredTemplate;
import org.eclipse.jnosql.mapping.semistructured.EntityConverter;
import org.eclipse.jnosql.mapping.semistructured.EventPersistManager;
import java.util.Objects;
import java.util.function.Function;
/**
* The producer of {@link ColumnTemplate}
*/
@ApplicationScoped
public class ColumnTemplateProducer implements Function<DatabaseManager, ColumnTemplate> {
@Inject
private EntityConverter converter;
@Inject
private EventPersistManager eventManager;
@Inject
private EntitiesMetadata entities;
@Inject
private Converters converters;
@Override
public ColumnTemplate apply(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
return new ProducerColumnTemplate(converter, manager,
eventManager, entities, converters);
}
@Vetoed
static class ProducerColumnTemplate extends AbstractSemistructuredTemplate implements ColumnTemplate {
private final EntityConverter converter;
private final DatabaseManager manager;
private final EventPersistManager eventManager;
private final EntitiesMetadata entities;
private final Converters converters;
ProducerColumnTemplate(EntityConverter converter,
DatabaseManager manager,
EventPersistManager eventManager,
EntitiesMetadata entities,
Converters converters) {
this.converter = converter;
this.manager = manager;
this.eventManager = eventManager;
this.entities = entities;
this.converters = converters;
}
ProducerColumnTemplate() {
this(null, null, null, null, null);
}
@Override
protected EntityConverter converter() {
return converter;
}
@Override
protected DatabaseManager manager() {
return manager;
}
@Override
protected EventPersistManager eventManager() {
return eventManager;
}
@Override
protected EntitiesMetadata entities() {
return entities;
}
@Override
protected Converters converters() {
return converters;
}
}
}