org.eclipse.jnosql.mapping.arangodb.document.DefaultArangoDBTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arangodb-extension Show documentation
Show all versions of arangodb-extension Show documentation
Eclipse JNoSQL mapping layer to ArangoDB
/*
* Copyright (c) 2017 Otávio Santana and others
* 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.arangodb.document;
import jakarta.nosql.document.DocumentCollectionManager;
import jakarta.nosql.mapping.Converters;
import jakarta.nosql.mapping.document.DocumentEntityConverter;
import jakarta.nosql.mapping.document.DocumentEventPersistManager;
import jakarta.nosql.mapping.document.DocumentWorkflow;
import org.eclipse.jnosql.mapping.reflection.ClassMappings;
import org.eclipse.jnosql.mapping.document.AbstractDocumentTemplate;
import org.eclipse.jnosql.communication.arangodb.document.ArangoDBDocumentCollectionManager;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Typed;
import javax.inject.Inject;
import java.util.Map;
import java.util.stream.Stream;
import static java.util.Objects.requireNonNull;
/**
* The Default implementation of {@link ArangoDBTemplate}
*/
@Typed(ArangoDBTemplate.class)
class DefaultArangoDBTemplate extends AbstractDocumentTemplate implements ArangoDBTemplate {
private Instance manager;
private DocumentEntityConverter converter;
private DocumentWorkflow flow;
private DocumentEventPersistManager persistManager;
private ClassMappings mappings;
private Converters converters;
@Inject
DefaultArangoDBTemplate(Instance manager,
DocumentEntityConverter converter, DocumentWorkflow flow,
DocumentEventPersistManager persistManager,
ClassMappings mappings,
Converters converters) {
this.manager = manager;
this.converter = converter;
this.flow = flow;
this.persistManager = persistManager;
this.mappings = mappings;
this.converters = converters;
}
DefaultArangoDBTemplate() {
}
@Override
protected DocumentEntityConverter getConverter() {
return converter;
}
@Override
protected DocumentCollectionManager getManager() {
return manager.get();
}
@Override
protected DocumentWorkflow getWorkflow() {
return flow;
}
@Override
protected DocumentEventPersistManager getPersistManager() {
return persistManager;
}
@Override
protected ClassMappings getClassMappings() {
return mappings;
}
@Override
protected Converters getConverters() {
return converters;
}
@Override
public Stream aql(String query, Map 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 Stream aql(String query, Map values, Class typeClass) {
return manager.get().aql(query, values, typeClass);
}
@Override
public Stream aql(String query, Class typeClass) {
return manager.get().aql(query, typeClass);
}
}