Search in sources :

Example 6 with DocumentTemplate

use of jakarta.nosql.mapping.document.DocumentTemplate in project jnosql-diana by eclipse.

the class DocumentTemplateConverterTest method shouldReturnTemplate.

@Test
public void shouldReturnTemplate() {
    final String prefix = UUID.randomUUID().toString();
    System.setProperty(prefix, prefix);
    System.setProperty(prefix + ".settings.key", "value");
    System.setProperty(prefix + ".settings.key2", "value2");
    System.setProperty(prefix + ".provider", DocumentConfigurationMock.class.getName());
    System.setProperty(prefix + ".database", "database");
    final DocumentTemplate template = config.getValue(prefix, DocumentTemplate.class);
    Assertions.assertNotNull(template);
    System.clearProperty(prefix);
    System.clearProperty(prefix + ".settings.key");
    System.clearProperty(prefix + ".settings.key2");
    System.clearProperty(prefix + ".provider");
    System.clearProperty(prefix + ".database");
}
Also used : DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Test(org.junit.jupiter.api.Test)

Example 7 with DocumentTemplate

use of jakarta.nosql.mapping.document.DocumentTemplate in project jnosql-diana by eclipse.

the class DefaultDocumentRepositoryProducer method get.

@Override
public <T, K, R extends Repository<T, K>> R get(Class<R> repositoryClass, DocumentCollectionManager manager) {
    Objects.requireNonNull(repositoryClass, "repository class is required");
    Objects.requireNonNull(manager, "manager class is required");
    DocumentTemplate template = producer.get(manager);
    return get(repositoryClass, template);
}
Also used : DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate)

Example 8 with DocumentTemplate

use of jakarta.nosql.mapping.document.DocumentTemplate in project jnosql-diana by eclipse.

the class RepositoryDocumentBean method create.

@Override
public Repository create(CreationalContext<Repository> context) {
    ClassMappings classMappings = getInstance(ClassMappings.class);
    DocumentTemplate template = provider.isEmpty() ? getInstance(DocumentTemplate.class) : getInstance(DocumentTemplate.class, DatabaseQualifier.ofDocument(provider));
    Converters converters = getInstance(Converters.class);
    DocumentRepositoryProxy handler = new DocumentRepositoryProxy(template, classMappings, type, converters);
    return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
Also used : Repository(jakarta.nosql.mapping.Repository) Converters(jakarta.nosql.mapping.Converters) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 9 with DocumentTemplate

use of jakarta.nosql.mapping.document.DocumentTemplate in project jnosql-diana by eclipse.

the class DefaultDocumentMapperSelectBuilderTest method shouldExecuteQuery.

@Test
public void shouldExecuteQuery() {
    DocumentTemplate template = Mockito.mock(DocumentTemplate.class);
    ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
    Stream<Person> people = mapperBuilder.selectFrom(Person.class).getResult(template);
    Mockito.verify(template).select(queryCaptor.capture());
    DocumentQuery query = queryCaptor.getValue();
    DocumentQuery queryExpected = select().from("Person").build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 10 with DocumentTemplate

use of jakarta.nosql.mapping.document.DocumentTemplate in project jnosql-diana by eclipse.

the class DefaultDocumentMapperSelectBuilderTest method shouldExecuteSingleQuery.

@Test
public void shouldExecuteSingleQuery() {
    DocumentTemplate template = Mockito.mock(DocumentTemplate.class);
    ArgumentCaptor<DocumentQuery> queryCaptor = ArgumentCaptor.forClass(DocumentQuery.class);
    Optional<Person> person = mapperBuilder.selectFrom(Person.class).getSingleResult(template);
    Mockito.verify(template).singleResult(queryCaptor.capture());
    DocumentQuery query = queryCaptor.getValue();
    DocumentQuery queryExpected = select().from("Person").build();
    assertEquals(queryExpected, query);
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)14 Test (org.junit.jupiter.api.Test)10 Person (jakarta.nosql.tck.entities.Person)6 DocumentQuery (jakarta.nosql.document.DocumentQuery)5 Pagination (jakarta.nosql.mapping.Pagination)3 DocumentQueryPagination (jakarta.nosql.mapping.document.DocumentQueryPagination)3 Converters (jakarta.nosql.mapping.Converters)2 ReactiveDocumentTemplate (org.eclipse.jnosql.mapping.document.reactive.ReactiveDocumentTemplate)2 ReactiveDocumentTemplateProducer (org.eclipse.jnosql.mapping.document.reactive.ReactiveDocumentTemplateProducer)2 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)2 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)1 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)1 Repository (jakarta.nosql.mapping.Repository)1 PersonRepository (jakarta.nosql.tck.entities.PersonRepository)1 ReactiveRepository (org.eclipse.jnosql.mapping.reactive.ReactiveRepository)1 Config (org.eclipse.microprofile.config.Config)1