Search in sources :

Example 91 with DataStoreTransaction

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

the class DataStoreIT method setUp.

@BeforeEach
public void setUp() throws IOException {
    try (DataStoreTransaction tx = dataStore.beginTransaction()) {
        tx.createObject(new Filtered(), null);
        tx.createObject(new Filtered(), null);
        tx.createObject(new Filtered(), null);
        Author georgeMartin = new Author();
        tx.createObject(georgeMartin, null);
        georgeMartin.setName("George R. R. Martin");
        Book book1 = new Book();
        tx.createObject(book1, null);
        book1.setTitle(SONG_OF_ICE_AND_FIRE);
        book1.setAuthors(Arrays.asList(georgeMartin));
        Book book2 = new Book();
        tx.createObject(book2, null);
        book2.setTitle(CLASH_OF_KINGS);
        book2.setAuthors(Arrays.asList(georgeMartin));
        Book book3 = new Book();
        tx.createObject(book3, null);
        book3.setTitle(STORM_OF_SWORDS);
        book3.setAuthors(Arrays.asList(georgeMartin));
        georgeMartin.setBooks(Arrays.asList(book1, book2, book3));
        addChapters(ICE_AND_FIRE_CHAPTER_COUNT, book1, tx);
        addChapters(CLASH_OF_KINGS_CHAPTER_COUNT, book2, tx);
        addChapters(STORM_OF_SWORDS_CHAPTER_COUNT, book3, tx);
        tx.save(book1, null);
        tx.save(book2, null);
        tx.save(book3, null);
        tx.save(georgeMartin, null);
        tx.commit(null);
    }
}
Also used : Book(example.Book) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Filtered(example.Filtered) Author(example.Author) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 92 with DataStoreTransaction

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

the class EmbeddedIT method setup.

@BeforeEach
public void setup() throws IOException {
    dataStore.populateEntityDictionary(EntityDictionary.builder().build());
    DataStoreTransaction tx = dataStore.beginTransaction();
    // id 1
    Embedded embedded = new Embedded();
    embedded.setSegmentIds(ImmutableSet.of(3L, 4L, 5L));
    tx.createObject(embedded, null);
    Left left = new Left();
    Right right = new Right();
    left.setOne2one(right);
    right.setOne2one(left);
    tx.createObject(left, null);
    tx.createObject(right, null);
    tx.commit(null);
    tx.close();
}
Also used : Left(example.Left) Right(example.Right) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Embedded(example.Embedded) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 93 with DataStoreTransaction

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

the class EmbeddedIdIT method setup.

@BeforeEach
public void setup() throws IOException {
    dataStore.populateEntityDictionary(EntityDictionary.builder().build());
    DataStoreTransaction tx = dataStore.beginTransaction();
    Building building1 = new Building();
    building1.setAddress(address1);
    building1.setName("Fort Knox");
    Building building2 = new Building();
    building2.setAddress(address3);
    building2.setName("Assembly Hall");
    building1.setNeighbors(Sets.newHashSet(building2));
    building2.setNeighbors(Sets.newHashSet(building1));
    tx.createObject(building1, null);
    tx.createObject(building2, null);
    tx.commit(null);
    tx.close();
}
Also used : Building(example.embeddedid.Building) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 94 with DataStoreTransaction

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

the class LegacyNPlusOneIT method setUp.

@BeforeEach
public void setUp() throws IOException {
    reset(logger);
    try (DataStoreTransaction tx = dataStore.beginTransaction()) {
        Book book1 = new Book();
        book1.setTitle("Test Book1");
        tx.createObject(book1, null);
        Book book2 = new Book();
        book2.setTitle("Test Book2");
        tx.createObject(book2, null);
        Book book3 = new Book();
        book3.setTitle("Test Book3");
        tx.createObject(book3, null);
        Author author1 = new Author();
        author1.setName("Bob1");
        tx.createObject(author1, null);
        Author author2 = new Author();
        author2.setName("Bob2");
        tx.createObject(author2, null);
        Author author3 = new Author();
        author3.setName("Bob3");
        tx.createObject(author3, null);
        Publisher publisher = new Publisher();
        tx.createObject(publisher, null);
        author1.setBooks(Arrays.asList(book1, book2));
        author2.setBooks(Arrays.asList(book1, book2));
        author3.setBooks(Arrays.asList(book3));
        book1.setAuthors(Arrays.asList(author1, author2));
        book2.setAuthors(Arrays.asList(author1, author2));
        book3.setAuthors(Arrays.asList(author3));
        book1.setPublisher(publisher);
        book2.setPublisher(publisher);
        publisher.setBooks(new HashSet<>(Arrays.asList(book1, book2)));
        tx.commit(null);
    }
}
Also used : Book(example.Book) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Author(example.Author) Publisher(example.Publisher) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 95 with DataStoreTransaction

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

the class HashMapDataStoreTest method testValidCommit.

@Test
public void testValidCommit() throws Exception {
    FirstBean object = new FirstBean();
    object.id = "0";
    object.name = "Test";
    try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
        assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
        t.createObject(object, null);
        assertFalse(t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null).iterator().hasNext());
        t.commit(null);
    }
    try (DataStoreTransaction t = inMemoryDataStore.beginTransaction()) {
        Iterable<Object> beans = t.loadObjects(EntityProjection.builder().type(FirstBean.class).build(), null);
        assertNotNull(beans);
        assertTrue(beans.iterator().hasNext());
        FirstBean bean = (FirstBean) IterableUtils.first(beans);
        assertTrue(!"0".equals(bean.id) && "Test".equals(bean.name));
    }
}
Also used : FirstBean(com.yahoo.elide.example.beans.FirstBean) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) 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