Search in sources :

Example 41 with DataStoreTransaction

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

the class MultiplexTransaction method getToManyRelation.

@Override
public <T, R> DataStoreIterable<R> getToManyRelation(DataStoreTransaction tx, T entity, Relationship relation, RequestScope scope) {
    DataStoreTransaction relationTx = getRelationTransaction(entity, relation.getName());
    Type<Object> entityType = EntityDictionary.getType(entity);
    DataStoreTransaction entityTransaction = getTransaction(entityType);
    return entityTransaction.getToManyRelation(relationTx, entity, relation, scope);
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction)

Example 42 with DataStoreTransaction

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

the class MultiplexTransaction method getToOneRelation.

@Override
public <T, R> R getToOneRelation(DataStoreTransaction tx, T entity, Relationship relation, RequestScope scope) {
    DataStoreTransaction relationTx = getRelationTransaction(entity, relation.getName());
    Type<Object> entityType = EntityDictionary.getType(entity);
    DataStoreTransaction entityTransaction = getTransaction(entityType);
    return entityTransaction.getToOneRelation(relationTx, entity, relation, scope);
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction)

Example 43 with DataStoreTransaction

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

the class MultiplexWriteTransaction method reverseTransactions.

/**
 * Attempt to reverse changes of last commit since not all transactions successfully committed.
 * @param restoreList List of database managers to reverse the last commit
 * @param cause cause to add any suppressed exceptions
 */
private void reverseTransactions(ArrayList<DataStore> restoreList, Throwable cause, RequestScope requestScope) {
    for (DataStore dataStore : restoreList) {
        try (DataStoreTransaction transaction = dataStore.beginTransaction()) {
            List<Object> list = dirtyObjects.get(dataStore);
            for (Object dirtyObject : list == null ? Collections.emptyList() : list) {
                Object cloned = clonedObjects.get(dirtyObject);
                if (cloned == NEWLY_CREATED_OBJECT) {
                    transaction.delete(dirtyObject, requestScope);
                } else {
                    transaction.save(cloned, requestScope);
                }
            }
            transaction.commit(requestScope);
        } catch (RuntimeException | IOException e) {
            cause.addSuppressed(e);
        }
    }
}
Also used : DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) IOException(java.io.IOException)

Example 44 with DataStoreTransaction

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

the class DataStoreLoadTest method testTabCharacter.

@Test
public void testTabCharacter() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    // Case sensitive query against case insensitive index must lowercase
    FilterExpression filter = filterParser.parseFilterExpression("name=ini='*est\tTa*'", ClassType.of(Item.class), false);
    Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).build(), mockScope);
    assertListContains(loaded, Lists.newArrayList(7L));
    verify(wrappedTransaction, never()).loadObjects(any(), any());
}
Also used : Item(com.yahoo.elide.datastores.search.models.Item) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 45 with DataStoreTransaction

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

the class DataStoreLoadTest method testPrefixPredicateWithInMemoryFiltering.

@Test
public void testPrefixPredicateWithInMemoryFiltering() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    testTransaction = new InMemoryStoreTransaction(testTransaction);
    // Case sensitive query against case insensitive index must lowercase
    FilterExpression filter = filterParser.parseFilterExpression("name==dru*", ClassType.of(Item.class), false);
    Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).build(), mockScope);
    assertListContains(loaded, Lists.newArrayList());
    verify(wrappedTransaction, never()).loadObjects(any(), any());
}
Also used : Item(com.yahoo.elide.datastores.search.models.Item) InMemoryStoreTransaction(com.yahoo.elide.core.datastore.inmemory.InMemoryStoreTransaction) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

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