Search in sources :

Example 21 with PreparedStatement

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

the class DefaultKeyValueTemplateTest method shouldExecutePrepare.

@Test
public void shouldExecutePrepare() {
    KeyValuePreparedStatement prepare = Mockito.mock(KeyValuePreparedStatement.class);
    when(prepare.getResult()).thenReturn(Stream.of(Value.of("12")));
    when(prepare.getSingleResult()).thenReturn(Optional.of(Value.of("12")));
    when(manager.prepare("get @id")).thenReturn(prepare);
    PreparedStatement statement = subject.prepare("get @id", Integer.class);
    statement.bind("id", 12);
    List<Integer> resultList = statement.<Integer>getResult().collect(toList());
    MatcherAssert.assertThat(resultList, Matchers.contains(12));
    Optional<Object> singleResult = statement.getSingleResult();
    assertTrue(singleResult.isPresent());
    assertEquals(12, singleResult.get());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 22 with PreparedStatement

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

the class ColumnRepositoryProxyTest 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)

Example 23 with PreparedStatement

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

the class GraphRepositoryProxyTest method shouldExecuteQuery2.

@Test
public void shouldExecuteQuery2() {
    PreparedStatement preparedStatement = Mockito.mock(PreparedStatement.class);
    when(template.prepare(Mockito.anyString())).thenReturn(preparedStatement);
    personRepository.findByQuery("Ada");
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(template).prepare(captor.capture());
    assertEquals("g.V().hasLabel('Person').has('name', name).toList()", captor.getValue());
    verify(preparedStatement).bind("name", "Ada");
}
Also used : PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 24 with PreparedStatement

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

the class DefaultColumnTemplateTest method shouldPreparedStatement.

@Test
public void shouldPreparedStatement() {
    PreparedStatement preparedStatement = subject.prepare("select * from Person where name = @name");
    preparedStatement.bind("name", "Ada");
    preparedStatement.getResult();
    ArgumentCaptor<ColumnQuery> queryCaptor = ArgumentCaptor.forClass(ColumnQuery.class);
    verify(managerMock).select(queryCaptor.capture());
    ColumnQuery query = queryCaptor.getValue();
    assertEquals("Person", query.getColumnFamily());
}
Also used : ColumnQuery(jakarta.nosql.column.ColumnQuery) PreparedStatement(jakarta.nosql.mapping.PreparedStatement) Test(org.junit.jupiter.api.Test)

Example 25 with PreparedStatement

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

the class DocumentReactiveRepositoryProxyTest 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)

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