Search in sources :

Example 56 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testInfixOperator.

@Test
public void testInfixOperator() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("name==*rum*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    assertFalse(loaded.needsInMemoryFilter());
    assertFalse(loaded.needsInMemoryPagination());
    assertFalse(loaded.needsInMemorySort());
    verify(wrappedTransaction, times(0)).loadObjects(any(), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 57 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testPrefixOperator.

@Test
public void testPrefixOperator() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("name==drum*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    DataStoreIterable<Object> loaded = testTransaction.loadObjects(projection, mockScope);
    assertTrue(loaded.needsInMemoryFilter());
    assertTrue(loaded.needsInMemoryPagination());
    assertTrue(loaded.needsInMemorySort());
    verify(wrappedTransaction, times(0)).loadObjects(any(), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 58 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testNgramTooSmall.

@Test
public void testNgramTooSmall() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==*ru*", ClassType.of(Item.class), false);
    EntityProjection projection = EntityProjection.builder().type(Item.class).filterExpression(filter).build();
    assertThrows(InvalidValueException.class, () -> testTransaction.loadObjects(projection, mockScope));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 59 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class MultiplexWriteTransaction method createObject.

@SuppressWarnings("resource")
@Override
public <T> void createObject(T entity, RequestScope scope) {
    DataStoreTransaction transaction = getTransaction(EntityDictionary.getType(entity));
    transaction.createObject(entity, scope);
    // mark this object as newly created to be deleted on reverse transaction
    clonedObjects.put(entity, NEWLY_CREATED_OBJECT);
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction)

Example 60 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class MultiplexWriteTransaction method getToManyRelation.

@Override
public <T, R> DataStoreIterable<R> getToManyRelation(DataStoreTransaction relationTx, T entity, Relationship relationship, RequestScope scope) {
    DataStoreTransaction transaction = getTransaction(EntityDictionary.getType(entity));
    DataStoreIterable<R> relation = super.getToManyRelation(relationTx, entity, relationship, scope);
    return hold(transaction, relation);
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction)

Aggregations

DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)139 Test (org.junit.jupiter.api.Test)101 RequestScope (com.yahoo.elide.core.RequestScope)40 DataStore (com.yahoo.elide.core.datastore.DataStore)30 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)28 Elide (com.yahoo.elide.Elide)27 ElideResponse (com.yahoo.elide.ElideResponse)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 PersistentResource (com.yahoo.elide.core.PersistentResource)17 Item (com.yahoo.elide.datastores.search.models.Item)17 Book (example.Book)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Author (example.Author)8 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)7 FirstBean (com.yahoo.elide.example.beans.FirstBean)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)6