Search in sources :

Example 11 with PreparedStatement

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

the class AbstractGraphTemplateTest method shouldExecutePrepareStatementSingleton.

@Test
public void shouldExecutePrepareStatementSingleton() {
    getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
    PreparedStatement prepare = getGraphTemplate().prepare("g.V().hasLabel(param)");
    prepare.bind("param", "Person");
    Optional<Person> otavio = prepare.getSingleResult();
    assertTrue(otavio.isPresent());
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 12 with PreparedStatement

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

the class AbstractGraphTemplateTest method shouldExecutePrepareStatement.

@Test
public void shouldExecutePrepareStatement() {
    getGraphTemplate().insert(Person.builder().withAge().withName("Otavio").build());
    PreparedStatement prepare = getGraphTemplate().prepare("g.V().hasLabel(param)");
    prepare.bind("param", "Person");
    List<Person> people = prepare.<Person>getResult().collect(Collectors.toList());
    MatcherAssert.assertThat(people.stream().map(Person::getName).collect(toList()), Matchers.contains("Otavio"));
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Person(org.eclipse.jnosql.mapping.graph.model.Person) Test(org.junit.jupiter.api.Test)

Example 13 with PreparedStatement

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

the class ColumnReactiveRepositoryProxyTest method shouldExecuteJNoSQLPrepare.

@Test
public void shouldExecuteJNoSQLPrepare() {
    PreparedStatement statement = Mockito.mock(PreparedStatement.class);
    when(template.prepare(Mockito.anyString())).thenReturn(statement);
    final Publisher<Person> publisher = personRepository.findByQuery("Ada");
    final CompletionSubscriber<Person, List<Person>> subscriber = ReactiveStreams.<Person>builder().toList().build();
    publisher.subscribe(subscriber);
    final CompletionStage<List<Person>> completion = subscriber.getCompletion();
    AtomicReference<List<Person>> reference = new AtomicReference<>();
    completion.thenAccept(reference::set);
    final List<Person> people = reference.get();
    assertNotNull(people);
    verify(statement).bind("id", "Ada");
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 14 with PreparedStatement

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

the class KeyValueRepositoryProxyTest method shouldFindByQueryWithParameter.

@Test
public void shouldFindByQueryWithParameter() {
    User user = new User("12", "Ada", 10);
    List<String> keys = Arrays.asList("key", "key2");
    PreparedStatement prepare = Mockito.mock(PreparedStatement.class);
    when(repository.prepare("get @id", User.class)).thenReturn(prepare);
    userRepository.findByQuery("id");
    verify(repository).prepare("get @id", User.class);
}
Also used : User(jakarta.nosql.tck.entities.User) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 15 with PreparedStatement

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

the class DocumentRepositoryProxyTest method shouldExecuteJNoSQLPrepare.

@Test
public void shouldExecuteJNoSQLPrepare() {
    PreparedStatement statement = Mockito.mock(PreparedStatement.class);
    when(template.prepare(Mockito.anyString())).thenReturn(statement);
    personRepository.findByQuery("Ada");
    verify(statement).bind("id", "Ada");
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Aggregations

PreparedStatement (jakarta.nosql.mapping.PreparedStatement)25 Test (org.junit.jupiter.api.Test)25 List (java.util.List)13 NonUniqueResultException (jakarta.nosql.NonUniqueResultException)11 Param (jakarta.nosql.mapping.Param)11 Query (jakarta.nosql.mapping.Query)11 Repository (jakarta.nosql.mapping.Repository)11 Method (java.lang.reflect.Method)11 Collection (java.util.Collection)11 Objects (java.util.Objects)11 Optional (java.util.Optional)11 Queue (java.util.Queue)11 Set (java.util.Set)11 Function (java.util.function.Function)11 Stream (java.util.stream.Stream)11 Assertions (org.junit.jupiter.api.Assertions)11 Mockito (org.mockito.Mockito)11 Person (org.eclipse.jnosql.mapping.graph.model.Person)3 Person (jakarta.nosql.tck.entities.Person)2 Arrays.asList (java.util.Arrays.asList)2