Search in sources :

Example 1 with BucketManager

use of jakarta.nosql.keyvalue.BucketManager in project jnosql-diana by eclipse.

the class GetQueryParser method query.

Stream<Value> query(String query, BucketManager manager) {
    GetQuery getQuery = provider.apply(query);
    Params params = Params.newParams();
    List<Value> values = getQuery.getKeys().stream().map(k -> Values.getValue(k, params)).collect(toList());
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    return values.stream().map(Value::get).map(manager::get).filter(Optional::isPresent).map(Optional::get);
}
Also used : Value(jakarta.nosql.Value) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) GetQueryProvider(jakarta.nosql.query.GetQuery.GetQueryProvider) Optional(java.util.Optional) BucketManager(jakarta.nosql.keyvalue.BucketManager) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) GetQuery(jakarta.nosql.query.GetQuery) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) Optional(java.util.Optional) GetQuery(jakarta.nosql.query.GetQuery) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 2 with BucketManager

use of jakarta.nosql.keyvalue.BucketManager in project jnosql-diana by eclipse.

the class GetQueryParser method prepare.

public KeyValuePreparedStatement prepare(String query, BucketManager manager) {
    GetQuery getQuery = provider.apply(query);
    Params params = Params.newParams();
    List<Value> values = getQuery.getKeys().stream().map(k -> Values.getValue(k, params)).collect(toList());
    return DefaultKeyValuePreparedStatement.get(values, manager, params, query);
}
Also used : Value(jakarta.nosql.Value) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) GetQueryProvider(jakarta.nosql.query.GetQuery.GetQueryProvider) Optional(java.util.Optional) BucketManager(jakarta.nosql.keyvalue.BucketManager) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) GetQuery(jakarta.nosql.query.GetQuery) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) Params(jakarta.nosql.Params) GetQuery(jakarta.nosql.query.GetQuery) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 3 with BucketManager

use of jakarta.nosql.keyvalue.BucketManager in project jnosql-diana by eclipse.

the class MockProducer method getBucketManagerMock.

@Produces
@Database(value = DatabaseType.KEY_VALUE, provider = "keyvalueMock")
public BucketManager getBucketManagerMock() {
    BucketManager bucketManager = Mockito.mock(BucketManager.class);
    Person person = Person.builder().withName("keyvalueMock").build();
    when(bucketManager.get("key")).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get(10L)).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get("user")).thenReturn(Optional.of(Value.of(new User("keyvalueMock", "keyvalueMock", 10))));
    return bucketManager;
}
Also used : User(jakarta.nosql.tck.entities.User) BucketManager(jakarta.nosql.keyvalue.BucketManager) Person(jakarta.nosql.tck.entities.Person) Produces(javax.enterprise.inject.Produces) Database(jakarta.nosql.mapping.Database)

Example 4 with BucketManager

use of jakarta.nosql.keyvalue.BucketManager in project jnosql-diana by eclipse.

the class MockProducer method getBucketManager.

@Produces
public BucketManager getBucketManager() {
    BucketManager bucketManager = Mockito.mock(BucketManager.class);
    Person person = Person.builder().withName("Default").build();
    when(bucketManager.get("key")).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get(10L)).thenReturn(Optional.ofNullable(Value.of(person)));
    when(bucketManager.get("user")).thenReturn(Optional.of(Value.of(new User("Default", "Default", 10))));
    return bucketManager;
}
Also used : User(jakarta.nosql.tck.entities.User) BucketManager(jakarta.nosql.keyvalue.BucketManager) Person(jakarta.nosql.tck.entities.Person) Produces(javax.enterprise.inject.Produces)

Example 5 with BucketManager

use of jakarta.nosql.keyvalue.BucketManager in project jnosql-diana by eclipse.

the class DefaultKeyValueRepositoryProducerTest method shouldCreateFromManager.

@Test
public void shouldCreateFromManager() {
    BucketManager manager = Mockito.mock(BucketManager.class);
    PersonRepository personRepository = producer.get(PersonRepository.class, manager);
    assertNotNull(personRepository);
}
Also used : PersonRepository(jakarta.nosql.tck.entities.PersonRepository) BucketManager(jakarta.nosql.keyvalue.BucketManager) Test(org.junit.jupiter.api.Test)

Aggregations

BucketManager (jakarta.nosql.keyvalue.BucketManager)25 BucketManagerFactory (jakarta.nosql.keyvalue.BucketManagerFactory)8 AfterAll (org.junit.jupiter.api.AfterAll)8 Test (org.junit.jupiter.api.Test)7 Params (jakarta.nosql.Params)4 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 Value (jakarta.nosql.Value)4 KeyValuePreparedStatement (jakarta.nosql.keyvalue.KeyValuePreparedStatement)4 Person (jakarta.nosql.tck.entities.Person)4 User (jakarta.nosql.tck.entities.User)4 List (java.util.List)4 Collectors.toList (java.util.stream.Collectors.toList)4 Stream (java.util.stream.Stream)4 Produces (javax.enterprise.inject.Produces)4 CouchbaseKeyValueConfiguration (org.eclipse.jnosql.communication.couchbase.keyvalue.CouchbaseKeyValueConfiguration)3 Database (jakarta.nosql.mapping.Database)2 KeyValueTemplateProducer (jakarta.nosql.mapping.keyvalue.KeyValueTemplateProducer)2 DelQuery (jakarta.nosql.query.DelQuery)2 DelQueryProvider (jakarta.nosql.query.DelQuery.DelQueryProvider)2